Ansi and UTF8 in SQLite database

Forum related to SQLite

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
inetMark
Fresh Boarder
Fresh Boarder
Posts: 10
Joined: 19.03.2008, 18:57

Ansi and UTF8 in SQLite database

Post by inetMark »

I used simple wrapper for connect to the SQLite database for INSERT, SELECT, UPATE, DELETE operations.
I am working in Delphi. This is simple code how I worked with my database with simple wrapper:

Code: Select all

var sqlDB: TSQLiteDatabase;
    sqlTB: TSQLiteTable;
begin
  sqlDB := TSQLiteDatabase.Create('D:\data.db');
  sqlDB.ExecSQL(AnsiToUFT8('INSERT INTO table1......'));
  //or
  sqlTB := sqlDB.GetTable(AnsiToUTF8('SELECT * FROM table1 WHERE filed1 = "string"'));
  //....
  //and this is way how to read data from TABLE into EDIT
  Edit1.Text := UTF8ToAnsi(sqlTB.FieldAsString('field1'));
end;
Information in SQLite is stored in UTF8 and you can see that I convert data from/to UTF8.

Now I have problem with Zeos components. If I read data which contains accented characters (such as 'káčatko') then they are not correctly in DBgrid. I need Zeos components for my report (becasuse Zeos works correctly with FastReport and simple wrapper not).

Is there any chance how I can solve this problem?
Or is there any options how I can set automatic conversion from ANSI to UTF8 (in write mode) and UTF8 to ANSI in read mode?

Thanks.
RavenIV
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 28.03.2008, 15:21

Post by RavenIV »

You don't need UTF8.

I use this Code to get the correct Characters (e.g. german special characters like ö ä ü)

Code: Select all

procedure TDmData.QuGetText(Sender: TField; var Text: string; DisplayText: Boolean);
var
  TempText: string;
begin
  TempText := Trim(Sender.AsString);
  if TempText <> '' then
  begin
    OemToChar(PChar(TempText), PChar(TempText));
    Text := TempText;
  end;
end;
Then go thru all Fields of the query and assign OnGetText:

Code: Select all

  for i := 0 to DmData.Query.Fields.Count - 1 do
  begin
    DmData.Query.Fields[i].OnGetText := DmData.QuGetText;
  end;
Post Reply