Search code examples
delphidelphi-2010firebirddbexpress

Why is my query returning the wrong string type?


According to the official Firebird documentation, columns containing Unicode strings (what SQL Server calls NVARCHAR) should be declared as VARCHAR(x) CHARACTER SET UNICODE_FSS. So I did that, but when I query the table with DBExpress, the result I get back is a TStringField, which is AnsiString only, not the TWideStringField I was expecting.

How do I get DBX to give me a Unicode string result from a Unicode string column?


Solution

  • With Firebird, your only option is to set the whole database connection to a Unicode char set, for example to utf8.

    That way, all the VarChar columns will result in fields of type TWideStringField. The fields will be always TWideStringFields despite the particular char set declared when creating the column.

    Char set at connection level

    Setting this, will result in this:

    TWideStringField

    I collect this images now from a example project I created while teaching Delphi a few months ago. You have to set this property before creating any persistent fields if that's your case.

    It looks like the driver does not support the UNICODE_FSS charset, as my first action was to create a new project, set the property and then create some fields. IMHO it's better to declare the whole database as utf8 or other charset supported by the driver in the create database sentence, and then match the database charset in Delphi to avoid string conversions.