2016-09-26 09:28:47 +00:00
|
|
|
|
|
|
|
var Expr = require ('./expr');
|
|
|
|
|
2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* The equivalent of a SQL value.
|
|
|
|
**/
|
2016-09-26 09:28:47 +00:00
|
|
|
module.exports = new Class
|
2015-01-23 13:09:30 +00:00
|
|
|
({
|
2016-09-26 09:28:47 +00:00
|
|
|
Extends: Expr
|
2015-01-23 13:09:30 +00:00
|
|
|
,Tag: 'sql-value'
|
|
|
|
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The master param.
|
|
|
|
**/
|
|
|
|
param:
|
|
|
|
{
|
|
|
|
type: Vn.Param
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this.link ({_param: x}, {'changed': this.onParamChange});
|
|
|
|
this.onParamChange ();
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._param;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The value.
|
|
|
|
**/
|
|
|
|
value:
|
|
|
|
{
|
2015-07-03 05:49:45 +00:00
|
|
|
type: String
|
2015-01-23 13:09:30 +00:00
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
if (Vn.Value.compare (x, this._value))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (x instanceof Date)
|
|
|
|
x = x.clone ();
|
|
|
|
|
|
|
|
this._value = x;
|
|
|
|
|
|
|
|
if (this._param && !this.paramLock)
|
|
|
|
{
|
|
|
|
this.paramLock = true;
|
|
|
|
this._param.value = x;
|
|
|
|
this.paramLock = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.signalEmit ('changed');
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,_value: undefined
|
|
|
|
,_param: null
|
|
|
|
,regexp: new RegExp ('(\\\\)|\'', 'g')
|
|
|
|
,paramLock: false
|
|
|
|
|
|
|
|
,onParamChange: function ()
|
|
|
|
{
|
2015-07-15 13:39:07 +00:00
|
|
|
if (this.paramLock || !this._param)
|
2015-01-23 13:09:30 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
this.paramLock = true;
|
|
|
|
this.value = this._param.value;
|
|
|
|
this.paramLock = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
,isReady: function ()
|
|
|
|
{
|
2015-07-17 14:34:42 +00:00
|
|
|
return this._value !== undefined;
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,replaceFunc: function (token)
|
|
|
|
{
|
|
|
|
switch (token)
|
|
|
|
{
|
|
|
|
case '\\': return '\\\\';
|
|
|
|
case '\'': return '\\\'';
|
|
|
|
}
|
|
|
|
|
|
|
|
return token;
|
|
|
|
}
|
|
|
|
|
|
|
|
,render: function (batch)
|
|
|
|
{
|
|
|
|
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\'');
|
|
|
|
default:
|
|
|
|
return 'NULL';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|