unit sqlunit;
{$mode objfpc}{$H+}
interface
uses sqlite3conn, sqldb, db, Forms, Dialogs, DBGrids;
type
TFormSQL = class(TForm)
DataSource1: TDataSource;
DBConnection: TSQLite3Connection;
DBGrid1: TDBGrid;
SQLQuery1: TSQLQuery;
SQLTransaction1: TSQLTransaction;
procedure sql_read(sql: ansistring);
private { private declarations }
public { public declarations }
end;
var FormSQL: TFormSQL;
implementation
{$R *.lfm}
procedure TFormSQL.sql_read(sql: ansistring);
{executes the sql-command 'sql' and reads all records into the dataset
'DBGrid1.DataSource.dataset'. If DBGrid1.Visible=True, the result is
shown in a Grid}
begin
try
SQLQuery1.Close; // sonst ist SQL-Befehl nicht änderbar
SQLQuery1.SQL.Text:=sql; // wanted SQL-Befehl
DBConnection.Connected:= True; // establish the connection to the DB
SQLTransaction1.Active:= True; // activate the transaction
SQLQuery1.Open; // open the SQL-query
SQLQuery1.Last; {puts the cursor at the last record in the dataset,
fetching all records from the underlying DB if needed}
except
on E: EDatabaseError do
begin
ShowMessage('DB-Error = ' + E.message);
end;
end; {try}
end; {sql_read}
end.