UseUnicod=True trigger WideString. Bug or feature?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
kaffeburk
Posts: 214
Joined: Mon 29 Jan 2007 08:03

UseUnicod=True trigger WideString. Bug or feature?

Post by kaffeburk » Tue 19 May 2020 11:14

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

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

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

Post by ViktorV » Tue 19 May 2020 13:39

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.

kaffeburk
Posts: 214
Joined: Mon 29 Jan 2007 08:03

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

Post by kaffeburk » Sun 24 May 2020 06:19

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.

oleg0k
Devart Team
Posts: 190
Joined: Wed 11 Mar 2020 08:28

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

Post by oleg0k » Tue 26 May 2020 13:23

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

myicq
Posts: 8
Joined: Sat 01 Jun 2019 16:11

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

Post by myicq » Mon 28 Sep 2020 23:02

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;

MaximG
Devart Team
Posts: 1822
Joined: Mon 06 Jul 2015 11:34

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

Post by MaximG » Fri 20 Nov 2020 12:23

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)

Post Reply