Discussion:
MSSQL doesn't commit 2nd transaction
(too old to reply)
Ondrej Pokorny
2018-06-17 19:07:29 UTC
Permalink
Hello,

I found a bug when I use 2 transaction with one MSSQL connection. If one
transaction has open SELECT results, the second transaction doesn't
commit UPDATE statements. No errors or exceptions are shown.

To reproduce:

1.) Create the following table:

CREATE TABLE [dbo].[test2](
    [ID] [int] NOT NULL
)

INSERT INTO [dbo].[test2] VALUES (1)
INSERT INTO [dbo].[test2] VALUES (2)

2.) Run the following program:

program MSSQL2Trans;
uses
  db, MSSQLConn, SQLDB;
var
  C: TMSSQLConnection;
  T1, T2: TSQLTransaction;
  Q1, Q2: TSQLQuery;
begin
  C := TMSSQLConnection.Create(nil);
  C.HostName := 'Ondrej-HP';
  C.DatabaseName := 'Aldat';
  T1 := TSQLTransaction.Create(C);
  T1.DataBase := C;
  C.Connected := True;
  T2 := TSQLTransaction.Create(C);
  T2.DataBase := C;

  Q1 := TSQLQuery.Create(C);
  Q1.SQL.Text := 'SELECT * FROM [dbo].[test2]';
  Q1.SQLConnection := C;
  Q1.Transaction := T1;
  Q1.PacketRecords := -1;
  Q1.Open;

  Q2 := TSQLQuery.Create(C);
  Q2.SQL.Text := 'UPDATE [dbo].[test2] SET [ID]=[ID]+1';
  Q2.SQLConnection := C;
  Q2.Transaction := T2;
  Q2.ExecSQL;
  (Q2.Transaction as TSQLTransaction).Commit;

  Q1.Next;

  C.Free;
end.

3.) You will see that test2 is not updated.

When it works:
A.) If you comment out the Q1-code, test2 is updated.
B.) If you use 2 different connections with 1 transaction each, test2 is
updated as well.

->

Is this a bug in fpc-db or is this some kind of MSSQL feature? Does it
mean I cannot use multiple transactions with one MSSQL connection?

Ondrej

_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal
LacaK
2018-06-18 06:36:22 UTC
Permalink
Post by Ondrej Pokorny
Is this a bug in fpc-db or is this some kind of MSSQL feature? Does it
mean I cannot use multiple transactions with one MSSQL connection?
AFAIK MS SQL Server does not natively supports concept of multiple
simultaneous independent transactions per one connection.
(AFAIK also others RDBMS does not support it with exception of Firebird,
which support it)
So there is question if sqlDB should "simulate"/support it at client
side in background by "open new connection per new transaction"
There was discuusion about it approx. 4 years ago. Michael's position is
that this should be supported on client side.
(my position - unimportant - is that sqlDB need not support something
that is not nature to majority of RDBMS)

-Laco.

_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists
Michael Van Canneyt
2018-06-18 09:17:50 UTC
Permalink
Post by LacaK
Post by Ondrej Pokorny
Is this a bug in fpc-db or is this some kind of MSSQL feature? Does it
mean I cannot use multiple transactions with one MSSQL connection?
AFAIK MS SQL Server does not natively supports concept of multiple
simultaneous independent transactions per one connection.
(AFAIK also others RDBMS does not support it with exception of Firebird,
which support it)
So there is question if sqlDB should "simulate"/support it at client
side in background by "open new connection per new transaction"
There was discuusion about it approx. 4 years ago. Michael's position is
that this should be supported on client side.
Indeed.

We already do this for MySQL and Postgres (which also do not support
multiple transactions). There is no reason why MS SQL should be an
exception. So if the current implementation does not support this,
we must check why this is so.

Michael.
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/lis
LacaK
2018-06-18 09:32:37 UTC
Permalink
Post by Michael Van Canneyt
We already do this for MySQL
No AFAICS
Post by Michael Van Canneyt
and Postgres (which also do not support
multiple transactions).
Yes (PostgreSQL is at this time only connector, that support this kind
of "transaction as connection")

L.

_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepa
Michael Van Canneyt
2018-06-18 09:55:11 UTC
Permalink
Post by LacaK
Post by Michael Van Canneyt
We already do this for MySQL
No AFAICS
Then that must be fixed too.

Michael.
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-de
Ondrej Pokorny
2018-06-18 09:56:01 UTC
Permalink
Post by LacaK
and Postgres (which also do not support multiple transactions).
Yes (PostgreSQL is at this time only connector, that support this kind
of "transaction as connection")
Thank you for the reply and thank you for confirming PostgreSQL.

I was just about to write that I use multiple transactions with fcl-db
on PostgreSQL and I haven't observed problems with it. So I wanted to
ask if this is a coinsidence that it works on PostgreSQL and if I need
to apply some precautions. Now I don't need to ask :)

I reported it: https://bugs.freepascal.org/view.php?id=33873

Ondrej
_______________________________________________
fpc-devel maillist - fpc-***@lists.freepascal.org
http://lists.freepascal.

Loading...