Skip to content

Commit

Permalink
(Fixes issue 2365)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiang.xue committed Jun 22, 2011
1 parent 63677c5 commit 522cfd9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Expand Up @@ -42,6 +42,7 @@ Version 1.1.8 work in progress
- Enh #2341: More verbose log message for CModel::onUnsafeAttribute. Added model class (Sam Dark)
- Enh #2357: Documented CWebApplication accessors with @property for better IDE autocomplete (Sam Dark)
- Enh #2361: Added CDbConnection::pdoClass that allows to specify and use custom PDO wrapper class (Sam Dark)
- Enh #2365: Added support for creating more complex index by using createIndex() of query builder. (Qiang)
- Enh #2389: MessageCommand now accepts overwrite option determining if merge result will overwrite existing file (Sam Dark)
- Enh #2424: CDbConnection::beginTransaction() will now trigger a trace message for better debugging (Y!!)
- Enh #2450: Added Ctype extension check to Yii requirements checker (Sam Dark)
Expand Down
9 changes: 7 additions & 2 deletions framework/db/schema/CDbSchema.php
Expand Up @@ -524,7 +524,7 @@ public function dropForeignKey($name, $table)
* @param string $name the name of the index. The name will be properly quoted by the method.
* @param string $table the table that the new index will be created for. The table name will be properly quoted by the method.
* @param string $column the column(s) that should be included in the index. If there are multiple columns, please separate them
* by commas. The column names will be properly quoted by the method.
* by commas. Each column name will be properly quoted by the method, unless a parenthesis is found in the name.
* @param boolean $unique whether to add UNIQUE constraint on the created index.
* @return string the SQL statement for creating a new index.
* @since 1.1.6
Expand All @@ -534,7 +534,12 @@ public function createIndex($name, $table, $column, $unique=false)
$cols=array();
$columns=preg_split('/\s*,\s*/',$column,-1,PREG_SPLIT_NO_EMPTY);
foreach($columns as $col)
$cols[]=$this->quoteColumnName($col);
{
if(strpos($col,'(')!==false)
$cols[]=$col;
else
$cols[]=$this->quoteColumnName($col);
}
return ($unique ? 'CREATE UNIQUE INDEX ' : 'CREATE INDEX ')
. $this->quoteTableName($name).' ON '
. $this->quoteTableName($table).' ('.implode(', ',$cols).')';
Expand Down

0 comments on commit 522cfd9

Please sign in to comment.