PhoneGap android database not working
I'm having problems doing the Database example from PhoneGap. http://docs.phonegap.com/phonegap_storage_storage.md.html#openDatabase
The Problem is, when i run the example to openDatabase and populates he retrieves me the the Success Alert, but when i try to do the select one it gives me an error:
"Error processing SQL:0"
Is there any issue with databases and the android phone that i don't know? I've tried also in the android's emulator and i'm keep getting the same issue.
Can you help me?
Here is the javascript code:
Now i have the following code:
document.addEventListener("deviceready", onDeviceReady, false);
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.code);
}
function successCB() {
alert("success!");
}
function queryDB(tx) {
tx.executeSql('SELECT * FROM DEMO', [], querySuccess, errorCB);
}
function querySuccess(tx, results) {
alert("i'm here =)");
}
function querySuccess(tx, results) {
// this will be empty since no rows were inserted.
console.log("Insert ID = " + results.insertId);
// this will be 0 since it is a select statement
console.log("Rows Affected = " + results.rowAffe开发者_StackOverflow中文版cted);
// the number of rows returned by the select statement
console.log("Insert ID = " + results.rows.length);
}
function onDeviceReady() {
$(document).ready(function() {
$('#submit').click(function() {
alert('clicked');
var db = window.openDatabase("test", "1.0", "Test DB", 1000000);
db.transaction(populateDB, errorCB, successCB);
db.transaction(queryDB, errorCB);
})
});
}
And still have the Succes alert when i do the populate transaction but the Alert of the queryDB has the Error processing SQL:0.
Thanks in advance,
ElkasPS: I'm also using jQuery MobileYou need to check if phonegap is ready:
document.addEventListener("deviceready", onDeviceReady, false);
I just made it. It seems that was a problem of operative system. I made a downgrade to the operative system and now the system works perfectly.
BTW, i had OS X Lion and now OS X Snow Leopard. Maybe the problem wasn't the OS but fixed it for now. When the 10.7.2 comes out I'll upgrade again and give here a reply if its working.
Regards,
Elkas
I Forgot to update this question. With Lion 10.7.2 its working perfectly.
Regards,
Elkas
精彩评论