Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 31 additions & 13 deletions src/35search.js
Original file line number Diff line number Diff line change
Expand Up @@ -690,20 +690,38 @@ yy.Search = class Search {
}

if (this.into) {
var a1, a2;
if (typeof this.into.args[0] !== 'undefined') {
a1 = new Function('params,alasql', 'var y;return ' + this.into.args[0].toJS())(
params,
alasql
);
}
if (typeof this.into.args[1] !== 'undefined') {
a2 = new Function('params,alasql', 'var y;return ' + this.into.args[1].toJS())(
params,
alasql
);
// Handle different INTO types
if (this.into instanceof yy.ParamValue) {
// INTO $variable or INTO ?
if (typeof this.into.param === 'string') {
// $variable syntax - replace the variable
params[this.into.param] = res;
} else {
// ? syntax - assign to parameter
params[this.into.param] = res;
}
if (cb) res = cb(res);
} else if (this.into instanceof yy.VarValue) {
// INTO @variable
alasql.vars[this.into.variable] = res;
if (cb) res = cb(res);
} else {
// INTO function (TXT(), JSON(), etc.)
var a1, a2;
if (typeof this.into.args[0] !== 'undefined') {
a1 = new Function('params,alasql', 'var y;return ' + this.into.args[0].toJS())(
params,
alasql
);
}
if (typeof this.into.args[1] !== 'undefined') {
a2 = new Function('params,alasql', 'var y;return ' + this.into.args[1].toJS())(
params,
alasql
);
}
res = alasql.into[this.into.funcid.toUpperCase()](a1, a2, res, [], cb);
}
res = alasql.into[this.into.funcid.toUpperCase()](a1, a2, res, [], cb);
} else {
if (stope.value && res.length > 0) {
res = res[0];
Expand Down
16 changes: 15 additions & 1 deletion src/40select.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,22 @@ yy.Select = class Select {
//
// Save data into parameters array
// like alasql('SELECT * INTO ? FROM ?',[outdata,srcdata]);
// or SELECT * INTO $variable FROM ?
//
query.intofns = `params[${JSON.stringify(this.into.param)}].push(r)`;
// Distinguish between ? (numeric param - push to array) and $variable (string param - replace array)
if (typeof this.into.param === 'string') {
// $variable syntax - replace the array
query.intoallfns = `
if(!params[${JSON.stringify(this.into.param)}]) params[${JSON.stringify(this.into.param)}]=[];
params[${JSON.stringify(this.into.param)}]=this.data;
res=this.data.length;
if(cb) res = cb(res);
return res;
`;
} else {
// ? syntax - push to existing array
query.intofns = `params[${JSON.stringify(this.into.param)}].push(r)`;
}
}

if (query.intofns) {
Expand Down
2 changes: 1 addition & 1 deletion test/test2169.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function runTest(testName, sql, params = [testData]) {
}
}

describe.skip('Test 2169: Comprehensive verification of compileToJS functionality', function () {
describe('Test 2169: Comprehensive verification of compileToJS functionality', function () {
it('1. Basic SELECT', function () {
runTest('Basic SELECT', 'SELECT name, age FROM ?');
});
Expand Down
16 changes: 8 additions & 8 deletions test/test336.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ if (typeof exports === 'object') {
//http://stackoverflow.com/questions/18811265/sql-creating-temporary-variables
//
describe('Test 336 SLT test #4', function () {
it.skip('1. CREATE DATABASE', function (done) {
it('1. CREATE DATABASE', function (done) {
alasql('CREATE DATABASE test336;USE test336');

done();
});

it.skip('2. Create table', function (done) {
it('2. Create table', function (done) {
var res = alasql(function () {
/*
CREATE TABLE t1(
Expand All @@ -33,13 +33,13 @@ describe('Test 336 SLT test #4', function () {
done();
});

it.skip('3. INSERT some data', function (done) {
it('3. INSERT some data', function (done) {
var res = alasql(function () {
/*
INSERT INTO t1 VALUES(382,414,67,992,483,'table tn1 row 1');
-- INSERT INTO t1 VALUES(231,468,97,414,795,'table tn1 row 2');
-- INSERT INTO t1 VALUES(810,355,805,274,858,'table tn1 row 3');
-- INSERT INTO t1 VALUES(536,956,417,418,381,'table tn1 row 4');
INSERT INTO t1 VALUES(231,468,97,414,795,'table tn1 row 2');
INSERT INTO t1 VALUES(810,355,805,274,858,'table tn1 row 3');
INSERT INTO t1 VALUES(536,956,417,418,381,'table tn1 row 4');
*/
});
// console.log(res);
Expand All @@ -48,7 +48,7 @@ describe('Test 336 SLT test #4', function () {
done();
});

it.skip('3. CREATE INDEX', function (done) {
it('3. CREATE INDEX', function (done) {
var res = alasql(function () {
/*
CREATE INDEX t1i0 ON t1(a1,b1,c1,d1,e1,x1);
Expand All @@ -64,7 +64,7 @@ describe('Test 336 SLT test #4', function () {
done();
});

it.skip('99. DROP DATABASE', function (done) {
it('99. DROP DATABASE', function (done) {
alasql('DROP DATABASE test336');
done();
});
Expand Down
20 changes: 10 additions & 10 deletions test/test343.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,54 @@ if (typeof exports === 'object') {
}

describe('Test 343 Use params for $variables', function () {
it.skip('1. CREATE DATABASE', function (done) {
it('1. CREATE DATABASE', function (done) {
alasql('CREATE DATABASE test343;USE test343');
done();
});

it.skip('2. Simple get undefined', function (done) {
it('2. Simple get undefined', function (done) {
var res = alasql('=$a');
assert.deepEqual(res, undefined);
done();
});

it.skip('3. Simple get from empty param {}', function (done) {
it('3. Simple get from empty param {}', function (done) {
var res = alasql('=$a', {});
assert.deepEqual(res, undefined);
done();
});

it.skip('4. Simple get from empty param {}', function (done) {
it('4. Simple get from empty param {}', function (done) {
var params = {a: 123};
var res = alasql('=$a', params);
assert.deepEqual(res, 123);
done();
});

it.skip('5. Simple set to param', function (done) {
it('5. Simple set to param', function (done) {
var params = {a: 123};
var res = alasql('SET $a = $a + 100', params);
assert.deepEqual(params.a, 223);
done();
});

it.skip('6. SELECT INTO $var', function (done) {
it('6. SELECT INTO $var', function (done) {
var params = {};
params.data = [{v: 1}, {v: 2}, {v: 3}];
var res = alasql('SELECT * INTO $arr FROM $data', params);
assert.deepEqual(params.arr, [{v: 1}, {v: 2}, {v: 3}]);
done();
});

it.skip('6. SEARCH AS $var', function (done) {
it('6. SEARCH INTO $var', function (done) {
var params = {};
params.data = [{v: 1}, {v: 2}, {v: 3}];
var res = alasql('SEARCH /v AS $vres FROM $data', params);
assert.deepEqual(params.vres, 3);
var res = alasql('SEARCH /v INTO $vres FROM $data', params);
assert.deepEqual(params.vres, [1, 2, 3]);
done();
});

it.skip('99. DROP DATABASE', function (done) {
it('99. DROP DATABASE', function (done) {
alasql.options.modifier = undefined;
alasql('DROP DATABASE test343');
done();
Expand Down
8 changes: 4 additions & 4 deletions test/test360.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if (typeof exports === 'object') {
}

describe('Test 360 AGGR function', function () {
it.skip('1. CREATE DATABASE', function (done) {
it('1. CREATE DATABASE', function (done) {
alasql('CREATE DATABASE test360;USE test360');
done();
});
Expand Down Expand Up @@ -564,7 +564,7 @@ describe('Test 360 AGGR function', function () {
},
];

it.skip('2. Prepare Data', function (done) {
it('2. Prepare Data without GROUP BY', function (done) {
var res = alasql(
function () {
/*
Expand All @@ -591,7 +591,7 @@ FROM ?
done();
});

it.skip('2. Prepare Data', function (done) {
it('3. Prepare Data with GROUP BY', function (done) {
var res = alasql(
function () {
/*
Expand All @@ -613,7 +613,7 @@ FROM ?
done();
});

it.skip('99. DROP DATABASE', function (done) {
it('99. DROP DATABASE', function (done) {
alasql.options.modifier = undefined;
alasql('DROP DATABASE test360');
done();
Expand Down
Loading