This is a migrated thread and some comments may be shown as answers.

SQLite execution fire after normal javascript code?

5 Answers 43 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Tim
Top achievements
Rank 1
Tim asked on 21 Mar 2014, 02:26 PM
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);
    }); 
}

5 Answers, 1 is accepted

Sort by
0
Tim
Top achievements
Rank 1
answered on 21 Mar 2014, 03:11 PM
Push.
0
Tim
Top achievements
Rank 1
answered on 21 Mar 2014, 03:43 PM
Any luck?
0
Zdravko
Telerik team
answered on 26 Mar 2014, 10:21 AM
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.

 
0
Tim
Top achievements
Rank 1
answered on 26 Mar 2014, 03:20 PM
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.
0
Kaloyan
Telerik team
answered on 28 Mar 2014, 02:11 PM
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.

 
Tags
General Discussion
Asked by
Tim
Top achievements
Rank 1
Answers by
Tim
Top achievements
Rank 1
Zdravko
Telerik team
Kaloyan
Telerik team
Share this question
or