alasql 0.1.9 → 0.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.bithoundrc +2 -1
- package/.bower.json +4 -4
- package/CHANGELOG.md +5 -0
- package/README.md +1 -1
- package/console/alasql.min.js +17 -10
- package/dist/alasql-worker.js +1 -1
- package/dist/alasql.js +823 -776
- package/dist/alasql.min.js +17 -10
- package/examples/country/city.js +16 -0
- package/examples/nodesample.js +16 -0
- package/examples/other/test.js +20 -0
- package/examples/param.js +4 -0
- package/examples/promise.js +10 -0
- package/examples/simple/ex102.js +10 -0
- package/examples/simple/jquery.js +6 -0
- package/examples/sqlite/test.js +5 -0
- package/gulpfile.js +3 -3
- package/meteor/.versions +2 -2
- package/meteor/package.js +1 -1
- package/package.json +21 -21
- package/src/05copyright.js +2 -2
- package/src/10start.js +1 -1
- package/src/15utility.js +43 -36
- package/src/38query.js +28 -25
- package/src/424select.js +2 -2
- package/src/50expression.js +50 -45
- package/src/55functions.js +26 -0
- package/src/70insert.js +1 -1
- package/src/72delete.js +206 -0
- package/src/alasqlparser.jison +8 -0
- package/src/alasqlparser.js +670 -664
- package/stuff/keywords/badwords.md +7 -0
- package/test/callback/cb1.js +59 -0
- package/test/callback/cb2.js +45 -0
- package/test/future/test119.js +77 -0
- package/test/future/test123.js +91 -0
- package/test/future/test131.js +30 -0
- package/test/future/test132.js +69 -0
- package/test/future/test134.js +51 -0
- package/test/future/test135.js +28 -0
- package/test/future/test136.js +23 -0
- package/test/future/test147.js +27 -0
- package/test/test240.js +132 -0
- package/test/test245.js +100 -0
- package/test/test247.js +84 -0
- package/test/test351.js +31 -0
- package/test/test352.js +49 -0
- /package/src/{alasqlparser1.jison → alasqlparser1_.jison} +0 -0
- /package/src/{alasqlparser1.js → alasqlparser1_.js} +0 -0
package/src/50expression.js
CHANGED
|
@@ -40,7 +40,7 @@ yy.ExpressionStatement.prototype.execute = function (databaseid, params, cb) {
|
|
|
40
40
|
if(cb) res = cb(res);
|
|
41
41
|
return res;
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
};
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
Expression class
|
|
@@ -121,7 +121,7 @@ yy.JavaScript.prototype.execute = function (databaseid, params, cb) {
|
|
|
121
121
|
expr(params,alasql);
|
|
122
122
|
if(cb) res = cb(res);
|
|
123
123
|
return res;
|
|
124
|
-
}
|
|
124
|
+
};
|
|
125
125
|
|
|
126
126
|
|
|
127
127
|
/**
|
|
@@ -131,26 +131,26 @@ yy.JavaScript.prototype.execute = function (databaseid, params, cb) {
|
|
|
131
131
|
MyVar, [My vairable], `MySQL variable`
|
|
132
132
|
*/
|
|
133
133
|
|
|
134
|
-
yy.Literal = function (params) { return yy.extend(this, params); }
|
|
134
|
+
yy.Literal = function (params) { return yy.extend(this, params); };
|
|
135
135
|
yy.Literal.prototype.toString = function() {
|
|
136
136
|
var s = this.value;
|
|
137
137
|
if(this.value1) s = this.value1+'.'+s;
|
|
138
138
|
// else s = tableid+'.'+s;
|
|
139
139
|
return L(s);
|
|
140
|
-
}
|
|
140
|
+
};
|
|
141
141
|
|
|
142
142
|
/**
|
|
143
143
|
Join class
|
|
144
144
|
@class
|
|
145
145
|
*/
|
|
146
146
|
|
|
147
|
-
yy.Join = function (params) { return yy.extend(this, params); }
|
|
147
|
+
yy.Join = function (params) { return yy.extend(this, params); };
|
|
148
148
|
yy.Join.prototype.toString = function() {
|
|
149
149
|
var s = NL()+ID();
|
|
150
150
|
if(this.joinmode) s += K(this.joinmode)+' ';
|
|
151
151
|
s += K('JOIN')+this.table.toString();
|
|
152
152
|
return s;
|
|
153
|
-
}
|
|
153
|
+
};
|
|
154
154
|
|
|
155
155
|
//yy.Join.prototype.toJavaScript = function(context, tableid) {
|
|
156
156
|
// return 'JOIN'+this.table.toString();
|
|
@@ -161,7 +161,7 @@ yy.Join.prototype.toString = function() {
|
|
|
161
161
|
@class
|
|
162
162
|
*/
|
|
163
163
|
|
|
164
|
-
yy.Table = function (params) { return yy.extend(this, params); }
|
|
164
|
+
yy.Table = function (params) { return yy.extend(this, params); };
|
|
165
165
|
yy.Table.prototype.toString = function() {
|
|
166
166
|
var s = this.tableid;
|
|
167
167
|
// if(this.joinmode)
|
|
@@ -174,7 +174,7 @@ yy.Table.prototype.toString = function() {
|
|
|
174
174
|
@class
|
|
175
175
|
*/
|
|
176
176
|
|
|
177
|
-
yy.View = function (params) { return yy.extend(this, params); }
|
|
177
|
+
yy.View = function (params) { return yy.extend(this, params); };
|
|
178
178
|
yy.View.prototype.toString = function() {
|
|
179
179
|
var s = this.viewid;
|
|
180
180
|
// if(this.joinmode)
|
|
@@ -187,7 +187,7 @@ yy.View.prototype.toString = function() {
|
|
|
187
187
|
@class
|
|
188
188
|
*/
|
|
189
189
|
|
|
190
|
-
yy.Op = function (params) { return yy.extend(this, params); }
|
|
190
|
+
yy.Op = function (params) { return yy.extend(this, params); };
|
|
191
191
|
yy.Op.prototype.toString = function() {
|
|
192
192
|
if(this.op == 'IN' || this.op == 'NOT IN') {
|
|
193
193
|
return this.left.toString()+" "+P(this.op)+" ("+this.right.toString()+")";
|
|
@@ -220,7 +220,7 @@ yy.Op.prototype.toType = function(tableid) {
|
|
|
220
220
|
if(this.op == '+') {
|
|
221
221
|
if(this.left.toType(tableid) == 'string' || this.right.toType(tableid) == 'string') return 'string';
|
|
222
222
|
if(this.left.toType(tableid) == 'number' || this.right.toType(tableid) == 'number') return 'number';
|
|
223
|
-
}
|
|
223
|
+
}
|
|
224
224
|
if(['AND','OR','NOT','=','==','===', '!=','!==','!===','>','>=','<','<=', 'IN', 'NOT IN', 'LIKE', 'NOT LIKE'].indexOf(this.op) >-1 ) return 'boolean';
|
|
225
225
|
if(this.op == 'BETWEEN' || this.op == 'NOT BETWEEN' || this.op == 'IS NULL' || this.op == 'IS NOT NULL') return 'boolean';
|
|
226
226
|
if(this.allsome) return 'boolean';
|
|
@@ -243,8 +243,8 @@ yy.Op.prototype.toJavaScript = function(context,tableid,defcols) {
|
|
|
243
243
|
} else if(typeof this.right == "number") {
|
|
244
244
|
return this.left.toJavaScript(context,tableid, defcols)+'['+this.right+']';
|
|
245
245
|
} else if(this.right instanceof yy.FuncValue) {
|
|
246
|
-
ss = [];
|
|
247
|
-
if(!this.right.args || this.right.args.length
|
|
246
|
+
var ss = [];
|
|
247
|
+
if(!this.right.args || 0 === this.right.args.length) {
|
|
248
248
|
} else {
|
|
249
249
|
var ss = this.right.args.map(function(arg){
|
|
250
250
|
return arg.toJavaScript(context,tableid, defcols);
|
|
@@ -255,7 +255,7 @@ yy.Op.prototype.toJavaScript = function(context,tableid,defcols) {
|
|
|
255
255
|
} else {
|
|
256
256
|
return this.left.toJavaScript(context,tableid, defcols)+'['+this.right.toJavaScript(context,tableid, defcols)+']';
|
|
257
257
|
}
|
|
258
|
-
}
|
|
258
|
+
}
|
|
259
259
|
|
|
260
260
|
if(this.op == '!') {
|
|
261
261
|
if(typeof this.right == "string") {
|
|
@@ -266,7 +266,7 @@ yy.Op.prototype.toJavaScript = function(context,tableid,defcols) {
|
|
|
266
266
|
|
|
267
267
|
if(this.op == 'IS') {
|
|
268
268
|
return '((typeof '+this.left.toJavaScript(context,tableid, defcols)+"=='undefined') == "
|
|
269
|
-
|
|
269
|
+
+ '(typeof '+this.right.toJavaScript(context,tableid, defcols)+"=='undefined'))";
|
|
270
270
|
}
|
|
271
271
|
|
|
272
272
|
|
|
@@ -286,18 +286,16 @@ yy.Op.prototype.toJavaScript = function(context,tableid,defcols) {
|
|
|
286
286
|
return '(!alasql.utils.deepEqual('+this.left.toJavaScript(context,tableid, defcols)+","+this.right.toJavaScript(context,tableid, defcols)+'))';
|
|
287
287
|
}
|
|
288
288
|
|
|
289
|
+
|
|
289
290
|
if(this.op == 'LIKE') {
|
|
290
|
-
|
|
291
|
-
".toUpperCase().match(new RegExp('^'+("+this.right.toJavaScript(context,tableid, defcols)+").replace(/\\\%/g,'.*').toUpperCase()+'$','g'))"
|
|
292
|
-
|
|
293
|
-
return s;
|
|
294
|
-
};
|
|
291
|
+
return "("+this.left.toJavaScript(context,tableid, defcols)+"+'')"+
|
|
292
|
+
".toUpperCase().match(new RegExp('^'+("+this.right.toJavaScript(context,tableid, defcols)+").replace(/\\\%/g,'.*').toUpperCase()+'$','g'))";
|
|
293
|
+
}
|
|
295
294
|
|
|
296
295
|
if(this.op == 'NOT LIKE') {
|
|
297
|
-
|
|
296
|
+
return "!(("+this.left.toJavaScript(context,tableid, defcols)+"+'')"+
|
|
298
297
|
".toUpperCase().match(new RegExp('^'+("+this.right.toJavaScript(context,tableid, defcols)+").replace(/\\\%/g,'.*').toUpperCase()+'$','g')))"
|
|
299
|
-
|
|
300
|
-
};
|
|
298
|
+
}
|
|
301
299
|
|
|
302
300
|
if(this.op == 'BETWEEN') {
|
|
303
301
|
return '(('+this.right1.toJavaScript(context,tableid, defcols)+'<='+this.left.toJavaScript(context,tableid, defcols)+')&&'+
|
|
@@ -309,12 +307,11 @@ yy.Op.prototype.toJavaScript = function(context,tableid,defcols) {
|
|
|
309
307
|
return '(('+this.right.left.toJavaScript(context,tableid, defcols)+'<='+this.left.toJavaScript(context,tableid, defcols)+')&&'+
|
|
310
308
|
'('+this.left.toJavaScript(context,tableid, defcols)+'<='+this.right.right.toJavaScript(context,tableid, defcols)+'))';
|
|
311
309
|
|
|
312
|
-
|
|
313
310
|
} else {
|
|
314
311
|
throw new Error('Wrong BETWEEN operator without AND part');
|
|
315
312
|
}
|
|
316
313
|
*/
|
|
317
|
-
}
|
|
314
|
+
}
|
|
318
315
|
|
|
319
316
|
if(this.op == 'NOT BETWEEN') {
|
|
320
317
|
return '!(('+this.right1.toJavaScript(context,tableid, defcols)+'<='+this.left.toJavaScript(context,tableid, defcols)+')&&'+
|
|
@@ -327,11 +324,11 @@ yy.Op.prototype.toJavaScript = function(context,tableid,defcols) {
|
|
|
327
324
|
// } else {
|
|
328
325
|
// throw new Error('Wrong NOT BETWEEN operator without AND part');
|
|
329
326
|
// }
|
|
330
|
-
}
|
|
327
|
+
}
|
|
331
328
|
|
|
332
329
|
if(this.op == 'IN') {
|
|
333
330
|
if(this.right instanceof yy.Select ) {
|
|
334
|
-
|
|
331
|
+
s = '(';
|
|
335
332
|
// s += 'this.query.queriesdata['+this.queriesidx+']';
|
|
336
333
|
// s += 'alasql.utils.flatArray(this.query.queriesfn['+(this.queriesidx)+'](params,null,context))';
|
|
337
334
|
s += 'alasql.utils.flatArray(this.queriesfn['+(this.queriesidx)+'](params,null,context))';
|
|
@@ -340,24 +337,27 @@ yy.Op.prototype.toJavaScript = function(context,tableid,defcols) {
|
|
|
340
337
|
return s;
|
|
341
338
|
} else if(this.right instanceof Array ) {
|
|
342
339
|
// if(this.right.length == 0) return 'false';
|
|
343
|
-
|
|
344
|
-
|
|
340
|
+
s = '(['
|
|
341
|
+
+ this.right.map(function(a){return a.toJavaScript(context,tableid, defcols);}).join(',')
|
|
342
|
+
+ '].indexOf('
|
|
343
|
+
+ this.left.toJavaScript(context,tableid, defcols)
|
|
344
|
+
+')>-1)';
|
|
345
345
|
//console.log(s);
|
|
346
346
|
return s;
|
|
347
347
|
} else {
|
|
348
|
-
|
|
349
|
-
|
|
348
|
+
s = '('+this.right.toJavaScript(context,tableid, defcols)+'.indexOf('
|
|
349
|
+
+ this.left.toJavaScript(context,tableid, defcols)+')>-1)';
|
|
350
350
|
//console.log('expression',350,s);
|
|
351
351
|
return s;
|
|
352
352
|
// } else {
|
|
353
353
|
// throw new Error('Wrong IN operator without SELECT part');
|
|
354
354
|
}
|
|
355
|
-
}
|
|
355
|
+
}
|
|
356
356
|
|
|
357
357
|
|
|
358
358
|
if(this.op == 'NOT IN') {
|
|
359
359
|
if(this.right instanceof yy.Select ) {
|
|
360
|
-
|
|
360
|
+
s = '(';
|
|
361
361
|
//this.query.queriesdata['+this.queriesidx+']
|
|
362
362
|
// s += 'alasql.utils.flatArray(this.query.queriesfn['+(this.queriesidx)+'](params,null,p))';
|
|
363
363
|
s += 'alasql.utils.flatArray(this.queriesfn['+(this.queriesidx)+'](params,null,p))';
|
|
@@ -366,50 +366,50 @@ yy.Op.prototype.toJavaScript = function(context,tableid,defcols) {
|
|
|
366
366
|
return s;
|
|
367
367
|
} else if(this.right instanceof Array ) {
|
|
368
368
|
// if(this.right.length == 0) return 'true';
|
|
369
|
-
|
|
369
|
+
s = '(['+this.right.map(function(a){return a.toJavaScript(context,tableid, defcols);}).join(',')+'].indexOf(';
|
|
370
370
|
s += this.left.toJavaScript(context,tableid, defcols)+')<0)';
|
|
371
371
|
return s;
|
|
372
372
|
} else {
|
|
373
|
-
|
|
373
|
+
s = '('+this.right.toJavaScript(context,tableid, defcols)+'.indexOf(';
|
|
374
374
|
s += this.left.toJavaScript(context,tableid, defcols)+')==-1)';
|
|
375
375
|
return s;
|
|
376
376
|
|
|
377
377
|
// throw new Error('Wrong NOT IN operator without SELECT part');
|
|
378
378
|
}
|
|
379
|
-
}
|
|
379
|
+
}
|
|
380
380
|
|
|
381
381
|
if(this.allsome == 'ALL') {
|
|
382
382
|
if(this.right instanceof yy.Select ) {
|
|
383
383
|
// var s = 'this.query.queriesdata['+this.queriesidx+']';
|
|
384
|
-
|
|
384
|
+
s = 'alasql.utils.flatArray(this.query.queriesfn['+(this.queriesidx)+'](params,null,p))';
|
|
385
385
|
|
|
386
386
|
s +='.every(function(b){return (';
|
|
387
387
|
s += this.left.toJavaScript(context,tableid, defcols)+')'+op+'b})';
|
|
388
388
|
return s;
|
|
389
389
|
} else if(this.right instanceof Array ) {
|
|
390
|
-
var s = '['+this.right.map(function(a){return a.toJavaScript(context,tableid, defcols)}).join(',')+'].every(function(b){return (';
|
|
390
|
+
var s = '['+this.right.map(function(a){return a.toJavaScript(context,tableid, defcols);}).join(',')+'].every(function(b){return (';
|
|
391
391
|
s += this.left.toJavaScript(context,tableid, defcols)+')'+op+'b})';
|
|
392
392
|
return s;
|
|
393
393
|
} else {
|
|
394
394
|
throw new Error('Wrong NOT IN operator without SELECT part');
|
|
395
395
|
}
|
|
396
|
-
}
|
|
396
|
+
}
|
|
397
397
|
|
|
398
398
|
if(this.allsome == 'SOME' || this.allsome == 'ANY') {
|
|
399
399
|
if(this.right instanceof yy.Select ) {
|
|
400
400
|
// var s = 'this.query.queriesdata['+this.queriesidx+']';
|
|
401
|
-
|
|
402
|
-
s+='.some(function(b){return (';
|
|
401
|
+
s = 'alasql.utils.flatArray(this.query.queriesfn['+(this.queriesidx)+'](params,null,p))';
|
|
402
|
+
s +='.some(function(b){return (';
|
|
403
403
|
s += this.left.toJavaScript(context,tableid, defcols)+')'+op+'b})';
|
|
404
404
|
return s;
|
|
405
405
|
} else if(this.right instanceof Array ) {
|
|
406
|
-
|
|
406
|
+
s = '['+this.right.map(function(a){return a.toJavaScript(context,tableid, defcols);}).join(',')+'].some(function(b){return (';
|
|
407
407
|
s += this.left.toJavaScript(context,tableid, defcols)+')'+op+'b})';
|
|
408
408
|
return s;
|
|
409
409
|
} else {
|
|
410
410
|
throw new Error('Wrong NOT IN operator without SELECT part');
|
|
411
411
|
}
|
|
412
|
-
}
|
|
412
|
+
}
|
|
413
413
|
|
|
414
414
|
// Special case for AND optimization (if reduced)
|
|
415
415
|
if(this.op == 'AND') {
|
|
@@ -429,15 +429,20 @@ yy.Op.prototype.toJavaScript = function(context,tableid,defcols) {
|
|
|
429
429
|
}
|
|
430
430
|
|
|
431
431
|
if(this.op == '^') {
|
|
432
|
-
return 'Math.pow('
|
|
433
|
-
|
|
432
|
+
return 'Math.pow('
|
|
433
|
+
+this.left.toJavaScript(context,tableid, defcols)
|
|
434
|
+
+','
|
|
435
|
+
+this.right.toJavaScript(context,tableid, defcols)
|
|
436
|
+
+')';
|
|
434
437
|
};
|
|
435
438
|
|
|
436
439
|
|
|
440
|
+
|
|
441
|
+
|
|
437
442
|
// Change names
|
|
438
443
|
// console.log(this);
|
|
439
444
|
return '('+this.left.toJavaScript(context,tableid, defcols)+op+this.right.toJavaScript(context,tableid, defcols)+')';
|
|
440
|
-
}
|
|
445
|
+
}
|
|
441
446
|
|
|
442
447
|
|
|
443
448
|
|
package/src/55functions.js
CHANGED
|
@@ -26,6 +26,32 @@ yy.FuncValue.prototype.toString = function() {
|
|
|
26
26
|
return s;
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
yy.FuncValue.prototype.execute = function (databaseid, params, cb) {
|
|
32
|
+
var res = 1;
|
|
33
|
+
alasql.precompile(this,databaseid,params); // Precompile queries
|
|
34
|
+
// console.log(34,this.toJavaScript('','',null));
|
|
35
|
+
var expr = new Function('params,alasql','var y;return '+this.toJavaScript('','',null));
|
|
36
|
+
expr(params,alasql);
|
|
37
|
+
if(cb) res = cb(res);
|
|
38
|
+
return res;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
//yy.FuncValue.prototype.compile = function(context, tableid, defcols){
|
|
43
|
+
// console.log('Expression',this);
|
|
44
|
+
// if(this.reduced) return returnTrue();
|
|
45
|
+
// return new Function('p','var y;return '+this.toJavaScript(context, tableid, defcols));
|
|
46
|
+
//};
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
// yy.FuncValue.prototype.compile = function(context, tableid, defcols){
|
|
50
|
+
// // console.log('Expression',this);
|
|
51
|
+
// if(this.reduced) return returnTrue();
|
|
52
|
+
// return new Function('p','var y;return '+this.toJavaScript(context, tableid, defcols));
|
|
53
|
+
// };
|
|
54
|
+
|
|
29
55
|
yy.FuncValue.prototype.findAggregator = function(query) {
|
|
30
56
|
if(this.args && this.args.length > 0) {
|
|
31
57
|
this.args.forEach(function(arg){
|
package/src/70insert.js
CHANGED
|
@@ -149,7 +149,7 @@ yy.Insert.prototype.compile = function (databaseid) {
|
|
|
149
149
|
});
|
|
150
150
|
} else {
|
|
151
151
|
// console.log(222,values);
|
|
152
|
-
// sw = 'var w='+JSONtoJavaScript(values)+';for(var k in w){r[k]=w[k]};';
|
|
152
|
+
// sw = 'var w='+JSONtoJavaScript(values)+';for(var k in w){if(/^__proto__$/.test(k))Object.defineProperty(r,k,{writable:true,enumerable:true,configurable:true});r[k]=w[k]};';
|
|
153
153
|
sw = JSONtoJavaScript(values);
|
|
154
154
|
}
|
|
155
155
|
}
|
package/src/72delete.js
CHANGED
|
@@ -1,3 +1,208 @@
|
|
|
1
|
+
<<<<<<< HEAD
|
|
2
|
+
/*
|
|
3
|
+
//
|
|
4
|
+
// DELETE for Alasql.js
|
|
5
|
+
// Date: 03.11.2014
|
|
6
|
+
// (c) 2014, Andrey Gershun
|
|
7
|
+
//
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
yy.Delete = function (params) { return yy.extend(this, params); }
|
|
11
|
+
yy.Delete.prototype.toString = function() {
|
|
12
|
+
var s = 'DELETE FROM '+this.table.toString();
|
|
13
|
+
if(this.where) s += ' WHERE '+this.where.toString();
|
|
14
|
+
return s;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
yy.Delete.prototype.compile = function (databaseid) {
|
|
18
|
+
// console.log(11,this);
|
|
19
|
+
databaseid = this.table.databaseid || databaseid;
|
|
20
|
+
var tableid = this.table.tableid;
|
|
21
|
+
var statement;
|
|
22
|
+
var db = alasql.databases[databaseid];
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if(this.where) {
|
|
27
|
+
// try {
|
|
28
|
+
// console.log(this, 22, this.where.toJavaScript('r',''));
|
|
29
|
+
// } catch(err){console.log(444,err)};
|
|
30
|
+
// var query = {};
|
|
31
|
+
wherefn = new Function('r,params','return ('+this.where.toJavaScript('r','')+')');
|
|
32
|
+
// console.log(wherefn);
|
|
33
|
+
statement = (function (params, cb) {
|
|
34
|
+
if(db.engineid && alasql.engines[db.engineid].deleteFromTable) {
|
|
35
|
+
return alasql.engines[db.engineid].deleteFromTable(databaseid, tableid, wherefn, params, cb);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if(alasql.options.autocommit && db.engineid && db.engineid == 'LOCALSTORAGE') {
|
|
39
|
+
alasql.engines[db.engineid].loadTableData(databaseid,tableid);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
var table = db.tables[tableid];
|
|
43
|
+
// table.dirty = true;
|
|
44
|
+
var orignum = table.data.length;
|
|
45
|
+
|
|
46
|
+
var newtable = [];
|
|
47
|
+
for(var i=0, ilen=table.data.length;i<ilen;i++) {
|
|
48
|
+
if(wherefn(table.data[i],params)) {
|
|
49
|
+
// Check for transaction - if it is not possible then return all back
|
|
50
|
+
if(table.delete) {
|
|
51
|
+
table.delete(i);
|
|
52
|
+
} else {
|
|
53
|
+
// SImply do not push
|
|
54
|
+
}
|
|
55
|
+
} else newtable.push(table.data[i]);
|
|
56
|
+
}
|
|
57
|
+
// table.data = table.data.filter(function(r){return !;});
|
|
58
|
+
table.data = newtable;
|
|
59
|
+
var res = orignum - table.data.length;
|
|
60
|
+
if(alasql.options.autocommit && db.engineid && db.engineid == 'LOCALSTORAGE') {
|
|
61
|
+
alasql.engines[db.engineid].saveTableData(databaseid,tableid);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// console.log('deletefn',table.data.length);
|
|
65
|
+
if(cb) cb(res);
|
|
66
|
+
return res;
|
|
67
|
+
});
|
|
68
|
+
// .bind(query);
|
|
69
|
+
|
|
70
|
+
// if(!this.queries) return;
|
|
71
|
+
// query.queriesfn = this.queries.map(function(q) {
|
|
72
|
+
// return q.compile(alasql.useid);
|
|
73
|
+
// });
|
|
74
|
+
|
|
75
|
+
} else {
|
|
76
|
+
statement = function (params, cb) {
|
|
77
|
+
if(alasql.options.autocommit && db.engineid) {
|
|
78
|
+
alasql.engines[db.engineid].loadTableData(databaseid,tableid);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var table = db.tables[tableid];
|
|
82
|
+
table.dirty = true;
|
|
83
|
+
var orignum = db.tables[tableid].data.length;
|
|
84
|
+
|
|
85
|
+
table.deleteall();
|
|
86
|
+
|
|
87
|
+
if(alasql.options.autocommit && db.engineid) {
|
|
88
|
+
alasql.engines[db.engineid].saveTableData(databaseid,tableid);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if(cb) cb(orignum);
|
|
92
|
+
return orignum;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
return statement;
|
|
97
|
+
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
yy.Delete.prototype.execute = function (databaseid, params, cb) {
|
|
101
|
+
return this.compile(databaseid)(params,cb);
|
|
102
|
+
}
|
|
103
|
+
||||||| merged common ancestors
|
|
104
|
+
/*
|
|
105
|
+
//
|
|
106
|
+
// DELETE for Alasql.js
|
|
107
|
+
// Date: 03.11.2014
|
|
108
|
+
// (c) 2014, Andrey Gershun
|
|
109
|
+
//
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
yy.Delete = function (params) { return yy.extend(this, params); }
|
|
113
|
+
yy.Delete.prototype.toString = function() {
|
|
114
|
+
var s = 'DELETE FROM '+this.table.toString();
|
|
115
|
+
if(this.where) s += ' WHERE '+this.where.toString();
|
|
116
|
+
return s;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
yy.Delete.prototype.compile = function (databaseid) {
|
|
120
|
+
// console.log(11,this);
|
|
121
|
+
databaseid = this.table.databaseid || databaseid;
|
|
122
|
+
var tableid = this.table.tableid;
|
|
123
|
+
var statement;
|
|
124
|
+
var db = alasql.databases[databaseid];
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
if(this.where) {
|
|
129
|
+
// try {
|
|
130
|
+
// console.log(this, 22, this.where.toJavaScript('r',''));
|
|
131
|
+
// } catch(err){console.log(444,err)};
|
|
132
|
+
// var query = {};
|
|
133
|
+
wherefn = new Function('r,params','return ('+this.where.toJavaScript('r','')+')');
|
|
134
|
+
// console.log(wherefn);
|
|
135
|
+
statement = (function (params, cb) {
|
|
136
|
+
if(db.engineid && alasql.engines[db.engineid].deleteFromTable) {
|
|
137
|
+
return alasql.engines[db.engineid].deleteFromTable(databaseid, tableid, wherefn, params, cb);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if(alasql.options.autocommit && db.engineid && db.engineid == 'LOCALSTORAGE') {
|
|
141
|
+
alasql.engines[db.engineid].loadTableData(databaseid,tableid);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
var table = db.tables[tableid];
|
|
145
|
+
// table.dirty = true;
|
|
146
|
+
var orignum = table.data.length;
|
|
147
|
+
|
|
148
|
+
var newtable = [];
|
|
149
|
+
for(var i=0, ilen=table.data.length;i<ilen;i++) {
|
|
150
|
+
if(wherefn(table.data[i],params)) {
|
|
151
|
+
// Check for transaction - if it is not possible then return all back
|
|
152
|
+
if(table.delete) {
|
|
153
|
+
table.delete(i);
|
|
154
|
+
} else {
|
|
155
|
+
// SImply do not push
|
|
156
|
+
}
|
|
157
|
+
} else newtable.push(table.data[i]);
|
|
158
|
+
}
|
|
159
|
+
// table.data = table.data.filter(function(r){return !;});
|
|
160
|
+
table.data = newtable;
|
|
161
|
+
var res = orignum - table.data.length;
|
|
162
|
+
if(alasql.options.autocommit && db.engineid && db.engineid == 'LOCALSTORAGE') {
|
|
163
|
+
alasql.engines[db.engineid].saveTableData(databaseid,tableid);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// console.log('deletefn',table.data.length);
|
|
167
|
+
if(cb) cb(res);
|
|
168
|
+
return res;
|
|
169
|
+
});
|
|
170
|
+
// .bind(query);
|
|
171
|
+
|
|
172
|
+
// if(!this.queries) return;
|
|
173
|
+
// query.queriesfn = this.queries.map(function(q) {
|
|
174
|
+
// return q.compile(alasql.useid);
|
|
175
|
+
// });
|
|
176
|
+
|
|
177
|
+
} else {
|
|
178
|
+
statement = function (params, cb) {
|
|
179
|
+
if(alasql.options.autocommit && db.engineid) {
|
|
180
|
+
alasql.engines[db.engineid].loadTableData(databaseid,tableid);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
var table = db.tables[tableid];
|
|
184
|
+
table.dirty = true;
|
|
185
|
+
var orignum = db.tables[tableid].data.length;
|
|
186
|
+
|
|
187
|
+
table.deleteall();
|
|
188
|
+
|
|
189
|
+
if(alasql.options.autocommit && db.engineid) {
|
|
190
|
+
alasql.engines[db.engineid].saveTableData(databaseid,tableid);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if(cb) cb(orignum);
|
|
194
|
+
return orignum;
|
|
195
|
+
};
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
return statement;
|
|
199
|
+
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
yy.Delete.prototype.execute = function (databaseid, params, cb) {
|
|
203
|
+
return this.compile(databaseid)(params,cb);
|
|
204
|
+
}
|
|
205
|
+
=======
|
|
1
206
|
/*
|
|
2
207
|
//
|
|
3
208
|
// DELETE for Alasql.js
|
|
@@ -121,3 +326,4 @@ yy.Delete.prototype.compile = function (databaseid) {
|
|
|
121
326
|
yy.Delete.prototype.execute = function (databaseid, params, cb) {
|
|
122
327
|
return this.compile(databaseid)(params,cb);
|
|
123
328
|
}
|
|
329
|
+
>>>>>>> release/0.0.46
|
package/src/alasqlparser.jison
CHANGED
|
@@ -63,6 +63,7 @@ NOT\s+BETWEEN return 'NOT_BETWEEN'
|
|
|
63
63
|
NOT\s+LIKE return 'NOT_LIKE'
|
|
64
64
|
'BY' return 'BY'
|
|
65
65
|
|
|
66
|
+
'CALL' return 'CALL'
|
|
66
67
|
'CASE' return 'CASE'
|
|
67
68
|
'CAST' return 'CAST'
|
|
68
69
|
'CHECK' return 'CHECK'
|
|
@@ -99,6 +100,8 @@ DATABASE(S)? return 'DATABASE'
|
|
|
99
100
|
'ENUM' return 'ENUM'
|
|
100
101
|
'ELSE' return 'ELSE'
|
|
101
102
|
'EXCEPT' return 'EXCEPT'
|
|
103
|
+
'EXEC' return 'CALL'
|
|
104
|
+
'EXECUTE' return 'CALL'
|
|
102
105
|
'EXISTS' return 'EXISTS'
|
|
103
106
|
'EXPLAIN' return 'EXPLAIN'
|
|
104
107
|
'FALSE' return 'FALSE'
|
|
@@ -334,6 +337,7 @@ Statement
|
|
|
334
337
|
: { $$ = undefined; }
|
|
335
338
|
| AlterTable
|
|
336
339
|
| AttachDatabase
|
|
340
|
+
| Call
|
|
337
341
|
| CreateDatabase
|
|
338
342
|
| CreateIndex
|
|
339
343
|
| CreateGraph
|
|
@@ -2686,3 +2690,7 @@ Query
|
|
|
2686
2690
|
: QUESTIONDASH FuncValue
|
|
2687
2691
|
;
|
|
2688
2692
|
|
|
2693
|
+
Call
|
|
2694
|
+
: CALL FuncValue
|
|
2695
|
+
{ $$ = $2; }
|
|
2696
|
+
;
|