TdwsSynDBDataBase and StartTransaction's bug

Issue #102 resolved
Former user created an issue

There is a bug in the "TdwsSynDBDataBase" class within the "dwsSynDBDatabase" unit and specifically in the implementation of the "BeginTransaction" method. In fact, the current code of the method is as follows:

Procedures TdwsSynDBDataBase.BeginTransaction;
Begin
  FConn.StartTransaction;
End;

But in my opinion the implementation should be as follows:

Procedures TdwsSynDBDataBase.BeginTransaction;
Begin
  If not FConn.IsConnected then
    FConn.Connect;
  FConn.StartTransaction;
End;

This is to prevent a script from failing in a script when it invokes the "BeginTransaction" method before executing any other query, as it is highlighted in the following sample script:

Var Database: = DataBase.Create ('OleDB MSSQL', ['HOST \ SQLEXPRESS', 'DatabaseTest']);
Database.BeginTransaction;
Var Query: = Database.Query ('select * from table');
// ... some write field operations on Query ...
Database.Commit;

Without the proposed correction, when the script arrives to execute the "BeginTransaction" statement, it has a malfunction because the connection to the DB has not been executed yet.

Comments (2)

  1. Former user Account Deleted reporter

    Or better:

    Var Database: = DataBase.Create ('OleDB MSSQL', ['HOST \ SQLEXPRESS', 'DatabaseTest']);
    Database.BeginTransaction;
    Database.Exec ('insert into table ...');
    // ... some other write operations on DB ...
    Database.Commit;
    
  2. Log in to comment