I am working on a phonegap application and have the follwoing code:
db = window.openDatabase("AjansDB", "1.0", "Ajans app DB", 2*1024*1024);
//creation
db.transaction(function (tx) {
var sql='CREATE TABLE IF NOT EXISTS USER_DATA (user_id INTEGER PRIMARY KEY, user_name VARCHAR(20))'
tx.executeSql(sql);
});
//insert
var sql="INSERT INTO USER_DATA (user_id,user_name) VALUES (?,?)";
tx.executeSql(sql,[1,"admin"], successCB, errorCB);
Now here is the problem: every time I select from the table I can retrieve the id but not the name ! The id would return "1" while the name would return "undefined"
db.transaction(function (tx) {
tx.executeSql('SELECT * FROM USER_DATA', [], function (tx, results) {
alert(results.rows.item(0).user_name);
});
});
What is going on wrong?
ps: I am not sure if this is gonna make any difference but I am using ionic and angular.js
Aucun commentaire:
Enregistrer un commentaire