adi
Posts: 0
Joined: Tue Jun 26, 2012 8:09 pm

phonegap database API

HI Max,
the Phonegap API does not work. and when i mean does not work i mean i cannot see the prints of querySuccess function, which suppose to print the DB content.

this is how i invoke the API, this code runs when you click the "Show My Location" button:
var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
db.transaction(populateDB, errorCB, successCB);

this are the public functions:

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")');
}

function errorCB(err) {
alert("Error processing SQL: " + err);
}

function successCB() {
alert("success!");
}

function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}

function querySuccess(tx, results) {
// this will be empty since no rows were inserted.
alert("Insert ID = " + results.insertId);
// this will be 0 since it is a select statement
alert("Rows Affected = " + results.rowAffected);
// the number of rows returned by the select statement
alert("Insert ID = " + results.rows.length);
}

function errorCB(err) {
alert("Error processing SQL: " + err.code);
}

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

phonegap database API

Thanks.. we'll test this. Can you also tell us on which device you tried this?

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

phonegap database API

Can you share the app for collaboration with a href="mailto:support@tiggzi.com" rel="nofollow"support@tiggzi.com/a?

adi
Posts: 0
Joined: Tue Jun 26, 2012 8:09 pm

phonegap database API

Hi Max, shared. device used for testing is samsung S2 android version 4.0.3

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

phonegap database API

The problem is in function querySuccess(tx, results), in row

code
alert("Insert ID = " + results.insertId);
/code

From PhoneGap documentation
[quote:]
"The result object has three properties. The first is the insertId which will return the row number of a success SQL insert statement. If the SQL statement is not an insert then the insertId is not set."
[/quote]
http://docs.phonegap.com/en/1.0.0/pho...

In your code, you fetch data from the database via "SELECT" sql statement and then try "results.insertId" property, where an "INVALID_ACCESS_ERR" error occurs.

"results.insertId" property should only be accessed after INSERT SQL statement.

adi
Posts: 0
Joined: Tue Jun 26, 2012 8:09 pm

phonegap database API

Got you Max, thank you!
i just used the coded "as is" from the phonegap API samples, i will revise it now.

Return to “Issues”