From 8e1079cd047aedd026cb10be9999c60174c59a23 Mon Sep 17 00:00:00 2001 From: resurtm Date: Thu, 23 May 2013 23:33:33 +0600 Subject: [PATCH 1/2] MSSQL more tests. --- tests/unit/data/mssql.sql | 2 +- tests/unit/framework/db/mssql/MssqlCommandTest.php | 55 +++++++++++++++++++++- 2 files changed, 54 insertions(+), 3 deletions(-) diff --git a/tests/unit/data/mssql.sql b/tests/unit/data/mssql.sql index d3bc8d2..959c6c6 100644 --- a/tests/unit/data/mssql.sql +++ b/tests/unit/data/mssql.sql @@ -62,7 +62,7 @@ CREATE TABLE [dbo].[tbl_type] ( [char_col3] [text], [float_col] [decimal](4,3) NOT NULL, [float_col2] [float] DEFAULT '1.23', - [blob_col] [binary], + [blob_col] [varbinary](MAX), [numeric_col] [decimal](5,2) DEFAULT '33.22', [time] [datetime] NOT NULL DEFAULT '2002-01-01 00:00:00', [bool_col] [tinyint] NOT NULL, diff --git a/tests/unit/framework/db/mssql/MssqlCommandTest.php b/tests/unit/framework/db/mssql/MssqlCommandTest.php index 422a00c..11d7565 100644 --- a/tests/unit/framework/db/mssql/MssqlCommandTest.php +++ b/tests/unit/framework/db/mssql/MssqlCommandTest.php @@ -21,11 +21,62 @@ class MssqlCommandTest extends \yiiunit\framework\db\CommandTest function testPrepareCancel() { - $this->markTestIncomplete(); + $this->markTestSkipped('MSSQL driver does not support this feature.'); } function testBindParamValue() { - $this->markTestIncomplete(); + $db = $this->getConnection(); + + // bindParam + $sql = 'INSERT INTO tbl_customer(email, name, address) VALUES (:email, :name, :address)'; + $command = $db->createCommand($sql); + $email = 'user4@example.com'; + $name = 'user4'; + $address = 'address4'; + $command->bindParam(':email', $email); + $command->bindParam(':name', $name); + $command->bindParam(':address', $address); + $command->execute(); + + $sql = 'SELECT name FROM tbl_customer WHERE email=:email'; + $command = $db->createCommand($sql); + $command->bindParam(':email', $email); + $this->assertEquals($name, $command->queryScalar()); + + $sql = 'INSERT INTO tbl_type (int_col, char_col, float_col, blob_col, numeric_col, bool_col) VALUES (:int_col, :char_col, :float_col, CONVERT([varbinary], :blob_col), :numeric_col, :bool_col)'; + $command = $db->createCommand($sql); + $intCol = 123; + $charCol = 'abc'; + $floatCol = 1.23; + $blobCol = "\x10\x11\x12"; + $numericCol = '1.23'; + $boolCol = false; + $command->bindParam(':int_col', $intCol); + $command->bindParam(':char_col', $charCol); + $command->bindParam(':float_col', $floatCol); + $command->bindParam(':blob_col', $blobCol); + $command->bindParam(':numeric_col', $numericCol); + $command->bindParam(':bool_col', $boolCol); + $this->assertEquals(1, $command->execute()); + + $sql = 'SELECT int_col, char_col, float_col, CONVERT([nvarchar], blob_col) AS blob_col, numeric_col FROM tbl_type'; + $row = $db->createCommand($sql)->queryRow(); + $this->assertEquals($intCol, $row['int_col']); + $this->assertEquals($charCol, trim($row['char_col'])); + $this->assertEquals($floatCol, $row['float_col']); + $this->assertEquals($blobCol, $row['blob_col']); + $this->assertEquals($numericCol, $row['numeric_col']); + + // bindValue + $sql = 'INSERT INTO tbl_customer(email, name, address) VALUES (:email, \'user5\', \'address5\')'; + $command = $db->createCommand($sql); + $command->bindValue(':email', 'user5@example.com'); + $command->execute(); + + $sql = 'SELECT email FROM tbl_customer WHERE name=:name'; + $command = $db->createCommand($sql); + $command->bindValue(':name', 'user5'); + $this->assertEquals('user5@example.com', $command->queryScalar()); } } From d67416ab8be16f1cf263adc9865621e1478d98ce Mon Sep 17 00:00:00 2001 From: resurtm Date: Thu, 23 May 2013 23:41:57 +0600 Subject: [PATCH 2/2] MSSQL: select what is really needed from information_schema.columns, not just everything as it was before. --- framework/yii/db/mssql/Schema.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/yii/db/mssql/Schema.php b/framework/yii/db/mssql/Schema.php index c52dfc3..add6185 100644 --- a/framework/yii/db/mssql/Schema.php +++ b/framework/yii/db/mssql/Schema.php @@ -163,7 +163,7 @@ class Schema extends \yii\db\Schema $column->isPrimaryKey = null; // primary key will be determined in findColumns() method $column->autoIncrement = $info['IsIdentity'] == 1; $column->unsigned = stripos($column->dbType, 'unsigned') !== false; - $column->comment = $info['Comment'] === null ? '' : $column['Comment']; + $column->comment = $info['Comment'] === null ? '' : $info['Comment']; $column->type = self::TYPE_STRING; if (preg_match('/^(\w+)(?:\(([^\)]+)\))?/', $column->dbType, $matches)) { @@ -221,7 +221,7 @@ class Schema extends \yii\db\Schema $sql = <<