alasql 2.1.7 → 2.2.0

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/dist/alasql.js CHANGED
@@ -1,7 +1,7 @@
1
- //! AlaSQL v2.1.6-develop-8399ae92 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
1
+ //! AlaSQL v2.1.8-develop-7e87d661 | © 2014-2022 Andrey Gershun & Mathias Wulff | License: MIT
2
2
  /*
3
3
  @module alasql
4
- @version 2.1.6-develop-8399ae92
4
+ @version 2.1.8-develop-7e87d661
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.6-develop-8399ae92';
145
+ alasql.version = '2.1.8-develop-7e87d661';
146
146
 
147
147
  /**
148
148
  Debug flag
@@ -3178,64 +3178,64 @@ alasql.pretty = function (sql, flag) {
3178
3178
  var utils = (alasql.utils = {});
3179
3179
 
3180
3180
  /**
3181
- Convert NaN to undefined
3182
- @function
3183
- @param {string} s JavaScript string to be modified
3184
- @return {string} Covered expression
3181
+ Convert NaN to undefined
3182
+ @function
3183
+ @param {string} s JavaScript string to be modified
3184
+ @return {string} Covered expression
3185
3185
 
3186
- @example
3186
+ @example
3187
3187
 
3188
- 123 => 123
3189
- undefined => undefined
3190
- NaN => undefined
3188
+ 123 => 123
3189
+ undefined => undefined
3190
+ NaN => undefined
3191
3191
 
3192
- */
3192
+ */
3193
3193
  function n2u(s) {
3194
3194
  return '(y=' + s + ',y===y?y:undefined)';
3195
3195
  }
3196
3196
 
3197
3197
  /**
3198
- Return undefined if s undefined
3199
- @param {string} s JavaScript string to be modified
3200
- @return {string} Covered expression
3198
+ Return undefined if s undefined
3199
+ @param {string} s JavaScript string to be modified
3200
+ @return {string} Covered expression
3201
3201
 
3202
- @example
3202
+ @example
3203
3203
 
3204
- 123,a => a
3205
- undefined,a => undefined
3206
- NaN,a => undefined
3204
+ 123,a => a
3205
+ undefined,a => undefined
3206
+ NaN,a => undefined
3207
3207
 
3208
- */
3208
+ */
3209
3209
  function und(s, r) {
3210
3210
  return '(y=' + s + ',typeof y=="undefined"?undefined:' + r + ')';
3211
3211
  }
3212
3212
 
3213
3213
  /**
3214
- Return always true. Stub for non-ecisting WHERE clause, because is faster then if(whenrfn) whenfn()
3215
- @function
3216
- @return {boolean} Always true
3217
- */
3214
+ Return always true. Stub for non-ecisting WHERE clause, because is faster then if(whenrfn) whenfn()
3215
+ @function
3216
+ @return {boolean} Always true
3217
+ */
3218
3218
  function returnTrue() {
3219
3219
  return true;
3220
3220
  }
3221
3221
 
3222
3222
  /**
3223
- Return undefined. Stub for non-ecisting WHERE clause, because is faster then if(whenrfn) whenfn()
3224
- @function
3225
- @return {undefined} Always undefined
3226
- */
3223
+ Return undefined. Stub for non-ecisting WHERE clause, because is faster then if(whenrfn) whenfn()
3224
+ @function
3225
+ @return {undefined} Always undefined
3226
+ */
3227
3227
  function returnUndefined() {}
3228
3228
 
3229
3229
  /**
3230
- Escape string
3231
- @function
3232
- @param {string} s Source string
3233
- @return {string} Escaped string
3234
- @example
3230
+ Escape string
3231
+ @function
3232
+ @param {string} s Source string
3233
+ @return {string} Escaped string
3234
+ @example
3235
3235
 
3236
- Pit\er's => Pit\\er\'s
3236
+ Pit\er's => Pit\\er\'s
3237
3237
 
3238
- */
3238
+ */
3239
3239
  // based on joliss/js-string-escape
