[yunqa.de] DISQLite3 rollback/commit failure after failed INSERT INTO

  • From: Sérgio Trindade <sptrindade@xxxxxxxx>
  • To: <yunqa@xxxxxxxxxxxxx>
  • Date: Tue, 22 Dec 2009 02:35:09 -0000

Hello, 

I'm using DISQLite3 v2.1.2 personal edition on Delphi 7 and have the following 
issue: after a floating point exception was generated while executing a 
malformed "INSERT INTO" statement, both rollback and commit fail with message 
"SQL statements in progress".

I have the following DELPHI code:

procedure TSQLiteDM.DatabaseExecute(const SQL: string);
begin
  DatabaseLock;
  try
    DatabaseCheckActive;
    Database.StartTransaction;
    try
      Database.Execute(SQL);
      Database.Commit;
    except
      Database.Rollback;                //>>> This will fail with error code 5!
      raise;
    end;
  finally
    DatabaseUnlock;
  end;
end;

Incorrect SQL statement, generating the exception:

'INSERT OR REPLACE INTO "tbLogData_AC1_DC1_LV1" 
("FileId","RecNum","EvtType","RecTime","Source","EvtId","EvtName","EvtDate","EvtTime","EvtData","EvtInfo")
 VALUES (1,8,'I','2009-12-04 
14:25:04.597','UDP:10.0.2.197',5200,'EV_COUNTER_CHANGED','2009-12-02','19:20:05',datetime('0001020000000100000000000000000000'),'Counter:
 1 (0x0001) [???];Value (before op.): 33554432 (0x02000000);Value (after op.): 
16777216 (0x01000000).')'

Correct statement would be:

'INSERT OR REPLACE INTO "tbLogData_AC1_DC1_LV1" 
("FileId","RecNum","EvtType","RecTime","Source","EvtId","EvtName","EvtDate","EvtTime","EvtData","EvtInfo")
 VALUES (1,8,'I','2009-12-04 
14:25:04.597','UDP:10.0.2.197',5200,'EV_COUNTER_CHANGED',datetime('2009-12-02'),'19:20:05','0001020000000100000000000000000000','Counter:
 1 (0x0001) [???];Value (before op.): 33554432 (0x02000000);Value (after op.): 
16777216 (0x01000000).')'


While the SQL statement can be corrected, the issue remains that an error on 
"INSERT INTO" caused commit/rollback to fail, which points to a bug on the 
SQLite3 code.

Other related posts: