2015-07-17 14:34:42 +00:00
|
|
|
|
2016-09-26 09:28:47 +00:00
|
|
|
var Connection = require ('./connection');
|
|
|
|
|
|
|
|
module.exports = new Class
|
2015-07-17 14:34:42 +00:00
|
|
|
({
|
|
|
|
Extends: Vn.Object
|
|
|
|
,Tag: 'db-query'
|
|
|
|
,Properties:
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The connection used to execute the statement.
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-17 14:34:42 +00:00
|
|
|
conn:
|
|
|
|
{
|
2016-09-26 09:28:47 +00:00
|
|
|
type: Connection
|
2015-07-17 14:34:42 +00:00
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._conn = x;
|
|
|
|
this.onChange ();
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._conn;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The model query.
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-17 14:34:42 +00:00
|
|
|
query:
|
|
|
|
{
|
|
|
|
type: String
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._stmt = new Sql.String ({query: x});
|
|
|
|
this.onChange ();
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._stmt.render (null);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* The model select statement.
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-17 14:34:42 +00:00
|
|
|
stmt:
|
|
|
|
{
|
|
|
|
type: Sql.Stmt
|
|
|
|
,set: function (x)
|
|
|
|
{
|
|
|
|
this._stmt = x;
|
|
|
|
this.onChange ();
|
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
|
|
|
return this._stmt;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
2017-04-05 14:06:07 +00:00
|
|
|
* The lot used to execute the statement.
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2017-04-05 14:06:07 +00:00
|
|
|
lot:
|
2015-07-17 14:34:42 +00:00
|
|
|
{
|
2017-04-05 14:06:07 +00:00
|
|
|
type: Vn.Lot
|
2015-07-17 14:34:42 +00:00
|
|
|
,set: function (x)
|
|
|
|
{
|
2017-04-05 14:06:07 +00:00
|
|
|
this.link ({_lot: x}, {'change': this.onChange});
|
|
|
|
this._autoLoad ();
|
2015-07-17 14:34:42 +00:00
|
|
|
}
|
|
|
|
,get: function ()
|
|
|
|
{
|
2017-04-05 14:06:07 +00:00
|
|
|
return this._lot;
|
2015-07-17 14:34:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Wether to execute automatically de query que it's ready.
|
2016-12-20 09:32:17 +00:00
|
|
|
*/
|
2015-07-17 14:34:42 +00:00
|
|
|
autoLoad:
|
|
|
|
{
|
|
|
|
type: Boolean,
|
|
|
|
value: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-08 11:42:27 +00:00
|
|
|
,appendChild: function (child)
|
2015-07-17 14:34:42 +00:00
|
|
|
{
|
2017-04-08 11:42:27 +00:00
|
|
|
if (child.nodeType === Node.TEXT_NODE)
|
|
|
|
this.query = child.textContent;
|
2015-07-17 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,execute: function ()
|
|
|
|
{
|
|
|
|
this._conn.execStmt (this._stmt,
|
|
|
|
this.onQueryDone.bind (this), this._batch);
|
|
|
|
}
|
|
|
|
|
|
|
|
,onQueryDone: function (resultSet)
|
|
|
|
{
|
2017-04-19 06:16:37 +00:00
|
|
|
this.emit ('ready', resultSet);
|
2015-07-17 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
,onChange: function ()
|
|
|
|
{
|
|
|
|
if (this.autoLoad && this._conn && this._stmt && this._batch)
|
|
|
|
this.execute ();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|