What’s the “best” method to supply a statement with mutliple parameters? I want to insert a single line into an SQLite database.
Adapting https://developer.mozilla.org/en/Storage#Binding_Parameters I thought the following would work:
var conn = Services.storage.openDatabase(dbfile); // Will also create the file if it does not exist
let statement = conn.createStatement("INSERT INTO persons (name, email, city) VALUES (:name, :email, :city)");
statement.params.name = myName;
statement.params.email = myEmail;
statement.params.city = myCity;
But obviously I can’t even create the statement itself:
Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [mozIStorageConnection.createStatement]
After that I’d like to execute it asynchronously…
There is nothing wrong with the code you show here – it works correctly. However,
createStatementwill validate the SQL code and throw anNS_ERROR_FAILUREerror if that code is invalid. In your case either the tablepersonsdoesn’t exist or not all of the fieldsname,emailandcityexist in it. You should take a look at thelastErrorStringattribute to see the error message: