diff options
author | Dracony <draconyster@gmail.com> | 2013-01-04 14:43:15 +0200 |
---|---|---|
committer | Dracony <draconyster@gmail.com> | 2013-01-04 14:43:15 +0200 |
commit | 918dc193c8da64bef3522456934fb40c14a2ceda (patch) | |
tree | d2a04dbedce54b7ad50161d0bb8a5f81fd611b1e /modules/database/classes | |
parent | f011e1d14d442cb9572e777513c8972c76f3cfe5 (diff) | |
download | PHPixie-918dc193c8da64bef3522456934fb40c14a2ceda.zip PHPixie-918dc193c8da64bef3522456934fb40c14a2ceda.tar.gz PHPixie-918dc193c8da64bef3522456934fb40c14a2ceda.tar.bz2 |
ORM and DB tweeks
Fixed orm to return all rows on find_all() call after find()
You cann now reset limit offset and group_by by passing NULL
Diffstat (limited to 'modules/database/classes')
-rw-r--r-- | modules/database/classes/database/query.php | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/modules/database/classes/database/query.php b/modules/database/classes/database/query.php index 5a151bd..5728514 100644 --- a/modules/database/classes/database/query.php +++ b/modules/database/classes/database/query.php @@ -11,13 +11,16 @@ * @method mixed data(array $data = null) Set data for insert or update queries.
* Without arguments returns current data, returns self otherwise.
*
- * @method mixed limit(int $limit = null) Set number of rows to return.
+ * @method mixed limit(int $limit = null) Set number of rows to return. If NULL is passed than no limit is used.
+ * If NULL is passed than no limit is used.
* Without arguments returns current limit, returns self otherwise.
*
* @method mixed offset(string $offset = null) Set the offset for the first row in result.
+ * If NULL is passed than no offset is used.
* Without arguments returns current offset, returns self otherwise.
*
* @method mixed group_by(string $group_by = null) A column to group rows by for aggregator functions.
+ * If NULL is passed than no grouping is done.
* Without arguments returns current group_by argument, returns self otherwise.
*
* @method mixed type(string $type = null) Set query type. Available types: select, update, insert, delete, count.
@@ -121,7 +124,7 @@ abstract class Query_Database { * @var array
* @access protected
*/
- protected $methods = array('table' => 'string','data' => 'array','limit' => 'integer','offset' => 'integer','group_by' => 'string','type' => 'string');
+ protected $methods = array('table' => 'string','data' => 'array','limit' => array('integer','NULL'),'offset' => array('integer','NULL'),'group_by' => array('string','NULL'),'type' => 'string');
/**
* Generates a query in format that can be executed on current database implementation
@@ -176,7 +179,6 @@ abstract class Query_Database { * @see $methods
*/
public function __call($method, $args) {
-
if (isset($this->methods[$method])) {
$property = '_'.$method;
@@ -185,9 +187,12 @@ abstract class Query_Database { return $this->$property;
$val = $args[0];
if (is_int($val))
- $val=(int) $val;
- if (gettype($val) != $this->methods[$method])
- throw new Exception("Method '{$method}' only accepts values of type: '{$this->methods[$method]}', '{$val}' was passed");
+ $val = (int) $val;
+ $allowed_types = $this->methods[$method];
+ if (!is_array($allowed_types))
+ $allowed_types=array($allowed_types);
+ if (!in_array(gettype($val),$allowed_types))
+ throw new Exception("Method '{$method}' only accepts values of type: ".implode(' or ',$allowed_types).", '{$val}' was passed");
$this->$property = $val;
return $this;
}
|