Recent

Author Topic: [Solved] Mysql to Sqlite3  (Read 3052 times)

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
[Solved] Mysql to Sqlite3
« on: May 09, 2012, 12:00:32 pm »
Hello,

I try to move a mysql database to sqlite3.
As the project is not that big, I move one table at the time.
I am using zeos for the mysql database.
Zeos: connection, table and datasource.
Sqlite: connection and datasource.

I try to write this:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var countrecord: longint; recordnumber: longint;
begin
  countrecord:= Ztable1.RecordCount;
  Button1.Caption:= inttostr (countrecord);
  for recordnumber:=0 to (countrecord - 1) do
  begin
     ZTable1.RecNo:= recordnumber;
     Sqlite3Dataset1.Insert;
     Sqlite3Dataset1.IndexFields[0].AsString:=ZTable1.FieldByName('Nogle').AsString;
     Sqlite3Dataset1.Post;
  end
end;       

All that I got is an exception class:
Code: [Select]
External SIGSEGV
I am aware that the code is not the best, but it's compile fine.

Can you please tell me where I should look?

Thank you
Best Regards
Jean-Christophe
« Last Edit: May 10, 2012, 06:25:22 pm by jeanchristophe »

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7505
Re: Mysql to Sqlite3
« Reply #1 on: May 09, 2012, 12:03:40 pm »
Code: [Select]
      Sqlite3Dataset1.IndexFields[0].AsString:=ZTable1.FieldByName('Nogle').AsString;


Why "indexfields" on the left, and fieldbyname on the right ? I don't get that. Both fieldbyname (or fields[0]), but indexfields? That is afaik something else (fields with indexes on them?)
 

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
Re: Mysql to Sqlite3
« Reply #2 on: May 09, 2012, 12:21:45 pm »
Sorry, my mistake!  :-[
I changed the line to:
Code: [Select]
Sqlite3Dataset1.FieldByName('Nogle').AsString:=ZTable1.FieldByName('Nogle').AsString;
The application is now running, but nothing is written in the sqlite table!
I keep looking.

Thanks for your (fast) help Marcov

Best Regards
Jean-Christophe

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Mysql to Sqlite3
« Reply #3 on: May 09, 2012, 12:49:36 pm »
To store the data in the sqlite database you need to call  TSqlite3Dataset.ApplyUpdates or set TSqlite3Dataset.SaveOnClose to True.

http://wiki.freepascal.org/Lazarus_Database_Tutorial#Using_the_TSQLite3Dataset

jeanchristophe

  • Jr. Member
  • **
  • Posts: 88
Re: Mysql to Sqlite3
« Reply #4 on: May 09, 2012, 02:08:52 pm »
Thank you very much for your answer Ludob.
It is now working!  :)

Best Regards
Jean-Christophe