-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix
DMLQueryBuilder::insertWithReturningPks()
- Loading branch information
Showing
6 changed files
with
54 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,31 +127,6 @@ public function testInsertVarbinary(mixed $expectedData, mixed $testData): void | |
$this->assertSame($expectedData, $resultData['blob_col']); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
* @throws InvalidCallException | ||
* @throws InvalidConfigException | ||
* @throws Throwable | ||
*/ | ||
public function testInsertWithReturningPks(): void | ||
{ | ||
$db = $this->getConnection(true); | ||
|
||
$command = $db->createCommand(); | ||
|
||
$this->assertSame( | ||
[ | ||
'id' => '4', | ||
'email' => '[email protected]', | ||
'name' => 'test_1', | ||
'address' => null, | ||
'status' => '0', | ||
'profile_id' => null, | ||
], | ||
$command->insertWithReturningPks('{{customer}}', ['name' => 'test_1', 'email' => '[email protected]']), | ||
); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
* @throws InvalidCallException | ||
|
@@ -189,9 +164,7 @@ public function testInsertWithReturningPksWithComputedColumn(): void | |
$result = $command->insertWithReturningPks('{{test_trigger}}', ['stringcol' => $insertedString]); | ||
$transaction->commit(); | ||
|
||
$this->assertIsArray($result); | ||
$this->assertSame($insertedString, $result['stringcol']); | ||
$this->assertSame('1', $result['id']); | ||
$this->assertSame(['id' => '1'], $result); | ||
} | ||
|
||
/** | ||
|
@@ -213,9 +186,7 @@ public function testInsertWithReturningPksWithRowVersionColumn(): void | |
$insertedString = 'test'; | ||
$result = $command->insertWithReturningPks('{{test_trigger}}', ['stringcol' => $insertedString]); | ||
|
||
$this->assertIsArray($result); | ||
$this->assertSame($insertedString, $result['stringcol']); | ||
$this->assertSame('1', $result['id']); | ||
$this->assertSame(['id' => '1'], $result); | ||
} | ||
|
||
/** | ||
|
@@ -240,9 +211,7 @@ public function testInsertWithReturningPksWithRowVersionNullColumn(): void | |
['stringcol' => $insertedString, 'RV' => new Expression('DEFAULT')], | ||
); | ||
|
||
$this->assertIsArray($result); | ||
$this->assertSame($insertedString, $result['stringcol']); | ||
$this->assertSame('1', $result['id']); | ||
$this->assertSame(['id' => '1'], $result); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,7 +113,7 @@ public static function insertWithReturningPks(): array | |
], | ||
[], | ||
<<<SQL | ||
SET NOCOUNT ON;DECLARE @temporary_inserted TABLE ([id] int , [email] varchar(128) , [name] varchar(128) NULL, [address] text NULL, [status] int NULL, [profile_id] int NULL);INSERT INTO [customer] ([email], [name], [address], [is_active], [related_id]) OUTPUT INSERTED.[id],INSERTED.[email],INSERTED.[name],INSERTED.[address],INSERTED.[status],INSERTED.[profile_id] INTO @temporary_inserted VALUES (:qp0, :qp1, :qp2, :qp3, :qp4);SELECT * FROM @temporary_inserted; | ||
INSERT INTO [customer] ([email], [name], [address], [is_active], [related_id]) OUTPUT INSERTED.[id] VALUES (:qp0, :qp1, :qp2, :qp3, :qp4) | ||
SQL, | ||
[ | ||
':qp0' => '[email protected]', | ||
|
@@ -128,7 +128,7 @@ public static function insertWithReturningPks(): array | |
['{{%type}}.[[related_id]]' => null, '[[time]]' => new Expression('now()')], | ||
[], | ||
<<<SQL | ||
SET NOCOUNT ON;DECLARE @temporary_inserted TABLE ([int_col] int , [int_col2] int NULL, [tinyint_col] tinyint NULL, [smallint_col] smallint NULL, [char_col] char(100) , [char_col2] varchar(100) NULL, [char_col3] text NULL, [float_col] decimal(4,3) , [float_col2] float NULL, [blob_col] varbinary(MAX) NULL, [numeric_col] decimal(5,2) NULL, [datetime_col] datetime , [bool_col] bit , [bool_col2] bit NULL);INSERT INTO {{%type}} ([related_id], [time]) OUTPUT INSERTED.[int_col],INSERTED.[int_col2],INSERTED.[tinyint_col],INSERTED.[smallint_col],INSERTED.[char_col],INSERTED.[char_col2],INSERTED.[char_col3],INSERTED.[float_col],INSERTED.[float_col2],INSERTED.[blob_col],INSERTED.[numeric_col],INSERTED.[datetime_col],INSERTED.[bool_col],INSERTED.[bool_col2] INTO @temporary_inserted VALUES (:qp0, now());SELECT * FROM @temporary_inserted; | ||
INSERT INTO {{%type}} ([related_id], [time]) VALUES (:qp0, now()) | ||
SQL, | ||
[':qp0' => null], | ||
], | ||
|
@@ -144,7 +144,7 @@ public static function insertWithReturningPks(): array | |
], | ||
[':phBar' => 'bar'], | ||
<<<SQL | ||
SET NOCOUNT ON;DECLARE @temporary_inserted TABLE ([id] int , [email] varchar(128) , [name] varchar(128) NULL, [address] text NULL, [status] int NULL, [profile_id] int NULL);INSERT INTO [customer] ([email], [name], [address], [is_active], [related_id], [col]) OUTPUT INSERTED.[id],INSERTED.[email],INSERTED.[name],INSERTED.[address],INSERTED.[status],INSERTED.[profile_id] INTO @temporary_inserted VALUES (:qp1, :qp2, :qp3, :qp4, :qp5, CONCAT(:phFoo, :phBar));SELECT * FROM @temporary_inserted; | ||
INSERT INTO [customer] ([email], [name], [address], [is_active], [related_id], [col]) OUTPUT INSERTED.[id] VALUES (:qp1, :qp2, :qp3, :qp4, :qp5, CONCAT(:phFoo, :phBar)) | ||
SQL, | ||
[ | ||
':phBar' => 'bar', | ||
|
@@ -173,7 +173,7 @@ public static function insertWithReturningPks(): array | |
), | ||
[':phBar' => 'bar'], | ||
<<<SQL | ||
SET NOCOUNT ON;DECLARE @temporary_inserted TABLE ([id] int , [email] varchar(128) , [name] varchar(128) NULL, [address] text NULL, [status] int NULL, [profile_id] int NULL);INSERT INTO [customer] ([email], [name], [address], [is_active], [related_id]) OUTPUT INSERTED.[id],INSERTED.[email],INSERTED.[name],INSERTED.[address],INSERTED.[status],INSERTED.[profile_id] INTO @temporary_inserted SELECT [email], [name], [address], [is_active], [related_id] FROM [customer] WHERE ([email]=:qp1) AND ([name]=:qp2) AND ([address]=:qp3) AND ([is_active]=:qp4) AND ([related_id] IS NULL) AND ([col]=CONCAT(:phFoo, :phBar));SELECT * FROM @temporary_inserted; | ||
INSERT INTO [customer] ([email], [name], [address], [is_active], [related_id]) OUTPUT INSERTED.[id] SELECT [email], [name], [address], [is_active], [related_id] FROM [customer] WHERE ([email]=:qp1) AND ([name]=:qp2) AND ([address]=:qp3) AND ([is_active]=:qp4) AND ([related_id] IS NULL) AND ([col]=CONCAT(:phFoo, :phBar)) | ||
SQL, | ||
[ | ||
':phBar' => 'bar', | ||
|
@@ -189,7 +189,7 @@ public static function insertWithReturningPks(): array | |
['order_id' => 1, 'item_id' => 1, 'quantity' => 1, 'subtotal' => 1.0], | ||
[], | ||
<<<SQL | ||
SET NOCOUNT ON;DECLARE @temporary_inserted TABLE ([order_id] int , [item_id] int , [quantity] int , [subtotal] decimal(10,0) );INSERT INTO {{%order_item}} ([order_id], [item_id], [quantity], [subtotal]) OUTPUT INSERTED.[order_id],INSERTED.[item_id],INSERTED.[quantity],INSERTED.[subtotal] INTO @temporary_inserted VALUES (:qp0, :qp1, :qp2, :qp3);SELECT * FROM @temporary_inserted; | ||
INSERT INTO {{%order_item}} ([order_id], [item_id], [quantity], [subtotal]) OUTPUT INSERTED.[item_id], INSERTED.[order_id] VALUES (:qp0, :qp1, :qp2, :qp3) | ||
SQL, | ||
[':qp0' => 1, ':qp1' => 1, ':qp2' => 1, ':qp3' => 1.0,], | ||
], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters