I have a problem with a webserver that stores data periodically in a node-sqlite3 driven database. It will work fine a few times and then just fails with
SQLITE_BUSY: database is locked
Sometimes all inserts are not completed to the database even when not failing, leaving only a portion of the inserts in the table.
setInterval(doInserts,60000);
doInserts() {
calculateData(function(data){
if(data)
{
insertData(data);
}
});
}
function insertData(data) {
var sqlite3 = require("sqlite3").verbose();
//user fs existSync to check if file exists and openSync(file,'w') to create if not
db.serialize(function(){
var stmt = db.prepare("INSERT INTO mytable (col1,col2) values (?,?)");
for(var i =0;i<data.length;i++)
stmt.run(data[0],data[1]);
stmt.finalize();
});
db.close();
}
Taking account I am new to both node and SQLite, I'm guessing that I am using something in the wrong way, causing multiple open threads or processes to lock up the db, but no documentation or research has gotten me any closer to a solution.
This is a node. js driver (Asynchronous, non-blocking SQLite3 bindings) for sqlite3. It is written in JavaScript, does not require compiling. It provides all most all connection/query from SQLit3. This is probably one of the best modules used for working with SQLite3 database and the module is actively maintained.
A standalone command-line shell program called sqlite3 is provided in SQLite's distribution. It can be used to create a database, define tables, insert and change rows, run queries and manage an SQLite database file. It also serves as an example for writing applications that use the SQLite library.
The amount of web traffic that SQLite can handle depends on how heavily the website uses its database. Generally speaking, any site that gets fewer than 100K hits/day should work fine with SQLite. The 100K hits/day figure is a conservative estimate, not a hard upper bound.
Just chipping in what solved it for me. This was happening whenever I had a data viewer application looking at the database. Once closed, it began working again!
I suspect you understand Node\Sqlite correctly. I had the same problem using Sqlite3#serialize. I ended up not using it in the end, and instead used the pattern in chapter 7.2.2 of Mixu's Node Book. to control the flow of the db queries. Basically you have an array of functions. Each function has a callback that invoke the next function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With