Describes how AnyDAC works with Unicode data and metadata. AnyDAC fully support Unicode data and metadata. Although an application may need to take the additional steps to use Unicode properly.
Most enterprise-class database applications must be able to work with character data encoded in different character sets or provided as Unicode. AnyDAC provides seamless support for:
Note, that the complete Unicode support may be achieved only with the Unicode Delphi version usage - Delphi 2009 and higher. And application is free to use the Delphi native ANSI or Unicode strings. AnyDAC will perform transparent character set conversion between Delphi application and DBMS character set.
In AnyDAC, UTF-16 encoded Unicode characters may be used for the following elements:
AnyDAC's handling of Unicode depends on:
Note: It is recommended to set the DBMS client character set to Unicode, for Delphi 2009 and higher, to avoid conversion loss.
In general, to configure connection definitions for Unicode, it is required to set the DBMS client character set to Unicode. How this is done depends on the version of Delphi and the used DBMS driver:
|
Driver |
Parameter |
|
Advantage Database Server |
Not supported. |
|
IBM DB2 Server |
Automatically set to UTF16 in Delphi 2009 and higher. Not supported in Delphi 2007 or less. |
|
Interbase or Firebird Server |
CharacterSet=utf8 |
|
Microsoft SQL Server |
Automatically set to UTF16 in Delphi 2009 and higher. Not supported in Delphi 2007 or less. |
|
MS Access Database |
Automatically set to UTF16 in Delphi 2009 and higher. Not supported in Delphi 2007 or less. |
|
MySQL Server |
CharacterSet=utf8 |
|
Oracle Server |
|
|
Postgre SQL |
CharacterSet=utf8 |
|
SQLite database |
Automatically set to UTF16 in Delphi 2009 and higher. Not supported in Delphi 2007 or less. |
|
Sybase SQL Anywhere |
Automatically set to UTF16 in Delphi 2009 and higher. Not supported in Delphi 2007 or less. |
|
dbExpress bridge driver |
Depends on dbExpress driver. |
|
ODBC bridge driver |
Automatically set to UTF16 in Delphi 2009 and higher. Not supported in Delphi 2007 or less. |
Starting with Delphi 2009, TADQuery.SQL, TADCommand.CommandText, IADPhysCommand.CommandText, and other property values are Unicode encoded. The SQL command text preprocessor supports only UCS2 encoding, which means that surrogate pairs are not supported.
Before sending SQL command text to the DBMS, AnyDAC converts it to:
To specify Unicode encoded SQL command text, just do the following:
ADQuery1.SQL.Text := 'select ''Hello world !'' where Lang = ''RU'' and Val = ''Привет мир !''';
Starting with Delphi 2009, TADScript.SQLScripts collections can contain Unicode encoded SQL script texts. On prior Delphi versions TADScript can load Unicode encoded SQL script files, but they will be converted into ACP encoding before processing. Other than that, SQL script text processing is similar to SQL command text processing.
To control SQL script file and log file encoding, use TADScript.ScriptOptions.FileEncoding property:
ADScript1.ScriptOptions.FileEncoding := enUTF16; ADScript1.SQLScriptFileName := 'u:\builddb.sql'; ADScript1.ExecuteAll;
Note: At the moment, AnyDAC does not support Unicode encoded column values in metadata result sets, returned by TADMetaInfoCommand, TADMetaInfoQuery and IADPhysMetaInfoCommand.
Unicode encoded metadata text is supported starting from Delphi 2009. It includes:
|
Driver |
Description |
|
Advantage Database Server |
|
|
IBM DB2 Server |
|
|
Interbase or Firebird Server |
If CharacterSet is UTF8 or UNICODE_FSS, then:
|
|
Microsoft SQL Server |
|
|
MS Access Database |
|
|
MySQL Server |
If CharacterSet is UTF8, then:
|
|
Oracle Server |
|
|
SQLite Database |
If StringFormat=Choose, then:
|
|
Postgre SQL |
If CharacterSet is UTF8, then:
|
|
Sybase SQL Anywhere |
|
|
dbExpress bridge driver |
Depends on dbExpress driver and DBMS. The general rule: DBX1-3:
|
|
ODBC bridge driver |
Depends on ODBC driver and DBMS. The general rule:
|
To read/write Unicode string values programmatically use:
To read/write the widestring field on Delphi 2009:
ADQuery1.Edit; ADQuery1.Fields[0].AsWideString := ADQuery1.Fields[0].AsWideString + 'русский + english'; ADQuery1.Post;
To read/write widememo field on Delphi 2009:
ADQuery1.Edit;
ADQuery1.FieldsByName('memo').Assign(Memo1.Lines);
ADQuery1.Post;
The Unicode encoded parameter value is converted to the character set supported by the DBMS Unicode and sent to the DBMS. This is not dependent on specified or default client character sets or Delphi versions.
Firebird and Interbase cannot send Unicode character data to a server if the CharacterSet parameter is not UTF8.
To read/write parameter value in Delphi 2009 do:
ADQuery1.Params[0].AsWideString := 'русский + english';
// the same as following
ADQuery1.Params[0].Value := 'русский + english';
ADQuery1.Params[0].DataType := ftWideString;
Starting from Delphi 2009, TADDataMove can read/write Unicode encoded text data files without conversion loss. On prior Delphi versions TADDataMove can read/write Unicode encoded text data files, but internally handles all data as ACP encoded. So, conversion loss is possible.
To control encoding of:
To read Unicode data file and create ACP encoded log file do:
ADDataMove1.TextFileName := 'u:\data.txt'; ADDataMove1.TextFileEncoding := enUTF8; ADDataMove1.LogFileName := 'u:\log.txt'; ADDataMove1.TextFileEncoding := enANSI; ADDataMove1.Destination := ADQuery1; ADDataMove1.SourceKind := skText; ADDataMove1.Execute;
To enable Unicode encoding for trace file output (MonitorBy=FlatFile), set TADMoniFlatFileClientLink.FileEncoding property value to ecUTF8 or ecUTF16.
All AnyDAC utilities are compiled with Delphi XE and are 100% Unicode enabled.
|
What do you think about this topic? Send feedback!
|