From 1ae09931b2572d9c3067c99f841a60cb3330b3f3 Mon Sep 17 00:00:00 2001 From: wei <> Date: Thu, 3 May 2007 00:48:04 +0000 Subject: Update active relations docs --- .../Relations/TActiveRecordBelongsTo.php | 20 ++-- .../Relations/TActiveRecordHasMany.php | 8 +- .../Relations/TActiveRecordHasManyAssociation.php | 107 ++++++++++++++++++++- .../ActiveRecord/Relations/TActiveRecordHasOne.php | 14 +-- .../Relations/TActiveRecordRelation.php | 11 +-- .../Relations/TActiveRecordRelationContext.php | 13 ++- .../Scaffold/InputBuilder/TScaffoldInputCommon.php | 1 + .../ActiveRecord/Scaffold/TScaffoldListView.php | 18 ++-- .../Data/ActiveRecord/Scaffold/TScaffoldView.php | 4 +- framework/Data/ActiveRecord/TActiveRecord.php | 1 + .../Data/Common/Mssql/TMssqlCommandBuilder.php | 6 +- framework/Data/Common/Mssql/TMssqlTableInfo.php | 1 - .../Data/Common/Sqlite/TSqliteCommandBuilder.php | 48 +++++++++ framework/Data/Common/Sqlite/TSqliteMetaData.php | 2 +- framework/Data/Common/Sqlite/TSqliteTableInfo.php | 9 ++ framework/Data/Common/TDbCommandBuilder.php | 39 ++++---- framework/prado-cli.php | 5 +- 17 files changed, 235 insertions(+), 72 deletions(-) create mode 100644 framework/Data/Common/Sqlite/TSqliteCommandBuilder.php (limited to 'framework') diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php b/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php index c72ba160..1168bf55 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordBelongsTo.php @@ -1,6 +1,6 @@ * @link http://www.pradosoft.com/ @@ -16,8 +16,8 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); /** - * Implements the foreign key relationship (TActiveRecord::BELONGS_TO) between - * the source objects and the related foreign object. Consider the + * Implements the foreign key relationship (TActiveRecord::BELONGS_TO) between + * the source objects and the related foreign object. Consider the * entity relationship between a Team and a Player. * * +------+ +--------+ @@ -38,17 +38,19 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * public $team_name; //foreign key player.team_name <-> team.name * public $age; * public $team; //foreign object TeamRecord - * - * protected static $RELATIONS = array( - * 'team' => array(self::BELONGS_TO, 'TeamRecord')); - * + * + * protected static $RELATIONS = array + * ( + * 'team' => array(self::BELONGS_TO, 'TeamRecord') + * ); + * * public static function finder($className=__CLASS__) * { * return parent::finder($className); * } * } * - * The $RELATIONS static property of PlayerRecord defines that the + * The static $RELATIONS property of PlayerRecord defines that the * property $team belongs to (or is a) TeamRecords. * * The team object may be fetched as follows. @@ -58,7 +60,7 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * The method with_xxx() (where xxx is the relationship property * name, in this case, team) fetchs the corresponding TeamRecords using * a second query (not by using a join). The with_xxx() accepts the same - * arguments as other finder methods of TActiveRecord, e.g. + * arguments as other finder methods of TActiveRecord, e.g. * with_team('location = ?', 'Madrid'). * * @author Wei Zhuo diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php index 795630ab..c5ce616e 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasMany.php @@ -34,8 +34,10 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * * public $players=array(); //list of players * - * protected static $RELATIONS=array( - * 'players' => array(self::HAS_MANY, 'PlayerRecord')); + * protected static $RELATIONS=array + * ( + * 'players' => array(self::HAS_MANY, 'PlayerRecord') + * ); * * public static function finder($className=__CLASS__) * { @@ -47,7 +49,7 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * // see TActiveRecordBelongsTo for detailed definition * } * - * The $RELATIONS static property of TeamRecord defines that the + * The static $RELATIONS property of TeamRecord defines that the * property $players has many PlayerRecords. * * The players list may be fetched as follows. diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php index 456848fe..50558a2b 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasManyAssociation.php @@ -1,16 +1,98 @@ + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2007 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package System.Data.ActiveRecord.Relations + */ /** * Loads base active record relations class. */ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); +/** + * Implements the M-N (many to many) relationship via association table. + * Consider the entity relationship between Articles and Categories + * via the association table Article_Category. + * + * +---------+ +------------------+ +----------+ + * | Article | * -----> * | Article_Category | * <----- * | Category | + * +---------+ +------------------+ +----------+ + * + * Where one article may have 0 or more categories and each category may have 0 + * or more articles. We may model Article-Category object relationship + * as active record as follows. + * + * class ArticleRecord + * { + * const TABLE='Article'; + * public $article_id; + * + * public $Categories=array(); //foreign object collection. + * + * protected static $RELATIONS = array + * ( + * 'Categories' => array(self::HAS_MANY, 'CategoryRecord', 'Article_Category') + * ); + * + * public static function finder($className=__CLASS__) + * { + * return parent::finder($className); + * } + * } + * class CategoryRecord + * { + * const TABLE='Category'; + * public $category_id; + * + * public $Articles=array(); + * + * protected static $RELATIONS = array + * ( + * 'Articles' => array(self::HAS_MANY, 'ArticleRecord', 'Article_Category') + * ); + * + * public static function finder($className=__CLASS__) + * { + * return parent::finder($className); + * } + * } + * + * + * The static $RELATIONS property of ArticleRecord defines that the + * property $Categories has many CategoryRecords. Similar, the + * static $RELATIONS property of CategoryRecord defines many ArticleRecords. + * + * The articles with categories list may be fetched as follows. + * + * $articles = TeamRecord::finder()->withCategories()->findAll(); + * + * The method with_xxx() (where xxx is the relationship property + * name, in this case, Categories) fetchs the corresponding CategoryRecords using + * a second query (not by using a join). The with_xxx() accepts the same + * arguments as other finder methods of TActiveRecord. + * + * @author Wei Zhuo + * @version $Id$ + * @package System.Data.ActiveRecord.Relations + * @since 3.1 + */ class TActiveRecordHasManyAssociation extends TActiveRecordRelation { private $_association; private $_sourceTable; private $_foreignTable; + /** + * Get the foreign key index values from the results and make calls to the + * database to find the corresponding foreign objects using association table. + * @param array original results. + */ protected function collectForeignObjects(&$results) { $association = $this->getAssociationTable(); @@ -26,6 +108,9 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation $this->fetchForeignObjects($results, $foreignKeys,$indexValues,$sourceKeys); } + /** + * @return TDbTableInfo association table information. + */ protected function getAssociationTable() { if($this->_association===null) @@ -38,6 +123,9 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation return $this->_association; } + /** + * @return TDbTableInfo source table information. + */ protected function getSourceTable() { if($this->_sourceTable===null) @@ -48,6 +136,9 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation return $this->_sourceTable; } + /** + * @return TDbTableInfo foreign table information. + */ protected function getForeignTable() { if($this->_foreignTable===null) @@ -59,6 +150,9 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation return $this->_foreignTable; } + /** + * @return TDbCommandBuilder + */ protected function getCommandBuilder() { return $this->getSourceRecord()->getRecordGateway()->getCommand($this->getSourceRecord()); @@ -117,6 +211,10 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation return $command; } + /** + * @param array source table column names. + * @return string comma separated source column names. + */ protected function getSourceColumns($sourceKeys) { $columns=array(); @@ -127,6 +225,13 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation return implode(', ', $columns); } + /** + * SQL inner join for M-N relationship via association table. + * @param array foreign table column key names. + * @param array source table index values. + * @param array source table column names. + * @return string inner join condition for M-N relationship via association table. + */ protected function getAssociationJoin($foreignKeys,$indexValues,$sourceKeys) { $refInfo= $this->getAssociationTable(); @@ -143,9 +248,7 @@ class TActiveRecordHasManyAssociation extends TActiveRecordRelation $joins[] = "{$fkTable}.{$fkField} = {$refTable}.{$refField}"; } $joinCondition = implode(' AND ', $joins); - $index = $this->getCommandBuilder()->getIndexKeyCondition($refInfo,array_keys($sourceKeys), $indexValues); - return "INNER JOIN {$refTable} ON ({$joinCondition}) AND {$index}"; } } diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php b/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php index 4286254b..6348f16b 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordHasOne.php @@ -21,7 +21,7 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * related to the source object. The HAS_ONE relation is very similar to the * HAS_MANY relationship (in fact, it is equivalent in the entities relationship point of view). * - * The difference of HAS_ONE from HAS_MANY is that the foreign object is singular. + * The difference of HAS_ONE from HAS_MANY is that the foreign object is singular. * That is, HAS_MANY will return a collection of records while HAS_ONE returns the * corresponding record. * @@ -32,7 +32,7 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * +-----+ +--------+ * * Where each engine belongs to only one car, that is, the Engine entity has - * a foreign key to the Car's primary key. We may model + * a foreign key to the Car's primary key. We may model * Engine-Car object relationship as active record as follows. * * class CarRecord extends TActiveRecord @@ -43,8 +43,10 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * * public $engine; //engine foreign object * - * protected static $RELATIONS=array( - * 'engine' => array(self::HAS_ONE, 'EngineRecord')); + * protected static $RELATIONS=array + * ( + * 'engine' => array(self::HAS_ONE, 'EngineRecord') + * ); * * public static function finder($className=__CLASS__) * { @@ -57,14 +59,14 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelation'); * public $engine_id; * public $capacity; * public $car_id; //foreign key to cars - * + * * public static function finder($className=__CLASS__) * { * return parent::finder($className); * } * } * - * The $RELATIONS static property of CarRecord defines that the + * The static $RELATIONS property of CarRecord defines that the * property $engine that will reference an EngineRecord instance. * * The car record with engine property list may be fetched as follows. diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php b/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php index 38455309..46609095 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordRelation.php @@ -18,8 +18,6 @@ Prado::using('System.Data.ActiveRecord.Relations.TActiveRecordRelationContext'); /** * Base class for active record relationships. * - * description - * * @author Wei Zhuo * @version $Id$ * @package System.Data.ActiveRecord.Relations @@ -66,7 +64,7 @@ abstract class TActiveRecordRelation static $stack=array(); $results = call_user_func_array(array($this->getSourceRecord(),$method),$args); - if(is_array($results) || $results instanceof TActiveRecord) + if(is_array($results) || $results instanceof ArrayAccess || $results instanceof TActiveRecord) { $this->collectForeignObjects($results); while($obj = array_pop($stack)) @@ -134,8 +132,9 @@ abstract class TActiveRecordRelation */ protected function getIndexValues($keys, $results) { - if(!is_array($results)) + if(!is_array($results) && !$results instanceof ArrayAccess) $results = array($results); + $values=array(); foreach($results as $result) { $value = array(); @@ -169,7 +168,7 @@ abstract class TActiveRecordRelation */ protected function setResultCollection(&$results, &$collections, $properties) { - if(is_array($results)) + if(is_array($results) || $results instanceof ArrayAccess) { for($i=0,$k=count($results);$i<$k;$i++) $this->setObjectProperty($results[$i], $properties, $collections); @@ -191,5 +190,5 @@ abstract class TActiveRecordRelation $source->{$prop} = isset($collections[$hash]) ? $collections[$hash] : array(); } } - + ?> \ No newline at end of file diff --git a/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php b/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php index 033d7638..167c90a5 100644 --- a/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php +++ b/framework/Data/ActiveRecord/Relations/TActiveRecordRelationContext.php @@ -57,11 +57,14 @@ class TActiveRecordRelationContext if(!isset($statics[self::RELATIONS_CONST])) throw new TActiveRecordException('ar_relations_undefined', get_class($this->_sourceRecord), self::RELATIONS_CONST); - if(isset($statics[self::RELATIONS_CONST][$property])) - return $statics[self::RELATIONS_CONST][$property]; - else - throw new TActiveRecordException('ar_undefined_relation_prop', - $property, get_class($this->_sourceRecord), self::RELATIONS_CONST); + $property = strtolower($property); + foreach($statics[self::RELATIONS_CONST] as $name => $relation) + { + if(strtolower($name)===$property) + return $relation; + } + throw new TActiveRecordException('ar_undefined_relation_prop', + $property, get_class($this->_sourceRecord), self::RELATIONS_CONST); } /** diff --git a/framework/Data/ActiveRecord/Scaffold/InputBuilder/TScaffoldInputCommon.php b/framework/Data/ActiveRecord/Scaffold/InputBuilder/TScaffoldInputCommon.php index e1d57124..84c381f0 100644 --- a/framework/Data/ActiveRecord/Scaffold/InputBuilder/TScaffoldInputCommon.php +++ b/framework/Data/ActiveRecord/Scaffold/InputBuilder/TScaffoldInputCommon.php @@ -190,6 +190,7 @@ class TScaffoldInputCommon extends TScaffoldInputBase { $value = $this->getRecordPropertyValue($column, $record); $control = new TDatePicker(); + $control->setFromYear(1900); $control->setInputMode(TDatePickerInputMode::DropDownList); $control->setDateFormat('yyyy-MM-dd'); if(!empty($value)) diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php index 71dc83cd..34f8a592 100644 --- a/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php +++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldListView.php @@ -50,16 +50,6 @@ Prado::using('System.Data.ActiveRecord.Scaffold.TScaffoldBase'); */ class TScaffoldListView extends TScaffoldBase { - /** - * Initialize the sort drop down list in non post back mode (i.e. GET requests). - */ - public function onLoad($param) - { - parent::onLoad($param); - if(!$this->getPage()->getIsPostBack()) - $this->initializeSort(); - } - /** * Initialize the sort drop down list and the column names repeater. */ @@ -87,6 +77,8 @@ class TScaffoldListView extends TScaffoldBase public function onPreRender($param) { parent::onPreRender($param); + if(!$this->getPage()->getIsPostBack()) + $this->initializeSort(); $this->loadRecordData(); } @@ -113,8 +105,10 @@ class TScaffoldListView extends TScaffoldBase if($offset + $limit > $total) $limit = $total - $offset; $criteria = new TActiveRecordCriteria($this->getSearchCondition(), $this->getSearchParameters()); - $criteria->setLimit($limit); - $criteria->setOffset($offset); + if($limit > 0) + $criteria->setLimit($limit); + if($offset <= $total) + $criteria->setOffset($offset); $order = explode(' ',$this->_sort->getSelectedValue(), 2); if(is_array($order) && count($order) === 2) $criteria->OrdersBy[$order[0]] = $order[1]; diff --git a/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php b/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php index c144fe37..ad7ba55d 100644 --- a/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php +++ b/framework/Data/ActiveRecord/Scaffold/TScaffoldView.php @@ -44,9 +44,9 @@ class TScaffoldView extends TScaffoldBase /** * Copy basic record details to the list/edit/search controls. */ - public function onLoad($param) + public function onPreRender($param) { - parent::onLoad($param); + parent::onPreRender($param); $this->getListView()->copyFrom($this); $this->getEditView()->copyFrom($this); $this->getSearchControl()->copyFrom($this); diff --git a/framework/Data/ActiveRecord/TActiveRecord.php b/framework/Data/ActiveRecord/TActiveRecord.php index cb3a1ebe..479f643b 100644 --- a/framework/Data/ActiveRecord/TActiveRecord.php +++ b/framework/Data/ActiveRecord/TActiveRecord.php @@ -328,6 +328,7 @@ abstract class TActiveRecord extends TComponent /** * @param TDbDataReader data reader + * @return array */ protected function collectObjects($reader) { diff --git a/framework/Data/Common/Mssql/TMssqlCommandBuilder.php b/framework/Data/Common/Mssql/TMssqlCommandBuilder.php index b22c08a5..3de6aa5e 100644 --- a/framework/Data/Common/Mssql/TMssqlCommandBuilder.php +++ b/framework/Data/Common/Mssql/TMssqlCommandBuilder.php @@ -1,6 +1,6 @@ * @link http://www.pradosoft.com/ @@ -13,8 +13,8 @@ Prado::using('System.Data.Common.TDbCommandBuilder'); /** - * TDbCommandBuilder provides basic methods to create query commands for tables - * giving by {@link setTableInfo TableInfo} the property. + * TMssqlCommandBuilder provides specifics methods to create limit/offset query commands + * for MSSQL servers. * * @author Wei Zhuo * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $ diff --git a/framework/Data/Common/Mssql/TMssqlTableInfo.php b/framework/Data/Common/Mssql/TMssqlTableInfo.php index e408440b..ee9c500b 100644 --- a/framework/Data/Common/Mssql/TMssqlTableInfo.php +++ b/framework/Data/Common/Mssql/TMssqlTableInfo.php @@ -60,7 +60,6 @@ class TMssqlTableInfo extends TDbTableInfo Prado::using('System.Data.Common.Mssql.TMssqlCommandBuilder'); return new TMssqlCommandBuilder($connection,$this); } - } ?> \ No newline at end of file diff --git a/framework/Data/Common/Sqlite/TSqliteCommandBuilder.php b/framework/Data/Common/Sqlite/TSqliteCommandBuilder.php new file mode 100644 index 00000000..9f1253c9 --- /dev/null +++ b/framework/Data/Common/Sqlite/TSqliteCommandBuilder.php @@ -0,0 +1,48 @@ + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2007 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $ + * @package System.Data.Common + */ + +Prado::using('System.Data.Common.TDbCommandBuilder'); + +/** + * TSqliteCommandBuilder provides specifics methods to create limit/offset query commands + * for Sqlite database. + * + * @author Wei Zhuo + * @version $Id: TDbCommandBuilder.php 1863 2007-04-12 12:43:49Z wei $ + * @package System.Data.Common + * @since 3.1 + */ +class TSqliteCommandBuilder extends TDbCommandBuilder +{ + /** + * Alters the sql to apply $limit and $offset. + * @param string SQL query string. + * @param integer maximum number of rows, -1 to ignore limit. + * @param integer row offset, -1 to ignore offset. + * @return string SQL with limit and offset. + */ + public function applyLimitOffset($sql, $limit=-1, $offset=-1) + { + $limit = $limit!==null ? intval($limit) : -1; + $offset = $offset!==null ? intval($offset) : -1; + if($limit > 0 || $offset > 0) + { + $limitStr = ' LIMIT '.$limit; + $offsetStr = $offset >= 0 ? ' OFFSET '.$offset : ''; + return $sql.$limitStr.$offsetStr; + } + else + return $sql; + } +} + +?> \ No newline at end of file diff --git a/framework/Data/Common/Sqlite/TSqliteMetaData.php b/framework/Data/Common/Sqlite/TSqliteMetaData.php index f9b49488..6c6ff232 100644 --- a/framework/Data/Common/Sqlite/TSqliteMetaData.php +++ b/framework/Data/Common/Sqlite/TSqliteMetaData.php @@ -49,7 +49,7 @@ class TSqliteMetaData extends TDbMetaData if($column->getIsPrimaryKey()) $primary[] = $col['name']; } - $info['TableName'] = $tableName; + $info['TableName'] = $table; if($this->getIsView($tableName)) $info['IsView'] = true; if(count($columns)===0) diff --git a/framework/Data/Common/Sqlite/TSqliteTableInfo.php b/framework/Data/Common/Sqlite/TSqliteTableInfo.php index 1581c3cc..e0bcb484 100644 --- a/framework/Data/Common/Sqlite/TSqliteTableInfo.php +++ b/framework/Data/Common/Sqlite/TSqliteTableInfo.php @@ -26,6 +26,15 @@ Prado::using('System.Data.Common.Sqlite.TSqliteTableColumn'); */ class TSqliteTableInfo extends TDbTableInfo { + /** + * @param TDbConnection database connection. + * @return TDbCommandBuilder new command builder + */ + public function createCommandBuilder($connection) + { + Prado::using('System.Data.Common.Sqlite.TSqliteCommandBuilder'); + return new TSqliteCommandBuilder($connection,$this); + } } ?> \ No newline at end of file diff --git a/framework/Data/Common/TDbCommandBuilder.php b/framework/Data/Common/TDbCommandBuilder.php index 440d579d..3535100f 100644 --- a/framework/Data/Common/TDbCommandBuilder.php +++ b/framework/Data/Common/TDbCommandBuilder.php @@ -117,37 +117,38 @@ class TDbCommandBuilder extends TComponent } /** - * NOT SAFE YET! + * Computes the SQL condition for search a set of column using regular expression + * (or LIKE, depending on database implementation) to match a string of + * keywords (default matches all keywords). + * @param array list of column id for potential search condition. + * @param string string of keywords + * @return string SQL search condition matching on a set of columns. */ public function getSearchExpression($fields, $keywords) { if(strlen(trim($keywords)) == 0) return ''; - $words = preg_split('/\s/', preg_quote($keywords, '\'')); - $result = array(); + $words = preg_split('/\s/u', $keywords); + $conditions = array(); foreach($fields as $field) { $column = $this->getTableInfo()->getColumn($field)->getColumnName(); - $result[] = $this->getRegexpCriteriaStr($column, $words); + $conditions[] = $this->getSearchCondition($column, $words); } - return '('.implode(' OR ', $result).')'; - } - - protected function getRegexpCriteriaStr($column, $words) - { - $regexp = implode('|', $words); - return "({$column} REGEXP '{$regexp}')"; + return '('.implode(' OR ', $conditions).')'; } /** - * Computes the SQL condition for search a set of column using regular expression - * to match a string of keywords. The implementation should only uses columns - * that permit regular expression matching. This method should be implemented in - * database specific command builder classes. - * @param array list of column id for potential search condition. - * @param string string of keywords - * @return string SQL condition for regular expression matching on a set of columns. + * @param string column name. + * @param array keywords + * @return string search condition for all words in one column. */ - //abstract public function createRegExpSearch($columnIds, $keywords); + protected function getSearchCondition($column, $words) + { + $conditions=array(); + foreach($words as $word) + $conditions[] = $column.' LIKE '.$this->getDbConnection()->quoteString('%'.$word.'%'); + return '('.implode(' AND ', $conditions).')'; + } /** * Appends the $where condition to the string "SELECT * FROM tableName WHERE ". diff --git a/framework/prado-cli.php b/framework/prado-cli.php index ca3e1461..3839e816 100755 --- a/framework/prado-cli.php +++ b/framework/prado-cli.php @@ -691,7 +691,6 @@ class PradoCommandLineActiveRecordGen extends PradoCommandLineAction { $prop .= <<