The statement in your code will not be executed if you have not included the sqlite plugin in your project.
var db = window.sqlitePlugin.openDatabase({name: "test.db"});
You should also wait for the deviceready event to fire before using cordova plugins.
You can use the window.openDatabase () call, which creates sqlite DB and does not need the sqlite plugin.
Below is the code for using the openDatabase call in your application.
if your sqlite plugin is working correctly then change the db call to.
var db = window.sqlitePlugin.openDatabase({name: "test.db"});
which does not use the sqlite plugin.
// Wait for device API libraries to load // document.addEventListener("deviceready", onDeviceReady, false); // device APIs are available // function onDeviceReady() { var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000); db.transaction(populateDB, errorCB, successCB); } // Populate the database // function populateDB(tx) { tx.executeSql('DROP TABLE IF EXISTS DEMO'); tx.executeSql('CREATE TABLE IF NOT EXISTS DEMO (id unique, data)'); tx.executeSql('INSERT INTO DEMO (id, data) VALUES (1, "First row")'); tx.executeSql('INSERT INTO DEMO (id, data) VALUES (2, "Second row")'); } // Transaction error callback // function errorCB(err) { alert("Error processing SQL: "+err); } // Transaction success callback // function successCB() { alert("success!"); }
The above code snippet is taken from the Cordoba API document. See here for more details. Although the documentation is rated at 3.0, it should work at 3.5
frank source share