node-sqlite3 icon indicating copy to clipboard operation
node-sqlite3 copied to clipboard

What happen if I do not pass a argument to #run and it get a error?

Open mageddo opened this issue 11 years ago • 3 comments

The #run method throw a exception or the error pass.?

mageddo avatar Oct 27 '15 16:10 mageddo

Do you mean this?

var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database(':memory:');

try { db.run(); }
catch (e) {
  console.log('got exception');
  console.log(e);
}

Output:

got exception
[TypeError: SQL query expected]

Graham--M avatar Nov 05 '15 00:11 Graham--M

Ok, but if I execute a invalid query a got a unhandled exception, is there others uhandleded exceptions cases that happens with this aproach?

db.run("INSERT INTO bookmark (id) VALUES (1)");
...
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: SQLITE_ERROR: no such table: bookmark
    at Error (native)

mageddo avatar Nov 13 '15 13:11 mageddo

I think I understand your original question now. You were asking if you can pass a callback method without having to pass a query parameters argument [param, ...].

db.run("INSERT INTO bookmark (id) VALUES (1)", function(err) {
  if (err)
    console.log(err.message);
  console.log("Finished callback");
});
SQLITE_ERROR: no such table: bookmark
Finished callback

The node-sqlite3 code checks if the last parameter is a function and uses that as the callback, so you can skip the optional parameters in-between and not have to use exceptions.

Graham--M avatar Nov 15 '15 19:11 Graham--M