Jump to content
ersaurabh101

sqlite statement not working

Recommended Posts

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.