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 6898719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:19:55+00:00 2026-05-27T07:19:55+00:00

I’m trying to write a way to synchronously execute a set of sqlite queries

  • 0

I’m trying to write a way to synchronously execute a set of sqlite queries within a WebDB environment. I’ve come up with what I think amounts to a synchronous routine, but I’m not sure how to test it. Here’s what I have:

var db = openDatabase("test1", "1.0", "test", 5 * 1024 * 1024);

function synchronousSql(tx, sqlStack, callback) {
    if (sqlStack.length !== 0) {
        var q = sqlStack.shift();
        console.log(+new Date() + ' ' + q);
        tx.executeSql(q, [], synchronousSql(tx, sqlStack, callback), null);
    } else {
        callback();
    }
}

var seq = [
    'drop table if exists table1',
    'drop table if exists table2',
    'drop table if exists table3',
    'drop table if exists table4',
    'drop table if exists table5',
    'create table table1(id integer, value text)',
    'create table table2(id integer, value text)',
    'create table table3(id integer, value text)',
    'create table table4(id integer, value text)',
    'create table table5(id integer, value text)',
    'drop table if exists table1',
    'drop table if exists table2',
    'drop table if exists table3',
    'drop table if exists table4',
    'drop table if exists table5'
    ];

db.transaction(function(tx) {
    synchronousSql(tx, seq, function() {
        console.log(+new Date() + ' - from synchronousSql callback');
    });
}, null, function() {
     console.log(+new Date() + ' - from transaction callback');   
});

On paper (I think) it should work. Looking at it, I think my alert message will pop up when the final statement is executed, not necessarily when it returns, but I’m not sure how to fix that. I tried specifying a callback in my arguments for the synchronousSql function but that meant I had to call it recursively with a callback, and if I used an empty anonymous function it seemed to overwrite the desired callback.

So I guess two questions: first, is this really synchronous; and second, how can I implement a final callback to run on the last callback of the stack?

edit: updated the code to a more recent version. First question still stands, though: is this truly synchronous?

  • 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-27T07:19:55+00:00Added an answer on May 27, 2026 at 7:19 am

    Put an alert() and a setTimeout() in your code to test whether they all execute at the same time or get separated. That’s usually a pretty good way to test it. If all code gets executed at the same time (async) then you’ll instantly have 10 alerts to hide – else you get one per x ms.

    On your second question: just check whether the stack is empty. You’ll probably have to pass a third variable through your function though. Unless you define the variable on the global scope, it won’t get overwritten.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.