You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
94 lines
3.4 KiB
94 lines
3.4 KiB
12 years ago
|
<?php
|
||
|
|
||
|
namespace yiiunit\framework\db\mssql;
|
||
|
|
||
9 years ago
|
use yii\db\Schema;
|
||
12 years ago
|
|
||
11 years ago
|
/**
|
||
|
* @group db
|
||
|
* @group mssql
|
||
|
*/
|
||
8 years ago
|
class CommandTest extends \yiiunit\framework\db\CommandTest
|
||
12 years ago
|
{
|
||
11 years ago
|
protected $driverName = 'sqlsrv';
|
||
12 years ago
|
|
||
11 years ago
|
public function testAutoQuoting()
|
||
|
{
|
||
|
$db = $this->getConnection(false);
|
||
12 years ago
|
|
||
11 years ago
|
$sql = 'SELECT [[id]], [[t.name]] FROM {{customer}} t';
|
||
11 years ago
|
$command = $db->createCommand($sql);
|
||
11 years ago
|
$this->assertEquals("SELECT [id], [t].[name] FROM [customer] t", $command->sql);
|
||
11 years ago
|
}
|
||
12 years ago
|
|
||
11 years ago
|
public function testPrepareCancel()
|
||
|
{
|
||
|
$this->markTestSkipped('MSSQL driver does not support this feature.');
|
||
|
}
|
||
12 years ago
|
|
||
11 years ago
|
public function testBindParamValue()
|
||
|
{
|
||
|
$db = $this->getConnection();
|
||
12 years ago
|
|
||
11 years ago
|
// bindParam
|
||
11 years ago
|
$sql = 'INSERT INTO customer(email, name, address) VALUES (:email, :name, :address)';
|
||
11 years ago
|
$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();
|
||
12 years ago
|
|
||
11 years ago
|
$sql = 'SELECT name FROM customer WHERE email=:email';
|
||
11 years ago
|
$command = $db->createCommand($sql);
|
||
|
$command->bindParam(':email', $email);
|
||
|
$this->assertEquals($name, $command->queryScalar());
|
||
12 years ago
|
|
||
11 years ago
|
$sql = 'INSERT INTO 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)';
|
||
11 years ago
|
$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());
|
||
12 years ago
|
|
||
11 years ago
|
$sql = 'SELECT int_col, char_col, float_col, CONVERT([nvarchar], blob_col) AS blob_col, numeric_col FROM type';
|
||
11 years ago
|
$row = $db->createCommand($sql)->queryOne();
|
||
|
$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']);
|
||
12 years ago
|
|
||
11 years ago
|
// bindValue
|
||
11 years ago
|
$sql = 'INSERT INTO customer(email, name, address) VALUES (:email, \'user5\', \'address5\')';
|
||
11 years ago
|
$command = $db->createCommand($sql);
|
||
|
$command->bindValue(':email', 'user5@example.com');
|
||
|
$command->execute();
|
||
12 years ago
|
|
||
11 years ago
|
$sql = 'SELECT email FROM customer WHERE name=:name';
|
||
11 years ago
|
$command = $db->createCommand($sql);
|
||
|
$command->bindValue(':name', 'user5');
|
||
|
$this->assertEquals('user5@example.com', $command->queryScalar());
|
||
|
}
|
||
9 years ago
|
|
||
|
public function paramsNonWhereProvider()
|
||
|
{
|
||
|
return[
|
||
|
['SELECT SUBSTRING(name, :len, 6) AS name FROM {{customer}} WHERE [[email]] = :email GROUP BY name'],
|
||
|
['SELECT SUBSTRING(name, :len, 6) as name FROM {{customer}} WHERE [[email]] = :email ORDER BY name'],
|
||
|
['SELECT SUBSTRING(name, :len, 6) FROM {{customer}} WHERE [[email]] = :email'],
|
||
|
];
|
||
|
}
|
||
12 years ago
|
}
|