-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: added test for getInsertId() WIP
- Loading branch information
Showing
4 changed files
with
244 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Database\Connection::getInsertId() | ||
* @dataProvider? databases.ini mysql | ||
*/ | ||
|
||
use Tester\Assert; | ||
use Nette\Utils\DateTime; | ||
|
||
require __DIR__ . '/connect.inc.php'; // create $connection | ||
|
||
$connection->query('CREATE DATABASE IF NOT EXISTS nette_test'); | ||
$connection->query('USE nette_test'); | ||
|
||
$connection->query(' | ||
CREATE TEMPORARY TABLE noprimarykey ( | ||
col int | ||
) ENGINE=InnoDB | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO noprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('0', $connection->getInsertId()); | ||
|
||
$res = $connection->query('INSERT INTO noprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('0', $connection->getInsertId()); | ||
|
||
|
||
$connection->query(' | ||
CREATE TEMPORARY TABLE primarykey ( | ||
prim int NOT NULL, | ||
PRIMARY KEY(prim) | ||
) ENGINE=InnoDB | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO primarykey (prim) VALUES (5)'); | ||
Assert::equal('0', $connection->getInsertId()); | ||
|
||
$res = $connection->query('INSERT INTO primarykey (prim) VALUES (6)'); | ||
Assert::equal('0', $connection->getInsertId()); | ||
|
||
|
||
$connection->query(' | ||
CREATE TEMPORARY TABLE autoprimarykey ( | ||
prim int NOT NULL AUTO_INCREMENT, | ||
col int, | ||
PRIMARY KEY(prim) | ||
) ENGINE=InnoDB | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('1', $connection->getInsertId()); | ||
|
||
$res = $connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('2', $connection->getInsertId()); | ||
|
||
|
||
$connection->query(' | ||
CREATE TEMPORARY TABLE multiautoprimarykey ( | ||
prim1 int NOT NULL AUTO_INCREMENT, | ||
prim2 int NOT NULL, | ||
PRIMARY KEY(prim1, prim2) | ||
) ENGINE=InnoDB | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO multiautoprimarykey (prim2) VALUES (3)'); | ||
Assert::equal('1', $connection->getInsertId()); | ||
|
||
$res = $connection->query('INSERT INTO multiautoprimarykey (prim2) VALUES (3)'); | ||
Assert::equal('2', $connection->getInsertId()); |
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,55 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Database\Connection::getInsertId() | ||
* @dataProvider? databases.ini postgresql | ||
*/ | ||
|
||
use Tester\Assert; | ||
use Nette\Utils\DateTime; | ||
|
||
require __DIR__ . '/connect.inc.php'; // create $connection | ||
|
||
|
||
$connection->query(' | ||
CREATE TEMPORARY TABLE "primarykey" ( | ||
prim int NOT NULL, | ||
PRIMARY KEY(prim) | ||
) | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO primarykey (prim) VALUES (5)'); | ||
Assert::equal(PHP_VERSION_ID < 70011 ? FALSE : '0', $connection->getInsertId()); | ||
|
||
$res = $connection->query('INSERT INTO primarykey (prim) VALUES (6)'); | ||
Assert::equal(PHP_VERSION_ID < 70011 ? FALSE : '0', $connection->getInsertId()); | ||
|
||
|
||
$connection->query(' | ||
CREATE TEMPORARY TABLE "autoprimarykey" ( | ||
prim serial NOT NULL, | ||
col int, | ||
PRIMARY KEY(prim) | ||
) | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('1', $connection->getInsertId('autoprimarykey_prim_seq')); | ||
|
||
$res = $connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('2', $connection->getInsertId('autoprimarykey_prim_seq')); | ||
|
||
|
||
$connection->query(' | ||
CREATE TEMPORARY TABLE "multiautoprimarykey" ( | ||
prim1 serial NOT NULL, | ||
prim2 int NOT NULL, | ||
PRIMARY KEY(prim1, prim2) | ||
); | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO multiautoprimarykey (prim2) VALUES (3)'); | ||
Assert::equal('1', $connection->getInsertId('multiautoprimarykey_prim1_seq')); | ||
|
||
$res = $connection->query('INSERT INTO multiautoprimarykey (prim2) VALUES (3)'); | ||
Assert::equal('2', $connection->getInsertId('multiautoprimarykey_prim1_seq')); |
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 | ||
|
||
/** | ||
* Test: Nette\Database\Connection::getInsertId() | ||
* @dataProvider? databases.ini sqlite | ||
*/ | ||
|
||
use Tester\Assert; | ||
use Nette\Utils\DateTime; | ||
|
||
require __DIR__ . '/connect.inc.php'; // create $connection | ||
|
||
|
||
$connection->query(' | ||
CREATE TABLE [noprimarykey] ( | ||
[col] INTEGER | ||
) | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO noprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('1', $connection->getInsertId()); | ||
|
||
$res = $connection->query('INSERT INTO noprimarykey (col) VALUES (3)'); | ||
Assert::equal('2', $connection->getInsertId()); | ||
|
||
|
||
$connection->query(' | ||
CREATE TABLE [primarykey] ( | ||
[prim] INTEGER PRIMARY KEY NOT NULL | ||
) | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO primarykey (prim) VALUES (5)'); | ||
Assert::equal('5', $connection->getInsertId()); | ||
|
||
$res = $connection->query('INSERT INTO primarykey (prim) VALUES (6)'); | ||
Assert::equal('6', $connection->getInsertId()); | ||
|
||
|
||
$connection->query(' | ||
CREATE TABLE [autoprimarykey] ( | ||
[prim] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, | ||
[col] INTEGER | ||
) | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('1', $connection->getInsertId()); | ||
|
||
$res = $connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('2', $connection->getInsertId()); |
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,68 @@ | ||
<?php | ||
|
||
/** | ||
* Test: Nette\Database\Connection::getInsertId() | ||
* @dataProvider? databases.ini sqlsrv | ||
*/ | ||
|
||
use Tester\Assert; | ||
use Nette\Utils\DateTime; | ||
|
||
require __DIR__ . '/connect.inc.php'; // create $connection | ||
|
||
|
||
$connection->query(' | ||
CREATE TEMPORARY TABLE [noprimarykey] ( | ||
col int | ||
) | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO noprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('1', $connection->getInsertId()); | ||
|
||
$res = $connection->query('INSERT INTO noprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('2', $connection->getInsertId()); | ||
|
||
|
||
$connection->query(' | ||
CREATE TEMPORARY TABLE [primarykey] ( | ||
prim int NOT NULL, | ||
PRIMARY KEY(prim) | ||
) | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO primarykey (prim) VALUES (5)'); | ||
Assert::equal('5', $connection->getInsertId()); | ||
|
||
$res = $connection->query('INSERT INTO primarykey (prim) VALUES (6)'); | ||
Assert::equal('6', $connection->getInsertId()); | ||
|
||
|
||
$connection->query(' | ||
CREATE TEMPORARY TABLE [autoprimarykey] ( | ||
prim int NOT NULL IDENTITY(1,1), | ||
col int, | ||
PRIMARY KEY(prim) | ||
) | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('1', $connection->getInsertId()); | ||
|
||
$res = $connection->query('INSERT INTO autoprimarykey (col) VALUES (NULL)'); | ||
Assert::equal('2', $connection->getInsertId()); | ||
|
||
|
||
$connection->query(' | ||
CREATE TEMPORARY TABLE [multiautoprimarykey] ( | ||
prim1 int NOT NULL IDENTITY(1,1), | ||
prim2 int NOT NULL, | ||
PRIMARY KEY(prim1, prim2) | ||
) | ||
'); | ||
|
||
$res = $connection->query('INSERT INTO multiautoprimarykey (prim2) VALUES (3)'); | ||
Assert::equal('1', $connection->getInsertId()); | ||
|
||
$res = $connection->query('INSERT INTO multiautoprimarykey (prim2) VALUES (3)'); | ||
Assert::equal('2', $connection->getInsertId()); |