File tree Expand file tree Collapse file tree 4 files changed +16
-7
lines changed Expand file tree Collapse file tree 4 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -47,10 +47,6 @@ public function getColumns($table)
4747 $ this ->needStructure ();
4848 $ table = $ this ->resolveFQTableName ($ table );
4949
50- if (!isset ($ this ->structure ['columns ' ][$ table ])) {
51- throw new Nette \InvalidArgumentException ("Table ' $ table' does not exist. " );
52- }
53-
5450 return $ this ->structure ['columns ' ][$ table ];
5551 }
5652
@@ -141,7 +137,6 @@ public function rebuild()
141137 {
142138 $ this ->structure = $ this ->loadStructure ();
143139 $ this ->cache ->save ('structure ' , $ this ->structure );
144- $ this ->isRebuilt = TRUE ;
145140 }
146141
147142
@@ -196,6 +191,8 @@ public function loadStructure()
196191 }
197192 }
198193
194+ $ this ->isRebuilt = TRUE ;
195+
199196 return $ structure ;
200197 }
201198
@@ -245,7 +242,12 @@ protected function resolveFQTableName($table)
245242 return $ this ->structure ['aliases ' ][$ name ];
246243 }
247244
248- return $ name ;
245+ if (!$ this ->isRebuilt ()) {
246+ $ this ->rebuild ();
247+ return $ this ->resolveFQTableName ($ table );
248+ }
249+
250+ throw new Nette \InvalidArgumentException ("Table ' $ name' does not exist. " );
249251 }
250252
251253}
Original file line number Diff line number Diff line change @@ -122,7 +122,9 @@ class StructureTestCase extends TestCase
122122 {
123123 Assert::same ('id ' , $ this ->structure ->getPrimaryKey ('books ' ));
124124 Assert::same (['book_id ' , 'tag_id ' ], $ this ->structure ->getPrimaryKey ('Books_x_tags ' ));
125- Assert::null ($ this ->structure ->getPrimaryKey ('invalid ' ));
125+ Assert::exception (function () {
126+ $ this ->structure ->getPrimaryKey ('invalid ' );
127+ }, 'Nette\InvalidArgumentException ' , "Table 'invalid' does not exist. " );
126128 }
127129
128130
Original file line number Diff line number Diff line change @@ -22,4 +22,8 @@ test(function () use ($context) {
2222 'title ' => '1001 tipu a triku pro PHP ' ,
2323 'next_volume ' => NULL ,
2424 ], $ book ->toArray ());
25+
26+ Assert::exception (function () use ($ context ){
27+ $ context ->table ('not_existing_table ' )->get (1 );
28+ }, 'Nette\InvalidArgumentException ' , "Table 'not_existing_table' does not exist. " );
2529});
Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ require __DIR__ . '/../../connect.inc.php';
1111
1212$ context ->query ('CREATE DATABASE IF NOT EXISTS nette_test ' );
1313$ context ->query ('USE nette_test ' );
14+ $ context ->query ('CREATE TABLE `TABLE 30` (id int) ' );
1415
1516Assert::same (
1617 reformat ('SELECT * FROM `TABLE 30` ' ),
You can’t perform that action at this time.
0 commit comments