alasql 0.7.0 → 1.7.3

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.
@@ -13,7 +13,7 @@ jobs:
13
13
 
14
14
  strategy:
15
15
  matrix:
16
- node-version: [10.x, 12.x, 14.x, 15.x]
16
+ node-version: [12.x, 14.x, 15.x]
17
17
 
18
18
  steps:
19
19
  - uses: actions/checkout@v2
@@ -0,0 +1,4 @@
1
+ #!/bin/sh
2
+ . "$(dirname "$0")/_/husky.sh"
3
+
4
+ npm test
package/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <h2>
2
+ Please use version 1.x as prior versions has a security flaw if you use user generated data to concat your SQL strings instead of providing them as a parameters to AlaSQL.
3
+ </h2>
4
+
1
5
  _AlaSQL is an open source project used on more than two million page views per month - and we appreciate any and all contributions we can get. [Please help out](https://github.com/agershun/alasql/labels/Please%20help%20out%21)._
2
6
 
3
7
  _Have a question? Ask on [Stack Overflow](http://stackoverflow.com/questions/ask?tags=AlaSQL) using the "alasql" tag._
@@ -23,9 +27,7 @@ _Have a question? Ask on [Stack Overflow](http://stackoverflow.com/questions/ask
23
27
  <h2 align="center"><a href="http://alasql.org"><img src="https://cloud.githubusercontent.com/assets/1063454/19309516/94f8007e-9085-11e6-810f-62fd60b42185.png" alt="AlaSQL logo" styl="max-width:80%"/></a>
24
28
  </h2>
25
29
 
26
- <h2>
27
- Please use version 0.7 - prior versions has a security flaw if you concat your SQL strings instead of providing them as a parameter to AlaSQL.
28
- </h2>
30
+
29
31
 
30
32
  AlaSQL - _( [à la](http://en.wiktionary.org/wiki/%C3%A0_la) [SQL](http://en.wikipedia.org/wiki/SQL) ) [ælæ ɛskju:ɛl]_ - is an open source SQL database for JavaScript with a strong focus on query speed and data source flexibility for both relational data and schemaless data. It works in the web browser, Node.js, and mobile apps.
31
33
 
@@ -120,7 +122,7 @@ For the browser: include [alasql.min.js](https://cdn.jsdelivr.net/npm/alasql)
120
122
 
121
123
 
122
124
  ```html
123
- <script src="https://cdn.jsdelivr.net/npm/alasql@0.7"></script>
125
+ <script src="https://cdn.jsdelivr.net/npm/alasql@1.7"></script>
124
126
  ```
125
127
 
126
128
 
@@ -1,7 +1,7 @@
1
- //! AlaSQL v0.7.0-develop-b1a58b1bundefined | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
1
+ //! AlaSQL v1.7.3-develop-0be167bcundefined | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 0.7.0-develop-b1a58b1bundefined
4
+ @version 1.7.3-develop-0be167bcundefined
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2016 Andrey Gershun & Mathias Rangel Wulff
@@ -1,2 +1,2 @@
1
- //! AlaSQL v0.7.0-develop-b1a58b1bundefined | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
1
+ //! AlaSQL v1.7.3-develop-0be167bcundefined | © 2014-2018 Andrey Gershun & Mathias Rangel 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,t){"function"==typeof(e=e||[])&&(scope=t,t=e,e=[]),"object"!=typeof e&&(e=[e]);var o=i.lastid++;i.buffer[o]=t,i.webworker.postMessage({id:o,sql:r,params:e})}var s;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&&(s=function(r,e,n,s){return new Promise(function(t,o){i(r,e,function(r,e){e?o(e):(n&&s&&!1!==i.options.progress&&i.options.progress(n,s),t(r))})})},i.promise=function(r,e){if("undefined"==typeof Promise)throw new Error("Please include a Promise/A+ library");if("string"==typeof r)return s(r,e);if(!isArray(r)||r.length<1||void 0!==e)throw new Error("Error in .promise parameters");return function(r){if(!(r.length<1)){for(var e,t,o=[],n=0;n<r.length;n++){if("string"==typeof(t=r[n])&&(t=[t]),!isArray(t)||t.length<1||2<t.length)throw new Error("Error in .promise parameter");e=t[0],t=t[1]||void 0,o.push(s(e,t,n,r.length))}return Promise.all(o)}}(r)}),!(i=i||!1))throw new Error("alasql was not found");return i.worker=function(){throw new Error("Can find webworker in this enviroment")},"undefined"!=typeof Worker&&(i.worker=function(r,e,t){if(void 0===(r=!0===r?void 0:r))for(var o=document.getElementsByTagName("script"),n=0;n<o.length;n++){if("alasql-worker.js"===o[n].src.substr(-16).toLowerCase()){r=o[n].src.substr(0,o[n].src.length-16)+"alasql.js";break}if("alasql-worker.min.js"===o[n].src.substr(-20).toLowerCase()){r=o[n].src.substr(0,o[n].src.length-20)+"alasql.min.js";break}if("alasql.js"===o[n].src.substr(-9).toLowerCase()){r=o[n].src;break}if("alasql.min.js"===o[n].src.substr(-13).toLowerCase()){r=o[n].src.substr(0,o[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="importScripts('",s+=r,s+="');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(","),[],t)):!1===r&&delete i.webworker}),i.lastid=0,i.buffer={},i.worker(),i});
package/dist/alasql.fs.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v0.7.0-develop-b1a58b1bundefined | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
1
+ //! AlaSQL v1.7.3-develop-0be167bcundefined | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 0.7.0-develop-b1a58b1bundefined
4
+ @version 1.7.3-develop-0be167bcundefined
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 = '0.7.0-develop-b1a58b1bundefined';
145
+ alasql.version = '1.7.3-develop-0be167bcundefined';
146
146
 
147
147
  /**
148
148
  Debug flag
@@ -4328,6 +4328,12 @@ var getXLSX = function () {
4328
4328
  return XLSX;
4329
4329
  };
4330
4330
 
4331
+ var jss = JSON.stringify;
4332
+ var reName = /[^a-z\d@-_]+/gi;
4333
+ var nss = (e) => e.replace(reName, '');
4334
+ var reTick = /`/g;
4335
+ var tss = (e) => e.replace(reTick, '');
4336
+
4331
4337
  // set AlaSQl path
4332
4338
  alasql.path = alasql.utils.findAlaSQLPath();
4333
4339
 
@@ -6308,7 +6314,7 @@ yy.Search.prototype.toString = function () {
6308
6314
 
6309
6315
  yy.Search.prototype.toJS = function (context) {
6310
6316
 
6311
- var s = 'this.queriesfn[' + (this.queriesidx - 1) + '](this.params,null,' + context + ')';
6317
+ var s = 'this.queriesfn[' + jss(this.queriesidx - 1) + '](this.params,null,' + jss(context) + ')';
6312
6318
  // var s = '';
6313
6319
  return s;
6314
6320
  };
@@ -6669,11 +6675,11 @@ alasql.srch.SET = function (val, args, stope, params) {
6669
6675
  .map(function (st) {
6670
6676
 
6671
6677
  if (st.method === '@') {
6672
- return "alasql.vars['" + st.variable + "']=" + st.expression.toJS('x', '');
6678
+ return 'alasql.vars[' + jss(st.variable) + ']=' + st.expression.toJS('x', '');
6673
6679
  } else if (st.method === '$') {
6674
- return "params['" + st.variable + "']=" + st.expression.toJS('x', '');
6680
+ return 'params[' + jss(st.variable) + ']=' + st.expression.toJS('x', '');
6675
6681
  } else {
6676
- return "x['" + st.column.columnid + "']=" + st.expression.toJS('x', '');
6682
+ return 'x[' + jss(st.column.columnid) + ']=' + st.expression.toJS('x', '');
6677
6683
  }
6678
6684
  })
6679
6685
  .join(';');
@@ -6760,17 +6766,26 @@ var compileSearchOrder = function (order) {
6760
6766
  s += 'if(a' + dg + '==b' + dg + '){';
6761
6767
  } else {
6762
6768
  s +=
6763
- "if((a['" +
6764
- columnid +
6765
- "']||'')" +
6769
+ 'if((a[' +
6770
+ jss(columnid) +
6771
+ "]||'')" +
6766
6772
  dg +
6767
6773
  (ord.direction === 'ASC' ? '>' : '<') +
6768
- "(b['" +
6769
- columnid +
6770
- "']||'')" +
6774
+ '(b[' +
6775
+ jss(columnid) +
6776
+ "]||'')" +
6771
6777
  dg +
6772
6778
  ')return 1;';
6773
- s += "if((a['" + columnid + "']||'')" + dg + "==(b['" + columnid + "']||'')" + dg + '){';
6779
+ s +=
6780
+ 'if((a[' +
6781
+ jss(columnid) +
6782
+ "]||'')" +
6783
+ dg +
6784
+ '==(b[' +
6785
+ jss(columnid) +
6786
+ "]||'')" +
6787
+ dg +
6788
+ '){';
6774
6789
  }
6775
6790
  } else {
6776
6791
  dg = '.valueOf()';
@@ -7963,7 +7978,7 @@ yy.Select.prototype.compile = function (databaseid, params) {
7963
7978
  // If this is INTO() function, then call it
7964
7979
  // with one or two parameters
7965
7980
  //
7966
- var qs = "return alasql.into['" + this.into.funcid.toUpperCase() + "'](";
7981
+ var qs = 'return alasql.into[' + JSON.stringify(this.into.funcid.toUpperCase()) + '](';
7967
7982
  if (this.into.args && this.into.args.length > 0) {
7968
7983
  qs += this.into.args[0].toJS() + ',';
7969
7984
  if (this.into.args.length > 1) {
@@ -8409,7 +8424,7 @@ yy.Select.prototype.compileFrom = function (query) {
8409
8424
  ps += ');if(cb)res=cb(res,idx,query);return res';
8410
8425
  source.datafn = new Function('query,params,cb,idx,alasql', ps);
8411
8426
  } else if (tq instanceof yy.FuncValue) {
8412
- ps = "var res=alasql.from['" + tq.funcid.toUpperCase() + "'](";
8427
+ ps = 'var res=alasql.from[' + JSON.stringify(tq.funcid.toUpperCase()) + '](';
8413
8428
 
8414
8429
  if (tq.args && tq.args.length > 0) {
8415
8430
  if (tq.args[0]) {
@@ -8672,7 +8687,7 @@ yy.Select.prototype.compileJoins = function (query) {
8672
8687
  };
8673
8688
  // source.data = ;
8674
8689
 
8675
- var s = "var res=alasql.from['" + jn.func.funcid.toUpperCase() + "'](";
8690
+ var s = 'var res=alasql.from[' + JSON.stringify(jn.func.funcid.toUpperCase()) + '](';
8676
8691
 
8677
8692
  var args = jn.func.args;
8678
8693
  if (args && args.length > 0) {
@@ -10846,7 +10861,7 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
10846
10861
  if (!(!this.right.args || 0 === this.right.args.length)) {
10847
10862
  var ss = this.right.args.map(ref);
10848
10863
  }
10849
- s = '' + ljs + "['" + this.right.funcid + "'](" + ss.join(',') + ')';
10864
+ s = '' + ljs + '[' + JSON.stringify(this.right.funcid) + '](' + ss.join(',') + ')';
10850
10865
  } else {
10851
10866
  s = '' + ljs + '[' + rightJS() + ']';
10852
10867
  }
@@ -11385,7 +11400,7 @@ yy.AggrValue = function (params) {
11385
11400
  yy.AggrValue.prototype.toString = function (dontas) {
11386
11401
  var s = '';
11387
11402
  if (this.aggregatorid === 'REDUCE') {
11388
- s += this.funcid + '(';
11403
+ s += this.funcid.replace(re_invalidFnNameChars, '') + '(';
11389
11404
  } else {
11390
11405
  s += this.aggregatorid + '(';
11391
11406
  }
@@ -11657,13 +11672,15 @@ yy.Select.prototype.Where = function (expr) {
11657
11672
  yy.FuncValue = function (params) {
11658
11673
  return yy.extend(this, params);
11659
11674
  };
11675
+
11676
+ var re_invalidFnNameChars = /[^0-9A-Z_$]+/i;
11660
11677
  yy.FuncValue.prototype.toString = function (dontas) {
11661
11678
  var s = '';
11662
11679
 
11663
11680
  if (alasql.fn[this.funcid]) s += this.funcid;
11664
11681
  else if (alasql.aggr[this.funcid]) s += this.funcid;
11665
11682
  else if (alasql.stdlib[this.funcid.toUpperCase()] || alasql.stdfn[this.funcid.toUpperCase()])
11666
- s += this.funcid.toUpperCase();
11683
+ s += this.funcid.toUpperCase().replace(re_invalidFnNameChars, '');
11667
11684
 
11668
11685
  if (this.funcid !== 'CURRENT_TIMESTAMP') {
11669
11686
  s += '(';
@@ -11819,10 +11836,13 @@ stdlib.MIN = stdlib.LEAST = function () {
11819
11836
  );
11820
11837
  };
11821
11838
 
11822
- stdlib.SUBSTRING = stdlib.SUBSTR = stdlib.MID = function (a, b, c) {
11823
- if (arguments.length == 2) return und(a, 'y.substr(' + b + '-1)');
11824
- else if (arguments.length == 3) return und(a, 'y.substr(' + b + '-1,' + c + ')');
11825
- };
11839
+ stdlib.SUBSTRING =
11840
+ stdlib.SUBSTR =
11841
+ stdlib.MID =
11842
+ function (a, b, c) {
11843
+ if (arguments.length == 2) return und(a, 'y.substr(' + b + '-1)');
11844
+ else if (arguments.length == 3) return und(a, 'y.substr(' + b + '-1,' + c + ')');
11845
+ };
11826
11846
 
11827
11847
  stdfn.REGEXP_LIKE = function (a, b, c) {
11828
11848
 
@@ -12046,13 +12066,16 @@ alasql.aggr.VARP = function (v, s, stage) {
12046
12066
  }
12047
12067
  };
12048
12068
 
12049
- alasql.aggr.STD = alasql.aggr.STDDEV = alasql.aggr.STDEVP = function (v, s, stage) {
12050
- if (stage == 1 || stage == 2) {
12051
- return alasql.aggr.VARP(v, s, stage);
12052
- } else {
12053
- return Math.sqrt(alasql.aggr.VARP(v, s, stage));
12054
- }
12055
- };
12069
+ alasql.aggr.STD =
12070
+ alasql.aggr.STDDEV =
12071
+ alasql.aggr.STDEVP =
12072
+ function (v, s, stage) {
12073
+ if (stage == 1 || stage == 2) {
12074
+ return alasql.aggr.VARP(v, s, stage);
12075
+ } else {
12076
+ return Math.sqrt(alasql.aggr.VARP(v, s, stage));
12077
+ }
12078
+ };
12056
12079
 
12057
12080
  alasql._aggrOriginal = alasql.aggr;
12058
12081
  alasql.aggr = {};
@@ -12074,34 +12097,37 @@ for (var i = 0; i < 256; i++) {
12074
12097
  lut[i] = (i < 16 ? '0' : '') + i.toString(16);
12075
12098
  }
12076
12099
 
12077
- stdfn.NEWID = stdfn.UUID = stdfn.GEN_RANDOM_UUID = function () {
12078
- var d0 = (Math.random() * 0xffffffff) | 0;
12079
- var d1 = (Math.random() * 0xffffffff) | 0;
12080
- var d2 = (Math.random() * 0xffffffff) | 0;
12081
- var d3 = (Math.random() * 0xffffffff) | 0;
12082
- return (
12083
- lut[d0 & 0xff] +
12084
- lut[(d0 >> 8) & 0xff] +
12085
- lut[(d0 >> 16) & 0xff] +
12086
- lut[(d0 >> 24) & 0xff] +
12087
- '-' +
12088
- lut[d1 & 0xff] +
12089
- lut[(d1 >> 8) & 0xff] +
12090
- '-' +
12091
- lut[((d1 >> 16) & 0x0f) | 0x40] +
12092
- lut[(d1 >> 24) & 0xff] +
12093
- '-' +
12094
- lut[(d2 & 0x3f) | 0x80] +
12095
- lut[(d2 >> 8) & 0xff] +
12096
- '-' +
12097
- lut[(d2 >> 16) & 0xff] +
12098
- lut[(d2 >> 24) & 0xff] +
12099
- lut[d3 & 0xff] +
12100
- lut[(d3 >> 8) & 0xff] +
12101
- lut[(d3 >> 16) & 0xff] +
12102
- lut[(d3 >> 24) & 0xff]
12103
- );
12104
- };
12100
+ stdfn.NEWID =
12101
+ stdfn.UUID =
12102
+ stdfn.GEN_RANDOM_UUID =
12103
+ function () {
12104
+ var d0 = (Math.random() * 0xffffffff) | 0;
12105
+ var d1 = (Math.random() * 0xffffffff) | 0;
12106
+ var d2 = (Math.random() * 0xffffffff) | 0;
12107
+ var d3 = (Math.random() * 0xffffffff) | 0;
12108
+ return (
12109
+ lut[d0 & 0xff] +
12110
+ lut[(d0 >> 8) & 0xff] +
12111
+ lut[(d0 >> 16) & 0xff] +
12112
+ lut[(d0 >> 24) & 0xff] +
12113
+ '-' +
12114
+ lut[d1 & 0xff] +
12115
+ lut[(d1 >> 8) & 0xff] +
12116
+ '-' +
12117
+ lut[((d1 >> 16) & 0x0f) | 0x40] +
12118
+ lut[(d1 >> 24) & 0xff] +
12119
+ '-' +
12120
+ lut[(d2 & 0x3f) | 0x80] +
12121
+ lut[(d2 >> 8) & 0xff] +
12122
+ '-' +
12123
+ lut[(d2 >> 16) & 0xff] +
12124
+ lut[(d2 >> 24) & 0xff] +
12125
+ lut[d3 & 0xff] +
12126
+ lut[(d3 >> 8) & 0xff] +
12127
+ lut[(d3 >> 16) & 0xff] +
12128
+ lut[(d3 >> 24) & 0xff]
12129
+ );
12130
+ };
12105
12131
 
12106
12132
  /*
12107
12133
  //
@@ -18753,6 +18779,7 @@ LS.dropDatabase = function (lsdbid, ifexists, cb) {
18753
18779
 
18754
18780
  LS.attachDatabase = function (lsdbid, databaseid, args, params, cb) {
18755
18781
  var res = 1;
18782
+ // console.warn({lsdbid, databaseid, args, params, cb, dbs: Object.keys(alasql.databases)})
18756
18783
  if (alasql.databases[databaseid]) {
18757
18784
  throw new Error('Unable to attach database as "' + databaseid + '" because it already exists');
18758
18785
  }
@@ -19655,7 +19682,14 @@ var saveAs =
19655
19682
  FS_proto.WRITING = 1;
19656
19683
  FS_proto.DONE = 2;
19657
19684
 
19658
- FS_proto.error = FS_proto.onwritestart = FS_proto.onprogress = FS_proto.onwrite = FS_proto.onabort = FS_proto.onerror = FS_proto.onwriteend = null;
19685
+ FS_proto.error =
19686
+ FS_proto.onwritestart =
19687
+ FS_proto.onprogress =
19688
+ FS_proto.onwrite =
19689
+ FS_proto.onabort =
19690
+ FS_proto.onerror =
19691
+ FS_proto.onwriteend =
19692
+ null;
19659
19693
 
19660
19694
  return saveAs;
19661
19695
  })(
package/dist/alasql.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v0.7.0-develop-b1a58b1bundefined | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
1
+ //! AlaSQL v1.7.3-develop-0be167bcundefined | © 2014-2018 Andrey Gershun & Mathias Rangel Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 0.7.0-develop-b1a58b1bundefined
4
+ @version 1.7.3-develop-0be167bcundefined
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 = '0.7.0-develop-b1a58b1bundefined';
145
+ alasql.version = '1.7.3-develop-0be167bcundefined';
146
146
 
147
147
  /**
148
148
  Debug flag
@@ -4323,6 +4323,12 @@ var getXLSX = function () {
4323
4323
  return XLSX;
4324
4324
  };
4325
4325
 
4326
+ var jss = JSON.stringify;
4327
+ var reName = /[^a-z\d@-_]+/gi;
4328
+ var nss = (e) => e.replace(reName, '');
4329
+ var reTick = /`/g;
4330
+ var tss = (e) => e.replace(reTick, '');
4331
+
4326
4332
  // set AlaSQl path
4327
4333
  alasql.path = alasql.utils.findAlaSQLPath();
4328
4334
 
@@ -6303,7 +6309,7 @@ yy.Search.prototype.toString = function () {
6303
6309
 
6304
6310
  yy.Search.prototype.toJS = function (context) {
6305
6311
 
6306
- var s = 'this.queriesfn[' + (this.queriesidx - 1) + '](this.params,null,' + context + ')';
6312
+ var s = 'this.queriesfn[' + jss(this.queriesidx - 1) + '](this.params,null,' + jss(context) + ')';
6307
6313
  // var s = '';
6308
6314
  return s;
6309
6315
  };
@@ -6664,11 +6670,11 @@ alasql.srch.SET = function (val, args, stope, params) {
6664
6670
  .map(function (st) {
6665
6671
 
6666
6672
  if (st.method === '@') {
6667
- return "alasql.vars['" + st.variable + "']=" + st.expression.toJS('x', '');
6673
+ return 'alasql.vars[' + jss(st.variable) + ']=' + st.expression.toJS('x', '');
6668
6674
  } else if (st.method === '$') {
6669
- return "params['" + st.variable + "']=" + st.expression.toJS('x', '');
6675
+ return 'params[' + jss(st.variable) + ']=' + st.expression.toJS('x', '');
6670
6676
  } else {
6671
- return "x['" + st.column.columnid + "']=" + st.expression.toJS('x', '');
6677
+ return 'x[' + jss(st.column.columnid) + ']=' + st.expression.toJS('x', '');
6672
6678
  }
6673
6679
  })
6674
6680
  .join(';');
@@ -6755,17 +6761,26 @@ var compileSearchOrder = function (order) {
6755
6761
  s += 'if(a' + dg + '==b' + dg + '){';
6756
6762
  } else {
6757
6763
  s +=
6758
- "if((a['" +
6759
- columnid +
6760
- "']||'')" +
6764
+ 'if((a[' +
6765
+ jss(columnid) +
6766
+ "]||'')" +
6761
6767
  dg +
6762
6768
  (ord.direction === 'ASC' ? '>' : '<') +
6763
- "(b['" +
6764
- columnid +
6765
- "']||'')" +
6769
+ '(b[' +
6770
+ jss(columnid) +
6771
+ "]||'')" +
6766
6772
  dg +
6767
6773
  ')return 1;';
6768
- s += "if((a['" + columnid + "']||'')" + dg + "==(b['" + columnid + "']||'')" + dg + '){';
6774
+ s +=
6775
+ 'if((a[' +
6776
+ jss(columnid) +
6777
+ "]||'')" +
6778
+ dg +
6779
+ '==(b[' +
6780
+ jss(columnid) +
6781
+ "]||'')" +
6782
+ dg +
6783
+ '){';
6769
6784
  }
6770
6785
  } else {
6771
6786
  dg = '.valueOf()';
@@ -7958,7 +7973,7 @@ yy.Select.prototype.compile = function (databaseid, params) {
7958
7973
  // If this is INTO() function, then call it
7959
7974
  // with one or two parameters
7960
7975
  //
7961
- var qs = "return alasql.into['" + this.into.funcid.toUpperCase() + "'](";
7976
+ var qs = 'return alasql.into[' + JSON.stringify(this.into.funcid.toUpperCase()) + '](';
7962
7977
  if (this.into.args && this.into.args.length > 0) {
7963
7978
  qs += this.into.args[0].toJS() + ',';
7964
7979
  if (this.into.args.length > 1) {
@@ -8404,7 +8419,7 @@ yy.Select.prototype.compileFrom = function (query) {
8404
8419
  ps += ');if(cb)res=cb(res,idx,query);return res';
8405
8420
  source.datafn = new Function('query,params,cb,idx,alasql', ps);
8406
8421
  } else if (tq instanceof yy.FuncValue) {
8407
- ps = "var res=alasql.from['" + tq.funcid.toUpperCase() + "'](";
8422
+ ps = 'var res=alasql.from[' + JSON.stringify(tq.funcid.toUpperCase()) + '](';
8408
8423
 
8409
8424
  if (tq.args && tq.args.length > 0) {
8410
8425
  if (tq.args[0]) {
@@ -8667,7 +8682,7 @@ yy.Select.prototype.compileJoins = function (query) {
8667
8682
  };
8668
8683
  // source.data = ;
8669
8684
 
8670
- var s = "var res=alasql.from['" + jn.func.funcid.toUpperCase() + "'](";
8685
+ var s = 'var res=alasql.from[' + JSON.stringify(jn.func.funcid.toUpperCase()) + '](';
8671
8686
 
8672
8687
  var args = jn.func.args;
8673
8688
  if (args && args.length > 0) {
@@ -10841,7 +10856,7 @@ yy.Op.prototype.toJS = function (context, tableid, defcols) {
10841
10856
  if (!(!this.right.args || 0 === this.right.args.length)) {
10842
10857
  var ss = this.right.args.map(ref);
10843
10858
  }
10844
- s = '' + ljs + "['" + this.right.funcid + "'](" + ss.join(',') + ')';
10859
+ s = '' + ljs + '[' + JSON.stringify(this.right.funcid) + '](' + ss.join(',') + ')';
10845
10860
  } else {
10846
10861
  s = '' + ljs + '[' + rightJS() + ']';
10847
10862
  }
@@ -11380,7 +11395,7 @@ yy.AggrValue = function (params) {
11380
11395
  yy.AggrValue.prototype.toString = function (dontas) {
11381
11396
  var s = '';
11382
11397
  if (this.aggregatorid === 'REDUCE') {
11383
- s += this.funcid + '(';
11398
+ s += this.funcid.replace(re_invalidFnNameChars, '') + '(';
11384
11399
  } else {
11385
11400
  s += this.aggregatorid + '(';
11386
11401
  }
@@ -11652,13 +11667,15 @@ yy.Select.prototype.Where = function (expr) {
11652
11667
  yy.FuncValue = function (params) {
11653
11668
  return yy.extend(this, params);
11654
11669
  };
11670
+
11671
+ var re_invalidFnNameChars = /[^0-9A-Z_$]+/i;
11655
11672
  yy.FuncValue.prototype.toString = function (dontas) {
11656
11673
  var s = '';
11657
11674
 
11658
11675
  if (alasql.fn[this.funcid]) s += this.funcid;
11659
11676
  else if (alasql.aggr[this.funcid]) s += this.funcid;
11660
11677
  else if (alasql.stdlib[this.funcid.toUpperCase()] || alasql.stdfn[this.funcid.toUpperCase()])
11661
- s += this.funcid.toUpperCase();
11678
+ s += this.funcid.toUpperCase().replace(re_invalidFnNameChars, '');
11662
11679
 
11663
11680
  if (this.funcid !== 'CURRENT_TIMESTAMP') {
11664
11681
  s += '(';
@@ -11814,10 +11831,13 @@ stdlib.MIN = stdlib.LEAST = function () {
11814
11831
  );
11815
11832
  };
11816
11833
 
11817
- stdlib.SUBSTRING = stdlib.SUBSTR = stdlib.MID = function (a, b, c) {
11818
- if (arguments.length == 2) return und(a, 'y.substr(' + b + '-1)');
11819
- else if (arguments.length == 3) return und(a, 'y.substr(' + b + '-1,' + c + ')');
11820
- };
11834
+ stdlib.SUBSTRING =
11835
+ stdlib.SUBSTR =
11836
+ stdlib.MID =
11837
+ function (a, b, c) {
11838
+ if (arguments.length == 2) return und(a, 'y.substr(' + b + '-1)');
11839
+ else if (arguments.length == 3) return und(a, 'y.substr(' + b + '-1,' + c + ')');
11840
+ };
11821
11841
 
11822
11842
  stdfn.REGEXP_LIKE = function (a, b, c) {
11823
11843
 
@@ -12041,13 +12061,16 @@ alasql.aggr.VARP = function (v, s, stage) {
12041
12061
  }
12042
12062
  };
12043
12063
 
12044
- alasql.aggr.STD = alasql.aggr.STDDEV = alasql.aggr.STDEVP = function (v, s, stage) {
12045
- if (stage == 1 || stage == 2) {
12046
- return alasql.aggr.VARP(v, s, stage);
12047
- } else {
12048
- return Math.sqrt(alasql.aggr.VARP(v, s, stage));
12049
- }
12050
- };
12064
+ alasql.aggr.STD =
12065
+ alasql.aggr.STDDEV =
12066
+ alasql.aggr.STDEVP =
12067
+ function (v, s, stage) {
12068
+ if (stage == 1 || stage == 2) {
12069
+ return alasql.aggr.VARP(v, s, stage);
12070
+ } else {
12071
+ return Math.sqrt(alasql.aggr.VARP(v, s, stage));
12072
+ }
12073
+ };
12051
12074
 
12052
12075
  alasql._aggrOriginal = alasql.aggr;
12053
12076
  alasql.aggr = {};
@@ -12069,34 +12092,37 @@ for (var i = 0; i < 256; i++) {
12069
12092
  lut[i] = (i < 16 ? '0' : '') + i.toString(16);
12070
12093
  }
12071
12094
 
12072
- stdfn.NEWID = stdfn.UUID = stdfn.GEN_RANDOM_UUID = function () {
12073
- var d0 = (Math.random() * 0xffffffff) | 0;
12074
- var d1 = (Math.random() * 0xffffffff) | 0;
12075
- var d2 = (Math.random() * 0xffffffff) | 0;
12076
- var d3 = (Math.random() * 0xffffffff) | 0;
12077
- return (
12078
- lut[d0 & 0xff] +
12079
- lut[(d0 >> 8) & 0xff] +
12080
- lut[(d0 >> 16) & 0xff] +
12081
- lut[(d0 >> 24) & 0xff] +
12082
- '-' +
12083
- lut[d1 & 0xff] +
12084
- lut[(d1 >> 8) & 0xff] +
12085
- '-' +
12086
- lut[((d1 >> 16) & 0x0f) | 0x40] +
12087
- lut[(d1 >> 24) & 0xff] +
12088
- '-' +
12089
- lut[(d2 & 0x3f) | 0x80] +
12090
- lut[(d2 >> 8) & 0xff] +
12091
- '-' +
12092
- lut[(d2 >> 16) & 0xff] +
12093
- lut[(d2 >> 24) & 0xff] +
12094
- lut[d3 & 0xff] +
12095
- lut[(d3 >> 8) & 0xff] +
12096
- lut[(d3 >> 16) & 0xff] +
12097
- lut[(d3 >> 24) & 0xff]
12098
- );
12099
- };
12095
+ stdfn.NEWID =
12096
+ stdfn.UUID =
12097
+ stdfn.GEN_RANDOM_UUID =
12098
+ function () {
12099
+ var d0 = (Math.random() * 0xffffffff) | 0;
12100
+ var d1 = (Math.random() * 0xffffffff) | 0;
12101
+ var d2 = (Math.random() * 0xffffffff) | 0;
12102
+ var d3 = (Math.random() * 0xffffffff) | 0;
12103
+ return (
12104
+ lut[d0 & 0xff] +
12105
+ lut[(d0 >> 8) & 0xff] +
12106
+ lut[(d0 >> 16) & 0xff] +
12107
+ lut[(d0 >> 24) & 0xff] +
12108
+ '-' +
12109
+ lut[d1 & 0xff] +
12110
+ lut[(d1 >> 8) & 0xff] +
12111
+ '-' +
12112
+ lut[((d1 >> 16) & 0x0f) | 0x40] +
12113
+ lut[(d1 >> 24) & 0xff] +
12114
+ '-' +
12115
+ lut[(d2 & 0x3f) | 0x80] +
12116
+ lut[(d2 >> 8) & 0xff] +
12117
+ '-' +
12118
+ lut[(d2 >> 16) & 0xff] +
12119
+ lut[(d2 >> 24) & 0xff] +
12120
+ lut[d3 & 0xff] +
12121
+ lut[(d3 >> 8) & 0xff] +
12122
+ lut[(d3 >> 16) & 0xff] +
12123
+ lut[(d3 >> 24) & 0xff]
12124
+ );
12125
+ };
12100
12126
 
12101
12127
  /*
12102
12128
  //
@@ -18748,6 +18774,7 @@ LS.dropDatabase = function (lsdbid, ifexists, cb) {
18748
18774
 
18749
18775
  LS.attachDatabase = function (lsdbid, databaseid, args, params, cb) {
18750
18776
  var res = 1;
18777
+ // console.warn({lsdbid, databaseid, args, params, cb, dbs: Object.keys(alasql.databases)})
18751
18778
  if (alasql.databases[databaseid]) {
18752
18779
  throw new Error('Unable to attach database as "' + databaseid + '" because it already exists');
18753
18780
  }
@@ -19650,7 +19677,14 @@ var saveAs =
19650
19677
  FS_proto.WRITING = 1;
19651
19678
  FS_proto.DONE = 2;
19652
19679
 
19653
- FS_proto.error = FS_proto.onwritestart = FS_proto.onprogress = FS_proto.onwrite = FS_proto.onabort = FS_proto.onerror = FS_proto.onwriteend = null;
19680
+ FS_proto.error =
19681
+ FS_proto.onwritestart =
19682
+ FS_proto.onprogress =
19683
+ FS_proto.onwrite =
19684
+ FS_proto.onabort =
19685
+ FS_proto.onerror =
19686
+ FS_proto.onwriteend =
19687
+ null;
19654
19688
 
19655
19689
  return saveAs;
19656
19690
  })(