From e576d6e5a594a0b27c4b80f3a995b7eaacb74268 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 22:36:40 +0000 Subject: [PATCH 1/4] Initial plan From 9407b71b07f8e093d2bef0e1dea96cc77449b4c4 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 22:40:23 +0000 Subject: [PATCH 2/4] Add test2200.js to demonstrate SHOW COLUMNS/INDEX qualified name issue Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com> --- test/test2200.js | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 test/test2200.js diff --git a/test/test2200.js b/test/test2200.js new file mode 100644 index 0000000000..da31439824 --- /dev/null +++ b/test/test2200.js @@ -0,0 +1,81 @@ +if (typeof exports === 'object') { + var assert = require('assert'); + var alasql = require('..'); +} + +var test = '2200'; + +describe('Test ' + test + ' - SHOW COLUMNS and SHOW INDEX with qualified table names', function () { + it('1. Setup test databases and tables', function (done) { + alasql('CREATE DATABASE test2200a'); + alasql('CREATE DATABASE test2200b'); + alasql('USE test2200a'); + alasql('CREATE TABLE table1 (col1 INT, col2 VARCHAR(50))'); + alasql('CREATE INDEX idx_col1 ON table1(col1)'); + alasql('USE test2200b'); + alasql('CREATE TABLE table2 (col3 DECIMAL(10,2), col4 BOOLEAN)'); + alasql('CREATE INDEX idx_col3 ON table2(col3)'); + done(); + }); + + it('2. SHOW COLUMNS with unqualified name (USE context)', function () { + alasql('USE test2200a'); + var res = alasql('SHOW COLUMNS FROM table1'); + assert.equal(res.length, 2); + assert.equal(res[0].columnid, 'col1'); + assert.equal(res[0].dbtypeid, 'INT'); + assert.equal(res[1].columnid, 'col2'); + assert.equal(res[1].dbtypeid, 'VARCHAR'); + assert.equal(res[1].dbsize, 50); + }); + + it('3. SHOW COLUMNS with qualified name (database.table)', function () { + // This test should work regardless of current USE context + alasql('USE test2200b'); + var res = alasql('SHOW COLUMNS FROM test2200a.table1'); + assert.equal(res.length, 2, 'Should return 2 columns'); + assert.equal(res[0].columnid, 'col1'); + assert.equal(res[0].dbtypeid, 'INT'); + assert.equal(res[1].columnid, 'col2'); + assert.equal(res[1].dbtypeid, 'VARCHAR'); + assert.equal(res[1].dbsize, 50); + }); + + it('4. SHOW INDEX with unqualified name (USE context)', function () { + alasql('USE test2200a'); + var res = alasql('SHOW INDEX FROM table1'); + assert.equal(res.length, 1); + assert.ok(res[0].hh, 'Should have index hash'); + }); + + it('5. SHOW INDEX with qualified name (database.table)', function () { + // This test should work regardless of current USE context + alasql('USE test2200b'); + var res = alasql('SHOW INDEX FROM test2200a.table1'); + assert.equal(res.length, 1, 'Should return 1 index'); + assert.ok(res[0].hh, 'Should have index hash'); + }); + + it('6. SHOW COLUMNS with qualified name in different database', function () { + alasql('USE test2200a'); + var res = alasql('SHOW COLUMNS FROM test2200b.table2'); + assert.equal(res.length, 2, 'Should return 2 columns'); + assert.equal(res[0].columnid, 'col3'); + assert.equal(res[0].dbtypeid, 'DECIMAL'); + assert.equal(res[1].columnid, 'col4'); + assert.equal(res[1].dbtypeid, 'BOOLEAN'); + }); + + it('7. SHOW INDEX with qualified name in different database', function () { + alasql('USE test2200a'); + var res = alasql('SHOW INDEX FROM test2200b.table2'); + assert.equal(res.length, 1, 'Should return 1 index'); + assert.ok(res[0].hh, 'Should have index hash'); + }); + + it('8. Cleanup test databases', function (done) { + alasql('DROP DATABASE test2200a'); + alasql('DROP DATABASE test2200b'); + done(); + }); +}); From aa119a77693bf6bf3eaa6c1a4b9d7b9bb1ecbdd1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 22:41:43 +0000 Subject: [PATCH 3/4] Fix SHOW COLUMNS and SHOW INDEX to handle qualified table names Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com> --- src/78show.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/78show.js b/src/78show.js index 56675c1e90..af73f6dc8a 100755 --- a/src/78show.js +++ b/src/78show.js @@ -72,7 +72,7 @@ yy.ShowColumns.prototype.toString = function () { }; yy.ShowColumns.prototype.execute = function (databaseid, params, cb) { - var db = alasql.databases[this.databaseid || databaseid]; + var db = alasql.databases[this.table.databaseid || this.databaseid || databaseid]; var table = db.tables[this.table.tableid]; if (table && table.columns) { @@ -101,7 +101,7 @@ yy.ShowIndex.prototype.toString = function () { return s; }; yy.ShowIndex.prototype.execute = function (databaseid, params, cb) { - var db = alasql.databases[this.databaseid || databaseid]; + var db = alasql.databases[this.table.databaseid || this.databaseid || databaseid]; var table = db.tables[this.table.tableid]; var res = []; if (table && table.indices) { From 51826eb734b7ed5a644ad394339e86c62dceaf26 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 19 Nov 2025 23:07:06 +0000 Subject: [PATCH 4/4] Refactor test2200.js to use before/after hooks and rename test variable to testId Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com> --- test/test2200.js | 137 ++++++++++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 68 deletions(-) diff --git a/test/test2200.js b/test/test2200.js index da31439824..3e370a76af 100644 --- a/test/test2200.js +++ b/test/test2200.js @@ -3,79 +3,80 @@ if (typeof exports === 'object') { var alasql = require('..'); } -var test = '2200'; +var testId = '2200'; -describe('Test ' + test + ' - SHOW COLUMNS and SHOW INDEX with qualified table names', function () { - it('1. Setup test databases and tables', function (done) { - alasql('CREATE DATABASE test2200a'); - alasql('CREATE DATABASE test2200b'); - alasql('USE test2200a'); - alasql('CREATE TABLE table1 (col1 INT, col2 VARCHAR(50))'); - alasql('CREATE INDEX idx_col1 ON table1(col1)'); - alasql('USE test2200b'); - alasql('CREATE TABLE table2 (col3 DECIMAL(10,2), col4 BOOLEAN)'); - alasql('CREATE INDEX idx_col3 ON table2(col3)'); - done(); - }); +describe( + 'Test ' + testId + ' - SHOW COLUMNS and SHOW INDEX with qualified table names', + function () { + before(function () { + alasql('CREATE DATABASE test2200a'); + alasql('CREATE DATABASE test2200b'); + alasql('USE test2200a'); + alasql('CREATE TABLE table1 (col1 INT, col2 VARCHAR(50))'); + alasql('CREATE INDEX idx_col1 ON table1(col1)'); + alasql('USE test2200b'); + alasql('CREATE TABLE table2 (col3 DECIMAL(10,2), col4 BOOLEAN)'); + alasql('CREATE INDEX idx_col3 ON table2(col3)'); + }); - it('2. SHOW COLUMNS with unqualified name (USE context)', function () { - alasql('USE test2200a'); - var res = alasql('SHOW COLUMNS FROM table1'); - assert.equal(res.length, 2); - assert.equal(res[0].columnid, 'col1'); - assert.equal(res[0].dbtypeid, 'INT'); - assert.equal(res[1].columnid, 'col2'); - assert.equal(res[1].dbtypeid, 'VARCHAR'); - assert.equal(res[1].dbsize, 50); - }); + it('1. SHOW COLUMNS with unqualified name (USE context)', function () { + alasql('USE test2200a'); + var res = alasql('SHOW COLUMNS FROM table1'); + assert.equal(res.length, 2); + assert.equal(res[0].columnid, 'col1'); + assert.equal(res[0].dbtypeid, 'INT'); + assert.equal(res[1].columnid, 'col2'); + assert.equal(res[1].dbtypeid, 'VARCHAR'); + assert.equal(res[1].dbsize, 50); + }); - it('3. SHOW COLUMNS with qualified name (database.table)', function () { - // This test should work regardless of current USE context - alasql('USE test2200b'); - var res = alasql('SHOW COLUMNS FROM test2200a.table1'); - assert.equal(res.length, 2, 'Should return 2 columns'); - assert.equal(res[0].columnid, 'col1'); - assert.equal(res[0].dbtypeid, 'INT'); - assert.equal(res[1].columnid, 'col2'); - assert.equal(res[1].dbtypeid, 'VARCHAR'); - assert.equal(res[1].dbsize, 50); - }); + it('2. SHOW COLUMNS with qualified name (database.table)', function () { + // This test should work regardless of current USE context + alasql('USE test2200b'); + var res = alasql('SHOW COLUMNS FROM test2200a.table1'); + assert.equal(res.length, 2, 'Should return 2 columns'); + assert.equal(res[0].columnid, 'col1'); + assert.equal(res[0].dbtypeid, 'INT'); + assert.equal(res[1].columnid, 'col2'); + assert.equal(res[1].dbtypeid, 'VARCHAR'); + assert.equal(res[1].dbsize, 50); + }); - it('4. SHOW INDEX with unqualified name (USE context)', function () { - alasql('USE test2200a'); - var res = alasql('SHOW INDEX FROM table1'); - assert.equal(res.length, 1); - assert.ok(res[0].hh, 'Should have index hash'); - }); + it('3. SHOW INDEX with unqualified name (USE context)', function () { + alasql('USE test2200a'); + var res = alasql('SHOW INDEX FROM table1'); + assert.equal(res.length, 1); + assert.ok(res[0].hh, 'Should have index hash'); + }); - it('5. SHOW INDEX with qualified name (database.table)', function () { - // This test should work regardless of current USE context - alasql('USE test2200b'); - var res = alasql('SHOW INDEX FROM test2200a.table1'); - assert.equal(res.length, 1, 'Should return 1 index'); - assert.ok(res[0].hh, 'Should have index hash'); - }); + it('4. SHOW INDEX with qualified name (database.table)', function () { + // This test should work regardless of current USE context + alasql('USE test2200b'); + var res = alasql('SHOW INDEX FROM test2200a.table1'); + assert.equal(res.length, 1, 'Should return 1 index'); + assert.ok(res[0].hh, 'Should have index hash'); + }); - it('6. SHOW COLUMNS with qualified name in different database', function () { - alasql('USE test2200a'); - var res = alasql('SHOW COLUMNS FROM test2200b.table2'); - assert.equal(res.length, 2, 'Should return 2 columns'); - assert.equal(res[0].columnid, 'col3'); - assert.equal(res[0].dbtypeid, 'DECIMAL'); - assert.equal(res[1].columnid, 'col4'); - assert.equal(res[1].dbtypeid, 'BOOLEAN'); - }); + it('5. SHOW COLUMNS with qualified name in different database', function () { + alasql('USE test2200a'); + var res = alasql('SHOW COLUMNS FROM test2200b.table2'); + assert.equal(res.length, 2, 'Should return 2 columns'); + assert.equal(res[0].columnid, 'col3'); + assert.equal(res[0].dbtypeid, 'DECIMAL'); + assert.equal(res[1].columnid, 'col4'); + assert.equal(res[1].dbtypeid, 'BOOLEAN'); + }); - it('7. SHOW INDEX with qualified name in different database', function () { - alasql('USE test2200a'); - var res = alasql('SHOW INDEX FROM test2200b.table2'); - assert.equal(res.length, 1, 'Should return 1 index'); - assert.ok(res[0].hh, 'Should have index hash'); - }); + it('6. SHOW INDEX with qualified name in different database', function () { + alasql('USE test2200a'); + var res = alasql('SHOW INDEX FROM test2200b.table2'); + assert.equal(res.length, 1, 'Should return 1 index'); + assert.ok(res[0].hh, 'Should have index hash'); + }); - it('8. Cleanup test databases', function (done) { - alasql('DROP DATABASE test2200a'); - alasql('DROP DATABASE test2200b'); - done(); - }); -}); + after(function () { + alasql('DROP DATABASE test2200a'); + alasql('DROP DATABASE test2200b'); + }); + } +);