Refactoring. Add SqlResultProvider. Add TODO in SqlDbDriver.whereExpr().
This commit is contained in:
@ -2,44 +2,50 @@
|
||||
|
||||
class SqlCriteria
|
||||
{
|
||||
public $select = '*';
|
||||
private $select = array();
|
||||
|
||||
public $distinct = '';
|
||||
private $distinct = '';
|
||||
|
||||
public $where = array();
|
||||
private $where = array();
|
||||
|
||||
public $order = array();
|
||||
private $order = array('sort' => array(), 'order' => array());
|
||||
|
||||
public $limit = '';
|
||||
private $limit = '';
|
||||
|
||||
/**
|
||||
* @return SqlCriteria
|
||||
* @var SqlModel
|
||||
*/
|
||||
public static function getInstance()
|
||||
private $model;
|
||||
|
||||
public function find()
|
||||
{
|
||||
return self;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $conditions array @ex array('field=?' => $value, 'field in ? => new DbExpr('(1,2,3)'))
|
||||
* @param $cond string Condition with "?" placeholder @ex 'field=?'
|
||||
* @param $value string|array|DbExpr Value. Array transformed to DbExpr(implode(',' Array)) All elements in the array mast be integer
|
||||
* @return SqlCriteria
|
||||
* @desc Allow multiple calls
|
||||
*/
|
||||
public function where($conditions)
|
||||
public function where($cond, $value)
|
||||
{
|
||||
$this->where = $conditions;
|
||||
$this->where[$cond] = $value;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $fields array @ex array('field1', 'field2' => SqlModel::ORDER_DESC)
|
||||
* @param $field string Field @ex 'field'
|
||||
* @param $order_desc bool Descendant sort direction
|
||||
* @return SqlCriteria
|
||||
* @desc Allow multiple calls
|
||||
*/
|
||||
public function order($fields)
|
||||
public function order($field, $order_desc = false)
|
||||
{
|
||||
if (!is_array($fields)) {
|
||||
$fields = array($fields);
|
||||
$this->order['sort'][] = $field;
|
||||
if ($order_desc) {
|
||||
$this->order['order'][$field] = 'desc';
|
||||
}
|
||||
$this->order = $fields;
|
||||
return $this;
|
||||
}
|
||||
|
||||
@ -50,23 +56,20 @@ class SqlCriteria
|
||||
*/
|
||||
public function limit($limit, $offset = 0)
|
||||
{
|
||||
if (empty($offset)) {
|
||||
$this->limit = (int) $limit;
|
||||
if ($offset) {
|
||||
$this->limit = (int) $offset . ',';
|
||||
}
|
||||
$this->limit = (int)$limit . ',' . (int) $offset;
|
||||
$this->limit .= (int) $limit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $select array @ex array('field1', 'field2', 'field3' => 'field')
|
||||
* @return string
|
||||
* @param string $field
|
||||
* @return SqlCriteria
|
||||
*/
|
||||
public function select($select)
|
||||
public function select($field)
|
||||
{
|
||||
if (!is_array($select)) {
|
||||
$select = array($select);
|
||||
}
|
||||
$this->select = $select;
|
||||
$this->select[] = $field;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user