Alasql: AUTOINCREMENT for INDEXEDDB does not seem to work

Created on 6 Apr 2017  路  6Comments  路  Source: agershun/alasql

Using alasql 0.3.9 in browser (Firefox, Chrome).
The code below prints out the contents of the table, but no value is assigned to aid:

alasql.promise( 'CREATE INDEXEDDB DATABASE IF NOT EXISTS geo2;'+
                'ATTACH INDEXEDDB DATABASE geo2;'+
                'USE geo2;'+
                'DROP TABLE IF EXISTS autoinctab;'+
                'CREATE TABLE IF NOT EXISTS autoinctab (aid INT AUTOINCREMENT, aname STRING);'+
                'INSERT INTO autoinctab (aname) VALUES ("bar1"),("bar2");')
       .then ( function() {
           alasql.promise('SELECT * FROM autoinctab')
                 .then ( function(res) {  console.log("res:"+JSON.stringify(res)); } )
                 .catch( function(err) {  console.log("err:"+err); } )
       })
       .catch( function(err) { console.log(err); })

Result:
res:[{"aname":"bar1"},{"aname":"bar2"}]

I was expecting something like this:
res:[{"aid":0,"aname":"bar1"},{"aid":1,"aname":"bar2"}]

! Bug Code provided to reproduced Good first issue Help wanted

All 6 comments

Might be relate to #462 where AUTOINCREMENT was not working for localstorage

I think the problem is deeper than AUTOINCREMENT. It seems table rows are determined by the INSERT statement, not the CREATE TABLE statement. Create a table with 3 columns, but only insert data into 1 column (aname). Each row only has 1 column (aname); it should have 3 columns with the other, non-specified columns containing NULL values:

alasql.promise( 'CREATE INDEXEDDB DATABASE IF NOT EXISTS geo2;'+
                'ATTACH INDEXEDDB DATABASE geo2;'+
                'USE geo2;'+
                'DROP TABLE IF EXISTS autoinctab;'+
                'CREATE TABLE IF NOT EXISTS autoinctab (aid INT, aname STRING, bname STRING);'+
                'INSERT INTO autoinctab (aname) VALUES ("bar1"),("bar2");')
       .then ( function() {
           alasql.promise('SELECT * FROM autoinctab')
                 .then ( function(res) {  console.log("res:"+JSON.stringify(res)); } )
                 .catch( function(err) {  console.log("err:"+err); } )
       })
       .catch( function(err) { console.log(err); })

Gives the same result as above:

Result:

res:[{"aname":"bar1"},{"aname":"bar2"}]

I was expecting something like this:

res:[{"aid":NULL,"aname":"bar1","bname":NULL},{"aid":NULL,"aname":"bar2","bname":NULL}]

@rexx-org Thank you for looking into this. Values that are null will never be part of the output from Alasql.

any update on this

@SathishRamV No update on this. PRs very welcome.

if alasql is having capability to alter indexeddb , we can use old indexeddb method to add id and we can alter the current table.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AmyBlankenship picture AmyBlankenship  路  6Comments

carloszimm picture carloszimm  路  3Comments

Serge-SDL picture Serge-SDL  路  4Comments

umasudhan picture umasudhan  路  4Comments

SamanthaAdrichem picture SamanthaAdrichem  路  4Comments