Page 1 of 1

UNICODE string getting problem from LiteQuery

Posted: Thu 18 May 2017 11:05
by AlexeyPikurov
LiteDAC 2.6.19, Delphi XE3, x32 project.

My code:

Code: Select all

var s: string;
....
    with LiteQuery do begin
      Close;         //       0          1         2         3       4
      SQL.Text := 'select internal_idx, dt_utc, uinfrom, msg_type, msg ' +
                  'from privates ' +
                  'where uinwith=:uinwith and uin_owner=:uin_owner and dt_utc>=:dtFrom and dt_utc<=:dtTo and servid=:servid ' +
                  'order by dt_utc';

      ParamByName('uinwith').AsInteger   := iUINWith;
      ParamByName('uin_owner').AsInteger := iUINOwner;
      ParamByName('servid').AsInteger    := iServID;
      ParamByName('dtFrom').AsDateTime   := dtUTCFrom;
      ParamByName('dtTo').AsDateTime     := dtUTCTo;

      Open;

        while not eof do begin
          s := FieldList[4].AsString;
          Next;
        end;
    end; 
DataBase: "L$ғарыш айлағы/ғарышалаң"
"s" variable: "L$?арыш айла?ы/?арышала?"

Why in "s" variable is stored a non-unicode string? In database all Ok. How can I get the original UTF8 string from DB in this query?

Re: UNICODE string getting problem from LiteQuery

Posted: Fri 19 May 2017 09:13
by MaximG
To use various national charsets when working with SQLite database, set the UseUnicode property of the TLiteConnection component to True.

For example:

Code: Select all

LiteConnection1.Options.UseUnicode := True;

Re: UNICODE string getting problem from LiteQuery

Posted: Fri 19 May 2017 13:30
by AlexeyPikurov
It doesn't work. UNICODE strings saving Ok into DB table (with this option or without it, no matter).

Image

When I read varchar from DB — I have a problem, LiteQuery component converts it to ANSI, with "?" symbols instead a national characters. I checked it under debugger.

Re: UNICODE string getting problem from LiteQuery

Posted: Mon 22 May 2017 09:16
by AlexeyPikurov
Please help me, I'm a registered customer.

Re: UNICODE string getting problem from LiteQuery

Posted: Tue 23 May 2017 07:15
by MaximG
Of course, we are ready to help you and will investigate the problem. For this, we will need DB file (it can include only the described table) and a full source code of a small project, execution of which causes the problem. Please send this data using the e-support form ( https://www.devart.com - menu «Support»\«Request Support» )

Re: UNICODE string getting problem from LiteQuery

Posted: Wed 31 May 2017 14:52
by AlexeyPikurov
Ok, I found the problem.

Line "LiteQuery.Connection.Options.UseUnicode := true;" MUST be after "LiteConnection.Connect;".
Only in this case UNICODE symbols do not converting to ANSI.

Code:

Code: Select all

  LiteConnection := TLiteConnection.Create(nil);
  LiteConnection.Options.UseUnicode := true;

  LiteQuery := TLiteQuery.Create(Nil);
  LiteQuery.Connection := LiteConnection;
// wrong!
// LiteQuery.Connection.Options.UseUnicode := true;

  LiteConnection.ConnectString := 'Direct=True;' +
                                  'Database=' + ExtractFilePath(ParamStr(0)) + 'testunicode.db;' +
                                  'Login Prompt=False';
  LiteConnection.Connect;

  // only right here!
  LiteQuery.Connection.Options.UseUnicode := true;

  LiteSQL := TLiteSQL.Create(Nil);
  LiteSQL.Connection := LiteConnection;
Full example code source with test database (Delphi XE3).

Re: UNICODE string getting problem from LiteQuery

Posted: Fri 02 Jun 2017 07:23
by MaximG
You can specify the connection parameters in LiteDAC in two ways: either using the LiteConnection.Options property, or by passing a string indicating the values of these parameters to the LiteConnection.ConnectString property. In the second case, if you did not specify any of the connection parameters (for example, UseUnicode) in the passed string, this parameter will get a default value when it is opened (for UseUniсode it is False). Add this parameter in the ConnectString :

Code: Select all

LiteConnection.ConnectString := 'Direct=True;' +
'Database=' + ExtractFilePath(ParamStr(0)) + 'testunicode.db;' +
'Login Prompt=False;' +
'UseUnicode=True'; 

Re: UNICODE string getting problem from LiteQuery

Posted: Fri 02 Jun 2017 15:22
by AlexeyPikurov
Thank you, Max, I'll try it!

Re: UNICODE string getting problem from LiteQuery

Posted: Tue 06 Jun 2017 07:23
by MaximG
We were glad to help you. Please don't hesitate to contact us with questions concerning LiteDAC usage.