I recently faced an app for ipad that checking whether a particular folder had contained text, it had to proceed with an import of all files in the database. In practice, a reset of the db.
This is the first cycle, for each file found i create import queries:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
//start import db.execute('BEGIN'); //for each file found for ( var i=0; i<=dirItems.length-1; i++ ) { //pb is a Progress Bar pb.setValue(i+1); pb.setMessage('Importing '+(i+1)+' of '+dirItems.length); //in this function parse all txt files and create import mImport.import_db(dirItems[i].toString()); } //end import db.execute('COMMIT'); |
The important point are the commands:
1 2 |
db.execute('BEGIN'); db.execute('COMMIT'); |
This commands determine the start and the end of the import process.
The Begin indicates we are starting a series of queries that are going to query the database, while the Commit marks the end of the whole process.
Then take all the sqlite query will process and making it much faster to process them one at a time.
Note: The best way is to package individual files for import and not the whole process, so you have better control over errors.
Like this:
1 2 3 4 5 6 7 8 9 10 |
//for each file found for ( var i=0; i<=dirItems.length-1; i++ ) { db.execute('BEGIN'); //import process file db.execute('COMMIT'); } |
Hello! I’m at work browsing your blog from my new iphone 3gs! Just wanted to say I love reading your blog and look forward to all your posts! Carry on the superb work!
I am surprised by the information in this article I found it to be not only incredibly motivating but it really also made me reflect. It is hard now a days to locate related information to ones search, so I’m happy that I found this blog post