AlaSQL / alasql

AlaSQL.js - JavaScript SQL database for browser and Node.js. Handles both traditional relational tables and nested JSON data (NoSQL). Export, store, and import data from localStorage, IndexedDB, or Excel.
http://alasql.org
MIT License
7.04k stars 659 forks source link

Multiple asynch queries to IndexedDB fail #1170

Open Sjoerd82 opened 4 years ago

Sjoerd82 commented 4 years ago

I'm brand new to alaSQL, so forgive me if this is a known bug (couldn't find it though), or if I'm doing this wrong..

I have a query that does a UNION on a few IndexedDB tables. This fails with a weird error, so I thought, OK, let just split them into two queries and I'll combine the arrays in JS. If I simply fire either one of the queries it works, but when I fire both queries, I get the same error.

    var qQueryA = 'ATTACH INDEXEDDB DATABASE mydatabase; \
              USE mydatabase; \
           SELECT n.tableA_id \
                , cp.tableB_id \
                , cp.tableB_name \
                , \'queryA\' AS source \
             FROM tableA n \
       INNER JOIN assoc_tableB asoc_cp \
               ON asoc_cp.tableC_id = n.tableC_id \
       INNER JOIN tableB cp \
               ON cp.tableB_id = asoc_tableB_id'

    var qQueryB = 'ATTACH INDEXEDDB DATABASE mydatabase; \
              USE mydatabase; \
           SELECT n.tableA_id \
                , cp.tableB_id \
                , cp.tableB_name \
                , \'queryB\' AS source \
            FROM tableA n \
      INNER JOIN assoc_tableB asoc_cp \
              ON asoc_cp.tableD_id = n.tableD_id \
             AND NOT asoc_cp.tableD_id IS NULL \
      INNER JOIN tableB cp \
              ON cp.tableB _id = asoc_cp.tableB _id'

This fails: alasql([qQueryA,qQueryB]) .then( result => { console.log(result) })

This fails, unless I comment one out: alasql.promise(qQueryA) .then( result => { console.log(result) }) alasql.promise(qQueryB) .then( result => { console.log(result) })

The error is: Uncaught TypeError: Cannot read property '-1630748626' of undefined

Since this is IndexedDB, I probably cannot do these synchronously as a temporary workaround...?

On a side note, I had to specify: AND NOT asoc_cp.tableD_id IS NULL

To avoid inner joining NULLs, kinda unexpected?

Sjoerd82 commented 4 years ago

Update: When I instead of using IndexedDB, use regular objects it works fine. So, it is definitely IndexedDB related.

mathiasrw commented 4 years ago

what happens if you only do the 'ATTACH INDEXEDDB DATABASE mydatabase; \ USE mydatabase;

once?

what happens if you seperate the attach and use part into each own so its

alasql(['ATTACH INDEXEDDB DATABASE mydatabase;', 'USE mydatabase;', qQueryA,qQueryB]) .then( result => { console.log(result) })

(and remove the attach and use part of the queries)