(* Collection of code snippets by Arne Vajhøj *)
(* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) *)
program DB3;

uses
  sqldb, mysql55conn, sysutils;

procedure dump(con : TMySQL55Connection);

var
  q : TSQLQuery;

begin
  q := TSQLQuery.Create(nil);
  q.DataBase := con;
  q.SQL.Text := 'SELECT f1,f2 FROM t1 WHERE f1 > :f1';
  q.Params.ParamByName('f1').AsInteger := 6;
  q.Open;
  while not q.EOF do begin
    writeln(IntToStr(q.FieldByName('f1').AsInteger) + ' ' + q.FieldByName('f2').AsString);
    q.Next;
  end;
  q.Free;
end;

procedure modify(con : TMySQL55Connection; tx : TSQLTransaction; f1 : integer; f2 : string);

var
  q : TSQLQuery;

begin
  q := TSQLQuery.Create(nil);
  q.DataBase := con;
  q.SQL.Text := 'INSERT INTO t1 (f1,f2) VALUES(:f1,:f2)';
  q.Params.ParamByName('f1').AsInteger := f1;
  q.Params.ParamByName('f2').AsString := f2;
  q.ExecSQL;
  tx.Commit;
  q.Free;
end;

var
  con : TMySQL55Connection;
  tx : TSQLTransaction;

begin
  con := TMySQL55Connection.Create(nil);
  con.HostName := 'localhost';
  con.UserName:= 'root';
  con.Password:= '';
  con.DatabaseName:= 'test';
  con.Open;
  tx := TSQLTransaction.Create(nil);
  con.Transaction := tx;
  dump(con);
  modify(con, tx, 10, 'JJJJJJJJJJ');
  dump(con);
  tx.Free;
  con.Free;
end.

