为什么行尾的符号 char(10) 会丢失?

Why does symbol char(10) at the end of line lose?

在我的例子中,当我在 Delphi 中获取字段时,我在行尾丢失了一个符号 $A。我认为,问题出在 FireDac 组件中。我使用 Delphi 10.1 Berlin 和 Sqlite(我不知道版本)。当我启动下面的程序时,消息中有结果 3!=4。 这是代码:

FD := TFDQuery.Create(nil);
FD.Connection := FDConnection1;
FD.ExecSQL('create table t2 (f2 text)');
FD.ExecSQL('insert into t2 values(''123''||char(10))');
FD.Open('select f2, length(f2) as l from t2');
ShowMessage(IntToStr(Length(FD.FieldByName('f2').AsString))+'!='+FD.FieldByName('l').AsString);

最后一个符号 $A 丢失。 可能有人向我解释这种奇怪的行为。

您需要关闭 TFDQuery.FormatOptions.StrsTrim 属性:

Controls the removing of trailing spaces from string values and zero bytes from binary values
...
For SQLite, this property is applied to all string columns