1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| procedure TFormMain.Button10Click(Sender: TObject);
var strm: TStream;
Result : boolean;
begin
strm:=TMemoryStream.Create;
imgSrc.Picture.SaveToStream(strm);
with pgQueryUID do try
if not DataBase.Connected then DataBase.Connected := True;
Close;
TSQLTransaction(pgQueryUID.Transaction).StartTransaction;
with SQL, Params do begin
Clear;
SQL.Text := 'INSERT INTO test2012 '+
'(teid, tenom, teblob) '+
'VALUES ' +
'(:paID, :paNOM, :paIMAGE );';
ParamByName('paID').AsString := AleaString();
ParamByName('paNOM').AsString := 'TEST numéro 6';
ParamByName('paIMAGE').SetBlobData(Strm, Strm.Size);
end;
ExecSQL;
Close;
TSQLTransaction(pgQueryUID.Transaction).Commit;
Result := True;
except
on E: EPQDatabaseError do
begin
TSQLTransaction(pgQueryUID.Transaction).Rollback;
Showmessage('Database error: '+
'Severity: '+E.Severity + LineEnding +
'SQLSTATE: '+E.SQLSTATE + LineEnding +
'Primary mesage: '+E.MESSAGE_PRIMARY + LineEnding +
'Detailed message: '+E.MESSAGE_DETAIL + LineEnding +
'Message hint: '+E.MESSAGE_HINT + LineEnding +
'Statement position: '+E.STATEMENT_POSITION);
Result := False;
end;
on Z: Exception do
begin
// Assume it's an executable query.
// A query containing a syntax error etc will be wrongly detected as executable
// todo: fix this based on detailed error message retrieved from db!?!?
showmessage('Exception : '+Z.ClassName+'/'+Z.Message);
end;
end;
strm.Free;
end; |