Forum > Databases

sqlite

(1/2) > >>

quest:
Hi, I try use lazarus and sqlite, but this code
procedure TForm1.Button2Click(Sender: TObject);
begin
     popis1.Caption:='obsah Edit1: '+Edit1.Text;
     SqliteDataset1:=TSqliteDataset.Create(nil);
     with SqliteDataset1 do
     begin
          FileName:='pokus.db';
          TableName:='customer';
          SQL:='INSERT INTO customer(cust_firstname, cust_lastname, cust_no) values ('''+Edit1.Text+''','''+Edit2.Text+''','''+Edit3.Text+''')';
          Open;
          Close;
          Destroy;
     end;
end;
insert values twice, why?
I use lazarus 0.9.7 20050509 and sqliteds 1.13
thanks

matthijs:
If the TSqliteDataSet is developed like all other datasets, you should not use 'Open' but 'ExecSQL' to let the record be inserted. The 'Open' method is only to be used when reocrds are returned. So try that and check if the records gets inserted twice.

Anonymous:
Thank you, now it is work fine

Anonymous:
I rewrote code and as I wrote, it is work fine, but only on win.
uses
{$ifdef Linux}
  cmem,
{$endif}
  Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, Buttons,
  StdCtrls, crt, SqliteDS, sqldb, ComCtrls, DB;
....
procedure TForm1.Button2Click(Sender: TObject);
begin
     popis1.Caption:='INSERT INTO customer';
     SqliteDataset1:=TSqliteDataset.Create(nil);
     with SqliteDataset1 do
     begin
          FileName:='pokus.db';
          TableName:='customer';
          ExecSQL('INSERT INTO customer(cust_firstname,cust_lastname,cust_no) values'+'('''+Edit1.Text+''','''+Edit2.Text+''','''+Edit3.Text+''')');
          Destroy;
     end;
     comboupdate;
end;
on linux nothing insert.

LuizAmérico:
After calling ExecSql try to evaluate the SqliteReturnString property of TSqliteDataset. THis will give a hint what's going on

Navigation

[0] Message Index

[#] Next page

Go to full version