Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix RECORDSET returning empty columns if there's no matched rows issu… #1733

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
6 changes: 6 additions & 0 deletions src/40select.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,12 @@ function modify(query, res) {
} else {
// Cannot recognize columns
columns = [];
if (query && query.sources) {
query.sources.forEach((source) => {
if(source?.columns?.columnid != null)
columns = columns.concat({columnid:source?.columns?.columnid});
})
}
}
}

Expand Down
64 changes: 64 additions & 0 deletions test/test1547.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
if (typeof exports === 'object') {
var assert = require('assert');
var alasql = require('..');
}

describe('Test 1547 - Empty recordset', function () {
const test = '1547';

before(function () {
alasql('create database test' + test);
alasql('use test' + test);
});

after(function () {
alasql('drop database test' + test);
});

it('Returns columns for empty recordset', function () {
alasql('create table one (a int)');
alasql('insert into one values (1),(2),(3),(4),(5)');
let res = alasql('recordset of select * from one where a = 999');
assert.deepEqual(res, {
columns: [
{
columnid: 'a',
},
],
data: [],
});

/* assert(
(() => {
const testdata = {
columns: [
{
columnid: 'a',
},
],
data: [],
};

if (
res.columns.length !== testdata.columns.length ||
res.data.length !== testdata.data.length
) {
return false;
} else {
let cols = res.columns;

for (let col of cols) {
let index = testdata.columns.findIndex((c) => c.columnid === col.columnid);

if (index === -1) {
return false;
}
}

return true;
}
})(),
'Response should not have missing coloumns'
);*/
});
});