Lazarus

Programming => General => Topic started by: marius.maximus on March 15, 2019, 02:05:48 pm

Title: Insert into SqLite over TSQLQuery console app vs gui app
Post by: marius.maximus on March 15, 2019, 02:05:48 pm
I try insert into SqLite text with Russian and Korean chars  (debian x64) over TSQLQuery   
I have different result if build console application and gtk2 application

SQLQuery11.FieldByName('name').AsString := ('RU:белая PL:ŁĘŃÓĆ KR:흰 염소');
gtk2 text in sqlite database is correct "RU:белая PL:ŁĘŃÓĆ KR:흰 염소"
console application write to database over SQLQuery11  result is  "U:белаÑ. PL:Å.Ä.Å.Ã.Ä. KR:í.° ì.¼ì.."

SQLite3Connection11.ExecuteDirect  works correct on both platform ,

Where's my mistake?


Code: Pascal  [Select][+][-]
  1. unit test_unit;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, SQLite3Conn, SQLDB;
  9.  
  10.  
  11. procedure my_test;
  12.  
  13. implementation
  14.  
  15. procedure my_test;
  16. // need: uses SQLite3Conn, SQLDB
  17. var
  18.     SQLite3Connection11: TSQLite3Connection;
  19.     SQLQuery11: TSQLQuery;
  20.     SQLTransaction11: TSQLTransaction;
  21.  
  22. begin
  23.   SQLite3Connection11:=TSQLite3Connection.Create(nil);
  24.   SQLTransaction11 := TSQLTransaction.Create(nil);
  25.   SQLQuery11:= TSQLQuery.Create(nil);
  26.  
  27.  
  28.   SQLite3Connection11.DatabaseName:='koza.db';
  29.   SQLite3Connection11.Transaction := SQLTransaction11;
  30.   SQLite3Connection11.Open;
  31.  
  32.  
  33.   // create table
  34.   SQLite3Connection11.ExecuteDirect('create table  IF NOT EXISTS  koza  (ID INTEGER PRIMARY KEY AUTOINCREMENT, name text)');
  35.  
  36.   // insert
  37.   SQLite3Connection11.ExecuteDirect('insert into koza(name) values ("RU:белая PL:ŁĘŃÓĆ KR:흰 염소")');
  38.  
  39.  
  40.   SQLQuery11.DataBase := SQLite3Connection11;
  41.  
  42.   SQLQuery11.sql.Text:='select * from koza';
  43.   SQLQuery11.Open;
  44.  
  45.   SQLQuery11.Insert;
  46.   SQLQuery11.FieldByName('name').AsString := ('RU:белая PL:ŁĘŃÓĆ KR:흰 염소');
  47.   SQLQuery11.ApplyUpdates;
  48.  
  49.   SQLTransaction11.Commit;
  50.  
  51.   SQLQuery11.free;
  52.   SQLTransaction11.free;
  53.   SQLite3Connection11.free;
  54. end;
  55.  
  56. end.
  57.  
  58.  
Title: Re: Insert into SqLite over TSQLQuery console app vs gui app
Post by: Zvoni on March 15, 2019, 02:57:44 pm
The encoding of the Database is correct (UTF16)?

As a sidenote: don't use AUTOINCREMENT in SQLite.
Just define UNIQUE, PRIMARY KEY and NOT NULL, but leave AUTOINCREMENT out
Title: Re: Insert into SqLite over TSQLQuery console app vs gui app
Post by: Leledumbo on March 16, 2019, 08:46:36 pm
Encoding of the two files containing query having the Russian/Korean chars are the same? What if you turn the db operation into its own unit and uses it from both the GUI and console program?
TinyPortal © 2005-2018