diff --git a/framework/yii/db/Command.php b/framework/yii/db/Command.php index 4b5dfc5..1564b50 100644 --- a/framework/yii/db/Command.php +++ b/framework/yii/db/Command.php @@ -661,7 +661,7 @@ class Command extends \yii\base\Component * @param string|array $columns comma separated string or array of columns that the primary key will consist of. * @return Command the command object itself. */ - public function addPrimaryKey($name,$table,$columns) + public function addPrimaryKey($name, $table, $columns) { $sql = $this->db->getQueryBuilder()->addPrimaryKey($name, $table, $columns); return $this->setSql($sql); @@ -673,7 +673,7 @@ class Command extends \yii\base\Component * @param string $table the table that the primary key constraint will be removed from. * @return Command the command object itself */ - public function dropPrimarykey($name,$table) + public function dropPrimarykey($name, $table) { $sql = $this->db->getQueryBuilder()->dropPrimarykey($name, $table); return $this->setSql($sql); diff --git a/framework/yii/db/QueryBuilder.php b/framework/yii/db/QueryBuilder.php index aab7d3e..4d7a451 100644 --- a/framework/yii/db/QueryBuilder.php +++ b/framework/yii/db/QueryBuilder.php @@ -276,12 +276,16 @@ class QueryBuilder extends \yii\base\Object * @param string|array $columns comma separated string or array of columns that the primary key will consist of. * @return string the SQL statement for adding a primary key constraint to an existing table. */ - public function addPrimaryKey($name,$table,$columns) + public function addPrimaryKey($name, $table, $columns) { - if(is_string($columns)) + if (is_string($columns)) { $columns=preg_split('/\s*,\s*/',$columns,-1,PREG_SPLIT_NO_EMPTY); - foreach($columns as $i=>$col) + } + + foreach ($columns as $i=>$col) { $columns[$i]=$this->db->quoteColumnName($col); + } + return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' ADD CONSTRAINT ' . $this->db->quoteColumnName($name) . ' PRIMARY KEY (' . implode(', ', $columns). ' )'; @@ -293,7 +297,7 @@ class QueryBuilder extends \yii\base\Object * @param string $table the table that the primary key constraint will be removed from. * @return string the SQL statement for removing a primary key constraint from an existing table. * */ - public function dropPrimarykey($name,$table) + public function dropPrimarykey($name, $table) { return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name); diff --git a/framework/yii/db/mysql/QueryBuilder.php b/framework/yii/db/mysql/QueryBuilder.php index 5d3ee57..e785bae 100644 --- a/framework/yii/db/mysql/QueryBuilder.php +++ b/framework/yii/db/mysql/QueryBuilder.php @@ -94,7 +94,7 @@ class QueryBuilder extends \yii\db\QueryBuilder * @param string $table the table that the primary key constraint will be removed from. * @return string the SQL statement for removing a primary key constraint from an existing table. * */ - public function dropPrimarykey($name,$table) + public function dropPrimarykey($name, $table) { return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' DROP PRIMARY KEY'; } diff --git a/framework/yii/db/sqlite/QueryBuilder.php b/framework/yii/db/sqlite/QueryBuilder.php index a3f3f2a..01f5691 100644 --- a/framework/yii/db/sqlite/QueryBuilder.php +++ b/framework/yii/db/sqlite/QueryBuilder.php @@ -188,7 +188,7 @@ class QueryBuilder extends \yii\db\QueryBuilder * @return string the SQL statement for adding a primary key constraint to an existing table. * @throws NotSupportedException this is not supported by SQLite */ - public function addPrimaryKey($name,$table,$columns) + public function addPrimaryKey($name, $table, $columns) { throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); } @@ -200,7 +200,7 @@ class QueryBuilder extends \yii\db\QueryBuilder * @return string the SQL statement for removing a primary key constraint from an existing table. * @throws NotSupportedException this is not supported by SQLite * */ - public function dropPrimarykey($name,$table) + public function dropPrimarykey($name, $table) { throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.'); }