Skip to content

Commit d1b867d

Browse files
Copilotmathiasrw
andcommitted
Add test for NULL values in INTO SQL() - confirms issue exists
Co-authored-by: mathiasrw <[email protected]>
1 parent de047c6 commit d1b867d

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

test/test042_null_issue.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
if (typeof exports === 'object') {
2+
var assert = require('assert');
3+
var alasql = require('..');
4+
}
5+
6+
describe('Test 042 - NULL values in INTO SQL()', function () {
7+
it('1. Should output NULL for null values', function (done) {
8+
var data = [
9+
{a: 1, b: 'test', c: null, d: 3},
10+
{a: 2, b: null, c: 4, d: null},
11+
{a: null, b: 'value', c: null, d: null},
12+
];
13+
var res = alasql('SELECT * INTO SQL({tableid:"test_table"}) FROM ?', [data]);
14+
15+
console.log('Generated SQL:');
16+
console.log(res);
17+
18+
// Check that NULL appears in the output instead of empty values
19+
assert(res.indexOf('NULL') > -1, 'Output should contain NULL keyword');
20+
21+
// Check that we don't have consecutive commas (,,) which indicate missing values
22+
assert(res.indexOf(',,') === -1, 'Output should not contain consecutive commas (,,)');
23+
24+
// Verify specific patterns for NULL values
25+
// First row: c should be NULL
26+
assert(res.indexOf('(1,\'test\',NULL,3)') > -1, 'First row should have NULL for c');
27+
28+
// Second row: b and d should be NULL
29+
assert(res.indexOf('(2,NULL,4,NULL)') > -1, 'Second row should have NULL for b and d');
30+
31+
// Third row: a, c, and d should be NULL
32+
assert(res.indexOf('(NULL,\'value\',NULL,NULL)') > -1, 'Third row should have NULL for a, c, and d');
33+
34+
done();
35+
});
36+
37+
it('2. Should handle undefined values as NULL', function (done) {
38+
var data = [
39+
{a: 1, b: 'test'},
40+
{a: 2, b: undefined, c: 4},
41+
];
42+
var res = alasql('SELECT * INTO SQL({tableid:"test_table"}) FROM ?', [data]);
43+
44+
console.log('Generated SQL with undefined:');
45+
console.log(res);
46+
47+
// Check that NULL appears in the output
48+
assert(res.indexOf('NULL') > -1, 'Output should contain NULL keyword for undefined values');
49+
50+
// Check that we don't have consecutive commas
51+
assert(res.indexOf(',,') === -1, 'Output should not contain consecutive commas (,,)');
52+
53+
done();
54+
});
55+
56+
it('3. Should handle mixed NULL, undefined, and empty strings', function (done) {
57+
var data = [
58+
{a: 1, b: '', c: null, d: undefined},
59+
];
60+
var res = alasql('SELECT * INTO SQL({tableid:"test_table"}) FROM ?', [data]);
61+
62+
console.log('Generated SQL with mixed values:');
63+
console.log(res);
64+
65+
// Empty string should remain as empty string
66+
assert(res.indexOf("''") > -1, 'Empty string should be preserved as \'\'');
67+
68+
// null and undefined should become NULL
69+
assert(res.indexOf('NULL') > -1, 'null and undefined should become NULL');
70+
71+
done();
72+
});
73+
});

0 commit comments

Comments
 (0)