Reputation: 219
I have the following code for my sqlite to store a name and image from camera. I know from the Eclipse console that I am getting the name and image path. The console.log(addRecord) is getting the name and image path but I am getting a "cannot executeSql of undefined" message on the transaction line and on the queryDB function so I think I am making a mistake with my insert statement? Also, is the datatype text correct for imageURI?. Any help appreciated.
function onDeviceReady() {
var db = window.openDatabase("database", "1.0", "Profiles", 5000);
if(db) {
console.log('The device is ready');
db.transaction(populateDB, errorCB, successCB, insertRecord); // only do stuff if db exists
}
else{
console.log('There is a problem');
}
function populateDB(tx) {
tx.executeSql('DROP TABLE IF EXISTS USERS');//get rid of this once working?
tx.executeSql('CREATE TABLE IF NOT EXISTS USERS (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, username VARCHAR NOT NULL, imagePath TEXT)');
console.log('The table USERS is created');
}
//Insert the details
function insertRecord(tx) {
userName = document.getElementById('userName').value;
imagePath;
var addRecord = 'INSERT INTO USERS (username, imagePath) VALUES ("' + userName + '","' + imagePath + '")';
console.log(addRecord);
tx.executeSql(addRecord, [userName, imagePath], queryDB, errorCB);
}
// Query the database
function queryDB(tx) {
var getUsers = "SELECT * FROM USERS ORDER BY id ASC', [], querySuccess, errorCB";
db.transaction(function (tx) {
tx.executeSql(getUsers, [], querySuccess, queryFailure);
}, errorCB, successCB);
}
// Query the success callback
function querySuccess(tx, results) {
console.log("You are in the querysuccess function");
}
// Transaction error callback
function errorCB(err) {
console.log("Error processing SQL: " + err.code);
}
function queryFailure(err) {
console.log("Error processing SQL: " + err.code);
}
// Transaction success callback
function successCB() {
console.log('The db and table are working');
}
Upvotes: 0
Views: 668
Reputation: 700830
The identifier queryFailure
is undefined. Add the function:
function queryFailure(tx, results) {
console.log("You are in the queryFailure function");
}
Once you get it running, you will see that the queryFailure
function is called, because you have an error in the query. This:
var getUsers = "SELECT * FROM USERS ORDER BY id ASC', [], querySuccess, errorCB";
should be:
var getUsers = "SELECT * FROM USERS ORDER BY id ASC";
Upvotes: 1