Advertisement
Guest User

Fred

a guest
Aug 10th, 2008
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.34 KB | None | 0 0
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3. //Use a second TQuery, to perform changes, and avoid exception after ExecSQL
  4. with ASQLite3Query2 do begin
  5.    Close;
  6.    SQL.Clear;
  7.    SQL.Text := 'INSERT INTO books (isbn,language) VALUES (NULL,:a)';
  8.    Params[0].AsString := 'test';
  9.    ExecSQL;
  10. end;
  11.  
  12.   ASQLite3Query1.Refresh;
  13. end;
  14.  
  15. procedure TForm1.FormActivate(Sender: TObject);
  16. begin
  17.   With ASQLite3DB1 do begin
  18.     DefaultDir := ExtractFileDir(Application.ExeName);
  19.     Database := 'mybooks.sqlite';
  20.     Open;
  21.     SQLite3_ExecSQL('CREATE TABLE IF NOT EXISTS books (isbn INTEGER PRIMARY KEY, language VARCHAR)');
  22.   end;
  23.  
  24.   //Do I need TUpdateSQL?
  25.   With ASQLite3UpdateSQL1 do begin
  26.     InsertSQL.Text := 'INSERT INTO books *';
  27.   end;
  28.  
  29.   With ASQLite3Query1 do begin
  30.     Connection := ASQLite3DB1;
  31.     SQL.Text := 'SELECT * FROM books';
  32.     UpdateSQL := ASQLite3UpdateSQL1;
  33.     Open;
  34.   end;
  35.  
  36.   //Do I need a second TQuery?
  37.   With ASQLite3Query2 do begin
  38.     Connection := ASQLite3DB1;
  39.     SQL.Text := 'SELECT * FROM books';
  40.     UpdateSQL := ASQLite3UpdateSQL1;
  41.     Open;
  42.   end;
  43.  
  44.   DataSource1.DataSet := ASQLite3Query1;
  45.  
  46.   With NextDBGrid1 do begin
  47.     DataSource := DataSource1;
  48.     Columns[ASQLite3Query1.FieldCount-1].Options := NextDBGrid1.Columns[ASQLite3Query1.FieldCount-1].Options + [coAutoSize];
  49.   end;
  50.  
  51. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement