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

  • SEARCH
  • Home
  • 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 6056257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:21:22+00:00 2026-05-23T08:21:22+00:00

I have a common routine for clearing out my DB: function clearDB() { //

  • 0

I have a common routine for clearing out my DB:

function clearDB() { // Clears the database based on code in the file "db_definition.js".
    var dwdb_dfd = $.Deferred();
    var idx = 0;

    this.maxDeletes = g_sSQL_dropWorkoutDB.length;
    this.successCount = 0;
    parentThis = this;
    do {
        $.when(transactDB(g_sSQL_dropDB[idx])).done(function() {
            if(parentThis.successCount++ >= parentThis.maxDeletes) dwdb_dfd.resolve();
        });
    } while (++idx < this.maxDeletes);
    return dwdb_dfd.promise();
}

And this routine is called from:

this.getNextDataSet = function() {
    $.when(clearDB()).done(function() {
    window.location.href = 'http://'+ document.location.host + '/webDBBuilder.php'
}

WebDBBuilder.php is a file that reads data from our server and builds/rebuilds the local WebDB (despite the W3C, dammit. We started this long before they abandoned us) from the data available on the server DB. This routine is called when the routine polling the server flags that new data is available. We then destroy certain tables in the local DB — the global var g_sSQL_dropDB is simply an array of DROP TABLE IF EXISTS tbl_someTable strings.

The transactDB() routine is yet another deferred-bearing-function that executes a SQL statement passed to it. The transactDB() is working as required as the tables in question are being deleted properly and it is used throughout the rest of the app. The getNextDataSet() function is part of a larger object. It is being called correctly.

The problem is that the page jump simply never happens. Is this some sort of scope problem with the Deferred object in the clearDB() function?

Is there something in the code I am missing? I’ve tried using done(), resolve(), $.when().then(). Nada.

Any help would be deeply appreciated. I’ve asked a couple of questions in the jQuery forum with basically no responses, so I figured I’d have better luck here with stackoverflow!

<———— Added ————–>

Thanks for the great input. I took the code Julian gave me and (with a minor syntax switch of $.map), it worked beautifully!

And you were right about the “this” reference in the function. I had pulled some code out of a class previously and simply had a brain fart. The var “g_sSQL_dropWorkoutDB” is indeed a global that sits in an included file that holds only the vars used to construct and remove the database.

Julian, thanks a bunch!

Scott.

  • 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-05-23T08:21:23+00:00Added an answer on May 23, 2026 at 8:21 am

    First of all, you can simplify your code greatly:

    function clearDB() {
        return $.when.apply( $, $.map( g_sSQL_dropWorkoutDB, function( _, item ) {
            return transactDB( item );
        }) ).fail(function() {
            console.log( arguments );
        });
    }
    

    Using $.when.apply, you can pass an array of objects to $.when as if they were its arguments. I use $.map to transform the list of items into transactDB objects. I haven’t tested the code, obviously, but it should work.

    Secondly, the way you assign variables to “this” in clearDB is quite suspicious. When you call clearDB like you do in getNextDataSet, “this” is the window object and maxDeletes & successCount are assigned as global variables in the process. Not sure it’s what you intended and it’s definitely not safe.

    Also, is it normal that g_sSQL_dropWorkoutDB is not passed to clearDB as an argument? Global variable or typo?

    Finally, I added a fail callback and I log the arguments. That way, you can check in the console if one of your transactDB calls does not, actually, fail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a common problem of moving our development SQL 2005 database onto shared
I have a common code of serializing a class object in my 3-4 methods
I have a common HTML header file which I use in several PHP files.
I have common functionality that I need to access from all screens of my
I want to create templates for base new reports on to have common designs.
We have several common libs. Ideally we want them all to use the latest
i have several common elements (components), that will generate some html. it seems my
I have a common comms library that i have written to communicate with our
I have a common script which Im including in my PHPcron files and the
I have a common resource, which I want 1 and only 1 instance of

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.