Browse Source

Updated code styling and added braces.

tags/2.0.0-beta
gevik 12 years ago
parent
commit
c338d4b76b
  1. 4
      framework/yii/db/Command.php
  2. 12
      framework/yii/db/QueryBuilder.php
  3. 2
      framework/yii/db/mysql/QueryBuilder.php
  4. 4
      framework/yii/db/sqlite/QueryBuilder.php

4
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. * @param string|array $columns comma separated string or array of columns that the primary key will consist of.
* @return Command the command object itself. * @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); $sql = $this->db->getQueryBuilder()->addPrimaryKey($name, $table, $columns);
return $this->setSql($sql); 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. * @param string $table the table that the primary key constraint will be removed from.
* @return Command the command object itself * @return Command the command object itself
*/ */
public function dropPrimarykey($name,$table) public function dropPrimarykey($name, $table)
{ {
$sql = $this->db->getQueryBuilder()->dropPrimarykey($name, $table); $sql = $this->db->getQueryBuilder()->dropPrimarykey($name, $table);
return $this->setSql($sql); return $this->setSql($sql);

12
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. * @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. * @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); $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); $columns[$i]=$this->db->quoteColumnName($col);
}
return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' ADD CONSTRAINT ' return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' ADD CONSTRAINT '
. $this->db->quoteColumnName($name) . ' PRIMARY KEY (' . $this->db->quoteColumnName($name) . ' PRIMARY KEY ('
. implode(', ', $columns). ' )'; . 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. * @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. * * @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) return 'ALTER TABLE ' . $this->db->quoteTableName($table)
. ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name); . ' DROP CONSTRAINT ' . $this->db->quoteColumnName($name);

2
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. * @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. * * @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'; return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' DROP PRIMARY KEY';
} }

4
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. * @return string the SQL statement for adding a primary key constraint to an existing table.
* @throws NotSupportedException this is not supported by SQLite * @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.'); 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. * @return string the SQL statement for removing a primary key constraint from an existing table.
* @throws NotSupportedException this is not supported by SQLite * * @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.'); throw new NotSupportedException(__METHOD__ . ' is not supported by SQLite.');
} }

Loading…
Cancel
Save