SQLite FireDAC尾随空格 [英] SQLite FireDAC trailing spaces

查看:73
本文介绍了SQLite FireDAC尾随空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有FireDAC的Delphi XE7来访问SQLite。

I'm using Delphi XE7 with FireDAC to access SQLite.

当我将数据放入TEXT字段时,所有尾随空格或#0字符都会被截断。

When I put data into a TEXT field, any trailing spaces or #0 characters get truncated.

是否可以在SQLite或FireDAC中进行某些更改以保留尾随空白?

Is there something I can change in either SQLite or FireDAC to have it preserve the trailing white space?

// The trailing spaces after Command don't come back from SQLite.
fFireDACQuery.ParamByName(kSQLFieldScriptCommands).AsString := 'Command          ';  


推荐答案

禁用 StrsTrim 属性。此属性描述为:

Disable the StrsTrim property. This property is described as:


TFDFormatOptions.StrsTrim

控制从字符串值中删除尾随空格,从二进制值中删除零个
字节。

Controls the removing of trailing spaces from string values and zero bytes from binary values.

您想存储二进制数据而不是文本。如果正确,请更好地定义您的字段数据类型,例如作为 BINARY [255] 用于固定长度的二进制文件255个字节的字符串(255是 ShortString )。

And it seems that you want to store binary data rather than text. If that is correct, better define your field data type e.g. as BINARY[255] for fixed length binary string of 255 bytes (255 is the maximum length of ShortString that you use).

您可以通过以下方式访问该字段的参数值:

Parameter value for such field you would then access this way:

var
  Data: RawByteString;
begin
  ReadByteDataSomehow(Data);

  FDQuery.FormatOptions.StrsTrim := False;
  FDQuery.SQL.Text := 'INSERT INTO MyTable (MyBinaryField) VALUES (:MyBinaryData)';
  FDQuery.ParamByName('MyBinaryData').AsByteStr := Data;
  FDQuery.ExecSQL;
end;

这篇关于SQLite FireDAC尾随空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