Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8322373
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:22:12+00:00 2026-06-08T23:22:12+00:00

Hey I’m using phonegap databases, and trying to understand why my callback is called

  • 0

Hey I’m using phonegap databases, and trying to understand why my callback is called before the process method has finished, below is the js code and the log which indicates my claim

Here is the code:(Method that is called first, is insertIntoDB(x,y);)

    var databaseVersion = 1;

function createTable(tx, tableName, tableColumns){
    var sqlStatement = 'CREATE TABLE IF NOT EXISTS '+tableName+' (_id unique, ' + tableColumns+')';
    tx.executeSql('DROP TABLE IF EXISTS '+tableName);
    tx.executeSql(sqlStatement);
    console.log('now doInsertion (if successful should be called');
}

function createMenuDataBase(tx){
    var tableName ="element";
    var tableColumns = ["name", "resource","remoteData", "picture", "pageId", "type", 
        "localAction", "replaceText", "textSize", "textColor","background", "sortOrder"];
    createTable(tx, tableName, tableColumns);
}



function insertIntoDB(tableName,json){
    checkDatabaseVersion(doInsertion,tableName,json);
}

function doInsertion(dbName,json){
    console.log('starting doInsertion');
    var sqlStart = "INSERT INTO "+dbName+" (";
    var sqlEnd =");"
    $.each(json.list, function(i, object) {
        var first = true;
        var columns="";
        var values = ") VALUES ("

        for (property in object) {
            //            alert(property);
            if(property!=undefined){

                if(first){
                    columns +=property;
                    values +=object[property];
                    first=false;
                } else {   
                    columns += ', '+property;
                    values +=', '+object[property];
                }
            }
        }
        console.log(sqlStart+columns+values+sqlEnd);
    });
}

function checkDatabaseVersion(callback,dbName,json){
    var localDatabaseVersion = localStorage.getItem("localDatabaseVersion");
    alert(localDatabaseVersion);
    if(localDatabaseVersion == 'undefined' || localDatabaseVersion == null){
        var db = window.openDatabase("Database", "1.0", "PhoneGap Demo", 200000);
        db.transaction(createMenuDataBase, errorCB, callback(dbName,json));


    //localStorage.setItem("localDatabaseVersion",databaseVersion);
    }
}

And here is the logcat from cordova/my app:

08-01 12:09:02.857: D/DroidGap(24433): onMessage(spinner,stop)
08-01 12:09:03.467: D/CordovaLog(24433): starting doInsertion
08-01 12:09:03.467: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 24 : starting doInsertion
08-01 12:09:03.472: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.9747386311565038, null, 9765, img, 1, 0, null, /content/picture/menu/product, null, null, mainMenu.menu, showProductCatalog(product), null, Y, 0);
08-01 12:09:03.477: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.9747386311565038, null, 9765, img, 1, 0, null, /content/picture/menu/product, null, null, mainMenu.menu, showProductCatalog(product), null, Y, 0);
08-01 12:09:03.477: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.9847155498013517, null, 9753, img, 1, 1, null, /content/picture/menu/social, null, null, mainMenu.menu, showSocialMedia(socialmedia), null, Y, 0);
08-01 12:09:03.477: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.9847155498013517, null, 9753, img, 1, 1, null, /content/picture/menu/social, null, null, mainMenu.menu, showSocialMedia(socialmedia), null, Y, 0);
08-01 12:09:03.482: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.5451258043474583, null, 9759, img, 1, 2, null, /content/picture/menu/store, null, null, mainMenu.menu, menu(store), null, Y, 0);
08-01 12:09:03.482: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.5451258043474583, null, 9759, img, 1, 2, null, /content/picture/menu/store, null, null, mainMenu.menu, menu(store), null, Y, 0);
08-01 12:09:03.482: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.6883956226802171, null, 9762, img, 1, 3, null, /content/picture/menu/showroom, null, null, mainMenu.menu, showCollection(collection), null, Y, 0);
08-01 12:09:03.482: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.6883956226802171, null, 9762, img, 1, 3, null, /content/picture/menu/showroom, null, null, mainMenu.menu, showCollection(collection), null, Y, 0);
08-01 12:09:03.487: D/CordovaLog(24433): INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.21612715546682493, null, 9768, img, 1, 4, null, /content/picture/menu/beskeder, null, null, mainMenu.menu, showNotificationList(notificationList), null, Y, 0);
08-01 12:09:03.487: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 46 : INSERT INTO element (name, resource, id, type, appId, sortOrder, background, picture, textColor, remoteData, pageId, localAction, replaceText, active, textSize) VALUES (menu0.21612715546682493, null, 9768, img, 1, 4, null, /content/picture/menu/beskeder, null, null, mainMenu.menu, showNotificationList(notificationList), null, Y, 0);
08-01 12:09:03.497: D/CordovaLog(24433): now doInsertion (if successful should be called
08-01 12:09:03.497: D/CordovaLog(24433): file:///android_asset/www/js/Database.js: Line 7 : now doInsertion (if successful should be called
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T23:22:14+00:00Added an answer on June 8, 2026 at 11:22 pm

    You are calling the callback instead of passing it:

    db.transaction(createMenuDataBase, errorCB, callback(dbName,json));
    
    callback(dbName,json) //Calls the function and passes the result to `db.transaction` as callback but it's not a function since the result is not a function.
    

    Try this:

    db.transaction(createMenuDataBase, errorCB, callback);
    

    Or in case callback needs those arguments then:

    db.transaction(createMenuDataBase, errorCB, callback.bind( null, dbName, json ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey folks I am trying to implement a search functionality in a website using
Hey trying to get a validation check working on a boolean field called 'activated'.
Hey I'm using Phonegap' FileTransfer. And I get a 401 code 3 error (unauthorized)
Hey all i am trying to search through a CSV file using the following
*Hey , I have finished developing my app In my iphone apps I have
Hey guys I am making a terminal application using Swing and Apache Commons. I
Hey all i have an XML file that i am trying to loop though.
Hey guys here is my question. im using JCombobox. if a student have CB
Hey can we hide/show tab layout on button click which will be placed below
Hey there, I'm writing a python plugin for a geo referencing program called QGIS

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.