英文:
Unable to Save or Load Foreign Characters with FireDAC TFDQuery
问题
I have an SQLite database that is configured as:
SQLiteFDConnection->Params->Values["StringFormat"] = _D("Unicode");
SQLiteFDConnection->Params->Values["OpenMode"] = _D("CreateUTF8");
It has two tables accessed through a TFDQuery
:
A) Table1
(TFDQuery
) has persistent fields and uses a TDataSource
to show items in a TDBGrid
.
B) Table2
(TFDQuery
) also has persistent fields.
Table1
works, it shows foreign characters correctly, and the persistent fields are set up to use TWideStringField
.
Table2
's field is also a TWideStringField
and directly uses Table2
to ExecSQL()
INSERT INTO
and UPDATE
statements. For reading back, it uses TFDQuery::Open()
then FieldByName()
. However, the foreign characters are just question marks.
My question is, since I set up the StringFormat
to be Unicode
, why is Table2
not properly using Unicode?
Updating uses:
SQLiteDataModule->Table2->ExecSQL("UPDATE Table2 SET Name=:N where UniqueId=:U",
OPENARRAY(Variant, (UnicodeStringVarName, UniqueId)));
Reading it back uses Select * from Table2
in SQLiteDataModule->Table2->Open()
:
String Name = SQLiteDataModule->Table2->FieldByName("Name")->AsString;
One problem is I can't output debug information to the Event window and show the correct characters. I wanted to check it just before the Update
query, but it always shows ?? ??
(there are 4 chars). The Name
is used in a TTreeNode
and I can see foreign characters if I use a normal string, so somewhere between storing and loading it back results with ?? ??
.
String is a UnicodeString
.
Any ideas?
英文:
I have an SQLite database that is configured as:
SQLiteFDConnection->Params->Values["StringFormat"]=_D("Unicode");
SQLiteFDConnection->Params->Values["OpenMode"]=_D("CreateUTF8");
It has two tables accessed through a TFDQuery
:
A) Table1
(TFDQuery
) has persistent fields and uses a TDataSource
to show items in a TDBGrid
.
B) Table2
(TFDQuery
) also has persistent fields.
Table1
works, it shows foreign characters correctly, and the persistent fields are setup to use TWideStringField
.
Table2
's field is also a TWideStringField
and directly uses the Table2
to ExecSQL()
INSERT INTO
and UPDATE
statements. For reading back, it uses TFDQuery::Open()
then FieldByName()
. However, the foreign characters are just question marks.
My question is, since I setup the StringFormat
to be Unicode
, why is Table2
not properly using Unicode?
Updating uses:
SQLiteDataModule->Table2->ExecSQL("UPDATE Table2 SET Name=:N where UniqueId=:U",
OPENARRAY(Variant, (UnicodeStringVarName, UniqueId)));
Reading it back uses Select * from Table2
in SQLiteDataModule->Table2->Open()
:
String Name=SQLiteDataModule->Table2->FieldByName("Name")->AsString;
One problem is I can't output debug information to the Event window and show the correct characters. I wanted to check it just before the Update
query, but it always shows ?? ??
(there are 4 chars). The Name
is used in a TTreeNode
and I can see foreign characters if I use a normal string, so somewhere between storing and loading it back results with ?? ??
.
String is a UnicodeString
.
Any ideas?
答案1
得分: 1
需要手动提供字段类型:
SQLiteDataModule->Table2->ExecSQL("UPDATE Table2 SET Name=:N where UniqueId=:U",
OPENARRAY(Variant, (UnicodeStringVarName, UniqueId)),
OPENARRAY(TFieldType, (ftWideString)); // <<<< Field Types
请注意,这是代码示例中的一部分,只提供了翻译,不包括其他内容。
英文:
The answer is you need to provide the field types manually:
SQLiteDataModule->Table2->ExecSQL("UPDATE Table2 SET Name=:N where UniqueId=:U",
OPENARRAY(Variant, (UnicodeStringVarName, UniqueId)),
OPENARRAY(TFieldType, (ftWideString)); // <<<< Field Types
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论