File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -418,8 +418,16 @@ private function buildForUpdate($query) {
418418 * @return string
419419 */
420420 private function buildTableName ($ alias , $ name ) {
421- $ name = rtrim (trim ($ name ), '; ' );
422- return sprintf ("(%s) %s " , $ name , $ alias );
421+ if (is_object ($ name )) {
422+ $ name = (string ) $ name ;
423+ $ lines = explode ("\n" , $ name );
424+ foreach ($ lines as &$ line ) {
425+ $ line = "\t{$ line }" ;
426+ }
427+ $ name = join ("\n" , $ lines );
428+ $ name = '( ' . trim (rtrim (trim ($ name ), '; ' )) . ') ' ;
429+ }
430+ return sprintf ("%s %s " , $ name , $ alias );
423431 }
424432
425433 /**
Original file line number Diff line number Diff line change @@ -132,4 +132,16 @@ public function testForUpdate() {
132132 ->asString ();
133133 $ this ->assertEquals ('SELECT a FROM test t FOR UPDATE ; ' , $ str );
134134 }
135+
136+ public function testInnerSelect () {
137+ $ select = TestSelect::create ()
138+ ->from ('a ' , 'table ' )
139+ ->where ('a.id=1 ' );
140+
141+ $ str = (string ) TestSelect::create ()
142+ ->from ('t ' , $ select )
143+ ->asString ();
144+
145+ $ this ->assertEquals ('SELECT * FROM (SELECT * FROM table a WHERE a.id=1) t ; ' , $ str );
146+ }
135147}
You can’t perform that action at this time.
0 commit comments