I'm struggling to set up a transaction isolation of TCRSQLConnection. I need repeatable read isolation level. I've tried this:
Code: Select all
function SQLSelectInt( SQLcmd: string; conn: TSQLConnection; defaultVal: int64 = 0): int64;
var
DS :TCustomSQLDataSet;
v :variant;
begin
try
conn.Execute( SQLcmd, nil, @DS);
v := DS.Fields[0].Value;
if VarIsNull( v) then
result := defaultVal
else
result := v;
except
on E:exception do
raise exception.Create( e.Message + #13#10 + #13#10 + SQLcmd);
end;
end;
procedure TForm2.FormCreate(Sender: TObject);
var
tr: TDBXTransaction;
i: int64;
begin
CRSQLConnection1.params.Values['TransIsolation'] := 'RepeatableRead'; //doesn't work
CRSQLConnection1.Open;
CRSQLConnection1.ExecuteDirect( 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL REPEATABLE READ;'); //doesn't work
tr := CRSQLConnection1.BeginTransaction(
TDBXIsolations.RepeatableRead); //doesn't work
CRSQLConnection1.ExecuteDirect( 'SET TRANSACTION ISOLATION LEVEL REPEATABLE READ;'); //doesn't work
i := SQLSelectInt('select max(sr_id) from public.sortiment', CRSQLConnection1); //breakpoint here for insert record from another connection
showMessage( IntToStr(i)); //here I see sr_id inserted after I started transaction :-(
CRSQLConnection1.CommitFreeAndNil(tr);
end;
Thanks a lot for any reaction.
Pavel
(Delphi XE2, PostgreSQL 9.6.6)