From 94e94e0a8566f23d16658a04c55b0bbfdd6689aa Mon Sep 17 00:00:00 2001 From: "godzilla80@gmx.net" <> Date: Sun, 14 Feb 2010 01:22:57 +0000 Subject: Merge Branches & Trunk /trunk:r2680,2692,2707-2736 /branches/3.1:r2682-2686,2694-2702,2705,2738-2762 --- framework/Data/DataGateway/TDataGatewayCommand.php | 5 +- framework/Data/DataGateway/TSqlCriteria.php | 72 +++++++++++++++++++--- 2 files changed, 68 insertions(+), 9 deletions(-) (limited to 'framework/Data/DataGateway') diff --git a/framework/Data/DataGateway/TDataGatewayCommand.php b/framework/Data/DataGateway/TDataGatewayCommand.php index 7425e6c4..e290f457 100644 --- a/framework/Data/DataGateway/TDataGatewayCommand.php +++ b/framework/Data/DataGateway/TDataGatewayCommand.php @@ -148,7 +148,8 @@ class TDataGatewayCommand extends TComponent $ordering = $criteria->getOrdersBy(); $limit = $criteria->getLimit(); $offset = $criteria->getOffset(); - $command = $this->getBuilder()->createFindCommand($where,$parameters,$ordering,$limit,$offset); + $select = $criteria->getSelect(); + $command = $this->getBuilder()->createFindCommand($where,$parameters,$ordering,$limit,$offset,$select); $this->onCreateCommand($command, $criteria); return $command; } @@ -232,7 +233,7 @@ class TDataGatewayCommand extends TComponent throw new TDbException('dbtablegateway_missing_pk_values', $this->getTableInfo()->getTableFullName()); } - if($count>1 && !is_array($values[0])) + if($count>1 && (!isset($values[0]) || !is_array($values[0]))) $values = array($values); if($count > 1 && count($values[0]) !== $count) { diff --git a/framework/Data/DataGateway/TSqlCriteria.php b/framework/Data/DataGateway/TSqlCriteria.php index 4ebdeb48..14e37b35 100644 --- a/framework/Data/DataGateway/TSqlCriteria.php +++ b/framework/Data/DataGateway/TSqlCriteria.php @@ -31,6 +31,11 @@ */ class TSqlCriteria extends TComponent { + /** + * @var mixed + * @since 3.1.7 + */ + private $_select='*'; private $_condition; private $_parameters; private $_ordersBy; @@ -55,6 +60,60 @@ class TSqlCriteria extends TComponent $this->setCondition($condition); } + /** + * Gets the field list to be placed after the SELECT in the SQL. Default to '*' + * @return mixed + * @since 3.1.7 + */ + public function getSelect() + { + return $this->_select; + } + + /** + * Sets the field list to be placed after the SELECT in the SQL. + * + * Different behavior depends on type of assigned value + * string + * usage without modification + * + * null + * will be expanded to full list of quoted table column names (quoting depends on database) + * + * array + * - Column names will be quoted if used as key or value of array + * + * array('col1', 'col2', 'col2') + * // SELECT `col1`, `col2`, `col3` FROM... + * + * + * - Column aliasing + * + * array('mycol1' => 'col1', 'mycol2' => 'COUNT(*)') + * // SELECT `col1` AS mycol1, COUNT(*) AS mycol2 FROM... + * + * + * - NULL and scalar values (strings will be quoted depending on database) + * + * array('col1' => 'my custom string', 'col2' => 1.0, 'col3' => 'NULL') + * // SELECT "my custom string" AS `col1`, 1.0 AS `col2`, NULL AS `col3` FROM... + * + * + * - If the *-wildcard char is used as key or value, add the full list of quoted table column names + * + * array('col1' => 'NULL', '*') + * // SELECT `col1`, `col2`, `col3`, NULL AS `col1` FROM... + * + * + * @param mixed + * @since 3.1.7 + * @see TDbCommandBuilder::getSelectFieldList() + */ + public function setSelect($value) + { + $this->_select = $value; + } + /** * @return string search conditions. */ @@ -68,17 +127,17 @@ class TSqlCriteria extends TComponent * @param string search conditions. */ public function setCondition($value) - { + { if(empty($value)) { return; } - + // supporting the following SELECT-syntax: // [ORDER BY {col_name | expr | position} // [ASC | DESC], ...] // [LIMIT {[offset,] row_count | row_count OFFSET offset}] // See: http://dev.mysql.com/doc/refman/5.0/en/select.html - + if(preg_match('/ORDER\s+BY\s+(.*?)(?=LIMIT)|ORDER\s+BY\s+(.*?)$/i', $value, $matches) > 0) { // condition contains ORDER BY $value = str_replace($matches[0], '', $value); @@ -88,7 +147,7 @@ class TSqlCriteria extends TComponent $this->setOrdersBy($matches[2]); } } - + if(preg_match('/LIMIT\s+([\d\s,]+)/i', $value, $matches) > 0) { // condition contains limit $value = str_replace($matches[0], '', $value); // remove limit from query @@ -106,7 +165,7 @@ class TSqlCriteria extends TComponent $value = str_replace($matches[0], '', $value); // remove offset from query $this->_offset = (int)$matches[1]; // set offset in criteria } - + $this->_condition = trim($value); } @@ -222,5 +281,4 @@ class TSqlCriteria extends TComponent return $str; } } - -?> +?> \ No newline at end of file -- cgit v1.2.3