Fastest way to INSERT Sqlite?
Posted: Wed Feb 13, 2013 8:10 am
I seem to be missing something and can't figure it out. I'm seeing that INSERT should be pretty fast but it's not the case for me. I know I've gotta be overlooking something simple. I have the following code that uses data from a web service that pulls around 30,000 rows of items with only 3 colums of data. I'm then trying to insert that data into an empty table, then update another table from that table.
The thing is that I'm trying to run this in the background and still allow the user to browse through the app, so I obviously want it to go as fast as possible. This process will only be run once. Right now it's taking 10+ minutes for it to complete and drags down the iOS version of the app while it's running. The "executeSQL()" is just a function that gets the dbid and executes the statement. From what I keep seeing, 30,000 items should go extremely fast with using begin transaction and commit transaction, but this isn't working for me. Any feedback would be greatly appreciated.
Code: Select all
on updateQtyOh qtyToUpdate
if qtyToUpdate = 1 then
put executeSQL("BEGIN IMMEDIATE TRANSACTION") into resultSet
put "Updating All Quantities" into field "updateStatus"
show field "updateStatus"
end if
put revXMLNodeContents(xmlQtyTree_ONCE, "string/NewDataSet/Table[" & qtyToUpdate & "]/I") into qty_itemno
put revXMLNodeContents(xmlQtyTree_ONCE, "string/NewDataSet/Table[" & qtyToUpdate & "]/Q") into qty_qty
put revXMLNodeContents(xmlQtyTree_ONCE, "string/NewDataSet/Table[" & qtyToUpdate & "]/C") into qty_cprc
put "INSERT INTO Onhand_Cache VALUES (" & qty_itemno & "," & qty_qty & "," & qty_cprc & ")" into qtySQL
put executeSQL(qtySQL) into qtyResult
put (1+qtyToUpdate) into qtyToUpdate
if qtyToUpdate <= totalQtys then
send "updateQtyOh qtyToUpdate" to me in 0 milliseconds
else
put executeSQL("COMMIT TRANSACTION") into tResult
put "UPDATE Items SET QTYOH = (SELECT OnHand_Cache.QTYOH FROM OnHand_Cache WHERE OnHand_Cache.ITEMNO = Items.ITEMNO), CPRC = (SELECT OnHand_Cache.CPRC FROM OnHand_Cache WHERE OnHand_Cache.ITEMNO = Items.ITEMNO)" & \
"WHERE EXISTS (SELECT * FROM OnHand_Cache WHERE OnHand_Cache.ITEMNO = Items.ITEMNO)" into qtySQL
put executeSQL(qtySQL) into qtyResult
put "Update Complete" into field "updateStatus"
revDeleteXMLTree xmlQtyTree_ONCE
end if
end updateQtyOh