File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed
tests/Database/Table/bugs Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -486,8 +486,8 @@ protected function execute()
486486 foreach ($ result ->getPdoStatement () as $ key => $ row ) {
487487 $ row = $ this ->createRow ($ result ->normalizeRow ($ row ));
488488 $ primary = $ row ->getSignature (FALSE );
489- $ usedPrimary = $ usedPrimary && $ primary ;
490- $ this ->rows [$ primary ? : $ key ] = $ row ;
489+ $ usedPrimary = $ usedPrimary && ( string ) $ primary !== '' ;
490+ $ this ->rows [$ usedPrimary ? $ primary : $ key ] = $ row ;
491491 }
492492 $ this ->data = $ this ->rows ;
493493
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /**
4+ * Test: Zero Primary key bug
5+ * @dataProvider? ../../databases.ini mysql
6+ */
7+
8+ use Tester \Assert ;
9+
10+ require __DIR__ . '/../../connect.inc.php ' ;
11+
12+ $ context ->query ('CREATE DATABASE IF NOT EXISTS nette_test ' );
13+ $ context ->query ('USE nette_test ' );
14+
15+ $ context ->query ('
16+ CREATE TABLE ships (
17+ id INTEGER PRIMARY KEY NOT NULL,
18+ name TEXT NOT NULL
19+ );
20+ ' );
21+
22+ $ context ->query ('
23+ INSERT INTO ships (id, name) VALUES(2, "Enterprise");
24+ ' );
25+
26+ $ context ->query ('
27+ INSERT INTO ships (id, name) VALUES(0, "Endeavour");
28+ ' );
29+
30+ Assert::same (2 , $ context ->table ('ships ' )->order ('id DESC ' )->count ());
31+
32+ $ result = $ context ->table ('ships ' )->order ('id DESC ' )->fetchAll (); // SELECT * FROM `ships` ORDER BY id DESC
33+
34+ Assert::same ("Enterprise " , $ result [2 ]->name );
35+
36+ Assert::same ("Endeavour " , $ result [0 ]->name );
You can’t perform that action at this time.
0 commit comments