From 824fa3ec31d1eb95d429d48221279d0050df92dd Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Aug 2026 11:32:00 +0000 Subject: [PATCH 1/4] Initial plan From 24b0870894c7ed04be4b9a8ed89d1be6be5e6c19 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 20 Aug 2026 11:39:01 +0000 Subject: [PATCH 2/4] Fix AUTOINCREMENT for IndexedDB (issue #861) Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com> --- src/91indexeddb.js | 19 +++++++++++++++ test/test861.js | 58 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 test/test861.js diff --git a/src/91indexeddb.js b/src/91indexeddb.js index efb3b97e41..798944604b 100755 --- a/src/91indexeddb.js +++ b/src/91indexeddb.js @@ -350,6 +350,25 @@ IDB.intoTable = function (databaseid, tableid, value, columns, cb) { var ixdb = request.result; var tx = ixdb.transaction([tableid], 'readwrite'); var tb = tx.objectStore(tableid); + // Apply AUTOINCREMENT / IDENTITY values before inserting + if (table && table.identities) { + for (var columnid in table.identities) { + var ident = table.identities[columnid]; + for (var i = 0; i < value.length; i++) { + var userProvided = + typeof value[i][columnid] !== 'undefined' && value[i][columnid] !== null; + if (!userProvided) { + value[i][columnid] = ident.value; + } + // Advance counter: if the inserted value is >= current, sync counter past it + if (userProvided && +value[i][columnid] >= ident.value) { + ident.value = +value[i][columnid] + ident.step; + } else { + ident.value += ident.step; + } + } + } + } for (var i = 0, ilen = value.length; i < ilen; i++) { tb.add(value[i]); } diff --git a/test/test861.js b/test/test861.js new file mode 100644 index 0000000000..f77632e9df --- /dev/null +++ b/test/test861.js @@ -0,0 +1,58 @@ +if (typeof exports === 'object') { + var assert = require('assert'); + var alasql = require('..'); +} else { + __dirname = '.'; +} + +// IndexedDB tests only run in a browser environment +if (typeof exports != 'object') { + describe('Test 861 - AUTOINCREMENT for IndexedDB', function () { + it('1. AUTOINCREMENT column should be populated on INSERT', async () => { + const sql = alasql.promise; + + await sql(` + CREATE INDEXEDDB DATABASE IF NOT EXISTS test861; + ATTACH INDEXEDDB DATABASE test861; + USE test861; + DROP TABLE IF EXISTS autoinctab; + CREATE TABLE IF NOT EXISTS autoinctab (aid INT AUTOINCREMENT, aname STRING); + `); + + await sql('INSERT INTO autoinctab (aname) VALUES ("bar1"),("bar2")'); + + const res = await sql('SELECT * FROM autoinctab'); + + assert.strictEqual(res.length, 2); + assert.strictEqual(res[0].aid, 1); + assert.strictEqual(res[0].aname, 'bar1'); + assert.strictEqual(res[1].aid, 2); + assert.strictEqual(res[1].aname, 'bar2'); + + await sql('DROP INDEXEDDB DATABASE test861'); + }); + + it('2. AUTOINCREMENT continues incrementing across multiple INSERTs', async () => { + const sql = alasql.promise; + + await sql(` + CREATE INDEXEDDB DATABASE IF NOT EXISTS test861b; + ATTACH INDEXEDDB DATABASE test861b; + USE test861b; + DROP TABLE IF EXISTS autoinctab2; + CREATE TABLE IF NOT EXISTS autoinctab2 (aid INT AUTOINCREMENT, aname STRING); + `); + + await sql('INSERT INTO autoinctab2 (aname) VALUES ("row1")'); + await sql('INSERT INTO autoinctab2 (aname) VALUES ("row2")'); + + const res = await sql('SELECT * FROM autoinctab2'); + + assert.strictEqual(res.length, 2); + assert.strictEqual(res[0].aid, 1); + assert.strictEqual(res[1].aid, 2); + + await sql('DROP INDEXEDDB DATABASE test861b'); + }); + }); +} From 40acc2d125cc7d20ba5a20b8581b8d1ae06e1326 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 25 Aug 2026 08:56:18 +0000 Subject: [PATCH 3/4] Address review feedback: fix assertions and guard identity loop Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com> --- src/91indexeddb.js | 4 ++-- test/test861.js | 10 ++-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/91indexeddb.js b/src/91indexeddb.js index 798944604b..844e6d66b1 100755 --- a/src/91indexeddb.js +++ b/src/91indexeddb.js @@ -350,8 +350,8 @@ IDB.intoTable = function (databaseid, tableid, value, columns, cb) { var ixdb = request.result; var tx = ixdb.transaction([tableid], 'readwrite'); var tb = tx.objectStore(tableid); - // Apply AUTOINCREMENT / IDENTITY values before inserting - if (table && table.identities) { + // Apply AUTOINCREMENT / IDENTITY values before inserting (only when table has identity columns) + if (table && table.identities && Object.keys(table.identities).length > 0) { for (var columnid in table.identities) { var ident = table.identities[columnid]; for (var i = 0; i < value.length; i++) { diff --git a/test/test861.js b/test/test861.js index f77632e9df..1543edc58a 100644 --- a/test/test861.js +++ b/test/test861.js @@ -23,11 +23,7 @@ if (typeof exports != 'object') { const res = await sql('SELECT * FROM autoinctab'); - assert.strictEqual(res.length, 2); - assert.strictEqual(res[0].aid, 1); - assert.strictEqual(res[0].aname, 'bar1'); - assert.strictEqual(res[1].aid, 2); - assert.strictEqual(res[1].aname, 'bar2'); + assert.deepStrictEqual(res, [{aid: 1, aname: 'bar1'}, {aid: 2, aname: 'bar2'}]); await sql('DROP INDEXEDDB DATABASE test861'); }); @@ -48,9 +44,7 @@ if (typeof exports != 'object') { const res = await sql('SELECT * FROM autoinctab2'); - assert.strictEqual(res.length, 2); - assert.strictEqual(res[0].aid, 1); - assert.strictEqual(res[1].aid, 2); + assert.deepStrictEqual(res, [{aid: 1, aname: 'row1'}, {aid: 2, aname: 'row2'}]); await sql('DROP INDEXEDDB DATABASE test861b'); }); From 89bbac16d9677aaa9e154d52dac64498d324099a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 25 Aug 2026 09:38:49 +0000 Subject: [PATCH 4/4] Fix formatting of test861.js to pass yarn test-format-all Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com> --- test/test861.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/test861.js b/test/test861.js index 1543edc58a..0177d18c99 100644 --- a/test/test861.js +++ b/test/test861.js @@ -23,7 +23,10 @@ if (typeof exports != 'object') { const res = await sql('SELECT * FROM autoinctab'); - assert.deepStrictEqual(res, [{aid: 1, aname: 'bar1'}, {aid: 2, aname: 'bar2'}]); + assert.deepStrictEqual(res, [ + {aid: 1, aname: 'bar1'}, + {aid: 2, aname: 'bar2'}, + ]); await sql('DROP INDEXEDDB DATABASE test861'); }); @@ -44,7 +47,10 @@ if (typeof exports != 'object') { const res = await sql('SELECT * FROM autoinctab2'); - assert.deepStrictEqual(res, [{aid: 1, aname: 'row1'}, {aid: 2, aname: 'row2'}]); + assert.deepStrictEqual(res, [ + {aid: 1, aname: 'row1'}, + {aid: 2, aname: 'row2'}, + ]); await sql('DROP INDEXEDDB DATABASE test861b'); });