SQL for AIR asynchronous vs synchronous question
Gidday guys
I've set up a SQLite database that's going to be processing up to 150 000 rows at a time. I'm using parametized queries wrapped in a transaction, so it should all be pretty quick. I'm using asynchronous methods.
I've set the queries, and managed to get a static test query into the database using the parameters. Wahooo!!!
However, now I've made it dynamic to receive bulk data, I'm getting the error:
"Operation cannot be performed while SQLStatement.executing is true"
I'm wondering if someone can
a) suggest whether synchronous might be a better option
or
b) guide me as to what sequence of functions and event listeners would fix my following set up...
THE PROCESS:
- I have a bunch of filenames in an array, that need to be tweaked before thrown into the database
- I set up the sql connection (leg work done earlier), the query statement, and then start a transaction:
insertStmt.sqlConnection = conn;
insertStmt.text = "INSERT OR IGNORE INTO tester3 VALUES (@col1, @col2) ";
conn.begin();
- array is thrown into a function which starts up an enterFrame iteration (so display doesn't freeze), where I tweak the filenames, and put each tweaked filename and some other data (also headed for the database) into an object, and deliver it to the function that prepares the data into the parameters...
prepareParameters({col1:col1var, col2:col2var});
prepareParameters(row:Object):void
{
insertStmt.parameters["@col1"] = row.col1;
insertStmt.parameters["@col2"] = row.col2;
insertStmt.execute();
}
- at the end of array loop, call function to end transaction
I think the problem is that the loop is sending the next object to prepareParameters() before the database has finished executing the last insert statement.
I tried setting up a results listener to try and make Flash not return back to the loop until the listener received something, but I get the same error.
My first thought was 'hey, shouldn't Flash wait until after insertStmt.execute(); has finished before returning to the loop that called it's function? But maybe that only happens in synchronous processing?
Thanks for your thoughts guys.
