How to get value from table in sqlite Phonegap

I am using sqlite for Phonegap.

I have one table in my database called "Phone" in which I have 3 columns.

Table structure:

ID PhoneName Version 1 A 1.3 2 B 3.4 

I get the ID value.

How to get PhoneName value from table?

+4
source share
2 answers

Using cordova 2.7.0 I did it as follows.

 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 this helps.

+9
source

Use this.

  function devicereadyFun(){ var dBase = window.sqlitePlugin.openDatabase({ name: 'ebe.db', location: 'default' }); dBase.executeSql("select * from Phone where ID = ?", ['1'], function(rsp){ alert(rsp.rows.item(0).ID); alert(rsp.rows.item(0).PhoneName); alert(rsp.rows.item(0).Version); }); } document.addEventListener('deviceready', devicereadyFun, false); 
0
source

Source: https://habr.com/ru/post/1490055/