Uncaught error from appstudioFunctions.js

I am running this code at the beginning of my PWA opening. I have been testing the app all day

function CountTrackingRecords(){
SyncButtonValue('Checking Tracking...');
console.log('enter tracking record count');
DB = SqlOpenDatabase("pts.db3", "1.0", "PTS");
s = new Array(["SELECT COUNT(*) as c FROM tracking;", [], CountTrackingRecordsCallBack]);
Sql(DB, s);
}

function CountTrackingRecordsCallBack(transaction, results)
{
c = results.rows.item(0)['c'];
if (c >= 1)
{
 SyncButtonValue("Alert - There are " + c + " records to sync.");
}
else{
SyncButtonValue("Ready - There are " + c + " records to sync.");
 }
}

I am now getting this error out of the blue. (testing in Chrome)

Error encountered:
Uncaught ReferenceError: error is not defined
Url: http://127.0.0.1:63946/PTS/nsb/library/appstudioFunctions.js
Line: 1542
Column: 65

This is the code at Line 1542 Col 65:

NSB._sqlError = function (lastSQL) {
// returns an appropriate sqlError function give lastSQL
return function (tx, err) {
    NSB.MsgBox("SQlite error:" + err.messages + "( Code " + error.code + ") " + lastSQL);
    return false;
};
};

The JS console show red line under “error.code”

Help! I was supposed to show my client today.

should it be “err.code” instead of “error.code” ?

I dont know. That code line that errors is inside appstudioFunctions.js

Maybe try changing:

s = new Array(["SELECT COUNT(*) as c FROM tracking;", [], CountTrackingRecordsCallBack]);

To

s = new Array(["SELECT COUNT(*) as c FROM tracking;"], [], CountTrackingRecordsCallBack);

Comparing the appstudioFunctions.js that is deployed in Chrome and the appstudioFunctions.js that is in my project “nsb”, they have different NSB._sqlerror functions.

The function in the project nsb folder:

NSB._sqlError = function (lastSQL) {
    // returns an appropriate sqlError function give lastSQL
    return function (tx, err) {
        NSB.MsgBox('SQLite error: {errmsg} (Code {errcode}) {sql}'.supplant({
            "errmsg": err.message,
            "errcode": err.code,
            "sql": lastSQL
        }));
        return false;
    };
};

The function in the deployed appstudioFunctions.js in Chrome

NSB._sqlError = function (lastSQL) {
    // returns an appropriate sqlError function give lastSQL
    return function (tx, err) {
        NSB.MsgBox("SQlite error:" + err.messages + "( Code " + error.code + ") " + lastSQL);
        return false;
    };
};

Why is the deployed code different?

Ryan

I built this app into an apk with VoltBuilder and I get the same error. See the image.

Are you initializing the DB AFTER deviceready ?

document.addEventListener("DOMContentLoaded", onDOMContentLoaded, False)

Function onDOMContentLoaded()
 initDB();
End Function

Function initDB()
 db = SqlOpenDatabase("my.db", "DatabaseName");
 JavaScript 
  db.transaction(function(transaction) {
  transaction.executeSql('CREATE TABLE IF NOT EXISTS......
 End JavaScript 
End Function

I figured out that my initDB() function was not being called. All good now.

Thanks Pro_Certs