Live
Live

Reputation: 21

Phonegap sqlite issues

I have some problems with my phonegap application.. It would be really nice if someone could explain to me how it's working. Everything with that i've tried to do with sqlite seems not to work i've tried almost every tutorial out.

I think this was the best tutorial.. I don't want to paste all the code so here's the link to that tutorial.

http://yashshah.net/sqlite-tutorial-in-phonegap/

I've done everything in this tutorial and it's not making a DB or giving me even an error.. It's the same thing on the phone (converted) and in browser.

It would be really nice if someone could explain to me what I'm doing wrong..

Upvotes: 0

Views: 108

Answers (1)

vikas agrahari
vikas agrahari

Reputation: 406

You can use this http://docs.phonegap.com/en/2.5.0/cordova_storage_storage.md.html#Storage .here, every thing is explained.

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 queryDB(tx) 
{      
tx.executeSql('SELECT * FROM demo', [], querySuccess, errorCB); 
}
function querySuccess(tx, results) 
{ 
var len = results.rows.length;     
alert("demo table: " + len + " rows found.");  
for (var i=0; i<len; i++)
{       
alert("Row = " + i + " ID = " + results.rows.item(i).id + " Data =  " +   results.rows.item(i).data);       
}    
}    // Transaction error callback   
function errorCB(err)
{        
alert("Error processing SQL: "+err.code); 
}    // Transaction success callback   
function successCB()
{       
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);     
db.transaction(queryDB, errorCB);   
}    // Cordova is ready   
function onDeviceReady() 
{        
var db = window.openDatabase("Database", "1.0", "Cordova Demo", 200000);     
db.transaction(populateDB, errorCB, successCB);    
}  

Upvotes: 1

Related Questions