Recent

Author Topic: Insert into SqLite over TSQLQuery console app vs gui app  (Read 2134 times)

marius.maximus

  • New Member
  • *
  • Posts: 32
Insert into SqLite over TSQLQuery console app vs gui app
« 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.  
« Last Edit: March 15, 2019, 02:08:25 pm by marius.maximus »

Zvoni

  • Hero Member
  • *****
  • Posts: 2317
Re: Insert into SqLite over TSQLQuery console app vs gui app
« Reply #1 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
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Insert into SqLite over TSQLQuery console app vs gui app
« Reply #2 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