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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T09:33:13+00:00 2026-06-10T09:33:13+00:00

When I launch code with this query, sometimes I can see all the tables

  • 0

When I launch code with this query, sometimes I can see all the tables listed, sometimes only one and I get always this error:

Query Error: Error: SQLITE_MISUSE: unknown error

I’ve read that SQLITE_MISUSE occurs when SQLITE API is used unproperly. Could you help me, because I can’t find whats wrong in this code.

EDIT. I’ve made changes to the code to get rid of the race issue.

The message with SQLITE_MISUSE wrror still occurs, however the vanishing tables issue is gone. Race in my queries was the case.

Here is the code.

var sqlite3 = require("node-sqlite3");
var fs = require('fs');

var query_count;
var init = function (response) {
    var db = new sqlite3.Database("test.db", function() {

        fs.readFile('./assets/sql/initDB.sql', function(err,data){
            if(err) {
                console.error("Could not open file: %s", err);
                return;
            }

            var query = data.toString('utf8');
            queries = query.split(";");

            db.serialize(function() {
                query_count = queries.length;
                for(var i=0; i<queries.length; i++) {
                    queries[i] = queries[i].replace("\r\n","");
                    db.run(queries[i], function(error) {
                        if(error) {
                            console.log("Query Error: "+error);
                        }

                        query_count--;

                        if( query_count <= 0 ) {
                            db.close();
                            listAllTables(response);
                        }
                    });
                }
            });
        });
    });
};

function listAllTables(response) {
    var db = new sqlite3.Database("./assets/sql/test.db", function () {
        db.all("SELECT name FROM sqlite_master WHERE type = 'table'", function (error, records) {
            for(var record in records) {
                response.write(record+": "+records[record]+"\n");
                for(var prop in records[record]) {
                    response.write("\t"+prop+": "+records[record][prop]+"\n");
                }
            }

            response.end();
            db.close();
        });
    });
}

exports.load_customers = function(response) {
    init(response);
};

The query file initDB.sql is like this:

CREATE TABLE IF NOT EXISTS TemporaryAuthTokens (
  authToken TEXT PRIMARY KEY NOT NULL UNIQUE,
  expireDate NUMERIC NOT NULL);

CREATE  TABLE IF NOT EXISTS User (
  id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE  ,
  login TEXT NOT NULL ,
  pass TEXT NOT NULL ,
  creationDate NUMERIC NOT NULL ,
  authToken TEXT NULL REFERENCES TemporaryAuthTokens(authToken)
  );
  • 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-10T09:33:14+00:00Added an answer on June 10, 2026 at 9:33 am

    You’ve got a race condition; it’s possible that your last query (whose callback closes the connection) will finish before one of the earlier queries did, and that will, needless to say, hose the earlier query. You need to rework your code so that the last query to finish, rather than the last query to start, closes the connection (e.g set a counter to the number of queries and have each query decrement it when it finishes. The one that decrements it to zero closes the connection).

    You might also want to look at the serialize method that’s available on database objects. Right now your initialization queries are all independent of each other, but if you started using foreign-key constraints you’d have trouble if the referenced table hadn’t been created yet, so you’d need to force the order of execution.

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

Sidebar

Related Questions

I have searched a lot about this topic and I can't get this code
I have the following C# code to launch an outlook window. The one think
I have code that is triggered on launch only after the app is upgraded
Launch app from homescreen can't get remote push payload? But launch from Notification Center
In this code C i launch a program from the command line and when
It am trying to launch this code that would normally run from a batch
I found this code to launch the browser with an intent: Intent intent =
I have this code set to run on my app launch: NSRect rect =
Trying to launch and pass tel. no. to skype by this code from my
I'm using this code to launch a .cmd file: try { String line; Process

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.