alasql 2.1.10 → 2.1.11
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 +52 -9
- package/package.json +1 -1
package/bin/alasql-cli.js
CHANGED
package/dist/alasql-worker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v2.1.
|
|
1
|
+
//! AlaSQL v2.1.11 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.1.
|
|
4
|
+
@version 2.1.11
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2016 Andrey Gershun & Mathias Rangel Wulff
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
//! AlaSQL v2.1.
|
|
1
|
+
//! AlaSQL v2.1.11 | © 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.1.
|
|
1
|
+
//! AlaSQL v2.1.11 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 2.1.
|
|
4
|
+
@version 2.1.11
|
|
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.1.
|
|
145
|
+
alasql.version = '2.1.11';
|
|
146
146
|
|
|
147
147
|
/**
|
|
148
148
|
Debug flag
|
|
@@ -4488,9 +4488,201 @@ alasql.parser.parseError = function (str, hash) {
|
|
|
4488
4488
|
}
|
|
4489
4489
|
*/
|
|
4490
4490
|
alasql.parse = function (sql) {
|
|
4491
|
-
|
|
4491
|
+
var ast = alasqlparser.parse(alasql.utils.uncomment(sql));
|
|
4492
|
+
checkSqlNames(ast);
|
|
4493
|
+
return ast;
|
|
4492
4494
|
};
|
|
4493
4495
|
|
|
4496
|
+
/*
|
|
4497
|
+
A name from the SQL text is pasted into generated code between single quotes, so a name that
|
|
4498
|
+
holds a quote, a backslash or a line break would end the string and make the rest code
|
|
4499
|
+
(GHSA-67vj-hh8j-j94f). Such a name is refused here, once, after parsing. A name is a table,
|
|
4500
|
+
column, database, view, index, trigger or CTE name, a variable (and the keys of its path) and a
|
|
4501
|
+
table alias. The alias of a column in the select list is not a name: it is a key of the result,
|
|
4502
|
+
and the code that writes it escapes it. Strings, numbers, parameters, JavaScript and the keys
|
|
4503
|
+
of a JSON value are data, not names.
|
|
4504
|
+
*/
|
|
4505
|
+
var checkSqlNames = (function () {
|
|
4506
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
4507
|
+
var badName = /['\\\n\r\u2028\u2029]/;
|
|
4508
|
+
var nameKeys = {
|
|
4509
|
+
as: 1,
|
|
4510
|
+
columnid: 1,
|
|
4511
|
+
tableid: 1,
|
|
4512
|
+
databaseid: 1,
|
|
4513
|
+
viewid: 1,
|
|
4514
|
+
indexid: 1,
|
|
4515
|
+
trigger: 1,
|
|
4516
|
+
variable: 1,
|
|
4517
|
+
dropcolumn: 1,
|
|
4518
|
+
renamecolumn: 1,
|
|
4519
|
+
renameto: 1,
|
|
4520
|
+
to: 1,
|
|
4521
|
+
tocolumnid: 1,
|
|
4522
|
+
forcolumnid: 1,
|
|
4523
|
+
};
|
|
4524
|
+
var nameListKeys = {columns: 1, fkcolumns: 1, props: 1};
|
|
4525
|
+
|
|
4526
|
+
function checkName(name) {
|
|
4527
|
+
if (badName.test(name)) throw new SyntaxError('Not a valid name: ' + name);
|
|
4528
|
+
}
|
|
4529
|
+
|
|
4530
|
+
// ORDER BY: a name that equals an alias of the select list is that alias and is allowed (the code
|
|
4531
|
+
// escapes it), anything else is checked. (In this version a string in ORDER BY is a constant.)
|
|
4532
|
+
function checkOrder(columns, order) {
|
|
4533
|
+
var aliases = {};
|
|
4534
|
+
(columns || []).forEach(function (col) {
|
|
4535
|
+
if (col && typeof col.as === 'string') aliases[col.as] = true;
|
|
4536
|
+
});
|
|
4537
|
+
order.forEach(function (ord) {
|
|
4538
|
+
var e = ord && ord.expression;
|
|
4539
|
+
var name;
|
|
4540
|
+
if (e instanceof alasql.yy.Column && !e.tableid) name = e.columnid;
|
|
4541
|
+
if (typeof name === 'string') {
|
|
4542
|
+
if (!hasOwn.call(aliases, name)) checkName(name);
|
|
4543
|
+
return;
|
|
4544
|
+
}
|
|
4545
|
+
checkNames(ord, false, false);
|
|
4546
|
+
});
|
|
4547
|
+
}
|
|
4548
|
+
|
|
4549
|
+
// The alias of an entry of the select list, of SEARCH RETURNS and of CREATE GRAPH is a key of
|
|
4550
|
+
// the result or a variable and is allowed. The name of an entry of WITH is a table name; in a
|
|
4551
|
+
// graph item, name is data.
|
|
4552
|
+
function entryOf(node, key) {
|
|
4553
|
+
var yy = alasql.yy;
|
|
4554
|
+
if (
|
|
4555
|
+
(node instanceof yy.Select && key === 'columns') ||
|
|
4556
|
+
(node instanceof yy.CreateGraph && key === 'graph') ||
|
|
4557
|
+
(node.srchid === 'RETURN' && key === 'args')
|
|
4558
|
+
)
|
|
4559
|
+
return 'alias';
|
|
4560
|
+
if (node instanceof yy.WithSelect && key === 'withs') return 'with';
|
|
4561
|
+
return '';
|
|
4562
|
+
}
|
|
4563
|
+
|
|
4564
|
+
// Names that never reach generated code: they are used only at run time, as the key of a
|
|
4565
|
+
// database, a table, an index, a trigger or a variable, so the walk leaves them alone and such a
|
|
4566
|
+
// name keeps working. freeKeys are names of the node itself, freeChild are children whose own
|
|
4567
|
+
// names are free (what they hold is still walked), and skipChild are children that are not
|
|
4568
|
+
// walked at all (PIVOT and UNPIVOT work on the result and build no code).
|
|
4569
|
+
var varValueFree = false;
|
|
4570
|
+
var intoVarFree = false;
|
|
4571
|
+
var freeKeys = [
|
|
4572
|
+
['CreateIndex', {indexid: 1}],
|
|
4573
|
+
['DropIndex', {indexid: 1}],
|
|
4574
|
+
['Reindex', {indexid: 1}],
|
|
4575
|
+
['CreateTrigger', {trigger: 1}],
|
|
4576
|
+
['DropTrigger', {trigger: 1}],
|
|
4577
|
+
['CreateDatabase', {databaseid: 1, as: 1}],
|
|
4578
|
+
['AttachDatabase', {databaseid: 1, as: 1}],
|
|
4579
|
+
['DetachDatabase', {databaseid: 1}],
|
|
4580
|
+
['DropDatabase', {databaseid: 1}],
|
|
4581
|
+
['ShowTables', {databaseid: 1}],
|
|
4582
|
+
['ShowColumns', {databaseid: 1}],
|
|
4583
|
+
['ShowIndex', {databaseid: 1}],
|
|
4584
|
+
['ShowCreateTable', {databaseid: 1}],
|
|
4585
|
+
['AlterTable', {renameto: 1, renamecolumn: 1, dropcolumn: 1}],
|
|
4586
|
+
];
|
|
4587
|
+
var freeChild = [
|
|
4588
|
+
['CreateTable', {table: 1}],
|
|
4589
|
+
['DropTable', {tables: 1}],
|
|
4590
|
+
['TruncateTable', {table: 1}],
|
|
4591
|
+
['AlterTable', {table: 1}],
|
|
4592
|
+
['ShowColumns', {table: 1}],
|
|
4593
|
+
['ShowIndex', {table: 1}],
|
|
4594
|
+
['ShowCreateTable', {table: 1}],
|
|
4595
|
+
['CreateIndex', {table: 1}],
|
|
4596
|
+
['CreateTrigger', {table: 1}],
|
|
4597
|
+
['Declare', {declares: 1}],
|
|
4598
|
+
];
|
|
4599
|
+
var skipChild = [['Select', {pivot: 1, unpivot: 1}]];
|
|
4600
|
+
|
|
4601
|
+
function freeOf(list, node) {
|
|
4602
|
+
var yy = alasql.yy;
|
|
4603
|
+
for (var i = 0; i < list.length; i++) {
|
|
4604
|
+
var cls = yy[list[i][0]];
|
|
4605
|
+
if (cls && node instanceof cls) return list[i][1];
|
|
4606
|
+
}
|
|
4607
|
+
return null;
|
|
4608
|
+
}
|
|
4609
|
+
|
|
4610
|
+
// An @variable: an expression pastes it escaped where varValueFree is true, FROM @x pastes it
|
|
4611
|
+
// raw, and SELECT INTO @x pastes it raw where intoVarFree is false.
|
|
4612
|
+
function freeVar(node, key, entry) {
|
|
4613
|
+
var yy = alasql.yy;
|
|
4614
|
+
if (key !== 'variable' || !(node instanceof yy.VarValue)) return false;
|
|
4615
|
+
if (entry === 'source') return false;
|
|
4616
|
+
if (entry === 'into') return intoVarFree;
|
|
4617
|
+
return varValueFree;
|
|
4618
|
+
}
|
|
4619
|
+
|
|
4620
|
+
// SET @x = value without a path is a run-time assignment; with a path the name is pasted
|
|
4621
|
+
function freeSet(node, key) {
|
|
4622
|
+
var yy = alasql.yy;
|
|
4623
|
+
return key === 'variable' && yy.SetVariable && node instanceof yy.SetVariable && !(node.props && node.props.length);
|
|
4624
|
+
}
|
|
4625
|
+
|
|
4626
|
+
// data is true inside a JSON value, where a plain object is data and only a node is looked at.
|
|
4627
|
+
// entry is what entryOf says about the node as an entry of its parent, or 'free' when its own
|
|
4628
|
+
// names never reach generated code.
|
|
4629
|
+
function checkNames(node, data, entry) {
|
|
4630
|
+
if (node === null || typeof node !== 'object') return;
|
|
4631
|
+
var i;
|
|
4632
|
+
if (Array.isArray(node)) {
|
|
4633
|
+
for (i = 0; i < node.length; i++) checkNames(node[i], data, false);
|
|
4634
|
+
return;
|
|
4635
|
+
}
|
|
4636
|
+
var isNode = Object.getPrototypeOf(node) !== Object.prototype;
|
|
4637
|
+
if (data && !isNode) {
|
|
4638
|
+
for (i in node) if (hasOwn.call(node, i)) checkNames(node[i], true, false);
|
|
4639
|
+
return;
|
|
4640
|
+
}
|
|
4641
|
+
var yy = alasql.yy;
|
|
4642
|
+
if (node instanceof yy.Json) {
|
|
4643
|
+
checkNames(node.value, true, false);
|
|
4644
|
+
return;
|
|
4645
|
+
}
|
|
4646
|
+
var fk = freeOf(freeKeys, node);
|
|
4647
|
+
var fc = freeOf(freeChild, node);
|
|
4648
|
+
var sc = freeOf(skipChild, node);
|
|
4649
|
+
for (var key in node) {
|
|
4650
|
+
if (!hasOwn.call(node, key)) continue;
|
|
4651
|
+
var value = node[key];
|
|
4652
|
+
if (sc && sc[key] === 1) continue;
|
|
4653
|
+
if (key === 'order' && node instanceof yy.Select && Array.isArray(value)) {
|
|
4654
|
+
checkOrder(node.columns, value);
|
|
4655
|
+
continue;
|
|
4656
|
+
}
|
|
4657
|
+
// the column list of a WITH entry renames the result at run time
|
|
4658
|
+
var child = (fc && fc[key] === 1) || (entry === 'with' && key === 'columns') ? 'free' : '';
|
|
4659
|
+
if (!child && node instanceof yy.Select) child = key === 'from' ? 'source' : key === 'into' ? 'into' : '';
|
|
4660
|
+
if (typeof value === 'string') {
|
|
4661
|
+
if (entry === 'free' || (fk && fk[key] === 1) || freeSet(node, key) || freeVar(node, key, entry))
|
|
4662
|
+
continue;
|
|
4663
|
+
if (key === 'name' ? entry === 'with' : nameKeys[key] === 1 && !(entry === 'alias' && key === 'as'))
|
|
4664
|
+
checkName(value);
|
|
4665
|
+
} else if (value !== null && typeof value === 'object') {
|
|
4666
|
+
if (Array.isArray(value)) {
|
|
4667
|
+
for (i = 0; i < value.length; i++) {
|
|
4668
|
+
if (typeof value[i] === 'string') {
|
|
4669
|
+
if (nameListKeys[key] === 1 && entry !== 'free' && child !== 'free') checkName(value[i]);
|
|
4670
|
+
} else {
|
|
4671
|
+
checkNames(value[i], false, child || entryOf(node, key));
|
|
4672
|
+
}
|
|
4673
|
+
}
|
|
4674
|
+
} else {
|
|
4675
|
+
checkNames(value, false, child);
|
|
4676
|
+
}
|
|
4677
|
+
}
|
|
4678
|
+
}
|
|
4679
|
+
}
|
|
4680
|
+
|
|
4681
|
+
return function (ast) {
|
|
4682
|
+
checkNames(ast, false, false);
|
|
4683
|
+
};
|
|
4684
|
+
})();
|
|
4685
|
+
|
|
4494
4686
|
/**
|
|
4495
4687
|
List of engines of external databases
|
|
4496
4688
|
@type {object}
|
|
@@ -7615,7 +7807,7 @@ yy.Select.prototype.compile = function (databaseid, params) {
|
|
|
7615
7807
|
// Save data into parameters array
|
|
7616
7808
|
// like alasql('SELECT * INTO ? FROM ?',[outdata,srcdata]);
|
|
7617
7809
|
//
|
|
7618
|
-
query.intofns = "params['" + this.into.param + "'].push(r)";
|
|
7810
|
+
query.intofns = "params['" + escapeq(this.into.param) + "'].push(r)";
|
|
7619
7811
|
}
|
|
7620
7812
|
|
|
7621
7813
|
if (query.intofns) {
|
|
@@ -8020,7 +8212,7 @@ yy.Select.prototype.compileFrom = function (query) {
|
|
|
8020
8212
|
return res;
|
|
8021
8213
|
};
|
|
8022
8214
|
} else if (tq instanceof yy.ParamValue) {
|
|
8023
|
-
ps = "var res = alasql.prepareFromData(params['" + tq.param + "']";
|
|
8215
|
+
ps = "var res = alasql.prepareFromData(params['" + escapeq(tq.param) + "']";
|
|
8024
8216
|
|
|
8025
8217
|
if (tq.array) ps += ',true';
|
|
8026
8218
|
ps += ');if(cb)res=cb(res,idx,query);return res';
|
|
@@ -8269,7 +8461,7 @@ yy.Select.prototype.compileJoins = function (query) {
|
|
|
8269
8461
|
// source.data = ;
|
|
8270
8462
|
var jnparam = jn.param.param;
|
|
8271
8463
|
|
|
8272
|
-
ps = "var res=alasql.prepareFromData(params['" + jnparam + "']";
|
|
8464
|
+
ps = "var res=alasql.prepareFromData(params['" + escapeq(jnparam) + "']";
|
|
8273
8465
|
if (jn.array) ps += ',true';
|
|
8274
8466
|
ps += ');if(cb)res=cb(res, idx, query);return res';
|
|
8275
8467
|
|
|
@@ -8967,9 +9159,10 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
8967
9159
|
|
|
8968
9160
|
if (columns && columns.length > 0) {
|
|
8969
9161
|
columns.forEach(function (tcol) {
|
|
9162
|
+
var escapedColumnId = escapeq(tcol.columnid);
|
|
8970
9163
|
if (joinstar && alasql.options.joinstar == 'underscore') {
|
|
8971
9164
|
ss.push(
|
|
8972
|
-
"'" + alias + '_' +
|
|
9165
|
+
"'" + alias + '_' + escapedColumnId + "':p['" + alias + "']['" + escapedColumnId + "']"
|
|
8973
9166
|
);
|
|
8974
9167
|
} else if (joinstar && alasql.options.joinstar == 'json') {
|
|
8975
9168
|
// ss.push('\''+alias+'_'+tcol.columnid+'\':p[\''+alias+'\'][\''+tcol.columnid+'\']');
|
|
@@ -8977,16 +9170,16 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
8977
9170
|
"r['" +
|
|
8978
9171
|
alias +
|
|
8979
9172
|
"']['" +
|
|
8980
|
-
|
|
9173
|
+
escapedColumnId +
|
|
8981
9174
|
"']=p['" +
|
|
8982
9175
|
alias +
|
|
8983
9176
|
"']['" +
|
|
8984
|
-
|
|
9177
|
+
escapedColumnId +
|
|
8985
9178
|
"'];";
|
|
8986
9179
|
} else {
|
|
8987
|
-
var value = "p['" + alias + "']['" +
|
|
9180
|
+
var value = "p['" + alias + "']['" + escapedColumnId + "']";
|
|
8988
9181
|
if (!columnIds[tcol.columnid]) {
|
|
8989
|
-
var key = "'" +
|
|
9182
|
+
var key = "'" + escapedColumnId + "':";
|
|
8990
9183
|
ss.push(key + value);
|
|
8991
9184
|
columnIds[tcol.columnid] = {
|
|
8992
9185
|
id: ss.length - 1,
|
|
@@ -9017,7 +9210,7 @@ function compileSelectStar(query, aliases, joinstar) {
|
|
|
9017
9210
|
} else {
|
|
9018
9211
|
|
|
9019
9212
|
// if column not exist, then copy all
|
|
9020
|
-
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]};';
|
|
9213
|
+
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]};';
|
|
9021
9214
|
|
|
9022
9215
|
query.dirtyColumns = true;
|
|
9023
9216
|
}
|
|
@@ -9044,7 +9237,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9044
9237
|
if (col.columnid === '*') {
|
|
9045
9238
|
if (col.func) {
|
|
9046
9239
|
sp +=
|
|
9047
|
-
"r=params['" + col.param + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
9240
|
+
"r=params['" + escapeq(col.param) + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
9048
9241
|
} else if (col.tableid) {
|
|
9049
9242
|
//Copy all
|
|
9050
9243
|
var ret = compileSelectStar(query, [col.tableid], false);
|
|
@@ -9096,7 +9289,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9096
9289
|
if (isMultisheetParam) {
|
|
9097
9290
|
sp =
|
|
9098
9291
|
'var r={};var w=p["' +
|
|
9099
|
-
tbid +
|
|
9292
|
+
escapeq(tbid) +
|
|
9100
9293
|
'"];' +
|
|
9101
9294
|
'var cols=[' +
|
|
9102
9295
|
self.columns
|
|
@@ -9107,7 +9300,7 @@ yy.Select.prototype.compileSelect1 = function (query, params) {
|
|
|
9107
9300
|
'];var colas=[' +
|
|
9108
9301
|
self.columns
|
|
9109
9302
|
.map(function (col) {
|
|
9110
|
-
return "'" + (col.as || col.columnid) + "'";
|
|
9303
|
+
return "'" + escapeq(col.as || col.columnid) + "'";
|
|
9111
9304
|
})
|
|
9112
9305
|
.join(',') +
|
|
9113
9306
|
'];' +
|
|
@@ -9270,9 +9463,9 @@ yy.Select.prototype.compileSelect2 = function (query, params) {
|
|
|
9270
9463
|
this.orderColumns.forEach(function (v, idx) {
|
|
9271
9464
|
var key = '$$$' + idx;
|
|
9272
9465
|
if (v instanceof yy.Column && query.xcolumns[v.columnid]) {
|
|
9273
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
9466
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
9274
9467
|
} else if (v instanceof yy.ParamValue && query.xcolumns[params[v.param]]) {
|
|
9275
|
-
s += "r['" + key + "']=r['" + params[v.param] + "'];";
|
|
9468
|
+
s += "r['" + key + "']=r['" + escapeq(params[v.param]) + "'];";
|
|
9276
9469
|
} else {
|
|
9277
9470
|
s += "r['" + key + "']=" + v.toJS('p', query.defaultTableid, query.defcols) + ';';
|
|
9278
9471
|
}
|
|
@@ -9365,7 +9558,7 @@ yy.Select.prototype.compileSelectGroup1 = function (query) {
|
|
|
9365
9558
|
query.groupColumns[colas] = col.nick;
|
|
9366
9559
|
|
|
9367
9560
|
// if(col.as) {
|
|
9368
|
-
s += "r['" + colas + "']=";
|
|
9561
|
+
s += "r['" + (col.as !== undefined ? escapeq(colas) : colas) + "']=";
|
|
9369
9562
|
// // } else {
|
|
9370
9563
|
// // s += 'r[\''+escapeq()+'\']=';
|
|
9371
9564
|
// // };
|
|
@@ -9392,7 +9585,7 @@ yy.Select.prototype.compileSelectGroup2 = function (query) {
|
|
|
9392
9585
|
self.columns.forEach(function (col) {
|
|
9393
9586
|
|
|
9394
9587
|
if (query.ingroup.indexOf(col.nick) > -1) {
|
|
9395
|
-
s += "r['" + (col.as
|
|
9588
|
+
s += "r['" + (col.as ? escapeq(col.as) : col.nick) + "']=g['" + col.nick + "'];";
|
|
9396
9589
|
}
|
|
9397
9590
|
});
|
|
9398
9591
|
|
|
@@ -9402,7 +9595,7 @@ yy.Select.prototype.compileSelectGroup2 = function (query) {
|
|
|
9402
9595
|
var key = '$$$' + idx;
|
|
9403
9596
|
|
|
9404
9597
|
if (v instanceof yy.Column && query.groupColumns[v.columnid]) {
|
|
9405
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
9598
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
9406
9599
|
} else {
|
|
9407
9600
|
s += "r['" + key + "']=" + v.toJS('g', '') + ';';
|
|
9408
9601
|
}
|
|
@@ -10479,7 +10672,7 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10479
10672
|
var ljs = '(' + leftJS() + '||{})';
|
|
10480
10673
|
|
|
10481
10674
|
if (typeof this.right === 'string') {
|
|
10482
|
-
s = ljs + '["' + this.right + '"]';
|
|
10675
|
+
s = ljs + '["' + escapeq(this.right) + '"]';
|
|
10483
10676
|
} else if (typeof this.right === 'number') {
|
|
10484
10677
|
s = ljs + '[' + this.right + ']';
|
|
10485
10678
|
} else if (this.right instanceof yy.FuncValue) {
|
|
@@ -10495,7 +10688,7 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
|
|
|
10495
10688
|
|
|
10496
10689
|
if (this.op === '!') {
|
|
10497
10690
|
if (typeof this.right === 'string') {
|
|
10498
|
-
s = '' + 'alasql.databases[alasql.useid].objects[' + leftJS() + ']["' + this.right + '"]';
|
|
10691
|
+
s = '' + 'alasql.databases[alasql.useid].objects[' + leftJS() + ']["' + escapeq(this.right) + '"]';
|
|
10499
10692
|
}
|
|
10500
10693
|
// TODO - add other cases
|
|
10501
10694
|
}
|
|
@@ -10824,7 +11017,7 @@ yy.ParamValue.prototype.toString = function () {
|
|
|
10824
11017
|
};
|
|
10825
11018
|
yy.ParamValue.prototype.toJS = function () {
|
|
10826
11019
|
if (typeof this.param === 'string') {
|
|
10827
|
-
return "params['" + this.param + "']";
|
|
11020
|
+
return "params['" + escapeq(this.param) + "']";
|
|
10828
11021
|
}
|
|
10829
11022
|
|
|
10830
11023
|
return 'params[' + this.param + ']';
|
|
@@ -11852,9 +12045,23 @@ var JSONtoString = (alasql.utils.JSONtoString = function (obj) {
|
|
|
11852
12045
|
return s;
|
|
11853
12046
|
});
|
|
11854
12047
|
|
|
12048
|
+
// A string value or key of a JSON value goes between double quotes in the generated code. A
|
|
12049
|
+
// backslash pair keeps its meaning; a lone backslash at the end, a double quote and a line break
|
|
12050
|
+
// are escaped, so the string cannot end early.
|
|
12051
|
+
function escapeJSONString(s) {
|
|
12052
|
+
return s.replace(/\\[\s\S]|\\$|"|\n|\r|\u2028|\u2029/g, function (c) {
|
|
12053
|
+
if (c.length === 2) return c;
|
|
12054
|
+
if (c === '\\') return '\\\\';
|
|
12055
|
+
if (c === '"') return '\\"';
|
|
12056
|
+
if (c === '\n') return '\\n';
|
|
12057
|
+
if (c === '\r') return '\\r';
|
|
12058
|
+
return c === '\u2028' ? '\\u2028' : '\\u2029';
|
|
12059
|
+
});
|
|
12060
|
+
}
|
|
12061
|
+
|
|
11855
12062
|
function JSONtoJS(obj, context, tableid, defcols) {
|
|
11856
12063
|
var s = '';
|
|
11857
|
-
if (typeof obj == 'string') s = '"' + obj + '"';
|
|
12064
|
+
if (typeof obj == 'string') s = '"' + escapeJSONString(obj) + '"';
|
|
11858
12065
|
else if (typeof obj == 'number') s = '(' + obj + ')';
|
|
11859
12066
|
else if (typeof obj == 'boolean') s = obj;
|
|
11860
12067
|
else if (typeof obj == 'object') {
|
|
@@ -11873,7 +12080,7 @@ function JSONtoJS(obj, context, tableid, defcols) {
|
|
|
11873
12080
|
var ss = [];
|
|
11874
12081
|
for (var k in obj) {
|
|
11875
12082
|
var s1 = '';
|
|
11876
|
-
if (typeof k == 'string') s1 += '"' + k + '"';
|
|
12083
|
+
if (typeof k == 'string') s1 += '"' + escapeJSONString(k) + '"';
|
|
11877
12084
|
else if (typeof k == 'number') s1 += k;
|
|
11878
12085
|
else if (typeof k == 'boolean') s1 += k;
|
|
11879
12086
|
else {
|