Skip to content
Browse files

Enhancements to the #2090.

  • Loading branch information...
1 parent 0c71699 commit f6bd5a492bc3184e5f1baf2860dbc31a0b007512 @resurtm resurtm committed Mar 22, 2013
View
4 framework/db/schema/CDbSchema.php
@@ -565,7 +565,8 @@ public function dropIndex($name, $table)
* Builds a SQL statement for adding a primary key constraint to an existing table.
* @param string $name the name of the primary key constraint.
* @param string $table the table that the primary key constraint will be added to.
- * @param mixed $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.
+ * Array value can be passed since 1.1.14.
* @return string the SQL statement for adding a primary key constraint to an existing table.
* @since 1.1.13
*/
@@ -592,5 +593,4 @@ public function dropPrimaryKey($name,$table)
return 'ALTER TABLE ' . $this->quoteTableName($table) . ' DROP CONSTRAINT '
. $this->quoteColumnName($name);
}
-
}
View
10 framework/db/schema/mysql/CMysqlSchema.php
@@ -335,16 +335,16 @@ public function dropPrimaryKey($name,$table)
}
/**
- * Builds a SQL statement for adding a primary key constraint too a table.
- * @param string $name Not used in the MySql syntax, the primary key is always called PRIMARY and is reserved.
+ * Builds a SQL statement for adding a primary key constraint to a table.
+ * @param string $name not used in the MySQL syntax, the primary key is always called PRIMARY and is reserved.
* @param string $table the table that the primary key constraint will be added to.
- * @param mixed $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.
* @since 1.1.14
*/
- 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)
$columns[$i]=$this->quoteColumnName($col);
View
4 framework/db/schema/sqlite/CSqliteSchema.php
@@ -300,10 +300,10 @@ public function dropIndex($name, $table)
/**
* Builds a SQL statement for adding a primary key constraint to an existing table.
- * Because SQLite does not support adding a primary key on an existing table this method will throw an exception
+ * Because SQLite does not support adding a primary key on an existing table this method will throw an exception.
* @param string $name the name of the primary key constraint.
* @param string $table the table that the primary key constraint will be added to.
- * @param string $columns the name of the column to that the constraint will be added on.
+ * @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.
* @since 1.1.13
*/
View
14 tests/framework/db/schema/CMysql2Test.php
@@ -6,6 +6,9 @@
class CMysql2Test extends CTestCase
{
+ /**
+ * @var CDbConnection
+ */
private $db;
public function setUp()
@@ -136,4 +139,15 @@ public function testDropIndex()
$expect='DROP INDEX `id_pk` ON `test`';
$this->assertEquals($expect, $sql);
}
+
+ public function testAddPrimaryKey()
+ {
+ $sql=$this->db->schema->addPrimaryKey('this-string-is-ignored','table','id');
+ $expect='ALTER TABLE `table` ADD PRIMARY KEY (`id` )';
+ $this->assertEquals($expect, $sql);
+
+ $sql=$this->db->schema->addPrimaryKey('this-string-is-ignored','table',array('id1','id2'));
+ $expect='ALTER TABLE `table` ADD PRIMARY KEY (`id1`, `id2` )';
+ $this->assertEquals($expect, $sql);
+ }
}

0 comments on commit f6bd5a4

Please sign in to comment.
Something went wrong with that request. Please try again.