SQLite execution fire after normal javascript code?

6 posts, 0 answers
  1. Tim
    Tim avatar
    57 posts
    Member since:
    Oct 2013

    Posted 21 Mar 2014 Link to this post

    Dear all,

    I've been spending some time trying to fix the underneath ambiguity, I reckon it's not a bug or error but just due to my lack of understanding on the nature of SQLite, hope someone can kindly point me to the right direction.

    What I'm trying to achieve is, in the following functionA, I'll return a value to the variable "realpw" in which the value is obtained by a function from SQLite database called app.logincheck. I also used an alert to check value. However, the problem occurs here, the alert(realpw) always reveal as undefined... In fact, I also have an other alert in my app.logincheck function to make sure when the db is opened (see code below), and the second alert occured only after the functionA is finished.

    Simply put, I was expecting app.logincheck to fire inside functionA. But what it can turn out is firing after functionA, any thought? Appreciate in advance for anyhelp!

    functionA = function(){
        $('#login').submit(function () { 
                    var realpw = app.logincheck($('#userName').val());
                    alert(realpw);
                     if (realpw === String($('#pwd').val())){
                            //Some functions that are not relevant here.
                    }
                    else{ alert('Invalid Login Credentials.'); }                    
        return false;
        });
    },    

    //SQLite javascript from other page
    app.logincheck = function(drivername){
        var render = function (tx, rs){                
            var row = rs.rows.item(0);
            var realpw = String(row.Password);
            return realpw;
        }

    var db = app.db;
    db.transaction(function(tx) {
        tx.executeSql("SELECT ID, DriverName, Password FROM table1 WHERE DriverName=? ORDER by ID DESC", [drivername], 
             render, 
             app.onError);
        }); 
    }
  2. Tim
    Tim avatar
    57 posts
    Member since:
    Oct 2013

    Posted 21 Mar 2014 Link to this post

    Push.
  3. Tim
    Tim avatar
    57 posts
    Member since:
    Oct 2013

    Posted 21 Mar 2014 Link to this post

    Any luck?
  4. Zdravko
    Admin
    Zdravko avatar
    657 posts

    Posted 26 Mar 2014 Link to this post

    Hi Tim,

    Thanks for contacting us.
    I would suggest using debug in simulator  and debug on device features in order to investigate similar issues.
    From first sight I think that you don't return your realpw value from app.logincheck function.

    If you still need further assistance please provide us your project name or the project itself in a private ticket so we could take a look, even though debugging a third party software is not in the scope of the support service.
    Thanks.

    Regards,
    Zdravko
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET. Seats are limited.

     
  5. Tim
    Tim avatar
    57 posts
    Member since:
    Oct 2013

    Posted 26 Mar 2014 in reply to Zdravko Link to this post

    Thanks for the reply,

    It's actually due to the asynchronous nature of Ajax, line codes are being fired almost simultaneously so that my realpw can never actually wait long enough to obtain the value from function. It's solved by rearranging the orders of codes.
  6. Kaloyan
    Admin
    Kaloyan avatar
    872 posts

    Posted 28 Mar 2014 Link to this post

    Hi Tim,

    Should we consider the issue as resolved or you are still facing it and need our assistance? Please, if you need us to investigate further, give us the name of a project inside your account where this is reproducible. Also, note it is recommended to provide this information in a separate support ticket in order to keep any sensitive information safe.

    Thank you for the clarification in advance.

    Regards,
    Kaloyan
    Telerik
     

    Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET. Seats are limited.

     
Back to Top