alasql 4.23.3 → 4.23.4
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/README.md +2 -2
- package/dist/alasql-worker.js +2 -2
- package/dist/alasql.fs.js +181 -21
- package/dist/alasql.js +181 -21
- package/dist/alasql.min.js +144 -143
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,10 +120,10 @@ import alasql from 'alasql';
|
|
|
120
120
|
// or: const alasql = require('alasql');
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
-
In the browser, include [alasql.min.js](https://cdn.jsdelivr.net/npm/alasql@4.23.
|
|
123
|
+
In the browser, include [alasql.min.js](https://cdn.jsdelivr.net/npm/alasql@4.23.4/dist/alasql.min.js):
|
|
124
124
|
|
|
125
125
|
```html
|
|
126
|
-
<script src="https://cdn.jsdelivr.net/npm/alasql@4.23.
|
|
126
|
+
<script src="https://cdn.jsdelivr.net/npm/alasql@4.23.4/dist/alasql.min.js"></script>
|
|
127
127
|
```
|
|
128
128
|
|
|
129
129
|
## Getting started
|
package/dist/alasql-worker.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v4.23.
|
|
1
|
+
//! AlaSQL v4.23.4 build: hotfix.v4.23.4-1d6df59b | © 2014-2026 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 4.23.
|
|
4
|
+
@version 4.23.4
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2026 Andrey Gershun & Mathias Wulff
|
package/dist/alasql.fs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v4.23.
|
|
1
|
+
//! AlaSQL v4.23.4 build: hotfix.v4.23.4-1d6df59b | © 2014-2026 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 4.23.
|
|
4
|
+
@version 4.23.4
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2026 Andrey Gershun & Mathias Wulff
|
|
@@ -96,8 +96,8 @@ function create() {
|
|
|
96
96
|
}
|
|
97
97
|
return alasql.exec(sql, params, cb, scope);
|
|
98
98
|
};
|
|
99
|
-
alasql.version = "4.23.
|
|
100
|
-
alasql.build = "hotfix.v4.23.
|
|
99
|
+
alasql.version = "4.23.4";
|
|
100
|
+
alasql.build = "hotfix.v4.23.4-1d6df59b";
|
|
101
101
|
alasql.debug = void 0;
|
|
102
102
|
return alasql;
|
|
103
103
|
}
|
|
@@ -4066,8 +4066,158 @@ function install(alasql, internal2) {
|
|
|
4066
4066
|
throw new Error("Have you used a reserved keyword without `escaping` it?\n" + str);
|
|
4067
4067
|
};
|
|
4068
4068
|
alasql.parse = function(sql) {
|
|
4069
|
-
|
|
4070
|
-
|
|
4069
|
+
var ast = alasqlparser.parse(alasql.utils.uncomment(sql));
|
|
4070
|
+
checkNames(ast, false, false);
|
|
4071
|
+
return ast;
|
|
4072
|
+
};
|
|
4073
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
4074
|
+
function checkOrder(columns, order) {
|
|
4075
|
+
var aliases = {};
|
|
4076
|
+
(columns || []).forEach(function(col) {
|
|
4077
|
+
if (col && typeof col.as === "string") aliases[col.as] = true;
|
|
4078
|
+
});
|
|
4079
|
+
order.forEach(function(ord) {
|
|
4080
|
+
var e = ord && ord.expression;
|
|
4081
|
+
var name;
|
|
4082
|
+
if (e instanceof alasql.yy.StringValue) name = e.value;
|
|
4083
|
+
else if (e instanceof alasql.yy.Column && !e.tableid) name = e.columnid;
|
|
4084
|
+
if (typeof name === "string") {
|
|
4085
|
+
if (!hasOwn.call(aliases, name)) checkName(name);
|
|
4086
|
+
return;
|
|
4087
|
+
}
|
|
4088
|
+
checkNames(ord, false, false);
|
|
4089
|
+
});
|
|
4090
|
+
}
|
|
4091
|
+
var badName = /['\\\n\r\u2028\u2029]/;
|
|
4092
|
+
var nameKeys = {
|
|
4093
|
+
as: 1,
|
|
4094
|
+
columnid: 1,
|
|
4095
|
+
tableid: 1,
|
|
4096
|
+
databaseid: 1,
|
|
4097
|
+
viewid: 1,
|
|
4098
|
+
indexid: 1,
|
|
4099
|
+
trigger: 1,
|
|
4100
|
+
variable: 1,
|
|
4101
|
+
dropcolumn: 1,
|
|
4102
|
+
renamecolumn: 1,
|
|
4103
|
+
renameto: 1,
|
|
4104
|
+
to: 1,
|
|
4105
|
+
tocolumnid: 1,
|
|
4106
|
+
forcolumnid: 1
|
|
4107
|
+
};
|
|
4108
|
+
var nameListKeys = { columns: 1, fkcolumns: 1, props: 1 };
|
|
4109
|
+
function checkName(name) {
|
|
4110
|
+
if (badName.test(name)) throw new SyntaxError("Not a valid name: " + name);
|
|
4111
|
+
}
|
|
4112
|
+
function entryOf(node, key) {
|
|
4113
|
+
var yy = alasql.yy;
|
|
4114
|
+
if (node instanceof yy.Select && key === "columns" || node instanceof yy.CreateGraph && key === "graph" || node.srchid === "RETURN" && key === "args")
|
|
4115
|
+
return "alias";
|
|
4116
|
+
if (node instanceof yy.WithSelect && key === "withs") return "with";
|
|
4117
|
+
return "";
|
|
4118
|
+
}
|
|
4119
|
+
var varValueFree = true;
|
|
4120
|
+
var intoVarFree = true;
|
|
4121
|
+
var freeKeys = [
|
|
4122
|
+
["CreateIndex", { indexid: 1 }],
|
|
4123
|
+
["DropIndex", { indexid: 1 }],
|
|
4124
|
+
["Reindex", { indexid: 1 }],
|
|
4125
|
+
["CreateTrigger", { trigger: 1 }],
|
|
4126
|
+
["DropTrigger", { trigger: 1 }],
|
|
4127
|
+
["CreateDatabase", { databaseid: 1, as: 1 }],
|
|
4128
|
+
["AttachDatabase", { databaseid: 1, as: 1 }],
|
|
4129
|
+
["DetachDatabase", { databaseid: 1 }],
|
|
4130
|
+
["DropDatabase", { databaseid: 1 }],
|
|
4131
|
+
["ShowTables", { databaseid: 1 }],
|
|
4132
|
+
["ShowColumns", { databaseid: 1 }],
|
|
4133
|
+
["ShowIndex", { databaseid: 1 }],
|
|
4134
|
+
["ShowCreateTable", { databaseid: 1 }],
|
|
4135
|
+
["AlterTable", { renameto: 1, renamecolumn: 1, dropcolumn: 1 }]
|
|
4136
|
+
];
|
|
4137
|
+
var freeChild = [
|
|
4138
|
+
["CreateTable", { table: 1 }],
|
|
4139
|
+
["DropTable", { tables: 1 }],
|
|
4140
|
+
["TruncateTable", { table: 1 }],
|
|
4141
|
+
["AlterTable", { table: 1 }],
|
|
4142
|
+
["ShowColumns", { table: 1 }],
|
|
4143
|
+
["ShowIndex", { table: 1 }],
|
|
4144
|
+
["ShowCreateTable", { table: 1 }],
|
|
4145
|
+
["CreateIndex", { table: 1 }],
|
|
4146
|
+
["CreateTrigger", { table: 1 }],
|
|
4147
|
+
["Declare", { declares: 1 }]
|
|
4148
|
+
];
|
|
4149
|
+
var skipChild = [["Select", { pivot: 1, unpivot: 1 }]];
|
|
4150
|
+
function freeOf(list, node) {
|
|
4151
|
+
var yy = alasql.yy;
|
|
4152
|
+
for (var i = 0; i < list.length; i++) {
|
|
4153
|
+
var cls = yy[list[i][0]];
|
|
4154
|
+
if (cls && node instanceof cls) return list[i][1];
|
|
4155
|
+
}
|
|
4156
|
+
return null;
|
|
4157
|
+
}
|
|
4158
|
+
function freeVar(node, key, entry) {
|
|
4159
|
+
var yy = alasql.yy;
|
|
4160
|
+
if (key !== "variable" || !(node instanceof yy.VarValue)) return false;
|
|
4161
|
+
if (entry === "source") return false;
|
|
4162
|
+
if (entry === "into") return intoVarFree;
|
|
4163
|
+
return varValueFree;
|
|
4164
|
+
}
|
|
4165
|
+
function freeSet(node, key) {
|
|
4166
|
+
var yy = alasql.yy;
|
|
4167
|
+
return key === "variable" && yy.SetVariable && node instanceof yy.SetVariable && !(node.props && node.props.length);
|
|
4168
|
+
}
|
|
4169
|
+
function checkNames(node, data, entry) {
|
|
4170
|
+
if (node === null || typeof node !== "object") return;
|
|
4171
|
+
var i;
|
|
4172
|
+
if (Array.isArray(node)) {
|
|
4173
|
+
for (i = 0; i < node.length; i++) checkNames(node[i], data, false);
|
|
4174
|
+
return;
|
|
4175
|
+
}
|
|
4176
|
+
var isNode = Object.getPrototypeOf(node) !== Object.prototype;
|
|
4177
|
+
if (data && !isNode) {
|
|
4178
|
+
for (i in node) if (hasOwn.call(node, i)) checkNames(node[i], true, false);
|
|
4179
|
+
return;
|
|
4180
|
+
}
|
|
4181
|
+
var yy = alasql.yy;
|
|
4182
|
+
if (node instanceof yy.Json) {
|
|
4183
|
+
checkNames(node.value, true, false);
|
|
4184
|
+
return;
|
|
4185
|
+
}
|
|
4186
|
+
var fk = freeOf(freeKeys, node);
|
|
4187
|
+
var fc = freeOf(freeChild, node);
|
|
4188
|
+
var sc = freeOf(skipChild, node);
|
|
4189
|
+
for (var key in node) {
|
|
4190
|
+
if (!hasOwn.call(node, key)) continue;
|
|
4191
|
+
var value = node[key];
|
|
4192
|
+
if (sc && sc[key] === 1) continue;
|
|
4193
|
+
if (key === "order" && node instanceof yy.Select && Array.isArray(value)) {
|
|
4194
|
+
checkOrder(node.columns, value);
|
|
4195
|
+
continue;
|
|
4196
|
+
}
|
|
4197
|
+
var child = fc && fc[key] === 1 || entry === "with" && key === "columns" ? "free" : "";
|
|
4198
|
+
if (!child && node instanceof yy.Select)
|
|
4199
|
+
child = key === "from" ? "source" : key === "into" ? "into" : "";
|
|
4200
|
+
if (typeof value === "string") {
|
|
4201
|
+
if (entry === "free" || fk && fk[key] === 1 || freeSet(node, key) || freeVar(node, key, entry))
|
|
4202
|
+
continue;
|
|
4203
|
+
if (key === "name" ? entry === "with" : nameKeys[key] === 1 && !(entry === "alias" && key === "as"))
|
|
4204
|
+
checkName(value);
|
|
4205
|
+
} else if (value !== null && typeof value === "object") {
|
|
4206
|
+
if (Array.isArray(value)) {
|
|
4207
|
+
for (i = 0; i < value.length; i++) {
|
|
4208
|
+
if (typeof value[i] === "string") {
|
|
4209
|
+
if (nameListKeys[key] === 1 && entry !== "free" && child !== "free")
|
|
4210
|
+
checkName(value[i]);
|
|
4211
|
+
} else {
|
|
4212
|
+
checkNames(value[i], false, child || entryOf(node, key));
|
|
4213
|
+
}
|
|
4214
|
+
}
|
|
4215
|
+
} else {
|
|
4216
|
+
checkNames(value, false, child);
|
|
4217
|
+
}
|
|
4218
|
+
}
|
|
4219
|
+
}
|
|
4220
|
+
}
|
|
4071
4221
|
alasql.engines = {};
|
|
4072
4222
|
alasql.databases = {};
|
|
4073
4223
|
alasql.databasenum = 0;
|
|
@@ -6667,7 +6817,7 @@ function install19(alasql) {
|
|
|
6667
6817
|
}
|
|
6668
6818
|
} else if (this.op === "!") {
|
|
6669
6819
|
if (typeof this.right === "string") {
|
|
6670
|
-
s = `alasql.databases[alasql.useid].objects[${leftJS()}]["${this.right}"]`;
|
|
6820
|
+
s = `alasql.databases[alasql.useid].objects[${leftJS()}]["${escapeq(this.right)}"]`;
|
|
6671
6821
|
}
|
|
6672
6822
|
} else if (this.op === "IS") {
|
|
6673
6823
|
const leftOperand = leftJS();
|
|
@@ -6902,7 +7052,7 @@ function install19(alasql) {
|
|
|
6902
7052
|
}
|
|
6903
7053
|
toJS() {
|
|
6904
7054
|
if (typeof this.param === "string") {
|
|
6905
|
-
return "params['" + this.param + "']";
|
|
7055
|
+
return "params['" + escapeq(this.param) + "']";
|
|
6906
7056
|
}
|
|
6907
7057
|
return "params[" + this.param + "]";
|
|
6908
7058
|
}
|
|
@@ -7228,9 +7378,19 @@ function install21(alasql, internal2) {
|
|
|
7228
7378
|
throw new Error(`2: Cannot show JSON object ${JSON.stringify(obj)}`);
|
|
7229
7379
|
}
|
|
7230
7380
|
};
|
|
7381
|
+
function escapeJSONString(s) {
|
|
7382
|
+
return s.replace(/\\[\s\S]|\\$|"|\n|\r|\u2028|\u2029/g, function(c) {
|
|
7383
|
+
if (c.length === 2) return c;
|
|
7384
|
+
if (c === "\\") return "\\\\";
|
|
7385
|
+
if (c === '"') return '\\"';
|
|
7386
|
+
if (c === "\n") return "\\n";
|
|
7387
|
+
if (c === "\r") return "\\r";
|
|
7388
|
+
return c === "\u2028" ? "\\u2028" : "\\u2029";
|
|
7389
|
+
});
|
|
7390
|
+
}
|
|
7231
7391
|
function JSONtoJS(obj, context, tableid, defcols) {
|
|
7232
7392
|
var s = "";
|
|
7233
|
-
if (typeof obj == "string") s = '"' + obj + '"';
|
|
7393
|
+
if (typeof obj == "string") s = '"' + escapeJSONString(obj) + '"';
|
|
7234
7394
|
else if (typeof obj == "number") s = "(" + obj + ")";
|
|
7235
7395
|
else if (typeof obj == "boolean") s = obj;
|
|
7236
7396
|
else if (typeof obj === "bigint") s = obj.toString() + "n";
|
|
@@ -7240,7 +7400,7 @@ function install21(alasql, internal2) {
|
|
|
7240
7400
|
} else if (!obj.toJS || obj instanceof yy.Json) {
|
|
7241
7401
|
let ss = [];
|
|
7242
7402
|
for (const k in obj) {
|
|
7243
|
-
let keyStr = typeof k === "string" ? `"${k}"` : k.toString();
|
|
7403
|
+
let keyStr = typeof k === "string" ? `"${escapeJSONString(k)}"` : k.toString();
|
|
7244
7404
|
let valueStr = JSONtoJS(obj[k], context, tableid, defcols);
|
|
7245
7405
|
ss.push(`${keyStr}:${valueStr}`);
|
|
7246
7406
|
}
|
|
@@ -8887,7 +9047,7 @@ function install27(alasql, internal2) {
|
|
|
8887
9047
|
return res;
|
|
8888
9048
|
};
|
|
8889
9049
|
} else if (tq instanceof yy.ParamValue) {
|
|
8890
|
-
let ps = `var res = alasql.prepareFromData(params['${tq.param}']`;
|
|
9050
|
+
let ps = `var res = alasql.prepareFromData(params['${escapeq(tq.param)}']`;
|
|
8891
9051
|
if (tq.array) ps += ",true";
|
|
8892
9052
|
ps += ");if(cb)res=cb(res,idx,query);return res";
|
|
8893
9053
|
source.datafn = new Function("query,params,cb,idx,alasql", ps);
|
|
@@ -9065,7 +9225,7 @@ function install28(alasql, internal2) {
|
|
|
9065
9225
|
srcwherefn: returnTrue
|
|
9066
9226
|
};
|
|
9067
9227
|
const jnparam = jn.param.param;
|
|
9068
|
-
ps = "let res=alasql.prepareFromData(params['" + jnparam + "']";
|
|
9228
|
+
ps = "let res=alasql.prepareFromData(params['" + escapeq(jnparam) + "']";
|
|
9069
9229
|
if (jn.array) ps += ",true";
|
|
9070
9230
|
ps += "); if(cb) res=cb(res, idx, query); return res";
|
|
9071
9231
|
source.datafn = new Function("query,params,cb,idx, alasql", ps);
|
|
@@ -10109,7 +10269,7 @@ function install32(alasql) {
|
|
|
10109
10269
|
if (col instanceof yy.Column) {
|
|
10110
10270
|
if (col.columnid === "*") {
|
|
10111
10271
|
if (col.func) {
|
|
10112
|
-
sp += "r=params['" + col.param + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
10272
|
+
sp += "r=params['" + escapeq(col.param) + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
10113
10273
|
} else if (col.tableid) {
|
|
10114
10274
|
var ret = compileSelectStar(query, [col.tableid], false);
|
|
10115
10275
|
if (ret.s) {
|
|
@@ -10136,10 +10296,10 @@ function install32(alasql) {
|
|
|
10136
10296
|
} else {
|
|
10137
10297
|
var isMultisheetParam = params && params.length > 1 && Array.isArray(params[0]) && params[0].length >= 1 && params[0][0].hasOwnProperty("sheetid");
|
|
10138
10298
|
if (isMultisheetParam) {
|
|
10139
|
-
sp = 'var r={};var w=p["' + tbid + '"];var cols=[' + self2.columns.map(function(col2) {
|
|
10299
|
+
sp = 'var r={};var w=p["' + escapeq(tbid) + '"];var cols=[' + self2.columns.map(function(col2) {
|
|
10140
10300
|
return "'" + col2.columnid + "'";
|
|
10141
10301
|
}).join(",") + "];var colas=[" + self2.columns.map(function(col2) {
|
|
10142
|
-
return "'" + (col2.as || col2.columnid) + "'";
|
|
10302
|
+
return "'" + escapeq(col2.as || col2.columnid) + "'";
|
|
10143
10303
|
}).join(",") + "];for (var i=0;i<Object.keys(p['" + tbid + "']).length;i++) for(var k=0;k<cols.length;k++){if (!r.hasOwnProperty(i)) r[i]={}; r[i][colas[k]]=w[i][cols[k]];}";
|
|
10144
10304
|
} else {
|
|
10145
10305
|
var needsRuntimeResolution = !col.tableid && query.sources.length > 1 && (!query.defcols[col.columnid] || query.defcols[col.columnid] === "-");
|
|
@@ -10289,9 +10449,9 @@ function install32(alasql) {
|
|
|
10289
10449
|
if (v._useColumnIndex !== void 0) {
|
|
10290
10450
|
s += "var keys=Object.keys(r);r['" + key + "']=r[keys[" + v.columnIndex + "]];";
|
|
10291
10451
|
} else if (v instanceof yy.Column && query.xcolumns[v.columnid]) {
|
|
10292
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
10452
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
10293
10453
|
} else if (v instanceof yy.ParamValue && query.xcolumns[params[v.param]]) {
|
|
10294
|
-
s += "r['" + key + "']=r['" + params[v.param] + "'];";
|
|
10454
|
+
s += "r['" + key + "']=r['" + escapeq(params[v.param]) + "'];";
|
|
10295
10455
|
} else {
|
|
10296
10456
|
s += "r['" + key + "']=" + v.toJS("p", query.defaultTableid, query.defcols) + ";";
|
|
10297
10457
|
}
|
|
@@ -10404,7 +10564,7 @@ function install32(alasql) {
|
|
|
10404
10564
|
}
|
|
10405
10565
|
}
|
|
10406
10566
|
query.groupColumns[colas] = col.nick;
|
|
10407
|
-
s += "r['" + colas + "']=";
|
|
10567
|
+
s += "r['" + (col.as !== void 0 ? escapeq(colas) : colas) + "']=";
|
|
10408
10568
|
if (col instanceof yy.Column) {
|
|
10409
10569
|
s += n2u(col.toJS("(this.groupSources.get(g) || g)", query.defaultTableid)) + ";";
|
|
10410
10570
|
} else {
|
|
@@ -10472,7 +10632,7 @@ function install32(alasql) {
|
|
|
10472
10632
|
var isInGroup = groupCol !== null && groupCol !== void 0 || query.ingroup.indexOf(col.nick) > -1;
|
|
10473
10633
|
if (isInGroup) {
|
|
10474
10634
|
var groupNick = groupCol && groupCol.nick || col.nick;
|
|
10475
|
-
s += "r['" + (col.as
|
|
10635
|
+
s += "r['" + (col.as ? escapeq(col.as) : col.nick) + "']=g['" + groupNick + "'];";
|
|
10476
10636
|
}
|
|
10477
10637
|
});
|
|
10478
10638
|
if (hasOrderColumns) {
|
|
@@ -10482,9 +10642,9 @@ function install32(alasql) {
|
|
|
10482
10642
|
if (v._useColumnIndex !== void 0) {
|
|
10483
10643
|
s += "var keys=Object.keys(r);r['" + key + "']=r[keys[" + v.columnIndex + "]];";
|
|
10484
10644
|
} else if (v instanceof yy.Column && groupProjectedColumnMap[groupKey]) {
|
|
10485
|
-
s += "r['" + key + "']=r['" + groupProjectedColumnMap[groupKey] + "'];";
|
|
10645
|
+
s += "r['" + key + "']=r['" + escapeq(groupProjectedColumnMap[groupKey]) + "'];";
|
|
10486
10646
|
} else if (v instanceof yy.Column && projectedSelectColumnMap[v.columnid]) {
|
|
10487
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
10647
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
10488
10648
|
} else if (v instanceof yy.Column && groupColMap[groupKey]) {
|
|
10489
10649
|
s += "r['" + key + "']=g['" + groupColMap[groupKey].nick + "'];";
|
|
10490
10650
|
} else {
|
package/dist/alasql.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
//! AlaSQL v4.23.
|
|
1
|
+
//! AlaSQL v4.23.4 build: hotfix.v4.23.4-1d6df59b | © 2014-2026 Andrey Gershun & Mathias Wulff | License: MIT
|
|
2
2
|
/*
|
|
3
3
|
@module alasql
|
|
4
|
-
@version 4.23.
|
|
4
|
+
@version 4.23.4
|
|
5
5
|
|
|
6
6
|
AlaSQL - JavaScript SQL database
|
|
7
7
|
© 2014-2026 Andrey Gershun & Mathias Wulff
|
|
@@ -107,8 +107,8 @@ function create() {
|
|
|
107
107
|
}
|
|
108
108
|
return alasql.exec(sql, params, cb, scope);
|
|
109
109
|
};
|
|
110
|
-
alasql.version = "4.23.
|
|
111
|
-
alasql.build = "hotfix.v4.23.
|
|
110
|
+
alasql.version = "4.23.4";
|
|
111
|
+
alasql.build = "hotfix.v4.23.4-1d6df59b";
|
|
112
112
|
alasql.debug = void 0;
|
|
113
113
|
var require2 = function() {
|
|
114
114
|
return null;
|
|
@@ -4081,8 +4081,158 @@ function install(alasql, internal2) {
|
|
|
4081
4081
|
throw new Error("Have you used a reserved keyword without `escaping` it?\n" + str);
|
|
4082
4082
|
};
|
|
4083
4083
|
alasql.parse = function(sql) {
|
|
4084
|
-
|
|
4085
|
-
|
|
4084
|
+
var ast = alasqlparser.parse(alasql.utils.uncomment(sql));
|
|
4085
|
+
checkNames(ast, false, false);
|
|
4086
|
+
return ast;
|
|
4087
|
+
};
|
|
4088
|
+
var hasOwn = Object.prototype.hasOwnProperty;
|
|
4089
|
+
function checkOrder(columns, order) {
|
|
4090
|
+
var aliases = {};
|
|
4091
|
+
(columns || []).forEach(function(col) {
|
|
4092
|
+
if (col && typeof col.as === "string") aliases[col.as] = true;
|
|
4093
|
+
});
|
|
4094
|
+
order.forEach(function(ord) {
|
|
4095
|
+
var e = ord && ord.expression;
|
|
4096
|
+
var name;
|
|
4097
|
+
if (e instanceof alasql.yy.StringValue) name = e.value;
|
|
4098
|
+
else if (e instanceof alasql.yy.Column && !e.tableid) name = e.columnid;
|
|
4099
|
+
if (typeof name === "string") {
|
|
4100
|
+
if (!hasOwn.call(aliases, name)) checkName(name);
|
|
4101
|
+
return;
|
|
4102
|
+
}
|
|
4103
|
+
checkNames(ord, false, false);
|
|
4104
|
+
});
|
|
4105
|
+
}
|
|
4106
|
+
var badName = /['\\\n\r\u2028\u2029]/;
|
|
4107
|
+
var nameKeys = {
|
|
4108
|
+
as: 1,
|
|
4109
|
+
columnid: 1,
|
|
4110
|
+
tableid: 1,
|
|
4111
|
+
databaseid: 1,
|
|
4112
|
+
viewid: 1,
|
|
4113
|
+
indexid: 1,
|
|
4114
|
+
trigger: 1,
|
|
4115
|
+
variable: 1,
|
|
4116
|
+
dropcolumn: 1,
|
|
4117
|
+
renamecolumn: 1,
|
|
4118
|
+
renameto: 1,
|
|
4119
|
+
to: 1,
|
|
4120
|
+
tocolumnid: 1,
|
|
4121
|
+
forcolumnid: 1
|
|
4122
|
+
};
|
|
4123
|
+
var nameListKeys = { columns: 1, fkcolumns: 1, props: 1 };
|
|
4124
|
+
function checkName(name) {
|
|
4125
|
+
if (badName.test(name)) throw new SyntaxError("Not a valid name: " + name);
|
|
4126
|
+
}
|
|
4127
|
+
function entryOf(node, key) {
|
|
4128
|
+
var yy = alasql.yy;
|
|
4129
|
+
if (node instanceof yy.Select && key === "columns" || node instanceof yy.CreateGraph && key === "graph" || node.srchid === "RETURN" && key === "args")
|
|
4130
|
+
return "alias";
|
|
4131
|
+
if (node instanceof yy.WithSelect && key === "withs") return "with";
|
|
4132
|
+
return "";
|
|
4133
|
+
}
|
|
4134
|
+
var varValueFree = true;
|
|
4135
|
+
var intoVarFree = true;
|
|
4136
|
+
var freeKeys = [
|
|
4137
|
+
["CreateIndex", { indexid: 1 }],
|
|
4138
|
+
["DropIndex", { indexid: 1 }],
|
|
4139
|
+
["Reindex", { indexid: 1 }],
|
|
4140
|
+
["CreateTrigger", { trigger: 1 }],
|
|
4141
|
+
["DropTrigger", { trigger: 1 }],
|
|
4142
|
+
["CreateDatabase", { databaseid: 1, as: 1 }],
|
|
4143
|
+
["AttachDatabase", { databaseid: 1, as: 1 }],
|
|
4144
|
+
["DetachDatabase", { databaseid: 1 }],
|
|
4145
|
+
["DropDatabase", { databaseid: 1 }],
|
|
4146
|
+
["ShowTables", { databaseid: 1 }],
|
|
4147
|
+
["ShowColumns", { databaseid: 1 }],
|
|
4148
|
+
["ShowIndex", { databaseid: 1 }],
|
|
4149
|
+
["ShowCreateTable", { databaseid: 1 }],
|
|
4150
|
+
["AlterTable", { renameto: 1, renamecolumn: 1, dropcolumn: 1 }]
|
|
4151
|
+
];
|
|
4152
|
+
var freeChild = [
|
|
4153
|
+
["CreateTable", { table: 1 }],
|
|
4154
|
+
["DropTable", { tables: 1 }],
|
|
4155
|
+
["TruncateTable", { table: 1 }],
|
|
4156
|
+
["AlterTable", { table: 1 }],
|
|
4157
|
+
["ShowColumns", { table: 1 }],
|
|
4158
|
+
["ShowIndex", { table: 1 }],
|
|
4159
|
+
["ShowCreateTable", { table: 1 }],
|
|
4160
|
+
["CreateIndex", { table: 1 }],
|
|
4161
|
+
["CreateTrigger", { table: 1 }],
|
|
4162
|
+
["Declare", { declares: 1 }]
|
|
4163
|
+
];
|
|
4164
|
+
var skipChild = [["Select", { pivot: 1, unpivot: 1 }]];
|
|
4165
|
+
function freeOf(list, node) {
|
|
4166
|
+
var yy = alasql.yy;
|
|
4167
|
+
for (var i = 0; i < list.length; i++) {
|
|
4168
|
+
var cls = yy[list[i][0]];
|
|
4169
|
+
if (cls && node instanceof cls) return list[i][1];
|
|
4170
|
+
}
|
|
4171
|
+
return null;
|
|
4172
|
+
}
|
|
4173
|
+
function freeVar(node, key, entry) {
|
|
4174
|
+
var yy = alasql.yy;
|
|
4175
|
+
if (key !== "variable" || !(node instanceof yy.VarValue)) return false;
|
|
4176
|
+
if (entry === "source") return false;
|
|
4177
|
+
if (entry === "into") return intoVarFree;
|
|
4178
|
+
return varValueFree;
|
|
4179
|
+
}
|
|
4180
|
+
function freeSet(node, key) {
|
|
4181
|
+
var yy = alasql.yy;
|
|
4182
|
+
return key === "variable" && yy.SetVariable && node instanceof yy.SetVariable && !(node.props && node.props.length);
|
|
4183
|
+
}
|
|
4184
|
+
function checkNames(node, data, entry) {
|
|
4185
|
+
if (node === null || typeof node !== "object") return;
|
|
4186
|
+
var i;
|
|
4187
|
+
if (Array.isArray(node)) {
|
|
4188
|
+
for (i = 0; i < node.length; i++) checkNames(node[i], data, false);
|
|
4189
|
+
return;
|
|
4190
|
+
}
|
|
4191
|
+
var isNode = Object.getPrototypeOf(node) !== Object.prototype;
|
|
4192
|
+
if (data && !isNode) {
|
|
4193
|
+
for (i in node) if (hasOwn.call(node, i)) checkNames(node[i], true, false);
|
|
4194
|
+
return;
|
|
4195
|
+
}
|
|
4196
|
+
var yy = alasql.yy;
|
|
4197
|
+
if (node instanceof yy.Json) {
|
|
4198
|
+
checkNames(node.value, true, false);
|
|
4199
|
+
return;
|
|
4200
|
+
}
|
|
4201
|
+
var fk = freeOf(freeKeys, node);
|
|
4202
|
+
var fc = freeOf(freeChild, node);
|
|
4203
|
+
var sc = freeOf(skipChild, node);
|
|
4204
|
+
for (var key in node) {
|
|
4205
|
+
if (!hasOwn.call(node, key)) continue;
|
|
4206
|
+
var value = node[key];
|
|
4207
|
+
if (sc && sc[key] === 1) continue;
|
|
4208
|
+
if (key === "order" && node instanceof yy.Select && Array.isArray(value)) {
|
|
4209
|
+
checkOrder(node.columns, value);
|
|
4210
|
+
continue;
|
|
4211
|
+
}
|
|
4212
|
+
var child = fc && fc[key] === 1 || entry === "with" && key === "columns" ? "free" : "";
|
|
4213
|
+
if (!child && node instanceof yy.Select)
|
|
4214
|
+
child = key === "from" ? "source" : key === "into" ? "into" : "";
|
|
4215
|
+
if (typeof value === "string") {
|
|
4216
|
+
if (entry === "free" || fk && fk[key] === 1 || freeSet(node, key) || freeVar(node, key, entry))
|
|
4217
|
+
continue;
|
|
4218
|
+
if (key === "name" ? entry === "with" : nameKeys[key] === 1 && !(entry === "alias" && key === "as"))
|
|
4219
|
+
checkName(value);
|
|
4220
|
+
} else if (value !== null && typeof value === "object") {
|
|
4221
|
+
if (Array.isArray(value)) {
|
|
4222
|
+
for (i = 0; i < value.length; i++) {
|
|
4223
|
+
if (typeof value[i] === "string") {
|
|
4224
|
+
if (nameListKeys[key] === 1 && entry !== "free" && child !== "free")
|
|
4225
|
+
checkName(value[i]);
|
|
4226
|
+
} else {
|
|
4227
|
+
checkNames(value[i], false, child || entryOf(node, key));
|
|
4228
|
+
}
|
|
4229
|
+
}
|
|
4230
|
+
} else {
|
|
4231
|
+
checkNames(value, false, child);
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4234
|
+
}
|
|
4235
|
+
}
|
|
4086
4236
|
alasql.engines = {};
|
|
4087
4237
|
alasql.databases = {};
|
|
4088
4238
|
alasql.databasenum = 0;
|
|
@@ -6516,7 +6666,7 @@ function install19(alasql) {
|
|
|
6516
6666
|
}
|
|
6517
6667
|
} else if (this.op === "!") {
|
|
6518
6668
|
if (typeof this.right === "string") {
|
|
6519
|
-
s = `alasql.databases[alasql.useid].objects[${leftJS()}]["${this.right}"]`;
|
|
6669
|
+
s = `alasql.databases[alasql.useid].objects[${leftJS()}]["${escapeq(this.right)}"]`;
|
|
6520
6670
|
}
|
|
6521
6671
|
} else if (this.op === "IS") {
|
|
6522
6672
|
const leftOperand = leftJS();
|
|
@@ -6751,7 +6901,7 @@ function install19(alasql) {
|
|
|
6751
6901
|
}
|
|
6752
6902
|
toJS() {
|
|
6753
6903
|
if (typeof this.param === "string") {
|
|
6754
|
-
return "params['" + this.param + "']";
|
|
6904
|
+
return "params['" + escapeq(this.param) + "']";
|
|
6755
6905
|
}
|
|
6756
6906
|
return "params[" + this.param + "]";
|
|
6757
6907
|
}
|
|
@@ -7077,9 +7227,19 @@ function install21(alasql, internal2) {
|
|
|
7077
7227
|
throw new Error(`2: Cannot show JSON object ${JSON.stringify(obj)}`);
|
|
7078
7228
|
}
|
|
7079
7229
|
};
|
|
7230
|
+
function escapeJSONString(s) {
|
|
7231
|
+
return s.replace(/\\[\s\S]|\\$|"|\n|\r|\u2028|\u2029/g, function(c) {
|
|
7232
|
+
if (c.length === 2) return c;
|
|
7233
|
+
if (c === "\\") return "\\\\";
|
|
7234
|
+
if (c === '"') return '\\"';
|
|
7235
|
+
if (c === "\n") return "\\n";
|
|
7236
|
+
if (c === "\r") return "\\r";
|
|
7237
|
+
return c === "\u2028" ? "\\u2028" : "\\u2029";
|
|
7238
|
+
});
|
|
7239
|
+
}
|
|
7080
7240
|
function JSONtoJS(obj, context, tableid, defcols) {
|
|
7081
7241
|
var s = "";
|
|
7082
|
-
if (typeof obj == "string") s = '"' + obj + '"';
|
|
7242
|
+
if (typeof obj == "string") s = '"' + escapeJSONString(obj) + '"';
|
|
7083
7243
|
else if (typeof obj == "number") s = "(" + obj + ")";
|
|
7084
7244
|
else if (typeof obj == "boolean") s = obj;
|
|
7085
7245
|
else if (typeof obj === "bigint") s = obj.toString() + "n";
|
|
@@ -7089,7 +7249,7 @@ function install21(alasql, internal2) {
|
|
|
7089
7249
|
} else if (!obj.toJS || obj instanceof yy.Json) {
|
|
7090
7250
|
let ss = [];
|
|
7091
7251
|
for (const k in obj) {
|
|
7092
|
-
let keyStr = typeof k === "string" ? `"${k}"` : k.toString();
|
|
7252
|
+
let keyStr = typeof k === "string" ? `"${escapeJSONString(k)}"` : k.toString();
|
|
7093
7253
|
let valueStr = JSONtoJS(obj[k], context, tableid, defcols);
|
|
7094
7254
|
ss.push(`${keyStr}:${valueStr}`);
|
|
7095
7255
|
}
|
|
@@ -8736,7 +8896,7 @@ function install27(alasql, internal2) {
|
|
|
8736
8896
|
return res;
|
|
8737
8897
|
};
|
|
8738
8898
|
} else if (tq instanceof yy.ParamValue) {
|
|
8739
|
-
let ps = `var res = alasql.prepareFromData(params['${tq.param}']`;
|
|
8899
|
+
let ps = `var res = alasql.prepareFromData(params['${escapeq(tq.param)}']`;
|
|
8740
8900
|
if (tq.array) ps += ",true";
|
|
8741
8901
|
ps += ");if(cb)res=cb(res,idx,query);return res";
|
|
8742
8902
|
source.datafn = new Function("query,params,cb,idx,alasql", ps);
|
|
@@ -8914,7 +9074,7 @@ function install28(alasql, internal2) {
|
|
|
8914
9074
|
srcwherefn: returnTrue
|
|
8915
9075
|
};
|
|
8916
9076
|
const jnparam = jn.param.param;
|
|
8917
|
-
ps = "let res=alasql.prepareFromData(params['" + jnparam + "']";
|
|
9077
|
+
ps = "let res=alasql.prepareFromData(params['" + escapeq(jnparam) + "']";
|
|
8918
9078
|
if (jn.array) ps += ",true";
|
|
8919
9079
|
ps += "); if(cb) res=cb(res, idx, query); return res";
|
|
8920
9080
|
source.datafn = new Function("query,params,cb,idx, alasql", ps);
|
|
@@ -9958,7 +10118,7 @@ function install32(alasql) {
|
|
|
9958
10118
|
if (col instanceof yy.Column) {
|
|
9959
10119
|
if (col.columnid === "*") {
|
|
9960
10120
|
if (col.func) {
|
|
9961
|
-
sp += "r=params['" + col.param + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
10121
|
+
sp += "r=params['" + escapeq(col.param) + "'](p['" + query.sources[0].alias + "'],p,params,alasql);";
|
|
9962
10122
|
} else if (col.tableid) {
|
|
9963
10123
|
var ret = compileSelectStar(query, [col.tableid], false);
|
|
9964
10124
|
if (ret.s) {
|
|
@@ -9985,10 +10145,10 @@ function install32(alasql) {
|
|
|
9985
10145
|
} else {
|
|
9986
10146
|
var isMultisheetParam = params && params.length > 1 && Array.isArray(params[0]) && params[0].length >= 1 && params[0][0].hasOwnProperty("sheetid");
|
|
9987
10147
|
if (isMultisheetParam) {
|
|
9988
|
-
sp = 'var r={};var w=p["' + tbid + '"];var cols=[' + self2.columns.map(function(col2) {
|
|
10148
|
+
sp = 'var r={};var w=p["' + escapeq(tbid) + '"];var cols=[' + self2.columns.map(function(col2) {
|
|
9989
10149
|
return "'" + col2.columnid + "'";
|
|
9990
10150
|
}).join(",") + "];var colas=[" + self2.columns.map(function(col2) {
|
|
9991
|
-
return "'" + (col2.as || col2.columnid) + "'";
|
|
10151
|
+
return "'" + escapeq(col2.as || col2.columnid) + "'";
|
|
9992
10152
|
}).join(",") + "];for (var i=0;i<Object.keys(p['" + tbid + "']).length;i++) for(var k=0;k<cols.length;k++){if (!r.hasOwnProperty(i)) r[i]={}; r[i][colas[k]]=w[i][cols[k]];}";
|
|
9993
10153
|
} else {
|
|
9994
10154
|
var needsRuntimeResolution = !col.tableid && query.sources.length > 1 && (!query.defcols[col.columnid] || query.defcols[col.columnid] === "-");
|
|
@@ -10138,9 +10298,9 @@ function install32(alasql) {
|
|
|
10138
10298
|
if (v._useColumnIndex !== void 0) {
|
|
10139
10299
|
s += "var keys=Object.keys(r);r['" + key + "']=r[keys[" + v.columnIndex + "]];";
|
|
10140
10300
|
} else if (v instanceof yy.Column && query.xcolumns[v.columnid]) {
|
|
10141
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
10301
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
10142
10302
|
} else if (v instanceof yy.ParamValue && query.xcolumns[params[v.param]]) {
|
|
10143
|
-
s += "r['" + key + "']=r['" + params[v.param] + "'];";
|
|
10303
|
+
s += "r['" + key + "']=r['" + escapeq(params[v.param]) + "'];";
|
|
10144
10304
|
} else {
|
|
10145
10305
|
s += "r['" + key + "']=" + v.toJS("p", query.defaultTableid, query.defcols) + ";";
|
|
10146
10306
|
}
|
|
@@ -10253,7 +10413,7 @@ function install32(alasql) {
|
|
|
10253
10413
|
}
|
|
10254
10414
|
}
|
|
10255
10415
|
query.groupColumns[colas] = col.nick;
|
|
10256
|
-
s += "r['" + colas + "']=";
|
|
10416
|
+
s += "r['" + (col.as !== void 0 ? escapeq(colas) : colas) + "']=";
|
|
10257
10417
|
if (col instanceof yy.Column) {
|
|
10258
10418
|
s += n2u(col.toJS("(this.groupSources.get(g) || g)", query.defaultTableid)) + ";";
|
|
10259
10419
|
} else {
|
|
@@ -10321,7 +10481,7 @@ function install32(alasql) {
|
|
|
10321
10481
|
var isInGroup = groupCol !== null && groupCol !== void 0 || query.ingroup.indexOf(col.nick) > -1;
|
|
10322
10482
|
if (isInGroup) {
|
|
10323
10483
|
var groupNick = groupCol && groupCol.nick || col.nick;
|
|
10324
|
-
s += "r['" + (col.as
|
|
10484
|
+
s += "r['" + (col.as ? escapeq(col.as) : col.nick) + "']=g['" + groupNick + "'];";
|
|
10325
10485
|
}
|
|
10326
10486
|
});
|
|
10327
10487
|
if (hasOrderColumns) {
|
|
@@ -10331,9 +10491,9 @@ function install32(alasql) {
|
|
|
10331
10491
|
if (v._useColumnIndex !== void 0) {
|
|
10332
10492
|
s += "var keys=Object.keys(r);r['" + key + "']=r[keys[" + v.columnIndex + "]];";
|
|
10333
10493
|
} else if (v instanceof yy.Column && groupProjectedColumnMap[groupKey]) {
|
|
10334
|
-
s += "r['" + key + "']=r['" + groupProjectedColumnMap[groupKey] + "'];";
|
|
10494
|
+
s += "r['" + key + "']=r['" + escapeq(groupProjectedColumnMap[groupKey]) + "'];";
|
|
10335
10495
|
} else if (v instanceof yy.Column && projectedSelectColumnMap[v.columnid]) {
|
|
10336
|
-
s += "r['" + key + "']=r['" + v.columnid + "'];";
|
|
10496
|
+
s += "r['" + key + "']=r['" + escapeq(v.columnid) + "'];";
|
|
10337
10497
|
} else if (v instanceof yy.Column && groupColMap[groupKey]) {
|
|
10338
10498
|
s += "r['" + key + "']=g['" + groupColMap[groupKey].nick + "'];";
|
|
10339
10499
|
} else {
|