Regression in MSSQL: transactions are not committed
Original Reporter info from Mantis: kluug.net @onpok
-
Reporter name: Ondrej Pokorny
Original Reporter info from Mantis: kluug.net @onpok
- Reporter name: Ondrej Pokorny
Description:
The changes are not committed to the server.
I tried to bisect the guilty version but gave up now with the following:
42965 fail
42737 OK
Steps to reproduce:
program MSSQLtrans;
uses
SysUtils, MSSQLConn, SQLDB;
procedure TestCommit(const RealTest: Boolean);
var
C: TMSSQLConnection;
T: TSQLTransaction;
Q: TSQLQuery;
procedure CreateObjects;
begin
C := TMSSQLConnection.Create(nil);
T := TSQLTransaction.Create(C);
C.Transaction := T;
C.HostName := 'ONDREJ-HP';
C.DatabaseName := 'Aldat';
C.Connected := True;
Q := TSQLQuery.Create(C);
Q.SQLConnection := C;
Q.Transaction := T;
end;
begin
CreateObjects;
Q.SQL.Text := 'CREATE TABLE testtrans (ID int)';
Q.ExecSQL;
Q.SQL.Text := 'INSERT INTO testtrans VALUES(1)';
Q.ExecSQL;
T.Commit;
if RealTest then // recreate connection to test if the commit succeded
begin
C.Free;
CreateObjects;
end;
Q.SQL.Text := 'SELECT * FROM testtrans';
try
Q.Open;
WriteLn(Q.Fields[0].AsInteger);
except
on E: Exception do
WriteLn(E.Message);
end;
C.Free;
end;
begin
WriteLn('one connection&transaction:');
TestCommit(False);
WriteLn('split connections&transactions:');
TestCommit(True);
ReadLn;
end.
----
Output:
one connection&transaction:
1
split connections&transactions:
TMSSQLConnection : Error 20018 :
General SQL Server error: Check messages from the SQL Server
Invalid object name 'testtrans'.
Mantis conversion info:
- Mantis ID: 36148
- Fixed in version: 3.3.1
- Fixed in revision: 43154 (#e67989a8)
- Target version: 3.2.0