Page 1 of 1

UseUnicod=True trigger WideString. Bug or feature?

Posted: Tue 19 May 2020 11:14
by kaffeburk
Hello Devart,

Found out that if i set a tUniconnection/Optins/UseUnicode = True the dataset will change from ftString to ftWidestring. This can be undone with datatypemapping in design or by the code:

Code: Select all

UniConnection2.DataTypeMap.Clear;
UniConnection2.DataTypeMap.AddDBTypeRule(221,ftString);
What is the reason for this? Can not a normal string handle unicode just fine?

Example code.
https://www.dropbox.com/s/trl22zp8zdvym ... e.rar?dl=0

Re: UseUnicod=True trigger WideString. Bug or feature?

Posted: Tue 19 May 2020 13:39
by ViktorV
This behavior is correct https://www.devart.com/unidac/docs/using-mysql.htm. When the UseUnicode property is set to True, you can retrieve string data at the client side in Unicode encoding format, which enables you to work simultaneously with almost any language. All TStringField values will be converted to TWideStringField.
The UseUnicode option enables support for Unicode characters for the entire project, not just for creating fields of type TWideStringField. To create individual fields of type TStringField, you can use Data Type Mapping.

Re: UseUnicod=True trigger WideString. Bug or feature?

Posted: Sun 24 May 2020 06:19
by kaffeburk
Powerful, nice done.

But in the documentation i think you forget to add info about the PgDataTypeMapUni unit. Without that unit the pgNumeric in your documentation wont work. Also some "pg" looks like they are missing, like pgVarchar.

We have quite a lot of clientdatasets where i don't want to change every fielddef from ftString to FtWIdechar and i need to programatically set the correct Data Type Mapping. By a lot of trial and error, like creating the Data Type Mapping in dfm and checking it i found that the code for varchar was 221. The syntax for mapping a Varchar to a ftString is also not documented. By more trial and error i did find it to be

Code: Select all

DataTypeMap.AddDBTypeRule(221,ftString);
I can also see that the lack of documentation about this was communicated five years ago.

viewtopic.php?t=31780

I find that a bit strange, it can hardly take more time to fix that then to read this. But it will take a lot more time for everybody to one and one invent the wheel over and over again.

Re: UseUnicod=True trigger WideString. Bug or feature?

Posted: Tue 26 May 2020 13:23
by oleg0k
Hello,
Thank you for the information, we'll describe that in more detail in future versions of UniDAC.
To map PostgreSQL character varying data type, you should use the constant pgCharacterVarying.

wbr, Oleg
Devart Team

Re: UseUnicod=True trigger WideString. Bug or feature? : for SQLite and D7

Posted: Mon 28 Sep 2020 23:02
by myicq
Adding to this tip, for others that may be struggling to get Unicode out of SQLite for use in ancient Delphi versions:

Just add some magic to your creation of connection:

Code: Select all

       
     theDB := TUniConnection.Create(nil);
     with theDB do
       begin
         ConnectString := 'Provider Name=SQLite;Direct=True;Force Create Database=True;Use Unicode=True';
         Database := databasename; 

        // ADD THIS to get Unicode out from a query
         DataTypeMap.AddDBTypeRule(
             603,                // this is "Text" in SQlite
             ftwidestring
            );

         Connect;
       end;

Re: UseUnicod=True trigger WideString. Bug or feature?

Posted: Fri 20 Nov 2020 12:23
by MaximG
Thank you for your input. There's no magic needed here, UniDAC offers the Data Type Mapping feature that does the trick (viewtopic.php?f=28&t=40663)