2015-01-23 13:09:30 +00:00
|
|
|
/**
|
|
|
|
* The equivalent of a SQL operation between exprs.
|
|
|
|
*
|
|
|
|
* @param {Array#Sql.Expr} expr Array with the exprs
|
|
|
|
* @param {Sql..Operation.Type} type The type of the operation
|
|
|
|
**/
|
|
|
|
Sql.Operation = new Class ().extend
|
|
|
|
({
|
|
|
|
Type:
|
|
|
|
{
|
2015-10-14 11:51:43 +00:00
|
|
|
EQUAL : 0
|
|
|
|
,LIKE : 1
|
|
|
|
,AND : 2
|
|
|
|
,OR : 3
|
|
|
|
,REGEXP : 4
|
2015-01-23 13:09:30 +00:00
|
|
|
}
|
|
|
|
,Operators:
|
|
|
|
[
|
|
|
|
'='
|
|
|
|
,'LIKE'
|
|
|
|
,'AND'
|
|
|
|
,'OR'
|
2015-10-14 11:51:43 +00:00
|
|
|
,'REGEXP'
|
2015-01-23 13:09:30 +00:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
Sql.Operation.implement
|
|
|
|
({
|
|
|
|
Extends: Sql.Expr
|
|
|
|
,Tag: 'sql-operation'
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
type:
|
|
|
|
{
|
|
|
|
enumType: Sql.Operation.Type
|
|
|
|
,value: -1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
,initialize: function (props)
|
|
|
|
{
|
|
|
|
this.parent (props);
|
|
|
|
this.link ({exprs: new Sql.List ()}, {'changed': this.onListChange});
|
|
|
|
}
|
|
|
|
|
|
|
|
,onListChange: function ()
|
|
|
|
{
|
|
|
|
this.signalEmit ('changed');
|
|
|
|
}
|
|
|
|
|
|
|
|
,isReady: function ()
|
|
|
|
{
|
|
|
|
return this.exprs.isReady ();
|
|
|
|
}
|
|
|
|
|
|
|
|
,render: function (batch)
|
|
|
|
{
|
|
|
|
var sql = '(';
|
|
|
|
var operator = ' '+ Sql.Operation.Operators[this.type] +' ';
|
|
|
|
var e = this.exprs.getArray ();
|
|
|
|
|
|
|
|
for (var i = 0; i < e.length; i++)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
sql += operator;
|
|
|
|
|
|
|
|
sql += e[i].render (batch);
|
|
|
|
}
|
|
|
|
|
|
|
|
sql += ')';
|
|
|
|
|
|
|
|
return sql;
|
|
|
|
}
|
|
|
|
});
|