You're not the only one that has had problem with Async transactions. They should be possible, but the statement doesn't get released until the execution is complete....which is problematic. Your best bet for this is to use a synchronous connection. Yes, that sucks for user experience if you have many bulk entries....but, if you don't need the data right away, perhaps you could do them when the application is idle
something like this... NativeApplication.nativeApplication.addEventListener(Event.USER_IDLE, onUserIdle); You could then check to see if you have already run the onAddBulkContacts via a Boolean value, and run it if have not run it before... From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Tac Tacelosky Sent: Tuesday, August 16, 2011 7:25 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] SQLite Insert Statements in a transaction I'm trying to get my head around how to do a SQLite bulk insert using transactions. This works, but it doesn't make sense to re-create a new SQLStatement in the loop: private function onAddBulkContacts():void { _responder = new Responder(resultEventHandler, errorEventHandler); contacts_db.connection.begin(null, _responder); var statement:SQLStatement; for (var i:uint=0; i<parseInt(bulkAdd.numberToAdd.text); i++) { statement = new SQLStatement(); statement.sqlConnection = contacts_db.connection; statement.text ="INSERT INTO contacts ('name', 'lastname') VALUES (@NAME, @LASTNAME)"; statement.addEventListener(SQLErrorEvent.ERROR, function(event:Event):void { trace('statement error');}); statement.addEventListener(SQLEvent.RESULT, function(event:Event):void { trace('result'); }); statement.parameters['@NAME'] = "Name " + i.toString(); statement.parameters['@LASTNAME'] = "LastName " + i.toString(); statement.execute(); } contacts_db.connection.commit(); } What I want to do is create the SQLStatement once, let it compile, then just pass in new arguments within the loop, the commit it at the end, e.g. private function onAddBulkContacts():void { _responder = new Responder(resultEventHandler, errorEventHandler); contacts_db.connection.begin(null, _responder); var statement:SQLStatement; statement = new SQLStatement(); statement.sqlConnection = contacts_db.connection; statement.text ="INSERT INTO contacts ('name', 'lastname') VALUES (@NAME, @LASTNAME)"; statement.addEventListener(SQLErrorEvent.ERROR, function(event:Event):void { trace('statement error');}); statement.addEventListener(SQLEvent.RESULT, function(event:Event):void { trace('result'); }); for (var i:uint=0; i<parseInt(bulkAdd.numberToAdd.text); i++) { statement.parameters['@NAME'] = "Name " + i.toString(); statement.parameters['@LASTNAME'] = "LastName " + i.toString(); statement.execute(); } contacts_db.connection.commit(); } But the latter code throw an error saying that it can't execute the second time through, since the statement itself is still executing (and I believe will be in that state until the commit). I guess I can understand that the statements get added to the execution queue, but it doesn't make sense that I have to add the SQL text within the loop, exactly the thing I'm trying to avoid. I'm sure there's a better way to do this, but I've spent way too long hacking and reading trying to figure out what the proper sequence is. Any ideas? Thanks, Tac _______________________________________________________________________________________________ The information contained in this e-mail is for the exclusive use of the intended recipient(s) and may be confidential, proprietary, and/or legally privileged. Inadvertent disclosure of this message does not constitute a waiver of any privilege. If you receive this message in error, please do not directly or indirectly use, print, copy, forward, or disclose any part of this message. Please also delete this e-mail and all copies and notify the sender. Thank you. For alternate languages please go to http://bayerdisclaimer.bayerweb.com _______________________________________________________________________________________________