Reputation: 233
I am facing a strange behaviour with FireDAC and Chinese character strings (guess this occurs also with any other unicode string).
I have a query like this:
Q.SQL.Add('select count(*) as CNT from TABLE where F = :P');
In the table the field F is a varchar(255).
V: Variant;
V := '你好'; // the string means 'Hello'
Q.ParamByName('P').Value := V; // Value is a Variant property
Initially I though the problem was varchar vs nvarchar, but the issue occurs before during internal FireDac Param assignment, much earlier than action against RDBMS.
The strange thing is that once FireDac Param is assigned it becomes '??', and is tranformed into varString.
Instead if I write:
Q.ParamByName('P').AsWideString := V; // AsWideString is a UnicodeString property
it works correctly.
To me this seems a unnatural behaviour, because as the variant variable V knows that the content is varUString, it is very unexpected that during the assignment to the FDParam the string is converted (wrong) to varString.
Did anybody notice this behaviour before?
Thank you
Upvotes: 0
Views: 224
Reputation: 2293
TFDParam
includes both a DataType
and FDDataType
property.
When you assign a variant it is going to make the assignment in accordance with the type of the parameter - after all you may want to insert an integer into the database and pass it string representation of the integer.
I have found in the past setting bout DataType and FDDataType is sometimes needed according to the values and the underlying schema.
Upvotes: 1