Hello Sergio,
in additional to what was said by Peter (MierlP), here is a small explanation to transactions.
Transactions is a long story.
When we worked on the past on 1 PC, all was OK : No need to isolate transactions from others users.
Now, when we work with many users, each user modify online data, we have to take care on the isolation writes. this is done by the transactions mechanism.
In short, you can see here an example (with PostGresSQL / DevArt ).
In the example below, a global transaction is started, and if all is OK it will commit the result (write on disk) .
This transaction is by default ReadCommited. You can googled this for further informations.
procedure TForm1.UniButton1Click(Sender: TObject);
begin
PgConnection1.StartTransaction;
try
//====================
Do_SommeOperations;
//====================
PgConnection1.Commit;
except
on E: Exception do
begin
PgConnection1.Rollback;
showmessage(E.Message);
end;
end;
end;
procedure TForm1.Do_SommeOperations;
var MyQuery:TPgSQL;
Query_Select:TPgQuery;
MyNumber:integer;
begin
//1. Retreiving somme values
Query_Select:=TPgQuery.Create(Nil);
try
Query_Select.Connection:=PgConnection1;
Query_Select.SQL.Clear;
Query_Select.SQL.Add('Select MyNumber From MyTable1 where (ID=100)');
Query_Select.Open;
if Query_Select.IsEmpty then
MyNumber:=-1
else
begin
if Not VarIsNULL(Query_Select.Fields[0].AsVariant) then
MyNumber:=Query_Select.Fields[0].AsInteger
else
MyNumber:=-1;
end;
finally
Query_Select.Free;
end;
//2. inserting values
MyQuery:=TPgSQL.Create(Nil);
try
MyQuery.Connection:=PgConnection1;
MyQuery.SQL.Clear;
With MyQuery.SQL do
begin
Add('Insert into MyTable2');
Add('(');
Add('ID,');
Add('MyNumber');
Add(')');
Add(' VALUES ');
Add('(');
Add('1,');
Add(':MyNumber');
Add(')');
end;
MyQuery.Execute;
With MyQuery.Params do
begin
ParamByName('MyNumber').DataType:=ftInteger;
ParamByName('MyNumber').aSinteger :=MyNumber;
end;
MyQuery.Execute;
finally
MyQuery.Free;
end;
end;
Best Regards