"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "tests/framework/db/mssql/QueryBuilderTest.php" between
yii2-2.0.35.tar.gz and yii2-2.0.36.tar.gz

About: Yii 2 is a high-performance component-based PHP framework for developing large-scale Web applications (source).

QueryBuilderTest.php  (yii2-2.0.35):QueryBuilderTest.php  (yii2-2.0.36)
<?php <?php
/** /**
* @link http://www.yiiframework.com/ * @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC * @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/ * @license http://www.yiiframework.com/license/
*/ */
namespace yiiunit\framework\db\mssql; namespace yiiunit\framework\db\mssql;
use yii\db\Expression;
use yii\db\Query; use yii\db\Query;
use yiiunit\data\base\TraversableObject; use yiiunit\data\base\TraversableObject;
/** /**
* @group db * @group db
* @group mssql * @group mssql
*/ */
class QueryBuilderTest extends \yiiunit\framework\db\QueryBuilderTest class QueryBuilderTest extends \yiiunit\framework\db\QueryBuilderTest
{ {
public $driverName = 'sqlsrv'; public $driverName = 'sqlsrv';
skipping to change at line 265 skipping to change at line 266
{ {
$data = parent::batchInsertProvider(); $data = parent::batchInsertProvider();
$data['escape-danger-chars']['expected'] = "INSERT INTO [customer] ([add ress]) VALUES ('SQL-danger chars are escaped: ''); --')"; $data['escape-danger-chars']['expected'] = "INSERT INTO [customer] ([add ress]) VALUES ('SQL-danger chars are escaped: ''); --')";
$data['bool-false, bool2-null']['expected'] = 'INSERT INTO [type] ([bool _col], [bool_col2]) VALUES (0, NULL)'; $data['bool-false, bool2-null']['expected'] = 'INSERT INTO [type] ([bool _col], [bool_col2]) VALUES (0, NULL)';
$data['bool-false, time-now()']['expected'] = 'INSERT INTO {{%type}} ({{ %type}}.[[bool_col]], [[time]]) VALUES (0, now())'; $data['bool-false, time-now()']['expected'] = 'INSERT INTO {{%type}} ({{ %type}}.[[bool_col]], [[time]]) VALUES (0, now())';
return $data; return $data;
} }
public function insertProvider()
{
return [
'regular-values' => [
'customer',
[
'email' => 'test@example.com',
'name' => 'silverfire',
'address' => 'Kyiv {{city}}, Ukraine',
'is_active' => false,
'related_id' => null,
],
[],
$this->replaceQuotes('INSERT INTO [[customer]] ([[email]], [[nam
e]], [[address]], [[is_active]], [[related_id]]) OUTPUT INSERTED.* VALUES (:qp0,
:qp1, :qp2, :qp3, :qp4)'),
[
':qp0' => 'test@example.com',
':qp1' => 'silverfire',
':qp2' => 'Kyiv {{city}}, Ukraine',
':qp3' => false,
':qp4' => null,
],
],
'params-and-expressions' => [
'{{%type}}',
[
'{{%type}}.[[related_id]]' => null,
'[[time]]' => new Expression('now()'),
],
[],
'INSERT INTO {{%type}} ({{%type}}.[[related_id]], [[time]]) OUTP
UT INSERTED.* VALUES (:qp0, now())',
[
':qp0' => null,
],
],
'carry passed params' => [
'customer',
[
'email' => 'test@example.com',
'name' => 'sergeymakinen',
'address' => '{{city}}',
'is_active' => false,
'related_id' => null,
'col' => new Expression('CONCAT(:phFoo, :phBar)', [':phFoo'
=> 'foo']),
],
[':phBar' => 'bar'],
$this->replaceQuotes('INSERT INTO [[customer]] ([[email]], [[nam
e]], [[address]], [[is_active]], [[related_id]], [[col]]) OUTPUT INSERTED.* VALU
ES (:qp1, :qp2, :qp3, :qp4, :qp5, CONCAT(:phFoo, :phBar))'),
[
':phBar' => 'bar',
':qp1' => 'test@example.com',
':qp2' => 'sergeymakinen',
':qp3' => '{{city}}',
':qp4' => false,
':qp5' => null,
':phFoo' => 'foo',
],
],
'carry passed params (query)' => [
'customer',
(new Query())
->select([
'email',
'name',
'address',
'is_active',
'related_id',
])
->from('customer')
->where([
'email' => 'test@example.com',
'name' => 'sergeymakinen',
'address' => '{{city}}',
'is_active' => false,
'related_id' => null,
'col' => new Expression('CONCAT(:phFoo, :phBar)', [':phF
oo' => 'foo']),
]),
[':phBar' => 'bar'],
$this->replaceQuotes('INSERT INTO [[customer]] ([[email]], [[nam
e]], [[address]], [[is_active]], [[related_id]]) OUTPUT INSERTED.* SELECT [[emai
l]], [[name]], [[address]], [[is_active]], [[related_id]] FROM [[customer]] WHER
E ([[email]]=:qp1) AND ([[name]]=:qp2) AND ([[address]]=:qp3) AND ([[is_active]]
=:qp4) AND ([[related_id]] IS NULL) AND ([[col]]=CONCAT(:phFoo, :phBar))'),
[
':phBar' => 'bar',
':qp1' => 'test@example.com',
':qp2' => 'sergeymakinen',
':qp3' => '{{city}}',
':qp4' => false,
':phFoo' => 'foo',
],
],
];
}
public function testResetSequence() public function testResetSequence()
{ {
$qb = $this->getQueryBuilder(); $qb = $this->getQueryBuilder();
$expected = "DBCC CHECKIDENT ('[item]', RESEED, (SELECT COALESCE(MAX([id ]),0) FROM [item])+1)"; $expected = "DBCC CHECKIDENT ('[item]', RESEED, (SELECT COALESCE(MAX([id ]),0) FROM [item])+1)";
$sql = $qb->resetSequence('item'); $sql = $qb->resetSequence('item');
$this->assertEquals($expected, $sql); $this->assertEquals($expected, $sql);
$expected = "DBCC CHECKIDENT ('[item]', RESEED, 4)"; $expected = "DBCC CHECKIDENT ('[item]', RESEED, 4)";
$sql = $qb->resetSequence('item', 4); $sql = $qb->resetSequence('item', 4);
skipping to change at line 300 skipping to change at line 390
'query' => [ 'query' => [
3 => 'MERGE [T_upsert] WITH (HOLDLOCK) USING (SELECT [email], 2 AS [status] FROM [customer] WHERE [name]=:qp0 ORDER BY (SELECT NULL) OFFSET 0 RO WS FETCH NEXT 1 ROWS ONLY) AS [EXCLUDED] ([email], [status]) ON ([T_upsert].[ema il]=[EXCLUDED].[email]) WHEN MATCHED THEN UPDATE SET [status]=[EXCLUDED].[status ] WHEN NOT MATCHED THEN INSERT ([email], [status]) VALUES ([EXCLUDED].[email], [ EXCLUDED].[status]);', 3 => 'MERGE [T_upsert] WITH (HOLDLOCK) USING (SELECT [email], 2 AS [status] FROM [customer] WHERE [name]=:qp0 ORDER BY (SELECT NULL) OFFSET 0 RO WS FETCH NEXT 1 ROWS ONLY) AS [EXCLUDED] ([email], [status]) ON ([T_upsert].[ema il]=[EXCLUDED].[email]) WHEN MATCHED THEN UPDATE SET [status]=[EXCLUDED].[status ] WHEN NOT MATCHED THEN INSERT ([email], [status]) VALUES ([EXCLUDED].[email], [ EXCLUDED].[status]);',
], ],
'query with update part' => [ 'query with update part' => [
3 => 'MERGE [T_upsert] WITH (HOLDLOCK) USING (SELECT [email], 2 AS [status] FROM [customer] WHERE [name]=:qp0 ORDER BY (SELECT NULL) OFFSET 0 RO WS FETCH NEXT 1 ROWS ONLY) AS [EXCLUDED] ([email], [status]) ON ([T_upsert].[ema il]=[EXCLUDED].[email]) WHEN MATCHED THEN UPDATE SET [address]=:qp1, [status]=:q p2, [orders]=T_upsert.orders + 1 WHEN NOT MATCHED THEN INSERT ([email], [status] ) VALUES ([EXCLUDED].[email], [EXCLUDED].[status]);', 3 => 'MERGE [T_upsert] WITH (HOLDLOCK) USING (SELECT [email], 2 AS [status] FROM [customer] WHERE [name]=:qp0 ORDER BY (SELECT NULL) OFFSET 0 RO WS FETCH NEXT 1 ROWS ONLY) AS [EXCLUDED] ([email], [status]) ON ([T_upsert].[ema il]=[EXCLUDED].[email]) WHEN MATCHED THEN UPDATE SET [address]=:qp1, [status]=:q p2, [orders]=T_upsert.orders + 1 WHEN NOT MATCHED THEN INSERT ([email], [status] ) VALUES ([EXCLUDED].[email], [EXCLUDED].[status]);',
], ],
'query without update part' => [ 'query without update part' => [
3 => 'MERGE [T_upsert] WITH (HOLDLOCK) USING (SELECT [email], 2 AS [status] FROM [customer] WHERE [name]=:qp0 ORDER BY (SELECT NULL) OFFSET 0 RO WS FETCH NEXT 1 ROWS ONLY) AS [EXCLUDED] ([email], [status]) ON ([T_upsert].[ema il]=[EXCLUDED].[email]) WHEN NOT MATCHED THEN INSERT ([email], [status]) VALUES ([EXCLUDED].[email], [EXCLUDED].[status]);', 3 => 'MERGE [T_upsert] WITH (HOLDLOCK) USING (SELECT [email], 2 AS [status] FROM [customer] WHERE [name]=:qp0 ORDER BY (SELECT NULL) OFFSET 0 RO WS FETCH NEXT 1 ROWS ONLY) AS [EXCLUDED] ([email], [status]) ON ([T_upsert].[ema il]=[EXCLUDED].[email]) WHEN NOT MATCHED THEN INSERT ([email], [status]) VALUES ([EXCLUDED].[email], [EXCLUDED].[status]);',
], ],
'values and expressions' => [ 'values and expressions' => [
3 => 'INSERT INTO {{%T_upsert}} ({{%T_upsert}}.[[email]], [[ts]] ) VALUES (:qp0, now())', 3 => 'INSERT INTO {{%T_upsert}} ({{%T_upsert}}.[[email]], [[ts]] ) OUTPUT INSERTED.* VALUES (:qp0, now())',
], ],
'values and expressions with update part' => [ 'values and expressions with update part' => [
3 => 'INSERT INTO {{%T_upsert}} ({{%T_upsert}}.[[email]], [[ts]] ) VALUES (:qp0, now())', 3 => 'INSERT INTO {{%T_upsert}} ({{%T_upsert}}.[[email]], [[ts]] ) OUTPUT INSERTED.* VALUES (:qp0, now())',
], ],
'values and expressions without update part' => [ 'values and expressions without update part' => [
3 => 'INSERT INTO {{%T_upsert}} ({{%T_upsert}}.[[email]], [[ts]] ) VALUES (:qp0, now())', 3 => 'INSERT INTO {{%T_upsert}} ({{%T_upsert}}.[[email]], [[ts]] ) OUTPUT INSERTED.* VALUES (:qp0, now())',
], ],
'query, values and expressions with update part' => [ 'query, values and expressions with update part' => [
3 => 'MERGE {{%T_upsert}} WITH (HOLDLOCK) USING (SELECT :phEmail AS [email], now() AS [[time]]) AS [EXCLUDED] ([email], [[time]]) ON ({{%T_upser t}}.[email]=[EXCLUDED].[email]) WHEN MATCHED THEN UPDATE SET [ts]=:qp1, [[orders ]]=T_upsert.orders + 1 WHEN NOT MATCHED THEN INSERT ([email], [[time]]) VALUES ( [EXCLUDED].[email], [EXCLUDED].[[time]]);', 3 => 'MERGE {{%T_upsert}} WITH (HOLDLOCK) USING (SELECT :phEmail AS [email], now() AS [[time]]) AS [EXCLUDED] ([email], [[time]]) ON ({{%T_upser t}}.[email]=[EXCLUDED].[email]) WHEN MATCHED THEN UPDATE SET [ts]=:qp1, [[orders ]]=T_upsert.orders + 1 WHEN NOT MATCHED THEN INSERT ([email], [[time]]) VALUES ( [EXCLUDED].[email], [EXCLUDED].[[time]]);',
], ],
'query, values and expressions without update part' => [ 'query, values and expressions without update part' => [
3 => 'MERGE {{%T_upsert}} WITH (HOLDLOCK) USING (SELECT :phEmail AS [email], now() AS [[time]]) AS [EXCLUDED] ([email], [[time]]) ON ({{%T_upser t}}.[email]=[EXCLUDED].[email]) WHEN MATCHED THEN UPDATE SET [ts]=:qp1, [[orders ]]=T_upsert.orders + 1 WHEN NOT MATCHED THEN INSERT ([email], [[time]]) VALUES ( [EXCLUDED].[email], [EXCLUDED].[[time]]);', 3 => 'MERGE {{%T_upsert}} WITH (HOLDLOCK) USING (SELECT :phEmail AS [email], now() AS [[time]]) AS [EXCLUDED] ([email], [[time]]) ON ({{%T_upser t}}.[email]=[EXCLUDED].[email]) WHEN MATCHED THEN UPDATE SET [ts]=:qp1, [[orders ]]=T_upsert.orders + 1 WHEN NOT MATCHED THEN INSERT ([email], [[time]]) VALUES ( [EXCLUDED].[email], [EXCLUDED].[[time]]);',
], ],
'no columns to update' => [ 'no columns to update' => [
3 => 'MERGE [T_upsert_1] WITH (HOLDLOCK) USING (VALUES (:qp0)) A S [EXCLUDED] ([a]) ON ([T_upsert_1].[a]=[EXCLUDED].[a]) WHEN NOT MATCHED THEN IN SERT ([a]) VALUES ([EXCLUDED].[a]);', 3 => 'MERGE [T_upsert_1] WITH (HOLDLOCK) USING (VALUES (:qp0)) A S [EXCLUDED] ([a]) ON ([T_upsert_1].[a]=[EXCLUDED].[a]) WHEN NOT MATCHED THEN IN SERT ([a]) VALUES ([EXCLUDED].[a]);',
], ],
 End of changes. 5 change blocks. 
3 lines changed or deleted 104 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)