I am working on a camera app using the PhoneGap.
The thing I am trying to accomplish is, that when my app takes a picture and I store the picture in the app directory, I want to insert an entry in the database also with the name of the file, path and uploaded flag entry.
I am having trouble doing this. And I am unsure where the problem is occurring.
The code used to create database and the Table and then insert the entry is shown below. I call the “insertInTable” function after the file is already saved in the app directory.
function insertInTable(name, path)
{
var db = window.openDatabase('taukydb', '1.0', 'Tauky Database', 200000);
db.transaction(populateDB, errorCB, successCB);
//db.transaction(successCB, errorCB, );
//return();
}
function populateDB(tx) {
tx.executeSql('CREATE TABLE IF NOT EXISTS taukytb (name UNIQUE, path, uploaded)');
tx.executeSql('INSERT INTO taukytb (name, path, uploaded) VALUES (filename, filepath, 0)');
}
// Transaction success callback
function successCB() {
alert("Hurrey!!!");
//this is just for testing
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);
db.transaction(queryDB, errorCB);
}
function queryDB(tx) {
tx.executeSql('SELECT * FROM taukytb', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
var len = results.rows.length;
alert(len);
}
// Transaction error callback
function errorCB1(err) {
alert("Error 11111 processing SQL: "+err.code);
//console.log("Error processing SQL: "+err.code);
}
// Transaction error callback
function errorCB(err) {
alert("Error processing SQL: "+err.code);
//console.log("Error processing SQL: "+err.code);
}
When I run this code, the function “succesCB” never gets called, neither the errorCB is called.
Please have a look at this. I am new to mobile development and I have been stuck on this since sometime now.
Thanking in advance
I have made few changes to make it work.
This change will call the
successCBas the query executes fine.This method however will not work as you expect as you are creating second database providing the transaction of that but then querying for the table of first database.
Below is the full source example which creates two database with same table in both
https://gist.github.com/3058562