I used sqlite to populate a DB with some Tables in it. I made a function at another javascript page that executes the database & selects some values from the table. The function is called at $(document).ready().
Javascript:
//DB Population
function onDeviceReady() {
var db = window.openDatabase("Database", "1.0", "SqliteTrial", 20000);
db.transaction(populateDB, errorCB, successCB);
}
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS Subjects');
tx.executeSql('CREATE TABLE IF NOT EXISTS Subjects (id unique, subjectname)');
tx.executeSql('INSERT INTO Subjects (id, subjectname) VALUES (1, "Math")');
tx.executeSql('INSERT INTO Subjects (id, subjectname) VALUES (2, "Science")');
}
function GetSubjectsFromDB()
{
console.log("");
tx.executeSql('SELECT * FROM Subjects', [], queryNSuccess, errorCB);
}
function queryNSuccess(tx, results) {
alert("Query Success");
console.log("Returned rows = " + results.rows.length);
if (!results.rowsAffected) {
console.log('No rows affected!');
return false;
}
console.log("Last inserted row ID = " + results.insertId);
}
function errorCB(err) {
alert("Error processing SQL: "+err.code);
}
Is there some problem with this line?
tx.executeSql('SELECT * FROM Subjects', [], queryNSuccess, errorCB);
The queryNSuccess isn't called, neither is the errorCB so I don't know what's wrong.
This is how I call it at another page:
Javascript:
$(document).ready(function () {
DisplayData();
GetSubjectsFromDB(tx);
});
GetSubjectsFromDB). Please show this code instead.