I am using Phonegap sqlite.
I have one table in my database named "Phone" in which I have 3 columns.
Table structure is:
ID PhoneName Version
1 A 1.3
2 B 3.4
I am getting the value of ID.
How do I retrieve the value of PhoneName from table?
Using cordova 2.7.0 I did it the following way.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady()
{
app.initialize();
getSingleRow(10);
getMultipleRows();
}
//Single row
function getSingleRow(id)
{
db.transaction
(
function (tx)
{
tx.executeSql
(
'SELECT ColumnName FROM tableName WHERE ID=?',
[id],
function(tx,results)
{
var len = results.rows.length;
if(len>0)
{
alert(results.rows.item(0)['ColumnName']);
}
}, errorCB
);
},errorCB,successCB
);
}
//Multiple records
function getMultipleRows()
{
db.transaction
(
function (tx)
{
tx.executeSql
(
'SELECT ColumnName FROM tableName',
[],
function(tx,results)
{
var len = results.rows.length;
if(len>0)
{
for (var i = 0; i < len; i++)
{
alert(results.rows.item(i)['ColumnName']);
}
}
}, errorCB
);
},errorCB,successCB
);
}
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With