The database has opened, and the table has created. But I can’t Insert record, I’m useing mozilla sqlite storage:
Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");
let file = FileUtils.getFile("ProfD", ["filef.sqlite"]);
let dbconn = Services.storage.openDatabase(file);
dbconn.executeSimpleSQL('CREATE TABLE IF NOT EXISTS "quicklink" ("id" INTEGER PRIMARY KEY NOT NULL , "name" VARCHAR NOT NULL , "href" VARCHAR NOT NULL )');
var sqlinsert=dbconn.createStatement('INSERT INTO "quicklink" ("name","href") VALUES (:name,:href)');
sqlinsert.params.name = "Something";
sqlinsert.params.href = "URL";
dbconn.close();
I don’t get any error(s) in firebug console, or whit the try{}catch(){} statement. Why? What is the problem whit it?
In general, you CANNOT do database access from client-side Javascript.
There are many exceptions (for example, maybe you’re using Node.js on a server, or maybe you’re using HP WebOS on a local Sqlite database), but I didn’t see anything in your post about your environment or database connectivity.
Assuming you CAN legitimately connect to a database with Javascript in your environment, I don’t see where you’re executing the prepared SQL statement.
Suggestions:
Please specify the database and database library you’re using
Please show us the “execute” statement and corresponding error handler
Please cut/paste any error messages you’re getting in the error handler or in the database log.
ADDENDUM:
OK – I’m with you now:
1) You’re using the Mozilla “Storage” API.
2) You need to call “executeStatement()” after your “createStatement()”.
3) You should also have a “handleError” function.
The documentation and sample code is here:
http://developer.mozilla.org/En/Storage