0
1
Fork 0
hedera-web-mindshore/js/sql/value.js

127 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-09-26 09:28:47 +00:00
var Expr = require ('./expr');
/**
* The equivalent of a SQL value.
2016-12-20 09:32:17 +00:00
*/
2016-09-26 09:28:47 +00:00
module.exports = new Class
({
2016-09-26 09:28:47 +00:00
Extends: Expr
2017-04-19 06:16:37 +00:00
,Implements: Vn.ParamIface
,Tag: 'sql-value'
,Properties:
{
2017-04-19 06:16:37 +00:00
value:
{
type: null
,set: function (x)
{
this._setValue (x);
}
,get: function ()
{
return this._value;
}
},
type:
{
type: Type
,set: function (x)
{
this._setType (x);
}
,get: function ()
{
return this._type;
}
},
param:
{
2017-04-19 06:16:37 +00:00
type: Vn.ParamIface
,set: function (x)
{
2017-04-19 06:16:37 +00:00
this._setParam (x);
}
,get: function ()
{
return this._param;
}
},
2017-04-19 06:16:37 +00:00
lot:
{
type: Vn.LotIface
,set: function (x)
{
this._setLot (x);
}
,get: function ()
{
return this._lot;
}
},
name:
{
2015-07-03 05:49:45 +00:00
type: String
,set: function (x)
{
2017-04-19 06:16:37 +00:00
this._name = x;
this._onLotChange ();
}
,get: function ()
{
2017-04-19 06:16:37 +00:00
return this._name;
}
},
oneWay:
{
type: Boolean
,set: function (x)
{
this._oneWay = x;
}
,get: function ()
{
return this._oneWay;
}
}
}
,regexp: new RegExp ('(\\\\)|\'', 'g')
,isReady: function ()
{
2015-07-17 14:34:42 +00:00
return this._value !== undefined;
}
,replaceFunc: function (token)
{
switch (token)
{
case '\\': return '\\\\';
case '\'': return '\\\'';
}
return token;
}
2017-03-23 16:20:51 +00:00
,render: function ()
{
var v = this._value;
switch (typeof v)
{
case 'number':
return v;
case 'boolean':
return (v) ? 'TRUE' : 'FALSE';
case 'string':
return "'" + v.replace (this.regexp, this.replaceFunc) + "'";
case 'object':
if (v instanceof Date)
return Vn.Date.strftime (v, '\'%Y-%m-%d\'');
}
2017-03-23 16:20:51 +00:00
return 'NULL';
}
});