|
| 1 | +if (typeof exports === 'object') { |
| 2 | + var assert = require('assert'); |
| 3 | + var alasql = require('..'); |
| 4 | +} |
| 5 | + |
| 6 | +var testId = '2200'; |
| 7 | + |
| 8 | +describe( |
| 9 | + 'Test ' + testId + ' - SHOW COLUMNS and SHOW INDEX with qualified table names', |
| 10 | + function () { |
| 11 | + before(function () { |
| 12 | + alasql('CREATE DATABASE test2200a'); |
| 13 | + alasql('CREATE DATABASE test2200b'); |
| 14 | + alasql('USE test2200a'); |
| 15 | + alasql('CREATE TABLE table1 (col1 INT, col2 VARCHAR(50))'); |
| 16 | + alasql('CREATE INDEX idx_col1 ON table1(col1)'); |
| 17 | + alasql('USE test2200b'); |
| 18 | + alasql('CREATE TABLE table2 (col3 DECIMAL(10,2), col4 BOOLEAN)'); |
| 19 | + alasql('CREATE INDEX idx_col3 ON table2(col3)'); |
| 20 | + }); |
| 21 | + |
| 22 | + it('1. SHOW COLUMNS with unqualified name (USE context)', function () { |
| 23 | + alasql('USE test2200a'); |
| 24 | + var res = alasql('SHOW COLUMNS FROM table1'); |
| 25 | + assert.equal(res.length, 2); |
| 26 | + assert.equal(res[0].columnid, 'col1'); |
| 27 | + assert.equal(res[0].dbtypeid, 'INT'); |
| 28 | + assert.equal(res[1].columnid, 'col2'); |
| 29 | + assert.equal(res[1].dbtypeid, 'VARCHAR'); |
| 30 | + assert.equal(res[1].dbsize, 50); |
| 31 | + }); |
| 32 | + |
| 33 | + it('2. SHOW COLUMNS with qualified name (database.table)', function () { |
| 34 | + // This test should work regardless of current USE context |
| 35 | + alasql('USE test2200b'); |
| 36 | + var res = alasql('SHOW COLUMNS FROM test2200a.table1'); |
| 37 | + assert.equal(res.length, 2, 'Should return 2 columns'); |
| 38 | + assert.equal(res[0].columnid, 'col1'); |
| 39 | + assert.equal(res[0].dbtypeid, 'INT'); |
| 40 | + assert.equal(res[1].columnid, 'col2'); |
| 41 | + assert.equal(res[1].dbtypeid, 'VARCHAR'); |
| 42 | + assert.equal(res[1].dbsize, 50); |
| 43 | + }); |
| 44 | + |
| 45 | + it('3. SHOW INDEX with unqualified name (USE context)', function () { |
| 46 | + alasql('USE test2200a'); |
| 47 | + var res = alasql('SHOW INDEX FROM table1'); |
| 48 | + assert.equal(res.length, 1); |
| 49 | + assert.ok(res[0].hh, 'Should have index hash'); |
| 50 | + }); |
| 51 | + |
| 52 | + it('4. SHOW INDEX with qualified name (database.table)', function () { |
| 53 | + // This test should work regardless of current USE context |
| 54 | + alasql('USE test2200b'); |
| 55 | + var res = alasql('SHOW INDEX FROM test2200a.table1'); |
| 56 | + assert.equal(res.length, 1, 'Should return 1 index'); |
| 57 | + assert.ok(res[0].hh, 'Should have index hash'); |
| 58 | + }); |
| 59 | + |
| 60 | + it('5. SHOW COLUMNS with qualified name in different database', function () { |
| 61 | + alasql('USE test2200a'); |
| 62 | + var res = alasql('SHOW COLUMNS FROM test2200b.table2'); |
| 63 | + assert.equal(res.length, 2, 'Should return 2 columns'); |
| 64 | + assert.equal(res[0].columnid, 'col3'); |
| 65 | + assert.equal(res[0].dbtypeid, 'DECIMAL'); |
| 66 | + assert.equal(res[1].columnid, 'col4'); |
| 67 | + assert.equal(res[1].dbtypeid, 'BOOLEAN'); |
| 68 | + }); |
| 69 | + |
| 70 | + it('6. SHOW INDEX with qualified name in different database', function () { |
| 71 | + alasql('USE test2200a'); |
| 72 | + var res = alasql('SHOW INDEX FROM test2200b.table2'); |
| 73 | + assert.equal(res.length, 1, 'Should return 1 index'); |
| 74 | + assert.ok(res[0].hh, 'Should have index hash'); |
| 75 | + }); |
| 76 | + |
| 77 | + after(function () { |
| 78 | + alasql('DROP DATABASE test2200a'); |
| 79 | + alasql('DROP DATABASE test2200b'); |
| 80 | + }); |
| 81 | + } |
| 82 | +); |
0 commit comments