Search code examples
actionscript-3flashsqliteair

Adobe Air SQLEvent.COMMIT, database is still locked when dispatched


My database is opened in Asynchronous mode, here is the part where I'm trying to insert some info there with commit, nothing more happend while doing this job.

conn.addEventListener(SQLEvent.COMMIT, commitHandler);
conn.begin();
for (var i:int = 0; i < someData.length; i++)
{
saveStmt = new SQLStatement();
saveStmt.sqlConnection = conn;
saveStmt.text = sql;
saveStmt.parameters["@some_ID"] = someData[i].id;
saveStmt.parameters["@some_title"] = someData[i].title;
saveStmt.execute();
}
conn.commit();
//here is commit handler
private function commitHandler(e:SQLEvent):void 
{
saveStmt = null;
conn.removeEventListener(SQLEvent.COMMIT, commitHandler);
conn.close(); //this gives error: Database file is currently locked
}

I'm getting error on conn.close();, it can't be done cause "Database file is currently locked"

From Adobe's help: The SQLEvent.COMMIT constant defines the value of the type property of a commit event object. This type of event is dispatched when a SQLConnection.commit() method call completes successfully.

What's might be wrong with the system? strange is that this error isn't permanent, it appears sometimes (in other cases everything goes without problem and database is closing successfully), I'm catching this error with conn.addEventListener(SQLErrorEvent.ERROR, errorHandler);,no other kind of errors appears, only described above.

Error above happens in Flash Pro's emulator and also on devices (has no problems on Nexus 7 tablet and getting them on Samsung Galaxy s3), I'm using Adobe Air 3.8 for Android, same happens with 3.7 and 3.6 also.


Solution

  • I would assume that this might have something to do with the size of the transaction. I attempted to reproduce this, admittedly with a limited dataset, but had no issues.

    I would suggest delaying the SQLConnection.close() call with a callLater() or a Timer.

    Also check the values of SQLConnection.inTransaction and SQLStatement.executing these may indicate that the lock is still active.