I'm tryping to populate offline SQLite database from online source
using AJAX library,
The main loop in the callback function is:
function dbLoad(ofs, limit) {
.....
req.onreadystatechange = function() {
if (req.readyState == 4) {
res=req.responseJS.entry;
offset+=1000
dbLoad(offset,1000)
db.execute('begin');
for(var i=0; i<res.length; i++){
db.execute('insert into dbtable values
('+res[i]+')');
}
db.execute('commit');
...
}
The database has 240,000 rows, 22Mb.
If the loading is uninterrupted (240x recursive calling of dbLoad),
the import of the table is OK.
If I interrupt loading, the offline SQLite database file is created,
and the following SQL query:
offset = db.execute('SELECT count(*) as count FROM dbtable').field(0)
--yields the number of rows (say, 3000).
However when I try to launch further importing, the above BEGIN-COMMIT
block is unstable - sometimes it works alright, and sometimes it gives
the error caught by Firebug:
Database operation failed. ERROR: SQL logic error or missing database
DETAILS: SQL logic error or missing database
db.execute('commit');
Database operation failed. ERROR: SQL logic error or missing database
DETAILS: SQL logic error or missing database
db.execute('begin');
The error may (and may not) arise both during stepwise debugging and
during uninterrupted running.
The database is not missing: when I add db.open('...') - db.close()
pair an error "Database is already open" pop up on first db.open().
What's the catch?
Thank you.