Jump to content


Photo

sqlite statement not working


  • Please log in to reply
No replies to this topic

#1 ersaurabh101

ersaurabh101
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 12 March 2017 - 02:00 PM

I have only 1 record ( this is - username,password saved in my table)

 

I need to select the username and count the no. of rows but both of the things not working, copying my code below

 

 

SELECT STATEMENT: returning me [object][object]

var selectStatement = "select username FROM loggedinuser";
var result;

function getusername() 

{

    db.transaction(function (tx) { 
        tx.executeSql(selectStatement,[],querySuccess); 
     });

     function querySuccess(tx, results) {

  for(var i=0; i<results.rows.length; i++) {
            var row = results.rows.item;
            result = { id: row['username']};
            alert(result);

            }
         }
    
}

COUNT STATEMENT:  below record is giving me result "1"  at alert(len);

var countStatement = "select COUNT(*) from loggedinuser";

var db = openDatabase("AddressBook", "1.0", "Address Book", 200000);  // Open SQLite Database
var user,password;

function countRecord(tx) {
        db.transaction(function (tx) {
    tx.executeSql('SELECT count(*) FROM loggedinuser', [], querySuccess, errorCB);   
        });   
}

function querySuccess(tx, results) {
    
    var len = results.rows.length;
    alert(len);
}

function errorCB(err) {
    alert("Error processing SQL: "+err.code);
}
        
countRecord();  

Please help..






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users