Lazarus

Programming => Databases => Topic started by: jeanchristophe on May 09, 2012, 12:00:32 pm

Title: [Solved] Mysql to Sqlite3
Post by: jeanchristophe 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
Title: Re: Mysql to Sqlite3
Post by: marcov 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?)
 
Title: Re: Mysql to Sqlite3
Post by: jeanchristophe 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
Title: Re: Mysql to Sqlite3
Post by: ludob 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
Title: Re: Mysql to Sqlite3
Post by: jeanchristophe on May 09, 2012, 02:08:52 pm
Thank you very much for your answer Ludob.
It is now working!  :)

Best Regards
Jean-Christophe
TinyPortal © 2005-2018