|
| 1 | +if (typeof exports === 'object') { |
| 2 | + var assert = require('assert'); |
| 3 | + var alasql = require('..'); |
| 4 | +} |
| 5 | + |
| 6 | +describe('Test 1547 - Empty recordset', function () { |
| 7 | + const test = '1547'; |
| 8 | + |
| 9 | + before(function () { |
| 10 | + alasql('create database test' + test); |
| 11 | + alasql('use test' + test); |
| 12 | + }); |
| 13 | + |
| 14 | + after(function () { |
| 15 | + alasql('drop database test' + test); |
| 16 | + }); |
| 17 | + |
| 18 | + it('Returns columns for empty recordset', function () { |
| 19 | + alasql('create table one (a int)'); |
| 20 | + alasql('insert into one values (1),(2),(3),(4),(5)'); |
| 21 | + let res = alasql('recordset of select * from one where a = 999'); |
| 22 | + |
| 23 | + // Verify that columns are returned even when there are no rows |
| 24 | + assert.strictEqual(res.columns.length, 1, 'Should have 1 column'); |
| 25 | + assert.strictEqual(res.columns[0].columnid, 'a', 'Column should be named "a"'); |
| 26 | + assert.strictEqual(res.data.length, 0, 'Data should be empty'); |
| 27 | + }); |
| 28 | + |
| 29 | + it('Returns multiple columns for empty recordset', function () { |
| 30 | + alasql('create table multi (id int, name varchar(50), amount double)'); |
| 31 | + alasql('insert into multi values (1, "test", 1.5), (2, "test2", 2.5)'); |
| 32 | + let res = alasql('recordset of select * from multi where id = 999'); |
| 33 | + |
| 34 | + // Verify that all columns are returned even when there are no rows |
| 35 | + assert.strictEqual(res.columns.length, 3, 'Should have 3 columns'); |
| 36 | + assert.strictEqual(res.columns[0].columnid, 'id', 'First column should be "id"'); |
| 37 | + assert.strictEqual(res.columns[1].columnid, 'name', 'Second column should be "name"'); |
| 38 | + assert.strictEqual(res.columns[2].columnid, 'amount', 'Third column should be "amount"'); |
| 39 | + assert.strictEqual(res.data.length, 0, 'Data should be empty'); |
| 40 | + }); |
| 41 | +}); |
0 commit comments