3240
3240
  var escapeq = (utils.escapeq = function (s) {
3241
3241
 
@@ -3262,49 +3262,49 @@ var escapeq = (utils.escapeq = function (s) {
3262
3262
  });
3263
3263
 
3264
3264
  /**
3265
- Double quotes for SQL statements
3266
- @param {string} s Source string
3267
- @return {string} Escaped string
3265
+ Double quotes for SQL statements
3266
+ @param {string} s Source string
3267
+ @return {string} Escaped string
3268
3268
 
3269
- @example
3269
+ @example
3270
3270
 
3271
- Piter's => Piter''s
3271
+ Piter's => Piter''s
3272
3272
 
3273
- */
3273
+ */
3274
3274
  var escapeqq = (utils.undoubleq = function (s) {
3275
3275
  return s.replace(/(\')/g, "''");
3276
3276
  });
3277
3277
 
3278
3278
  /**
3279
- Replace double quotes with single quote
3280
- @param {string} s Source string
3281
- @return {string} Replaced string
3282
- @example
3279
+ Replace double quotes with single quote
3280
+ @param {string} s Source string
3281
+ @return {string} Replaced string
3282
+ @example
3283
3283
 
3284
- Piter''s => Piter's
3284
+ Piter''s => Piter's
3285
3285
 
3286
- */
3286
+ */
3287
3287
  var doubleq = (utils.doubleq = function (s) {
3288
3288
  return s.replace(/(\'\')/g, "\\'");
3289
3289
  });
3290
3290
 
3291
3291
  /**
3292
- Replace sigle quote to escaped single quote
3293
- @param {string} s Source string
3294
- @return {string} Replaced string
3292
+ Replace sigle quote to escaped single quote
3293
+ @param {string} s Source string
3294
+ @return {string} Replaced string
3295
3295
 
3296
- @todo Chack this functions
3296
+ @todo Chack this functions
3297
3297
 
3298
- */
3298
+ */
3299
3299
  var doubleqq = (utils.doubleqq = function (s) {
3300
3300
  return s.replace(/\'/g, "'");
3301
3301
  });
3302
3302
 
3303
3303
  /**
3304
- Cut BOM first character for UTF-8 files (for merging two files)
3305
- @param {string} s Source string
3306
- @return {string} Replaced string
3307
- */
3304
+ Cut BOM first character for UTF-8 files (for merging two files)
3305
+ @param {string} s Source string
3306
+ @return {string} Replaced string
3307
+ */
3308
3308
 
3309
3309
  var cutbom = function (s) {
3310
3310
  if (s[0] === String.fromCharCode(65279)) {
@@ -3314,10 +3314,10 @@ var cutbom = function (s) {
3314
3314
  };
3315
3315
 
3316
3316
  /**
3317
- Get the global scope
3318
- Inspired by System.global
3319
- @return {object} The global scope
3320
- */
3317
+ Get the global scope
3318
+ Inspired by System.global
3319
+ @return {object} The global scope
3320
+ */
3321
3321
  utils.global = (function () {
3322
3322
  if (typeof self !== 'undefined') {
3323
3323
  return self;
@@ -3332,18 +3332,18 @@ utils.global = (function () {
3332
3332
  })();
3333
3333
 
3334
3334
  /**
3335
- Find out if a function is native to the enviroment
3336
- @param {function} Function to check
3337
- @return {boolean} True if function is native
3338
- */
3335
+ Find out if a function is native to the enviroment
3336
+ @param {function} Function to check
3337
+ @return {boolean} True if function is native
3338
+ */
3339
3339
  var isNativeFunction = (utils.isNativeFunction = function (fn) {
3340
3340
  return typeof fn === 'function' && !!~fn.toString().indexOf('[native code]');
3341
3341
  });
3342
3342
 
3343
3343
  /**
3344
- Find out if code is running in a web worker enviroment
3345
- @return {boolean} True if code is running in a web worker enviroment
3346
- */
3344
+ Find out if code is running in a web worker enviroment
3345
+ @return {boolean} True if code is running in a web worker enviroment
3346
+ */
3347
3347
  utils.isWebWorker = (function () {
3348
3348
  try {
3349
3349
  var importScripts = utils.global.importScripts;
@@ -3354,9 +3354,9 @@ utils.isWebWorker = (function () {
3354
3354
  })();
3355
3355
 
3356
3356
  /**
3357
- Find out if code is running in a node enviroment
3358
- @return {boolean} True if code is running in a node enviroment
3359
- */
3357
+ Find out if code is running in a node enviroment
3358
+ @return {boolean} True if code is running in a node enviroment
3359
+ */
3360
3360
  utils.isNode = (function () {
3361
3361
  try {
3362
3362
  return utils.isNativeFunction(utils.global.process.reallyExit);
@@ -3366,9 +3366,9 @@ utils.isNode = (function () {
3366
3366
  })();
3367
3367
 
3368
3368
  /**
3369
- Find out if code is running in a browser enviroment
3370
- @return {boolean} True if code is running in a browser enviroment
3371
- */
3369
+ Find out if code is running in a browser enviroment
3370
+ @return {boolean} True if code is running in a browser enviroment
3371
+ */
3372
3372
  utils.isBrowser = (function () {
3373
3373
  try {
3374
3374
  return utils.isNativeFunction(utils.global.location.reload);
@@ -3378,17 +3378,17 @@ utils.isBrowser = (function () {
3378
3378
  })();
3379
3379
 
3380
3380
  /**
3381
- Find out if code is running in a browser with a browserify setup
3382
- @return {boolean} True if code is running in a browser with a browserify setup
3383
- */
3381
+ Find out if code is running in a browser with a browserify setup
3382
+ @return {boolean} True if code is running in a browser with a browserify setup
3383
+ */
3384
3384
  utils.isBrowserify = (function () {
3385
3385
  return utils.isBrowser && typeof process !== 'undefined' && process.browser;
3386
3386
  })();
3387
3387
 
3388
3388
  /**
3389
- Find out if code is running in a browser with a requireJS setup
3390
- @return {boolean} True if code is running in a browser with a requireJS setup
3391
- */
3389
+ Find out if code is running in a browser with a requireJS setup
3390
+ @return {boolean} True if code is running in a browser with a requireJS setup
3391
+ */
3392
3392
  utils.isRequireJS = (function () {
3393
3393
  return (
3394
3394
  utils.isBrowser && typeof require === 'function' && typeof require.specified === 'function'
@@ -3396,37 +3396,37 @@ utils.isRequireJS = (function () {
3396
3396
  })();
3397
3397
 
3398
3398
  /**
3399
- Find out if code is running with Meteor in the enviroment
3400
- @return {boolean} True if code is running with Meteor in the enviroment
3399
+ Find out if code is running with Meteor in the enviroment
3400
+ @return {boolean} True if code is running with Meteor in the enviroment
3401
3401
 
3402
- @todo Find out if this is the best way to do this
3403
- */
3402
+ @todo Find out if this is the best way to do this
3403
+ */
3404
3404
  utils.isMeteor = (function () {
3405
3405
  return typeof Meteor !== 'undefined' && Meteor.release;
3406
3406
  })();
3407
3407
 
3408
3408
  /**
3409
- Find out if code is running on a Meteor client
3410
- @return {boolean} True if code is running on a Meteor client
3411
- */
3409
+ Find out if code is running on a Meteor client
3410
+ @return {boolean} True if code is running on a Meteor client
3411
+ */
3412
3412
  utils.isMeteorClient = utils.isMeteorClient = (function () {
3413
3413
  return utils.isMeteor && Meteor.isClient;
3414
3414
  })();
3415
3415
 
3416
3416
  /**
3417
- Find out if code is running on a Meteor server
3418
- @return {boolean} True if code is running on a Meteor server
3419
- */
3417
+ Find out if code is running on a Meteor server
3418
+ @return {boolean} True if code is running on a Meteor server
3419
+ */
3420
3420
  utils.isMeteorServer = (function () {
3421
3421
  return utils.isMeteor && Meteor.isServer;
3422
3422
  })();
3423
3423
 
3424
3424
  /**
3425
- Find out code is running in a cordovar enviroment
3426
- @return {boolean} True if code is running in a web worker enviroment
3425
+ Find out code is running in a cordovar enviroment
3426
+ @return {boolean} True if code is running in a web worker enviroment
3427
3427
 
3428
- @todo Find out if this is the best way to do this
3429
- */
3428
+ @todo Find out if this is the best way to do this
3429
+ */
3430
3430
  utils.isCordova = (function () {
3431
3431
  return typeof cordova === 'object';
3432
3432
  })();
@@ -3453,16 +3453,16 @@ utils.isArray = function (obj) {
3453
3453
  return '[object Array]' === Object.prototype.toString.call(obj);
3454
3454
  };
3455
3455
  /**
3456
- Load text file from anywhere
3457
- @param {string|object} path File path or HTML event
3458
- @param {boolean} asy True - async call, false - sync call
3459
- @param {function} success Success function
3460
- @param {function} error Error function
3461
- @return {string} Read data
3462
-
3463
- @todo Define Event type
3464
- @todo Smaller if-else structures.
3465
- */
3456
+ Load text file from anywhere
3457
+ @param {string|object} path File path or HTML event
3458
+ @param {boolean} asy True - async call, false - sync call
3459
+ @param {function} success Success function
3460
+ @param {function} error Error function
3461
+ @return {string} Read data
3462
+
3463
+ @todo Define Event type
3464
+ @todo Smaller if-else structures.
3465
+ */
3466
3466
  var loadFile = (utils.loadFile = function (path, asy, success, error) {
3467
3467
  var data, fs;
3468
3468
  if (utils.isNode || utils.isMeteorServer) {
@@ -3547,16 +3547,16 @@ var loadFile = (utils.loadFile = function (path, asy, success, error) {
3547
3547
  if (typeof path === 'string') {
3548
3548
  // For browser read from tag
3549
3549
  /*
3550
- SELECT * FROM TXT('#one') -- read data from HTML element with id="one"
3551
- */
3550
+ SELECT * FROM TXT('#one') -- read data from HTML element with id="one"
3551
+ */
3552
3552
  if (path.substr(0, 1) === '#' && typeof document !== 'undefined') {
3553
3553
  data = document.querySelector(path).textContent;
3554
3554
  success(data);
3555
3555
  } else {
3556
3556
  /*
3557
- Simply read file from HTTP request, like:
3558
- SELECT * FROM TXT('http://alasql.org/README.md');
3559
- */
3557
+ Simply read file from HTTP request, like:
3558
+ SELECT * FROM TXT('http://alasql.org/README.md');
3559
+ */
3560
3560
  var xhr = new XMLHttpRequest();
3561
3561
  xhr.onreadystatechange = function () {
3562
3562
  if (xhr.readyState === 4) {
@@ -3576,14 +3576,14 @@ var loadFile = (utils.loadFile = function (path, asy, success, error) {
3576
3576
  }
3577
3577
  } else if (path instanceof Event) {
3578
3578
  /*
3579
- For browser read from files input element
3580
- <input type="files" onchange="readFile(event)">
3581
- <script>
3582
- function readFile(event) {
3583
- alasql('SELECT * FROM TXT(?)',[event])
3584
- }
3585
- </script>
3586
- */
3579
+ For browser read from files input element
3580
+ <input type="files" onchange="readFile(event)">
3581
+ <script>
3582
+ function readFile(event) {
3583
+ alasql('SELECT * FROM TXT(?)',[event])
3584
+ }
3585
+ </script>
3586
+ */
3587
3587
  /** @type {array} List of files from <input> element */
3588
3588
  var files = path.target.files;
3589
3589
  /** type {object} */
@@ -3600,15 +3600,15 @@ var loadFile = (utils.loadFile = function (path, asy, success, error) {
3600
3600
  });
3601
3601
 
3602
3602
  /**
3603
- @function Load binary file from anywhere
3604
- @param {string} path File path
3605
- @param {boolean} asy True - async call, false - sync call
3606
- @param {function} success Success function
3607
- @param {function} error Error function
3608
- @return 1 for Async, data - for sync version
3609
-
3610
- @todo merge functionality from loadFile and LoadBinaryFile
3611
- */
3603
+ @function Load binary file from anywhere
3604
+ @param {string} path File path
3605
+ @param {boolean} asy True - async call, false - sync call
3606
+ @param {function} success Success function
3607
+ @param {function} error Error function
3608
+ @return 1 for Async, data - for sync version
3609
+
3610
+ @todo merge functionality from loadFile and LoadBinaryFile
3611
+ */
3612
3612
 
3613
3613
  var loadBinaryFile = (utils.loadBinaryFile = function (
3614
3614
  path,
@@ -3808,12 +3808,12 @@ var fileExists = (utils.fileExists = function (path, cb) {
3808
3808
  });
3809
3809
 
3810
3810
  /**
3811
- Save text file from anywhere
3812
- @param {string} path File path
3813
- @param {array} data Data object
3814
- @param {function} cb Callback
3815
- @param {object=} opts
3816
- */
3811
+ Save text file from anywhere
3812
+ @param {string} path File path
3813
+ @param {array} data Data object
3814
+ @param {function} cb Callback
3815
+ @param {object=} opts
3816
+ */
3817
3817
 
3818
3818
  var saveFile = (utils.saveFile = function (path, data, cb, opts) {
3819
3819
  var res = 1;
@@ -3895,21 +3895,21 @@ var saveFile = (utils.saveFile = function (path, data, cb, opts) {
3895
3895
  });
3896
3896
 
3897
3897
  /**
3898
- @function Is this IE9
3899
- @return {boolean} True for IE9 and false for other browsers
3898
+ @function Is this IE9
3899
+ @return {boolean} True for IE9 and false for other browsers
3900
3900
 
3901
- For IE9 compatibility issues
3902
- */
3901
+ For IE9 compatibility issues
3902
+ */
3903
3903
  function isIE() {
3904
3904
  var myNav = navigator.userAgent.toLowerCase();
3905
3905
  return myNav.indexOf('msie') !== -1 ? parseInt(myNav.split('msie')[1]) : false;
3906
3906
  }
3907
3907
 
3908
3908
  /**
3909
- @function Hash a string to signed integer
3910
- @param {string} source string
3911
- @return {integer} hash number
3912
- */
3909
+ @function Hash a string to signed integer
3910
+ @param {string} source string
3911
+ @return {integer} hash number
3912
+ */
3913
3913
 
3914
3914
  // FNV-1a inspired hashing
3915
3915
  var hash = (utils.hash = function (str) {
@@ -3923,12 +3923,12 @@ var hash = (utils.hash = function (str) {
3923
3923
  });
3924
3924
 
3925
3925
  /**
3926
- Union arrays
3927
- @function
3928
- @param {array} a
3929
- @param {array} b
3930
- @return {array}
3931
- */
3926
+ Union arrays
3927
+ @function
3928
+ @param {array} a
3929
+ @param {array} b
3930
+ @return {array}
3931
+ */
3932
3932
  var arrayUnion = (utils.arrayUnion = function (a, b) {
3933
3933
  var r = b.slice(0);
3934
3934
  a.forEach(function (i) {
@@ -3940,8 +3940,8 @@ var arrayUnion = (utils.arrayUnion = function (a, b) {
3940
3940
  });
3941
3941
 
3942
3942
  /**
3943
- Array Difference
3944
- */
3943
+ Array Difference
3944
+ */
3945
3945
  var arrayDiff = (utils.arrayDiff = function (a, b) {
3946
3946
  return a.filter(function (i) {
3947
3947
  return b.indexOf(i) < 0;
@@ -3949,8 +3949,8 @@ var arrayDiff = (utils.arrayDiff = function (a, b) {
3949
3949
  });
3950
3950
 
3951
3951
  /**
3952
- Arrays deep intersect (with records)
3953
- */
3952
+ Arrays deep intersect (with records)
3953
+ */
3954
3954
  var arrayIntersect = (utils.arrayIntersect = function (a, b) {
3955
3955
  var r = [];
3956
3956
  a.forEach(function (ai) {
@@ -3968,8 +3968,8 @@ var arrayIntersect = (utils.arrayIntersect = function (a, b) {
3968
3968
  });
3969
3969
 
3970
3970
  /**
3971
- Arrays deep union (with records)
3972
- */
3971
+ Arrays deep union (with records)
3972
+ */
3973
3973
  var arrayUnionDeep = (utils.arrayUnionDeep = function (a, b) {
3974
3974
  var r = b.slice(0);
3975
3975
  a.forEach(function (ai) {
@@ -3988,8 +3988,8 @@ var arrayUnionDeep = (utils.arrayUnionDeep = function (a, b) {
3988
3988
  });
3989
3989
 
3990
3990
  /**
3991
- Arrays deep union (with records)
3992
- */
3991
+ Arrays deep union (with records)
3992
+ */
3993
3993
  var arrayExceptDeep = (utils.arrayExceptDeep = function (a, b) {
3994
3994
  var r = [];
3995
3995
  a.forEach(function (ai) {
@@ -4008,8 +4008,8 @@ var arrayExceptDeep = (utils.arrayExceptDeep = function (a, b) {
4008
4008
  });
4009
4009
 
4010
4010
  /**
4011
- Arrays deep intersect (with records)
4012
- */
4011
+ Arrays deep intersect (with records)
4012
+ */
4013
4013
  var arrayIntersectDeep = (utils.arrayIntersectDeep = function (a, b) {
4014
4014
  var r = [];
4015
4015
  a.forEach(function (ai) {
@@ -4028,8 +4028,8 @@ var arrayIntersectDeep = (utils.arrayIntersectDeep = function (a, b) {
4028
4028
  });
4029
4029
 
4030
4030
  /**
4031
- Deep clone objects
4032
- */
4031
+ Deep clone objects
4032
+ */
4033
4033
  var cloneDeep = (utils.cloneDeep = function cloneDeep(obj) {
4034
4034
  if (null === obj || typeof obj !== 'object') {
4035
4035
  return obj;
@@ -4058,12 +4058,12 @@ var cloneDeep = (utils.cloneDeep = function cloneDeep(obj) {
4058
4058
  });
4059
4059
 
4060
4060
  /**
4061
- Check equality of objects
4062
- */
4061
+ Check equality of objects
4062
+ */
4063
4063
 
4064
4064
  /**
4065
- Compare two objects in deep
4066
- */
4065
+ Compare two objects in deep
4066
+ */
4067
4067
  var deepEqual = (utils.deepEqual = function (x, y) {
4068
4068
  if (x === y) {
4069
4069
  return true;
@@ -4084,10 +4084,10 @@ var deepEqual = (utils.deepEqual = function (x, y) {
4084
4084
  return false;
4085
4085
  });
4086
4086
  /**
4087
- Array with distinct records
4088
- @param {array} data
4089
- @return {array}
4090
- */
4087
+ Array with distinct records
4088
+ @param {array} data
4089
+ @return {array}
4090
+ */
4091
4091
  var distinctArray = (utils.distinctArray = function (data) {
4092
4092
  var uniq = {};
4093
4093
  // TODO: Speedup, because Object.keys is slow
@@ -4113,12 +4113,12 @@ var distinctArray = (utils.distinctArray = function (data) {
4113
4113
  });
4114
4114
 
4115
4115
  /**
4116
- Extend object a with properties of b
4117
- @function
4118
- @param {object} a
4119
- @param {object} b
4120
- @return {object}
4121
- */
4116
+ Extend object a with properties of b
4117
+ @function
4118
+ @param {object} a
4119
+ @param {object} b
4120
+ @return {object}
4121
+ */
4122
4122
  var extend = (utils.extend = function extend(a, b) {
4123
4123
  a = a || {};
4124
4124
  for (var key in b) {
@@ -4139,8 +4139,8 @@ var getValueOf = (utils.getValueOf = function (val) {
4139
4139
  });
4140
4140
 
4141
4141
  /**
4142
- Flat array by first row
4143
- */
4142
+ Flat array by first row
4143
+ */
4144
4144
  var flatArray = (utils.flatArray = function (a) {
4145
4145
 
4146
4146
  if (!a || 0 === a.length) {
@@ -4164,8 +4164,8 @@ var flatArray = (utils.flatArray = function (a) {
4164
4164
  });
4165
4165
 
4166
4166
  /**
4167
- Convert array of objects to array of arrays
4168
- */
4167
+ Convert array of objects to array of arrays
4168
+ */
4169
4169
  var arrayOfArrays = (utils.arrayOfArrays = function (a) {
4170
4170
  return a.map(function (aa) {
4171
4171
  var ar = [];
@@ -4183,12 +4183,18 @@ if (!Array.isArray) {
4183
4183
  }
4184
4184
 
4185
4185
  /**
4186
- Excel:convert number to Excel column, like 1 => 'A'
4187
- @param {integer} i Column number, starting with 0
4188
- @return {string} Column name, starting with 'A'
4189
- */
4186
+ Excel:convert number to Excel column, like 1 => 'A'
4187
+ @param {integer} i Column number, starting with 0
4188
+ @return {string} Column name, starting with 'A'
4189
+ */
4190
4190
 
4191
4191
  var xlsnc = (utils.xlsnc = function (i) {
4192
+ var first = '';
4193
+ if (i > 701) {
4194
+ let x = (((i - 26) / (26 * 26)) | 0) - 1;
4195
+ first = String.fromCharCode(65 + (x % 26));
4196
+ i = i % (26 * 26);
4197
+ }
4192
4198
  var addr = String.fromCharCode(65 + (i % 26));
4193
4199
  if (i >= 26) {
4194
4200
  i = ((i / 26) | 0) - 1;
@@ -4198,14 +4204,14 @@ var xlsnc = (utils.xlsnc = function (i) {
4198
4204
  addr = String.fromCharCode(65 + (i % 26)) + addr;
4199
4205
  }
4200
4206
  }
4201
- return addr;
4207
+ return first + addr;
4202
4208
  });
4203
4209
 
4204
4210
  /**
4205
- Excel:conver Excel column name to number
4206
- @param {string} s Column number, like 'A' or 'BE'
4207
- @return {string} Column name, starting with 0
4208
- */
4211
+ Excel:conver Excel column name to number
4212
+ @param {string} s Column number, like 'A' or 'BE'
4213
+ @return {string} Column name, starting with 0
4214
+ */
4209
4215
  var xlscn = (utils.xlscn = function (s) {
4210
4216
  var n = s.charCodeAt(0) - 65;
4211
4217
  if (s.length > 1) {
@@ -4226,12 +4232,12 @@ var domEmptyChildren = (utils.domEmptyChildren = function (container) {
4226
4232
  });
4227
4233
 
4228
4234
  /**
4229
- SQL LIKE emulation
4230
- @parameter {string} pattern Search pattern
4231
- @parameter {string} value Searched value
4232
- @parameter {string} escape Escape character (optional)
4233
- @return {boolean} If value LIKE pattern ESCAPE escape
4234
- */
4235
+ SQL LIKE emulation
4236
+ @parameter {string} pattern Search pattern
4237
+ @parameter {string} value Searched value
4238
+ @parameter {string} escape Escape character (optional)
4239
+ @return {boolean} If value LIKE pattern ESCAPE escape
4240
+ */
4235
4241
 
4236
4242
  var like = (utils.like = function (pattern, value, escape) {
4237
4243
  // Verify escape character
@@ -4302,9 +4308,9 @@ utils.glob = function (value, pattern) {
4302
4308
  };
4303
4309
 
4304
4310
  /**
4305
- Get path of alasql.js
4306
- @todo Rewrite and simplify the code. Review, is this function is required separately
4307
- */
4311
+ Get path of alasql.js
4312
+ @todo Rewrite and simplify the code. Review, is this function is required separately
4313
+ */
4308
4314
  utils.findAlaSQLPath = function () {
4309
4315
  /** type {string} Path to alasql library and plugins */
4310
4316
 
@@ -6579,8 +6585,10 @@ function queryfn3(query) {
6579
6585
  if (query.selectGroup.length > 0) {
6580
6586
 
6581
6587
  query.selectGroup.forEach(function (sg) {
6582
- if (sg.aggregatorid == 'COUNT' || sg.aggregatorid == 'SUM') {
6588
+ if (sg.aggregatorid == 'COUNT') {
6583
6589
  g[sg.nick] = 0;
6590
+ } else if (sg.aggregatorid == 'SUM') {
6591
+ g[sg.nick] = 'NULL';
6584
6592
  } else {
6585
6593
  g[sg.nick] = undefined;
6586
6594
  }
@@ -8703,16 +8711,93 @@ yy.Select.prototype.compileGroup = function (query) {
8703
8711
  ",g['$$_VALUES_" + colas + "']={},g['$$_VALUES_" + colas + "'][" + colexp + ']=true';
8704
8712
  }
8705
8713
  if (col.aggregatorid === 'SUM') {
8706
- return "'" + colas + "':(" + colexp + ')||0,';
8714
+ if ('funcid' in col.expression) {
8715
+ let colexpression = col.expression.args[0];
8716
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
8717
+ return "'" + colas + "':(" + colexp1 + ')||null,';
8718
+ }
8719
+ return "'" + colas + "':(" + colexp + ')||null,';
8707
8720
  } else if (
8708
- col.aggregatorid === 'MIN' ||
8709
- col.aggregatorid === 'MAX' ||
8710
8721
  col.aggregatorid === 'FIRST' ||
8711
8722
  col.aggregatorid === 'LAST'
8712
8723
  // || col.aggregatorid == 'AVG'
8713
8724
  // ) { return "'"+col.as+'\':r[\''+col.as+'\'],'; }//f.field.arguments[0].toJS();
8714
8725
  ) {
8715
8726
  return "'" + colas + "':" + colexp + ','; //f.field.arguments[0].toJS();
8727
+ } else if (col.aggregatorid === 'MIN') {
8728
+ if ('funcid' in col.expression) {
8729
+ let colexpression = col.expression.args[0];
8730
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
8731
+ return (
8732
+ "'" +
8733
+ colas +
8734
+ "': (typeof " +
8735
+ colexp1 +
8736
+ " == 'number' ? " +
8737
+ colexp1 +
8738
+ ': typeof ' +
8739
+ colexp1 +
8740
+ " == 'object' ? typeof Number(" +
8741
+ colexp1 +
8742
+ ") == 'number' && " +
8743
+ colexp1 +
8744
+ '!== null? ' +
8745
+ colexp1 +
8746
+ ' : null : null),'
8747
+ );
8748
+ }
8749
+ return (
8750
+ "'" +
8751
+ colas +
8752
+ "': (typeof " +
8753
+ colexp +
8754
+ " == 'number' ? " +
8755
+ colexp +
8756
+ ': typeof ' +
8757
+ colexp +
8758
+ " == 'object' ? typeof Number(" +
8759
+ colexp +
8760
+ ") == 'number' && " +
8761
+ colexp +
8762
+ '!== null? ' +
8763
+ colexp +
8764
+ ' : null : null),'
8765
+ );
8766
+ } else if (col.aggregatorid === 'MAX') {
8767
+ if ('funcid' in col.expression) {
8768
+ let colexpression = col.expression.args[0];
8769
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
8770
+ return (
8771
+ "'" +
8772
+ colas +
8773
+ "': (typeof " +
8774
+ colexp1 +
8775
+ " == 'number' ? " +
8776
+ colexp1 +
8777
+ ': typeof ' +
8778
+ colexp1 +
8779
+ " == 'object' ? typeof Number(" +
8780
+ colexp1 +
8781
+ ") == 'number' ? " +
8782
+ colexp1 +
8783
+ ' : null : null),'
8784
+ );
8785
+ }
8786
+ return (
8787
+ "'" +
8788
+ colas +
8789
+ "': (typeof " +
8790
+ colexp +
8791
+ " == 'number' ? " +
8792
+ colexp +
8793
+ ': typeof ' +
8794
+ colexp +
8795
+ " == 'object' ? typeof Number(" +
8796
+ colexp +
8797
+ ") == 'number' ? " +
8798
+ colexp +
8799
+ ' : null : null),'
8800
+ );
8716
8801
  } else if (col.aggregatorid === 'ARRAY') {
8717
8802
  return "'" + colas + "':[" + colexp + '],';
8718
8803
  } else if (col.aggregatorid === 'COUNT') {
@@ -8806,7 +8891,128 @@ yy.Select.prototype.compileGroup = function (query) {
8806
8891
  var post = "g['$$_VALUES_" + colas + "'][" + colexp + ']=true;}';
8807
8892
  }
8808
8893
  if (col.aggregatorid === 'SUM') {
8809
- return pre + "g['" + colas + "']+=(" + colexp + '||0);' + post; //f.field.arguments[0].toJS();
8894
+ if ('funcid' in col.expression) {
8895
+ let colexpression = col.expression.args[0];
8896
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
8897
+ return (
8898
+ pre +
8899
+ "if(g['" +
8900
+ colas +
8901
+ "'] == null && " +
8902
+ colexp1 +
8903
+ " == null){g['" +
8904
+ colas +
8905
+ "'] = null} else if(typeof g['" +
8906
+ colas +
8907
+ "']!== 'object' && typeof g['" +
8908
+ colas +
8909
+ "'] !== 'number' && typeof " +
8910
+ colexp1 +
8911
+ "!== 'object' && typeof " +
8912
+ colexp1 +
8913
+ "!== 'number'){g['" +
8914
+ colas +
8915
+ "'] = null} else if(typeof g['" +
8916
+ colas +
8917
+ "'] !== 'object' && typeof g['" +
8918
+ colas +
8919
+ "'] !== 'number' && typeof " +
8920
+ colexp1 +
8921
+ " == 'number'){g['" +
8922
+ colas +
8923
+ "'] = " +
8924
+ colexp1 +
8925
+ "} else if(typeof g['" +
8926
+ colas +
8927
+ "'] == 'number' && typeof " +
8928
+ colexp1 +
8929
+ " !== 'number' && typeof " +
8930
+ colexp1 +
8931
+ " !== 'object'){g['" +
8932
+ colas +
8933
+ "'] = g['" +
8934
+ colas +
8935
+ "']} else if((g['" +
8936
+ colas +
8937
+ "'] == null || (typeof g['" +
8938
+ colas +
8939
+ "'] !== 'number' && typeof g['" +
8940
+ colas +
8941
+ "'] !== 'object')) && (" +
8942
+ colexp1 +
8943
+ ' == null || (typeof ' +
8944
+ colexp1 +
8945
+ " !== 'number' && typeof " +
8946
+ colexp1 +
8947
+ " !== 'object'))){g['" +
8948
+ colas +
8949
+ "'] = null} else {g['" +
8950
+ colas +
8951
+ "']+=(" +
8952
+ colexp1 +
8953
+ '||0);}' +
8954
+ post
8955
+ );
8956
+ }
8957
+ return (
8958
+ pre +
8959
+ "if(g['" +
8960
+ colas +
8961
+ "'] == null && " +
8962
+ colexp +
8963
+ " == null){g['" +
8964
+ colas +
8965
+ "'] = null} else if(typeof g['" +
8966
+ colas +
8967
+ "']!== 'object' && typeof g['" +
8968
+ colas +
8969
+ "'] !== 'number' && typeof " +
8970
+ colexp +
8971
+ "!== 'object' && typeof " +
8972
+ colexp +
8973
+ "!== 'number'){g['" +
8974
+ colas +
8975
+ "'] = null} else if(typeof g['" +
8976
+ colas +
8977
+ "'] !== 'object' && typeof g['" +
8978
+ colas +
8979
+ "'] !== 'number' && typeof " +
8980
+ colexp +
8981
+ " == 'number'){g['" +
8982
+ colas +
8983
+ "'] = " +
8984
+ colexp +
8985
+ "} else if(typeof g['" +
8986
+ colas +
8987
+ "'] == 'number' && typeof " +
8988
+ colexp +
8989
+ " !== 'number' && typeof " +
8990
+ colexp +
8991
+ " !== 'object'){g['" +
8992
+ colas +
8993
+ "'] = g['" +
8994
+ colas +
8995
+ "']} else if((g['" +
8996
+ colas +
8997
+ "'] == null || (typeof g['" +
8998
+ colas +
8999
+ "'] !== 'number' && typeof g['" +
9000
+ colas +
9001
+ "'] !== 'object')) && (" +
9002
+ colexp +
9003
+ ' == null || (typeof ' +
9004
+ colexp +
9005
+ " !== 'number' && typeof " +
9006
+ colexp +
9007
+ " !== 'object'))){g['" +
9008
+ colas +
9009
+ "'] = null} else {g['" +
9010
+ colas +
9011
+ "']+=(" +
9012
+ colexp +
9013
+ '||0);}' +
9014
+ post
9015
+ );
8810
9016
  } else if (col.aggregatorid === 'COUNT') {
8811
9017
 
8812
9018
  if (col.expression.columnid === '*') {
@@ -8827,12 +9033,130 @@ yy.Select.prototype.compileGroup = function (query) {
8827
9033
  } else if (col.aggregatorid === 'ARRAY') {
8828
9034
  return pre + "g['" + colas + "'].push(" + colexp + ');' + post;
8829
9035
  } else if (col.aggregatorid === 'MIN') {
9036
+ if ('funcid' in col.expression) {
9037
+ let colexpression = col.expression.args[0];
9038
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
9039
+ return (
9040
+ pre +
9041
+ "if((g['" +
9042
+ colas +
9043
+ "'] == null && " +
9044
+ colexp1 +
9045
+ '!== null) ? y = ' +
9046
+ colexp1 +
9047
+ " : (g['" +
9048
+ colas +
9049
+ "'] !== null && " +
9050
+ colexp1 +
9051
+ " == null) ? y = g['" +
9052
+ colas +
9053
+ "'] : ((y=" +
9054
+ colexp1 +
9055
+ ") < g['" +
9056
+ colas +
9057
+ "'])){ if((typeof y == 'number')) {g['" +
9058
+ colas +
9059
+ "'] = y;} else if(typeof y == 'object' && y instanceof Date){g['" +
9060
+ colas +
9061
+ "'] = y;}else if(typeof y == 'object' && typeof Number(y) == 'number'){g['" +
9062
+ colas +
9063
+ "'] = Number(y);}}else if(g['" +
9064
+ colas +
9065
+ "']!== null && typeof g['" +
9066
+ colas +
9067
+ "'] == 'object' && y instanceof Date){g['" +
9068
+ colas +
9069
+ "'] = g['" +
9070
+ colas +
9071
+ "']}else if(g['" +
9072
+ colas +
9073
+ "']!== null && typeof g['" +
9074
+ colas +
9075
+ "'] == 'object'){g['" +
9076
+ colas +
9077
+ "'] = Number(g['" +
9078
+ colas +
9079
+ "'])}" +
9080
+ post
9081
+ );
9082
+ }
8830
9083
  return (
8831
- pre + 'if ((y=' + colexp + ") < g['" + colas + "']) g['" + colas + "'] = y;" + post
9084
+ pre +
9085
+ "if((g['" +
9086
+ colas +
9087
+ "'] == null && " +
9088
+ colexp +
9089
+ '!== null) ? y = ' +
9090
+ colexp +
9091
+ " : (g['" +
9092
+ colas +
9093
+ "'] !== null && " +
9094
+ colexp +
9095
+ " == null) ? y = g['" +
9096
+ colas +
9097
+ "'] : ((y=" +
9098
+ colexp +
9099
+ ") < g['" +
9100
+ colas +
9101
+ "'])){ if((typeof y == 'number')) {g['" +
9102
+ colas +
9103
+ "'] = y;} else if(typeof y == 'object' && y instanceof Date){g['" +
9104
+ colas +
9105
+ "'] = y;}else if(typeof y == 'object' && typeof Number(y) == 'number'){g['" +
9106
+ colas +
9107
+ "'] = Number(y);}}else if(g['" +
9108
+ colas +
9109
+ "']!== null && typeof g['" +
9110
+ colas +
9111
+ "'] == 'object' && y instanceof Date){g['" +
9112
+ colas +
9113
+ "'] = g['" +
9114
+ colas +
9115
+ "']}else if(g['" +
9116
+ colas +
9117
+ "']!== null && typeof g['" +
9118
+ colas +
9119
+ "'] == 'object'){g['" +
9120
+ colas +
9121
+ "'] = Number(g['" +
9122
+ colas +
9123
+ "'])}" +
9124
+ post
8832
9125
  );
8833
9126
  } else if (col.aggregatorid === 'MAX') {
9127
+ if ('funcid' in col.expression) {
9128
+ let colexpression = col.expression.args[0];
9129
+ let colexp1 = colexpression.toJS('p', tableid, defcols);
9130
+ return (
9131
+ pre +
9132
+ 'if ((y=' +
9133
+ colexp1 +
9134
+ ") > g['" +
9135
+ colas +
9136
+ "']){ if((typeof y == 'number')) {g['" +
9137
+ colas +
9138
+ "'] = y;} else if(typeof y == 'object' && y instanceof Date){g['" +
9139
+ colas +
9140
+ "'] = y;} else if(typeof y == 'object' && typeof Number(y) == 'number'){g['" +
9141
+ colas +
9142
+ "'] = Number(y);}}" +
9143
+ post
9144
+ );
9145
+ }
8834
9146
  return (
8835
- pre + 'if ((y=' + colexp + ") > g['" + colas + "']) g['" + colas + "'] = y;" + post
9147
+ pre +
9148
+ 'if ((y=' +
9149
+ colexp +
9150
+ ") > g['" +
9151
+ colas +
9152
+ "']){ if((typeof y == 'number')) {g['" +
9153
+ colas +
9154
+ "'] = y;} else if(typeof y == 'object' && y instanceof Date){g['" +
9155
+ colas +
9156
+ "'] = y;} else if(typeof y == 'object' && typeof Number(y) == 'number'){g['" +
9157
+ colas +
9158
+ "'] = Number(y);}}" +
9159
+ post
8836
9160
  );
8837
9161
  } else if (col.aggregatorid === 'FIRST') {
8838
9162
  return '';
@@ -8903,7 +9227,6 @@ yy.Select.prototype.compileGroup = function (query) {
8903
9227
  // s += 'group.count++;';
8904
9228
  s += '}';
8905
9229
  });
8906
-
8907
9230
  return new Function('p,params,alasql', 'var y;' + s);
8908
9231
  };
8909
9232