-
-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Selection::insert(): refactored new record fetch (BC break)
- Loading branch information
Showing
13 changed files
with
205 additions
and
57 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
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
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
/** | ||
* @dataProvider? ../../databases.ini | ||
*/ | ||
|
||
use Tester\Assert; | ||
|
||
require __DIR__ . '/../../connect.inc.php'; // create $connection | ||
|
||
Nette\Database\Helpers::loadFromFile($connection, __DIR__ . "/../../files/{$driverName}-nette_test4.sql"); | ||
|
||
//Insert into table without auto_increament primary key | ||
test(function () use ($context) { | ||
|
||
$inserted = $context->table('simple_pk')->insert([ | ||
'id' => 8, | ||
'name' => 'Michal' | ||
]); | ||
|
||
Assert::equal(8, $inserted->id); | ||
Assert::equal('Michal', $inserted->name); | ||
}); | ||
|
||
//Insert into table with composite primary key | ||
test(function () use ($context) { | ||
|
||
$inserted = $context->table('composite_pk')->insert([ | ||
'id1' => 8, | ||
'id2' => 10, | ||
'name' => 'Michal' | ||
]); | ||
|
||
Assert::equal(8, $inserted->id1); | ||
Assert::equal(10, $inserted->id2); | ||
Assert::equal('Michal', $inserted->name); | ||
}); | ||
|
||
//Insert into table with composite primary key and one of them is auto_increment | ||
test(function () use ($context, $driverName) { | ||
|
||
//Sqlite doesn't allow this type of table and sqlsrv's driver don't implement reflection | ||
if ($driverName == 'mysql' || $driverName == 'pgsql') { | ||
$inserted = $context->table('composite_pk_ai')->insert([ | ||
'id2' => 10, | ||
'name' => 'Michal' | ||
]); | ||
|
||
Assert::equal(10, $inserted->id2); | ||
Assert::equal('Michal', $inserted->name); | ||
} | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*!40102 SET storage_engine = InnoDB */; | ||
|
||
DROP DATABASE IF EXISTS nette_test; | ||
CREATE DATABASE nette_test; | ||
USE nette_test; | ||
|
||
|
||
CREATE TABLE simple_pk ( | ||
id int NOT NULL, | ||
name varchar(100), | ||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE composite_pk ( | ||
id1 int NOT NULL, | ||
id2 int NOT NULL, | ||
name varchar(100), | ||
PRIMARY KEY (id1, id2) | ||
); | ||
|
||
CREATE TABLE composite_pk_ai ( | ||
id1 int NOT NULL AUTO_INCREMENT, | ||
id2 int NOT NULL, | ||
name varchar(100), | ||
PRIMARY KEY (id1, id2) | ||
); |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
DROP SCHEMA IF EXISTS public CASCADE; | ||
CREATE SCHEMA public; | ||
|
||
CREATE TABLE simple_pk ( | ||
id int NOT NULL, | ||
name varchar(100), | ||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE composite_pk ( | ||
id1 int NOT NULL, | ||
id2 int NOT NULL, | ||
name varchar(100), | ||
PRIMARY KEY (id1, id2) | ||
); | ||
|
||
CREATE TABLE composite_pk_ai ( | ||
id1 serial NOT NULL, | ||
id2 int NOT NULL, | ||
name varchar(100), | ||
PRIMARY KEY (id1, id2) | ||
); |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
DROP TABLE IF EXISTS simple_pk; | ||
DROP TABLE IF EXISTS composite_pk; | ||
|
||
CREATE TABLE simple_pk ( | ||
id INT NOT NULL, | ||
name TEXT, | ||
PRIMARY KEY (id) | ||
); | ||
|
||
CREATE TABLE composite_pk ( | ||
id1 int NOT NULL, | ||
id2 int NOT NULL, | ||
name TEXT, | ||
PRIMARY KEY (id1, id2) | ||
); |
Oops, something went wrong.