alasql 2.2.7 → 2.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/alasql-cli.js +1 -1
- package/dist/alasql-worker.js +2 -2
- package/dist/alasql-worker.min.js +1 -1
- package/dist/alasql.fs.js +233 -26
- package/dist/alasql.js +233 -26
- package/dist/alasql.min.js +84 -41
- package/package.json +1 -1
package/bin/alasql-cli.js
CHANGED
package/dist/alasql-worker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v2.2.
|
|
1
|
+
//! AlaSQL v2.2.8 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.2.
|
|
4
|
+
@version 2.2.8
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
//! AlaSQL v2.2.
|
|
1
|
+
//! AlaSQL v2.2.8 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
!function(r,e){"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?module.exports=e():r.alasql=e()}(this,function(){function i(r,e,o){"function"==typeof(e=e||[])&&(scope=o,o=e,e=[]),"object"!=typeof e&&(e=[e]);var t=i.lastid++;i.buffer[t]=o,i.webworker.postMessage({id:t,sql:r,params:e})}var a;if(i.options={},i.options.progress=function(){},isArray=function(r){return"[object Array]"===Object.prototype.toString.call(r)},i.promise=function(){throw new Error("Please include a Promise/A+ library")},"undefined"!=typeof Promise&&(a=function(r,e,n,s){return new Promise(function(o,t){i(r,e,function(r,e){e?t(e):(n&&s&&!1!==i.options.progress&&i.options.progress(n,s),o(r))})})},i.promise=function(r,e){if("undefined"==typeof Promise)throw new Error("Please include a Promise/A+ library");if("string"==typeof r)return a(r,e);if(!isArray(r)||r.length<1||void 0!==e)throw new Error("Error in .promise parameters");var o=r;if(!(o.length<1)){for(var t,n,s=[],i=0;i<o.length;i++){if("string"==typeof(n=o[i])&&(n=[n]),!isArray(n)||n.length<1||2<n.length)throw new Error("Error in .promise parameter");t=n[0],n=n[1]||void 0,s.push(a(t,n,i,o.length))}return Promise.all(s)}}),i=i||!1)return i.worker=function(){throw new Error("Can find webworker in this enviroment")},"undefined"!=typeof Worker&&(i.worker=function(r,e,o){if(void 0===(r=!0===r?void 0:r))for(var t=document.getElementsByTagName("script"),n=0;n<t.length;n++){if("alasql-worker.js"===t[n].src.substr(-16).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-16)+"alasql.js";break}if("alasql-worker.min.js"===t[n].src.substr(-20).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-20)+"alasql.min.js";break}if("alasql.js"===t[n].src.substr(-9).toLowerCase()){r=t[n].src;break}if("alasql.min.js"===t[n].src.substr(-13).toLowerCase()){r=t[n].src.substr(0,t[n].src.length-13)+"alasql.min.js";break}}if(void 0===r)throw new Error("Path to alasql.js is not specified");var s;!1!==r?(s=(s="importScripts('")+r+"');self.onmessage = function(event) {alasql(event.data.sql,event.data.params, function(data){postMessage({id:event.data.id, data:data});});}",s=new Blob([s],{type:"text/plain"}),i.webworker=new Worker(URL.createObjectURL(s)),i.webworker.onmessage=function(r){var e=r.data.id;i.buffer[e](r.data.data),delete i.buffer[e]},i.webworker.onerror=function(r){throw r},1<arguments.length&&i("REQUIRE "+e.map(function(r){return'"'+r+'"'}).join(","),[],o)):!1===r&&delete i.webworker}),i.lastid=0,i.buffer={},i.worker(),i;throw new Error("alasql was not found")});
|
package/dist/alasql.fs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v2.2.
|
|
1
|
+
//! AlaSQL v2.2.8 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.2.
|
|
4
|
+
@version 2.2.8
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
|
|
@@ -142,7 +142,7 @@ var alasql = function(sql, params, cb, scope) {
|
|
|
142
142
|
Current version of alasql
|
|
143
143
|
@constant {string}
|
|
144
144
|
*/
|
|
145
|
-
alasql.version = '2.2.
|
|
145
|
+
alasql.version = '2.2.8';
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
Debug flag
|
|
@@ -4487,9 +4487,201 @@ alasql.parser.parseError = function (str, hash) {
|
|
|
4487
4487
|
}
|
|
4488
4488
|
*/
|
|
4489
4489
|
alasql.parse = function (sql) {
|
|
4490
|
-
|
|
4490
|
+
var ast = alasqlparser.parse(alasql.utils.uncomment(sql));
|
|
4491
|
+
checkSqlNames(ast);
|
|
4492
|
+
return ast;
|
|
4491
4493
|
};
|
|
4492
4494
|
|
|
4495
|
+
/*
|
|
4496
|
+
A name from the SQL text is pasted into generated code between single quotes, so a name that
|
|
4497
|
+
holds a quote, a backslash or a line break would end the string and make the rest code
|
|
4498
|
+
(GHSA-67vj-hh8j-j94f). Such a name is refused here, once, after parsing. A name is a table,
|
|
4499
|
+
column, database, view, index, trigger or CTE name, a variable (and the keys of its path) and a
|
|
4500
|
+
table alias. The alias of a column in the select list is not a name: it is a key of the result,
|
|
4501
|
+
and the code that writes it escapes it. Strings, numbers, parameters, JavaScript and the keys
|
|
4502
|
+
of a JSON value are data, not names.
|
|
4503
|
+
*/
|
|
4504
|
+
var checkSqlNames = (function () {
|
|
4505
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
4506
|
+
var badName = /['\\\n\r\u2028\u2029]/;
|
|
4507
|
+
var nameKeys = {
|
|
4508
|
+
as: 1,
|
|
4509
|
+
columnid: 1,
|
|
4510
|
+
tableid: 1,
|
|
4511
|
+
databaseid: 1,
|
|
4512
|
+
viewid: 1,
|
|
4513
|
+
indexid: 1,
|
|
4514
|
+
trigger: 1,
|
|
4515
|
+
variable: 1,
|
|
4516
|
+
dropcolumn: 1,
|
|
4517
|
+
renamecolumn: 1,
|
|
4518
|
+
renameto: 1,
|
|
4519
|
+
to: 1,
|
|
4520
|
+
tocolumnid: 1,
|
|
4521
|
+
forcolumnid: 1,
|
|
4522
|
+
};
|
|
4523
|
+
var nameListKeys = {columns: 1, fkcolumns: 1, props: 1};
|
|
4524
|
+
|
|
4525
|
+
function checkName(name) {
|
|
4526
|
+
if (badName.test(name)) throw new SyntaxError('Not a valid name: ' + name);
|
|
4527
|
+
}
|
|
4528
|
+
|
|
4529
|
+
// ORDER BY: a name that equals an alias of the select list is that alias and is allowed (the code
|
|
4530
|
+
// escapes it), anything else is checked. (In this version a string in ORDER BY is a constant.)
|
|
4531
|
+
function checkOrder(columns, order) {
|
|
4532
|
+
var aliases = {};
|
|
4533
|
+
(columns || []).forEach(function (col) {
|
|
4534
|
+
if (col && typeof col.as === 'string') aliases[col.as] = true;
|
|
4535
|
+
});
|
|
4536
|
+
order.forEach(function (ord) {
|
|
4537
|
+
var e = ord && ord.expression;
|
|
4538
|
+
var name;
|
|
4539
|
+
if (e instanceof alasql.yy.Column && !e.tableid) name = e.columnid;
|
|
4540
|
+
if (typeof name === 'string') {
|
|
4541
|
+
if (!hasOwn.call(aliases, name)) checkName(name);
|
|
4542
|
+
return;
|
|
4543
|
+
}
|
|
4544
|
+
checkNames(ord, false, false);
|
|
4545
|
+
});
|
|
4546
|
+
}
|
|
4547
|
+
|
|
4548
|
+
// The alias of an entry of the select list, of SEARCH RETURNS and of CREATE GRAPH is a key of
|
|
4549
|
+
// the result or a variable and is allowed. The name of an entry of WITH is a table name; in a
|
|
4550
|
+
// graph item, name is data.
|
|
4551
|
+
function entryOf(node, key) {
|
|
4552
|
+
var yy = alasql.yy;
|
|
4553
|
+
if (
|
|
4554
|
+
(node instanceof yy.Select && key === 'columns') ||
|
|
4555
|
+
(node instanceof yy.CreateGraph && key === 'graph') ||
|
|
4556
|
+
(node.srchid === 'RETURN' && key === 'args')
|
|
4557
|
+
)
|
|
4558
|
+
return 'alias';
|
|
4559
|
+
if (node instanceof yy.WithSelect && key === 'withs') return 'with';
|
|
4560
|
+
return '';
|
|
4561
|
+
}
|
|
4562
|
+
|
|
4563
|
+
// Names that never reach generated code: they are used only at run time, as the key of a
|
|
4564
|
+
// database, a table, an index, a trigger or a variable, so the walk leaves them alone and such a
|
|
4565
|
+
// name keeps working. freeKeys are names of the node itself, freeChild are children whose own
|
|
4566
|
+
// names are free (what they hold is still walked), and skipChild are children that are not
|
|
4567
|
+
// walked at all (PIVOT and UNPIVOT work on the result and build no code).
|
|
4568
|
+
var varValueFree = false;
|
|
4569
|
+
var intoVarFree = false;
|
|
4570
|
+
var freeKeys = [
|
|
4571
|
+
['CreateIndex', {indexid: 1}],
|
|
4572
|
+
['DropIndex', {indexid: 1}],
|
|
4573
|
+
['Reindex', {indexid: 1}],
|
|
4574
|
+
['CreateTrigger', {trigger: 1}],
|
|
4575
|
+
['DropTrigger', {trigger: 1}],
|
|
4576
|
+
['CreateDatabase', {databaseid: 1, as: 1}],
|
|
4577
|
+
['AttachDatabase', {databaseid: 1, as: 1}],
|
|
4578
|
+
['DetachDatabase', {databaseid: 1}],
|
|
4579
|
+
['DropDatabase', {databaseid: 1}],
|
|
4580
|
+
['ShowTables', {databaseid: 1}],
|
|
4581
|
+
['ShowColumns', {databaseid: 1}],
|
|
4582
|
+
['ShowIndex', {databaseid: 1}],
|
|
4583
|
+
['ShowCreateTable', {databaseid: 1}],
|
|
4584
|
+
['AlterTable', {renameto: 1, renamecolumn: 1, dropcolumn: 1}],
|
|
4585
|
+
];
|
|
4586
|
+
var freeChild = [
|
|
4587
|
+
['CreateTable', {table: 1}],
|
|
4588
|
+
['DropTable', {tables: 1}],
|
|
4589
|
+
['TruncateTable', {table: 1}],
|
|
4590
|
+
['AlterTable', {table: 1}],
|
|
4591
|
+
['ShowColumns', {table: 1}],
|
|
4592
|
+
['ShowIndex', {table: 1}],
|
|
4593
|
+
['ShowCreateTable', {table: 1}],
|
|
4594
|
+
['CreateIndex', {table: 1}],
|
|
4595
|
+
['CreateTrigger', {table: 1}],
|
|
4596
|
+
['Declare', {declares: 1}],
|
|
4597
|
+
];
|
|
4598
|
+
var skipChild = [['Select', {pivot: 1, unpivot: 1}]];
|
|
4599
|
+
|
|
4600
|
+
function freeOf(list, node) {
|
|
4601
|
+
var yy = alasql.yy;
|
|
4602
|
+
for (var i = 0; i < list.length; i++) {
|
|
4603
|
+
var cls = yy[list[i][0]];
|
|
4604
|
+
if (cls && node instanceof cls) return list[i][1];
|
|
4605
|
+
}
|
|
4606
|
+
return null;
|
|
4607
|
+
}
|
|
4608
|
+
|
|
4609
|
+
// An @variable: an expression pastes it escaped where varValueFree is true, FROM @x pastes it
|
|
4610
|
+
// raw, and SELECT INTO @x pastes it raw where intoVarFree is false.
|
|
4611
|
+
function freeVar(node, key, entry) {
|
|
4612
|
+
var yy = alasql.yy;
|
|
4613
|
+
if (key !== 'variable' || !(node instanceof yy.VarValue)) return false;
|
|
4614
|
+
if (entry === 'source') return false;
|
|
4615
|
+
if (entry === 'into') return intoVarFree;
|
|
4616
|
+
return varValueFree;
|
|
4617
|
+
}
|
|
4618
|
+
|
|
4619
|
+
// SET @x = value without a path is a run-time assignment; with a path the name is pasted
|
|
4620
|
+
function freeSet(node, key) {
|
|
4621
|
+
var yy = alasql.yy;
|
|
4622
|
+
return key === 'variable' && yy.SetVariable && node instanceof yy.SetVariable && !(node.props && node.props.length);
|
|
4623
|
+
}
|
|
4624
|
+
|
|
4625
|
+
// data is true inside a JSON value, where a plain object is data and only a node is looked at.
|
|
4626
|
+
// entry is what entryOf says about the node as an entry of its parent, or 'free' when its own
|
|
4627
|
+
// names never reach generated code.
|
|
4628
|
+
function checkNames(node, data, entry) {
|
|
4629
|
+
if (node === null || typeof node !== 'object') return;
|
|
4630
|
+
var i;
|
|
4631
|
+
if (Array.isArray(node)) {
|
|
4632
|
+
for (i = 0; i < node.length; i++) checkNames(node[i], data, false);
|
|
4633
|
+
return;
|
|
4634
|
+
}
|
|
4635
|
+
var isNode = Object.getPrototypeOf(node) !== Object.prototype;
|
|
4636
|
+
if (data && !isNode) {
|
|
4637
|
+
for (i in node) if (hasOwn.call(node, i)) checkNames(node[i], true, false);
|
|
4638
|
+
return;
|
|
4639
|
+
}
|
|
4640
|
+
var yy = alasql.yy;
|
|
4641
|
+
if (node instanceof yy.Json) {
|
|
4642
|
+
checkNames(node.value, true, false);
|
|
4643
|
+
return;
|
|
4644
|
+
}
|
|
4645
|
+
var fk = freeOf(freeKeys, node);
|
|
4646
|
+
var fc = freeOf(freeChild, node);
|
|
4647
|
+
var sc = freeOf(skipChild, node);
|
|
4648
|
+
for (var key in node) {
|
|
4649
|
+
if (!hasOwn.call(node, key)) continue;
|
|
4650
|
+
var value = node[key];
|
|
4651
|
+
if (sc && sc[key] === 1) continue;
|
|
4652
|
+
if (key === 'order' && node instanceof yy.Select && Array.isArray(value)) {
|
|
4653
|
+
checkOrder(node.columns, value);
|
|
4654
|
+
continue;
|
|
4655
|
+
}
|
|
4656
|
+
// the column list of a WITH entry renames the result at run time
|
|
4657
|
+
var child = (fc && fc[key] === 1) || (entry === 'with' && key === 'columns') ? 'free' : '';
|
|
4658
|
+
if (!child && node instanceof yy.Select) child = key === 'from' ? 'source' : key === 'into' ? 'into' : '';
|
|
4659
|
+
if (typeof value === 'string') {
|
|
4660
|
+
if (entry === 'free' || (fk && fk[key] === 1) || freeSet(node, key) || freeVar(node, key, entry))
|
|
4661
|
+
continue;
|
|
4662
|
+
if (key === 'name' ? entry === 'with' : nameKeys[key] === 1 && !(entry === 'alias' && key === 'as'))
|
|
4663
|
+
checkName(value);
|
|
4664
|
+
} else if (value !== null && typeof value === 'object') {
|
|
4665
|
+
if (Array.isArray(value)) {
|
|
4666
|
+
for (i = 0; i < value.length; i++) {
|
|
4667
|
+
if (typeof value[i] === 'string') {
|
|
4668
|
+
if (nameListKeys[key] === 1 && entry !== 'free' && child !== 'free') checkName(value[i]);
|
|
4669
|
+
} else {
|
|
4670
|
+
checkNames(value[i], false, child || entryOf(node, key));
|
|
4671
|
+
}
|
|
4672
|
+
}
|
|
4673
|
+
} else {
|
|
4674
|
+
checkNames(value, false, child);
|
|
4675
|
+
}
|
|
4676
|
+
}
|
|
4677
|
+
}
|
|
4678
|
+
}
|
|
4679
|
+
|
|
4680
|
+
return function (ast) {
|
|
4681
|
+
checkNames(ast, false, false);
|
|
4682
|
+
};
|
|
4683
|
+
})();
|
|
4684
|
+
|
|
4493
4685
|
/**
|
|
4494
4686
|
List of engines of external databases
|
|
4495
4687
|
@type {object}
|
|
@@ -7582,7 +7774,7 @@ yy.Select.prototype.compile = function (databaseid, params) {
|
|
|
7582
7774
|
// Save data into parameters array
|
|
7583
7775
|
// like alasql('SELECT * INTO ? FROM ?',[outdata,srcdata]);
|
|
7584
7776
|
//
|
|
7585
|
-
query.intofns = "params['" + this.into.param + "'].push(r)";
|
|
7777
|
+
query.intofns = "params['" + escapeq(this.into.param) + "'].push(r)";
|
|
7586
7778
|
}
|
|
7587
7779
|
|
|
7588
7780
|
if (query.intofns) {
|
|
@@ -7987,7 +8179,7 @@ yy.Select.prototype.compileFrom = function (query) {
|
|
|
7987
8179
|
return res;
|
|
7988
8180
|
};
|
|
7989
8181
|
} else if (tq instanceof yy.ParamValue) {
|
|
7990
|
-
ps = "var res = alasql.prepareFromData(params['" + tq.param + "']";
|
|
8182
|
+
ps = "var res = alasql.prepareFromData(params['" + escapeq(tq.param) + "']";
|
|
7991
8183
|
|
|
7992
8184
|
if (tq.array) ps += ',true';
|
|
7993
8185
|
ps += ');if(cb)res=cb(res,idx,query);return res';
|
|
@@ -8236,7 +8428,7 @@ yy.Select.prototype.compileJoins = function (query) {
|
|
|
8236
8428
|
// source.data = ;
|
|
8237
8429
|
var jnparam = jn.param.param;
|
|
8238
8430
|
|
|
8239
|
-
ps = "var res=alasql.prepareFromData(params['" + jnparam + "']";
|
|
8431
|
+
ps = "var res=alasql.prepareFromData(params['" + escapeq(jnparam) + "']";
|
|
8240
8432
|
if (jn.array) ps += ',true';
|
|
8241
8433
|
ps += ');if(cb)res=cb(res, idx, query);return res';
|
|
8242
8434
|
|
|
@@ -9018,9 +9210,10 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
9018
9210
|
|
|
9019
9211
|
if (columns && columns.length > 0) {
|
|
9020
9212
|
columns.forEach(function (tcol) {
|
|
9213
|
+
var escapedColumnId = escapeq(tcol.columnid);
|
|
9021
9214
|
if (joinstar && alasql.options.joinstar == 'underscore') {
|
|
9022
9215
|
ss.push(
|
|
9023
|
-
"'" + alias + '_' +
|
|
9216
|
+
"'" + alias + '_' + escapedColumnId + "':p['" + alias + "']['" + escapedColumnId + "']"
|
|
9024
9217
|
);
|
|
9025
9218
|
} else if (joinstar && alasql.options.joinstar == 'json') {
|
|
9026
9219
|
// ss.push('\''+alias+'_'+tcol.columnid+'\':p[\''+alias+'\'][\''+tcol.columnid+'\']');
|
|
@@ -9028,16 +9221,16 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
9028
9221
|
"r['" +
|
|
9029
9222
|
alias +
|
|
9030
9223
|
"']['" +
|
|
9031
|
-
|
|
9224
|
+
escapedColumnId +
|
|
9032
9225
|
"']=p['" +
|
|
9033
9226
|
alias +
|
|
9034
9227
|
"']['" +
|
|
9035
|
-
|
|
9228
|
+
escapedColumnId +
|
|
9036
9229
|
"'];";
|
|
9037
9230
|
} else {
|
|
9038
|
-
var value = "p['" + alias + "']['" +
|
|
9231
|
+
var value = "p['" + alias + "']['" + escapedColumnId + "']";
|
|
9039
9232
|
if (!columnIds[tcol.columnid]) {
|
|
9040
|
-
var key = "'" +
|
|
9233
|
+
var key = "'" + escapedColumnId + "':";
|
|
9041
9234
|
ss.push(key + value);
|
|
9042
9235
|
columnIds[tcol.columnid] = {
|
|
9043
9236
|
id: ss.length - 1,
|
|
@@ -9068,7 +9261,7 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
9068
9261
|
} else {
|
|
9069
9262
|
|
|
9070
9263
|
// if column not exist, then copy all
|
|
9071
|
-
sp += 'var w=p["' + alias + '"];for(var k in w){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=w[k]};';
|
|
9264
|
+
sp += 'var w=p["' + escapeq(alias) + '"];for(var k in w){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=w[k]};';
|
|
9072
9265
|
|
|
9073
9266
|
query.dirtyColumns = true;
|
|
9074
9267
|
}
|
|
@@ -9095,7 +9288,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9095
9288
|
if (col.columnid === '*') {
|
|
9096
9289
|
if (col.func) {
|
|
9097
9290
|
sp +=
|
|
9098
|
-
"r=params['" + col.param + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
9291
|
+
"r=params['" + escapeq(col.param) + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
9099
9292
|
} else if (col.tableid) {
|
|
9100
9293
|
//Copy all
|
|
9101
9294
|
var ret = compileSelectStar(query, [col.tableid], false);
|
|
@@ -9147,7 +9340,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9147
9340
|
if (isMultisheetParam) {
|
|
9148
9341
|
sp =
|
|
9149
9342
|
'var r={};var w=p["' +
|
|
9150
|
-
tbid +
|
|
9343
|
+
escapeq(tbid) +
|
|
9151
9344
|
'"];' +
|
|
9152
9345
|
'var cols=[' +
|
|
9153
9346
|
self.columns
|
|
@@ -9158,7 +9351,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9158
9351
|
'];var colas=[' +
|
|
9159
9352
|
self.columns
|
|
9160
9353
|
.map(function (col) {
|
|
9161
|
-
return "'" + (col.as || col.columnid) + "'";
|
|
9354
|
+
return "'" + escapeq(col.as || col.columnid) + "'";
|
|
9162
9355
|
})
|
|
9163
9356
|
.join(',') +
|
|
9164
9357
|
'];' +
|
|
@@ -9321,9 +9514,9 @@ yy.Select.prototype.compileSelect2 = function (query, params) {
|
|
|
9321
9514
|
this.orderColumns.forEach(function (v, idx) {
|
|
9322
9515
|
var key = '$$$' + idx;
|
|
9323
9516
|
if (v instanceof yy.Column && query.xcolumns[v.columnid]) {
|
|
9324
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
9517
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
9325
9518
|
} else if (v instanceof yy.ParamValue && query.xcolumns[params[v.param]]) {
|
|
9326
|
-
s += "r['" + key + "']=r['" + params[v.param] + "'];";
|
|
9519
|
+
s += "r['" + key + "']=r['" + escapeq(params[v.param]) + "'];";
|
|
9327
9520
|
} else {
|
|
9328
9521
|
s += "r['" + key + "']=" + v.toJS('p', query.defaultTableid, query.defcols) + ';';
|
|
9329
9522
|
}
|
|
@@ -9416,7 +9609,7 @@ yy.Select.prototype.compileSelectGroup1 = function (query) {
|
|
|
9416
9609
|
query.groupColumns[colas] = col.nick;
|
|
9417
9610
|
|
|
9418
9611
|
// if(col.as) {
|
|
9419
|
-
s += "r['" + colas + "']=";
|
|
9612
|
+
s += "r['" + (col.as !== undefined ? escapeq(colas) : colas) + "']=";
|
|
9420
9613
|
// // } else {
|
|
9421
9614
|
// // s += 'r[\''+escapeq()+'\']=';
|
|
9422
9615
|
// // };
|
|
@@ -9443,7 +9636,7 @@ yy.Select.prototype.compileSelectGroup2 = function (query) {
|
|
|
9443
9636
|
self.columns.forEach(function (col) {
|
|
9444
9637
|
|
|
9445
9638
|
if (query.ingroup.indexOf(col.nick) > -1) {
|
|
9446
|
-
s += "r['" + (col.as
|
|
9639
|
+
s += "r['" + (col.as ? escapeq(col.as) : col.nick) + "']=g['" + col.nick + "'];";
|
|
9447
9640
|
}
|
|
9448
9641
|
});
|
|
9449
9642
|
|
|
@@ -9453,7 +9646,7 @@ yy.Select.prototype.compileSelectGroup2 = function (query) {
|
|
|
9453
9646
|
var key = '$$$' + idx;
|
|
9454
9647
|
|
|
9455
9648
|
if (v instanceof yy.Column && query.groupColumns[v.columnid]) {
|
|
9456
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
9649
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
9457
9650
|
} else {
|
|
9458
9651
|
s += "r['" + key + "']=" + v.toJS('g', '') + ';';
|
|
9459
9652
|
}
|
|
@@ -10523,7 +10716,7 @@ yy.Over.prototype.toString = function () {
|
|
|
10523
10716
|
var ljs = '(' + leftJS() + '||{})';
|
|
10524
10717
|
|
|
10525
10718
|
if (typeof this.right === 'string') {
|
|
10526
|
-
s = ljs + '["' + this.right + '"]';
|
|
10719
|
+
s = ljs + '["' + escapeq(this.right) + '"]';
|
|
10527
10720
|
} else if (typeof this.right === 'number') {
|
|
10528
10721
|
s = ljs + '[' + this.right + ']';
|
|
10529
10722
|
} else if (this.right instanceof yy.FuncValue) {
|
|
@@ -10539,7 +10732,7 @@ yy.Over.prototype.toString = function () {
|
|
|
10539
10732
|
|
|
10540
10733
|
if (this.op === '!') {
|
|
10541
10734
|
if (typeof this.right === 'string') {
|
|
10542
|
-
s = '' + 'alasql.databases[alasql.useid].objects[' + leftJS() + ']["' + this.right + '"]';
|
|
10735
|
+
s = '' + 'alasql.databases[alasql.useid].objects[' + leftJS() + ']["' + escapeq(this.right) + '"]';
|
|
10543
10736
|
}
|
|
10544
10737
|
// TODO - add other cases
|
|
10545
10738
|
}
|
|
@@ -10903,7 +11096,7 @@ yy.Over.prototype.toString = function () {
|
|
|
10903
11096
|
|
|
10904
11097
|
toJS() {
|
|
10905
11098
|
if (typeof this.param === 'string') {
|
|
10906
|
-
return "params['" + this.param + "']";
|
|
11099
|
+
return "params['" + escapeq(this.param) + "']";
|
|
10907
11100
|
}
|
|
10908
11101
|
|
|
10909
11102
|
return 'params[' + this.param + ']';
|
|
@@ -11974,9 +12167,23 @@ var JSONtoString = (alasql.utils.JSONtoString = function (obj) {
|
|
|
11974
12167
|
return s;
|
|
11975
12168
|
});
|
|
11976
12169
|
|
|
12170
|
+
// A string value or key of a JSON value goes between double quotes in the generated code. A
|
|
12171
|
+
// backslash pair keeps its meaning; a lone backslash at the end, a double quote and a line break
|
|
12172
|
+
// are escaped, so the string cannot end early.
|
|
12173
|
+
function escapeJSONString(s) {
|
|
12174
|
+
return s.replace(/\\[\s\S]|\\$|"|\n|\r|\u2028|\u2029/g, function (c) {
|
|
12175
|
+
if (c.length === 2) return c;
|
|
12176
|
+
if (c === '\\') return '\\\\';
|
|
12177
|
+
if (c === '"') return '\\"';
|
|
12178
|
+
if (c === '\n') return '\\n';
|
|
12179
|
+
if (c === '\r') return '\\r';
|
|
12180
|
+
return c === '\u2028' ? '\\u2028' : '\\u2029';
|
|
12181
|
+
});
|
|
12182
|
+
}
|
|
12183
|
+
|
|
11977
12184
|
function JSONtoJS(obj, context, tableid, defcols) {
|
|
11978
12185
|
var s = '';
|
|
11979
|
-
if (typeof obj == 'string') s = '"' + obj + '"';
|
|
12186
|
+
if (typeof obj == 'string') s = '"' + escapeJSONString(obj) + '"';
|
|
11980
12187
|
else if (typeof obj == 'number') s = '(' + obj + ')';
|
|
11981
12188
|
else if (typeof obj == 'boolean') s = obj;
|
|
11982
12189
|
else if (typeof obj == 'object') {
|
|
@@ -11995,7 +12202,7 @@ function JSONtoJS(obj, context, tableid, defcols) {
|
|
|
11995
12202
|
var ss = [];
|
|
11996
12203
|
for (var k in obj) {
|
|
11997
12204
|
var s1 = '';
|
|
11998
|
-
if (typeof k == 'string') s1 += '"' + k + '"';
|
|
12205
|
+
if (typeof k == 'string') s1 += '"' + escapeJSONString(k) + '"';
|
|
11999
12206
|
else if (typeof k == 'number') s1 += k;
|
|
12000
12207
|
else if (typeof k == 'boolean') s1 += k;
|
|
12001
12208
|
else {
|