forked from AlaSQL/alasql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path59cast.js
48 lines (44 loc) · 1.54 KB
/
59cast.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
//
// CAST and CONVERT functions
// Date: 03.11.2014
// (c) 2014, Andrey Gershun
//
*/
yy.Cast = function(params) { return yy.extend(this, params); };
yy.Cast.prototype.toString = function() {
var s = 'CAST(';
s += this.expression.toString();
s += ' AS ';
s += this.dbtypeid;
if(typeof this.dbsize != 'undefined') {
s += '('+this.dbsize;
if(this.dbprecision) s += ','+dbprecision;
s += ')';
}
s += ')';
return s;
};
yy.Cast.prototype.toJavaScript = function(context, tableid, defcols) {
if(this.dbtypeid == 'INT') {
return '(('+this.expression.toJavaScript(context, tableid, defcols)+')|0)';
} if(this.dbtypeid == 'STRING') {
return '(""+'+this.expression.toJavaScript(context, tableid, defcols)+')';
} if(this.dbtypeid == 'NUMBER') {
return '(+('+this.expression.toJavaScript(context, tableid, defcols)+'))';
} if(this.dbtypeid == 'DATE') {
if(alasql.options.datetimeformat == 'javascript') {
return '(new Date('+this.expression.toJavaScript(context, tableid, defcols)+'))';
} else if(alasql.options.datetimeformat == 'sql') {
return this.expression.toJavaScript(context, tableid, defcols);
}
} if(this.dbtypeid == 'DATETIME') {
if(alasql.options.datetimeformat == 'javascript') {
return '(new Date('+this.expression.toJavaScript(context, tableid, defcols)+'))';
} else if(alasql.options.datetimeformat == 'sql') {
return this.expression.toJavaScript(context, tableid, defcols);
}
} else {
};
throw new Error('There is not such type conversion for '+this.toString());
};