alasql 4.1.11 → 4.2.1

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 CHANGED
@@ -97,10 +97,13 @@ var res = alasql("SELECT * FROM example1 ORDER BY b DESC");
97
97
  console.log(res); // [{a:2,b:6},{a:1,b:5},{a:3,b:4}]
98
98
  ```
99
99
 
100
-
101
100
  __If you are familiar with SQL, it should be no surprise that proper use of indexes on your tables is essential for good performance.__
102
101
 
102
+ #### Options
103
+
104
+ AlaSQL has several [configuration options](https://github.com/AlaSQL/alasql/wiki/AlaSQL-Options) which change the behavior. It can be set via SQL statements or via the options object before using `alasql`.
103
105
 
106
+ If you're using `NOW()` in queries often, setting `alasql.options.dateAsString` to `false` speed things up. It will just return a JS Date object instead of a string representation of a date.
104
107
 
105
108
  ## Installation
106
109
 
@@ -1,7 +1,7 @@
1
- //! AlaSQL v4.1.11 build: develop-1493d57a | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.2.0 build: develop-67d9f6dd | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 4.1.11
4
+ @version 4.2.0
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2023 Andrey Gershun & Mathias Wulff
package/dist/alasql.fs.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v4.1.11 build: develop-1493d57a | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.2.0 build: develop-67d9f6dd | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 4.1.11
4
+ @version 4.2.0
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2023 Andrey Gershun & Mathias Wulff
@@ -141,8 +141,8 @@ var alasql = function(sql, params, cb, scope) {
141
141
  Current version of alasql
142
142
  @constant {string}
143
143
  */
144
- alasql.version = '4.1.11';
145
- alasql.build = 'develop-1493d57a';
144
+ alasql.version = '4.2.0';
145
+ alasql.build = 'develop-67d9f6dd';
146
146
 
147
147
  /**
148
148
  Debug flag
@@ -3168,10 +3168,10 @@ alasql.pretty = function (sql, flag) {
3168
3168
 
3169
3169
  /*jshint unused:false*/
3170
3170
  /*
3171
- Utilities for Alasql.js
3171
+ Utilities for Alasql.js
3172
3172
 
3173
- @todo Review the list of utilities
3174
- @todo Find more effective utilities
3173
+ @todo Review the list of utilities
3174
+ @todo Find more effective utilities
3175
3175
  */
3176
3176
 
3177
3177
  /**
@@ -4210,43 +4210,46 @@ var domEmptyChildren = (utils.domEmptyChildren = function (container) {
4210
4210
  @parameter {string} escape Escape character (optional)
4211
4211
  @return {boolean} If value LIKE pattern ESCAPE escape
4212
4212
  */
4213
-
4213
+ var patternCache = {};
4214
4214
  var like = (utils.like = function (pattern, value, escape) {
4215
- // Verify escape character
4216
- if (!escape) escape = '';
4215
+ if (!patternCache[pattern]) {
4216
+ // Verify escape character
4217
+ if (!escape) escape = '';
4217
4218
 
4218
- var i = 0;
4219
- var s = '^';
4219
+ var i = 0;
4220
+ var s = '^';
4220
4221
 
4221
- while (i < pattern.length) {
4222
- var c = pattern[i],
4223
- c1 = '';
4224
- if (i < pattern.length - 1) c1 = pattern[i + 1];
4222
+ while (i < pattern.length) {
4223
+ var c = pattern[i],
4224
+ c1 = '';
4225
+ if (i < pattern.length - 1) c1 = pattern[i + 1];
4225
4226
 
4226
- if (c === escape) {
4227
- s += '\\' + c1;
4228
- i++;
4229
- } else if (c === '[' && c1 === '^') {
4230
- s += '[^';
4227
+ if (c === escape) {
4228
+ s += '\\' + c1;
4229
+ i++;
4230
+ } else if (c === '[' && c1 === '^') {
4231
+ s += '[^';
4232
+ i++;
4233
+ } else if (c === '[' || c === ']') {
4234
+ s += c;
4235
+ } else if (c === '%') {
4236
+ s += '[\\s\\S]*';
4237
+ } else if (c === '_') {
4238
+ s += '.';
4239
+ } else if ('/.*+?|(){}'.indexOf(c) > -1) {
4240
+ s += '\\' + c;
4241
+ } else {
4242
+ s += c;
4243
+ }
4231
4244
  i++;
4232
- } else if (c === '[' || c === ']') {
4233
- s += c;
4234
- } else if (c === '%') {
4235
- s += '[\\s\\S]*';
4236
- } else if (c === '_') {
4237
- s += '.';
4238
- } else if ('/.*+?|(){}'.indexOf(c) > -1) {
4239
- s += '\\' + c;
4240
- } else {
4241
- s += c;
4242
4245
  }
4243
- i++;
4244
- }
4245
4246
 
4246
- s += '$';
4247
- // if(value == undefined) return false;
4247
+ s += '$';
4248
+ // if(value == undefined) return false;
4248
4249
 
4249
- return ('' + (value ?? '')).search(RegExp(s, 'i')) > -1;
4250
+ patternCache[pattern] = RegExp(s, 'i');
4251
+ }
4252
+ return ('' + (value ?? '')).search(patternCache[pattern]) > -1;
4250
4253
  });
4251
4254
 
4252
4255
  utils.glob = function (value, pattern) {
@@ -4436,32 +4439,32 @@ alasql.parser.parseError = function (str, hash) {
4436
4439
  };
4437
4440
 
4438
4441
  /**
4439
- Jison parser
4440
- @param {string} sql SQL statement
4441
- @return {object} AST (Abstract Syntax Tree)
4442
+ Jison parser
4443
+ @param {string} sql SQL statement
4444
+ @return {object} AST (Abstract Syntax Tree)
4442
4445
 
4443
- @todo Create class AST
4444
- @todo Add other parsers
4446
+ @todo Create class AST
4447
+ @todo Add other parsers
4445
4448
 
4446
- @example
4447
- alasql.parse = function(sql) {
4449
+ @example
4450
+ alasql.parse = function(sql) {
4448
4451
  // My own parser here
4449
- }
4452
+ }
4450
4453
  */
4451
4454
  alasql.parse = function (sql) {
4452
4455
  return alasqlparser.parse(alasql.utils.uncomment(sql));
4453
4456
  };
4454
4457
 
4455
4458
  /**
4456
- List of engines of external databases
4457
- @type {object}
4458
- @todo Create collection type
4459
+ List of engines of external databases
4460
+ @type {object}
4461
+ @todo Create collection type
4459
4462
  */
4460
4463
  alasql.engines = {};
4461
4464
 
4462
4465
  /**
4463
- List of databases
4464
- @type {object}
4466
+ List of databases
4467
+ @type {object}
4465
4468
  */
4466
4469
  alasql.databases = {};
4467
4470
 
@@ -4472,7 +4475,7 @@ alasql.databases = {};
4472
4475
  alasql.databasenum = 0;
4473
4476
 
4474
4477
  /**
4475
- Alasql options object
4478
+ Alasql options object
4476
4479
  */
4477
4480
  alasql.options = {
4478
4481
  /** Log or throw error */
@@ -4546,6 +4549,9 @@ alasql.options = {
4546
4549
  joinstar: 'overwrite',
4547
4550
 
4548
4551
  loopbreak: 100000,
4552
+
4553
+ /** Whether GETDATE() and NOW() return dates as string. If false, then a Date object is returned */
4554
+ dateAsString: true,
4549
4555
  };
4550
4556
 
4551
4557
  //alasql.options.worker = false;
@@ -4666,10 +4672,10 @@ alasql.dexec = function (databaseid, sql, params, cb, scope) {
4666
4672
  var db = alasql.databases[databaseid];
4667
4673
  // if(db.databaseid != databaseid) console.trace('got!');
4668
4674
 
4669
- var hh;
4675
+ var hh = hash(sql);
4676
+
4670
4677
  // Create hash
4671
4678
  if (alasql.options.cache) {
4672
- hh = hash(sql);
4673
4679
  var statement = db.sqlCache[hh];
4674
4680
  // If database structure was not changed since last time return cache
4675
4681
  if (statement && db.dbversion === statement.dbversion) {
@@ -4677,8 +4683,17 @@ alasql.dexec = function (databaseid, sql, params, cb, scope) {
4677
4683
  }
4678
4684
  }
4679
4685
 
4680
- // Create AST
4681
- var ast = alasql.parse(sql);
4686
+ var ast = db.astCache[hh];
4687
+ if (alasql.options.cache && !ast) {
4688
+ // Create AST cache
4689
+ ast = alasql.parse(sql);
4690
+ if (ast) {
4691
+ // add to AST cache
4692
+ db.astCache[hh] = ast;
4693
+ }
4694
+ } else {
4695
+ ast = alasql.parse(sql);
4696
+ }
4682
4697
  if (!ast.statements) {
4683
4698
  return;
4684
4699
  }
@@ -4991,6 +5006,7 @@ var Database = (alasql.Database = function (databaseid) {
4991
5006
  Database.prototype.resetSqlCache = function () {
4992
5007
  this.sqlCache = {}; // Cache for compiled SQL statements
4993
5008
  this.sqlCacheSize = 0;
5009
+ this.astCache = {}; // Cache for AST objects
4994
5010
  };
4995
5011
 
4996
5012
  // Main SQL function
@@ -10689,14 +10705,13 @@ yy.Over = class Over {
10689
10705
  s += '.indexOf(';
10690
10706
  s += 'alasql.utils.getValueOf(' + leftJS() + '))>-1)';
10691
10707
  } else if (Array.isArray(this.right)) {
10692
- // if(this.right.length == 0) return 'false';
10708
+ // leverage JS Set, which is faster for lookups than arrays
10693
10709
  s =
10694
- '([' +
10710
+ '(new Set([' +
10695
10711
  this.right.map(ref).join(',') +
10696
- '].indexOf(alasql.utils.getValueOf(' +
10712
+ ']).has(alasql.utils.getValueOf(' +
10697
10713
  leftJS() +
10698
- '))>-1)';
10699
-
10714
+ ')))';
10700
10715
  } else {
10701
10716
  s = '(' + rightJS() + '.indexOf(' + leftJS() + ')>-1)';
10702
10717
 
@@ -10712,8 +10727,13 @@ yy.Over = class Over {
10712
10727
  s += '.indexOf(';
10713
10728
  s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
10714
10729
  } else if (Array.isArray(this.right)) {
10715
- s = '([' + this.right.map(ref).join(',') + '].indexOf(';
10716
- s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
10730
+ // leverage JS Set, which is faster for lookups than arrays
10731
+ s =
10732
+ '(!(new Set([' +
10733
+ this.right.map(ref).join(',') +
10734
+ ']).has(alasql.utils.getValueOf(' +
10735
+ leftJS() +
10736
+ '))))';
10717
10737
  } else {
10718
10738
  s = '(' + rightJS() + '.indexOf(';
10719
10739
  s += leftJS() + ')==-1)';
@@ -12991,27 +13011,31 @@ stdfn.OBJECT_ID = function (objid) {
12991
13011
  };
12992
13012
 
12993
13013
  stdfn.DATE = function (d) {
12994
- if (/\d{8}/.test(d)) return new Date(+d.substr(0, 4), +d.substr(4, 2) - 1, +d.substr(6, 2));
13014
+ if (!isNaN(d) && d.length === 8)
13015
+ return new Date(+d.substr(0, 4), +d.substr(4, 2) - 1, +d.substr(6, 2));
12995
13016
  return newDate(d);
12996
13017
  };
12997
13018
 
12998
13019
  stdfn.NOW = function () {
12999
- var d = new Date();
13000
- var s =
13001
- d.getFullYear() +
13002
- '-' +
13003
- ('0' + (d.getMonth() + 1)).substr(-2) +
13004
- '-' +
13005
- ('0' + d.getDate()).substr(-2);
13006
- s +=
13007
- ' ' +
13008
- ('0' + d.getHours()).substr(-2) +
13009
- ':' +
13010
- ('0' + d.getMinutes()).substr(-2) +
13011
- ':' +
13012
- ('0' + d.getSeconds()).substr(-2);
13013
- s += '.' + ('00' + d.getMilliseconds()).substr(-3);
13014
- return s;
13020
+ if (alasql.options.dateAsString) {
13021
+ var d = new Date();
13022
+ var s =
13023
+ d.getFullYear() +
13024
+ '-' +
13025
+ ('0' + (d.getMonth() + 1)).substr(-2) +
13026
+ '-' +
13027
+ ('0' + d.getDate()).substr(-2);
13028
+ s +=
13029
+ ' ' +
13030
+ ('0' + d.getHours()).substr(-2) +
13031
+ ':' +
13032
+ ('0' + d.getMinutes()).substr(-2) +
13033
+ ':' +
13034
+ ('0' + d.getSeconds()).substr(-2);
13035
+ s += '.' + ('00' + d.getMilliseconds()).substr(-3);
13036
+ return s;
13037
+ }
13038
+ return new Date();
13015
13039
  };
13016
13040
 
13017
13041
  stdfn.GETDATE = stdfn.NOW;
package/dist/alasql.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v4.1.11 build: develop-1493d57a | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v4.2.0 build: develop-67d9f6dd | © 2014-2023 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 4.1.11
4
+ @version 4.2.0
5
5
 
6
6
  AlaSQL - JavaScript SQL database
7
7
  © 2014-2023 Andrey Gershun & Mathias Wulff
@@ -141,8 +141,8 @@ var alasql = function(sql, params, cb, scope) {
141
141
  Current version of alasql
142
142
  @constant {string}
143
143
  */
144
- alasql.version = '4.1.11';
145
- alasql.build = 'develop-1493d57a';
144
+ alasql.version = '4.2.0';
145
+ alasql.build = 'develop-67d9f6dd';
146
146
 
147
147
  /**
148
148
  Debug flag
@@ -3168,10 +3168,10 @@ alasql.pretty = function (sql, flag) {
3168
3168
 
3169
3169
  /*jshint unused:false*/
3170
3170
  /*
3171
- Utilities for Alasql.js
3171
+ Utilities for Alasql.js
3172
3172
 
3173
- @todo Review the list of utilities
3174
- @todo Find more effective utilities
3173
+ @todo Review the list of utilities
3174
+ @todo Find more effective utilities
3175
3175
  */
3176
3176
 
3177
3177
  /**
@@ -4210,43 +4210,46 @@ var domEmptyChildren = (utils.domEmptyChildren = function (container) {
4210
4210
  @parameter {string} escape Escape character (optional)
4211
4211
  @return {boolean} If value LIKE pattern ESCAPE escape
4212
4212
  */
4213
-
4213
+ var patternCache = {};
4214
4214
  var like = (utils.like = function (pattern, value, escape) {
4215
- // Verify escape character
4216
- if (!escape) escape = '';
4215
+ if (!patternCache[pattern]) {
4216
+ // Verify escape character
4217
+ if (!escape) escape = '';
4217
4218
 
4218
- var i = 0;
4219
- var s = '^';
4219
+ var i = 0;
4220
+ var s = '^';
4220
4221
 
4221
- while (i < pattern.length) {
4222
- var c = pattern[i],
4223
- c1 = '';
4224
- if (i < pattern.length - 1) c1 = pattern[i + 1];
4222
+ while (i < pattern.length) {
4223
+ var c = pattern[i],
4224
+ c1 = '';
4225
+ if (i < pattern.length - 1) c1 = pattern[i + 1];
4225
4226
 
4226
- if (c === escape) {
4227
- s += '\\' + c1;
4228
- i++;
4229
- } else if (c === '[' && c1 === '^') {
4230
- s += '[^';
4227
+ if (c === escape) {
4228
+ s += '\\' + c1;
4229
+ i++;
4230
+ } else if (c === '[' && c1 === '^') {
4231
+ s += '[^';
4232
+ i++;
4233
+ } else if (c === '[' || c === ']') {
4234
+ s += c;
4235
+ } else if (c === '%') {
4236
+ s += '[\\s\\S]*';
4237
+ } else if (c === '_') {
4238
+ s += '.';
4239
+ } else if ('/.*+?|(){}'.indexOf(c) > -1) {
4240
+ s += '\\' + c;
4241
+ } else {
4242
+ s += c;
4243
+ }
4231
4244
  i++;
4232
- } else if (c === '[' || c === ']') {
4233
- s += c;
4234
- } else if (c === '%') {
4235
- s += '[\\s\\S]*';
4236
- } else if (c === '_') {
4237
- s += '.';
4238
- } else if ('/.*+?|(){}'.indexOf(c) > -1) {
4239
- s += '\\' + c;
4240
- } else {
4241
- s += c;
4242
4245
  }
4243
- i++;
4244
- }
4245
4246
 
4246
- s += '$';
4247
- // if(value == undefined) return false;
4247
+ s += '$';
4248
+ // if(value == undefined) return false;
4248
4249
 
4249
- return ('' + (value ?? '')).search(RegExp(s, 'i')) > -1;
4250
+ patternCache[pattern] = RegExp(s, 'i');
4251
+ }
4252
+ return ('' + (value ?? '')).search(patternCache[pattern]) > -1;
4250
4253
  });
4251
4254
 
4252
4255
  utils.glob = function (value, pattern) {
@@ -4436,32 +4439,32 @@ alasql.parser.parseError = function (str, hash) {
4436
4439
  };
4437
4440
 
4438
4441
  /**
4439
- Jison parser
4440
- @param {string} sql SQL statement
4441
- @return {object} AST (Abstract Syntax Tree)
4442
+ Jison parser
4443
+ @param {string} sql SQL statement
4444
+ @return {object} AST (Abstract Syntax Tree)
4442
4445
 
4443
- @todo Create class AST
4444
- @todo Add other parsers
4446
+ @todo Create class AST
4447
+ @todo Add other parsers
4445
4448
 
4446
- @example
4447
- alasql.parse = function(sql) {
4449
+ @example
4450
+ alasql.parse = function(sql) {
4448
4451
  // My own parser here
4449
- }
4452
+ }
4450
4453
  */
4451
4454
  alasql.parse = function (sql) {
4452
4455
  return alasqlparser.parse(alasql.utils.uncomment(sql));
4453
4456
  };
4454
4457
 
4455
4458
  /**
4456
- List of engines of external databases
4457
- @type {object}
4458
- @todo Create collection type
4459
+ List of engines of external databases
4460
+ @type {object}
4461
+ @todo Create collection type
4459
4462
  */
4460
4463
  alasql.engines = {};
4461
4464
 
4462
4465
  /**
4463
- List of databases
4464
- @type {object}
4466
+ List of databases
4467
+ @type {object}
4465
4468
  */
4466
4469
  alasql.databases = {};
4467
4470
 
@@ -4472,7 +4475,7 @@ alasql.databases = {};
4472
4475
  alasql.databasenum = 0;
4473
4476
 
4474
4477
  /**
4475
- Alasql options object
4478
+ Alasql options object
4476
4479
  */
4477
4480
  alasql.options = {
4478
4481
  /** Log or throw error */
@@ -4546,6 +4549,9 @@ alasql.options = {
4546
4549
  joinstar: 'overwrite',
4547
4550
 
4548
4551
  loopbreak: 100000,
4552
+
4553
+ /** Whether GETDATE() and NOW() return dates as string. If false, then a Date object is returned */
4554
+ dateAsString: true,
4549
4555
  };
4550
4556
 
4551
4557
  //alasql.options.worker = false;
@@ -4666,10 +4672,10 @@ alasql.dexec = function (databaseid, sql, params, cb, scope) {
4666
4672
  var db = alasql.databases[databaseid];
4667
4673
  // if(db.databaseid != databaseid) console.trace('got!');
4668
4674
 
4669
- var hh;
4675
+ var hh = hash(sql);
4676
+
4670
4677
  // Create hash
4671
4678
  if (alasql.options.cache) {
4672
- hh = hash(sql);
4673
4679
  var statement = db.sqlCache[hh];
4674
4680
  // If database structure was not changed since last time return cache
4675
4681
  if (statement && db.dbversion === statement.dbversion) {
@@ -4677,8 +4683,17 @@ alasql.dexec = function (databaseid, sql, params, cb, scope) {
4677
4683
  }
4678
4684
  }
4679
4685
 
4680
- // Create AST
4681
- var ast = alasql.parse(sql);
4686
+ var ast = db.astCache[hh];
4687
+ if (alasql.options.cache && !ast) {
4688
+ // Create AST cache
4689
+ ast = alasql.parse(sql);
4690
+ if (ast) {
4691
+ // add to AST cache
4692
+ db.astCache[hh] = ast;
4693
+ }
4694
+ } else {
4695
+ ast = alasql.parse(sql);
4696
+ }
4682
4697
  if (!ast.statements) {
4683
4698
  return;
4684
4699
  }
@@ -4991,6 +5006,7 @@ var Database = (alasql.Database = function (databaseid) {
4991
5006
  Database.prototype.resetSqlCache = function () {
4992
5007
  this.sqlCache = {}; // Cache for compiled SQL statements
4993
5008
  this.sqlCacheSize = 0;
5009
+ this.astCache = {}; // Cache for AST objects
4994
5010
  };
4995
5011
 
4996
5012
  // Main SQL function
@@ -10689,14 +10705,13 @@ yy.Over = class Over {
10689
10705
  s += '.indexOf(';
10690
10706
  s += 'alasql.utils.getValueOf(' + leftJS() + '))>-1)';
10691
10707
  } else if (Array.isArray(this.right)) {
10692
- // if(this.right.length == 0) return 'false';
10708
+ // leverage JS Set, which is faster for lookups than arrays
10693
10709
  s =
10694
- '([' +
10710
+ '(new Set([' +
10695
10711
  this.right.map(ref).join(',') +
10696
- '].indexOf(alasql.utils.getValueOf(' +
10712
+ ']).has(alasql.utils.getValueOf(' +
10697
10713
  leftJS() +
10698
- '))>-1)';
10699
-
10714
+ ')))';
10700
10715
  } else {
10701
10716
  s = '(' + rightJS() + '.indexOf(' + leftJS() + ')>-1)';
10702
10717
 
@@ -10712,8 +10727,13 @@ yy.Over = class Over {
10712
10727
  s += '.indexOf(';
10713
10728
  s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
10714
10729
  } else if (Array.isArray(this.right)) {
10715
- s = '([' + this.right.map(ref).join(',') + '].indexOf(';
10716
- s += 'alasql.utils.getValueOf(' + leftJS() + '))<0)';
10730
+ // leverage JS Set, which is faster for lookups than arrays
10731
+ s =
10732
+ '(!(new Set([' +
10733
+ this.right.map(ref).join(',') +
10734
+ ']).has(alasql.utils.getValueOf(' +
10735
+ leftJS() +
10736
+ '))))';
10717
10737
  } else {
10718
10738
  s = '(' + rightJS() + '.indexOf(';
10719
10739
  s += leftJS() + ')==-1)';
@@ -12991,27 +13011,31 @@ stdfn.OBJECT_ID = function (objid) {
12991
13011
  };
12992
13012
 
12993
13013
  stdfn.DATE = function (d) {
12994
- if (/\d{8}/.test(d)) return new Date(+d.substr(0, 4), +d.substr(4, 2) - 1, +d.substr(6, 2));
13014
+ if (!isNaN(d) && d.length === 8)
13015
+ return new Date(+d.substr(0, 4), +d.substr(4, 2) - 1, +d.substr(6, 2));
12995
13016
  return newDate(d);
12996
13017
  };
12997
13018
 
12998
13019
  stdfn.NOW = function () {
12999
- var d = new Date();
13000
- var s =
13001
- d.getFullYear() +
13002
- '-' +
13003
- ('0' + (d.getMonth() + 1)).substr(-2) +
13004
- '-' +
13005
- ('0' + d.getDate()).substr(-2);
13006
- s +=
13007
- ' ' +
13008
- ('0' + d.getHours()).substr(-2) +
13009
- ':' +
13010
- ('0' + d.getMinutes()).substr(-2) +
13011
- ':' +
13012
- ('0' + d.getSeconds()).substr(-2);
13013
- s += '.' + ('00' + d.getMilliseconds()).substr(-3);
13014
- return s;
13020
+ if (alasql.options.dateAsString) {
13021
+ var d = new Date();
13022
+ var s =
13023
+ d.getFullYear() +
13024
+ '-' +
13025
+ ('0' + (d.getMonth() + 1)).substr(-2) +
13026
+ '-' +
13027
+ ('0' + d.getDate()).substr(-2);
13028
+ s +=
13029
+ ' ' +
13030
+ ('0' + d.getHours()).substr(-2) +
13031
+ ':' +
13032
+ ('0' + d.getMinutes()).substr(-2) +
13033
+ ':' +
13034
+ ('0' + d.getSeconds()).substr(-2);
13035
+ s += '.' + ('00' + d.getMilliseconds()).substr(-3);
13036
+ return s;
13037
+ }
13038
+ return new Date();
13015
13039
  };
13016
13040
 
13017
13041
  stdfn.GETDATE = stdfn.NOW;