@@ -1402,9 +1402,9 @@ public function getOffsetLimit(int $offset, int $limit): String
14021402 return '' ;
14031403 }
14041404 switch ($ this ->driver ) {
1405- case 'mysql ' :return "LIMIT $ offset, $ limit " ;
1406- case 'pgsql ' :return "LIMIT $ limit OFFSET $ offset " ;
1407- case 'sqlsrv ' :return "OFFSET $ offset ROWS FETCH NEXT $ limit ROWS ONLY " ;
1405+ case 'mysql ' :return " LIMIT $ offset, $ limit " ;
1406+ case 'pgsql ' :return " LIMIT $ limit OFFSET $ offset " ;
1407+ case 'sqlsrv ' :return " OFFSET $ offset ROWS FETCH NEXT $ limit ROWS ONLY " ;
14081408 }
14091409 }
14101410
@@ -1415,13 +1415,16 @@ private function quoteColumnName(ReflectedColumn $column): String
14151415
14161416 public function getOrderBy (ReflectedTable $ table , array $ columnOrdering ): String
14171417 {
1418+ if (count ($ columnOrdering )==0 ) {
1419+ return '' ;
1420+ }
14181421 $ results = array ();
14191422 foreach ($ columnOrdering as $ i => list ($ columnName , $ ordering )) {
14201423 $ column = $ table ->getColumn ($ columnName );
14211424 $ quotedColumnName = $ this ->quoteColumnName ($ column );
14221425 $ results [] = $ quotedColumnName . ' ' . $ ordering ;
14231426 }
1424- return implode (', ' , $ results );
1427+ return ' ORDER BY ' . implode (', ' , $ results );
14251428 }
14261429
14271430 public function getSelect (ReflectedTable $ table , array $ columnNames ): String
@@ -1941,20 +1944,6 @@ public function selectCount(ReflectedTable $table, Condition $condition): int
19411944 return $ stmt ->fetchColumn (0 );
19421945 }
19431946
1944- public function selectAllUnordered (ReflectedTable $ table , array $ columnNames , Condition $ condition ): array
1945- {
1946- $ selectColumns = $ this ->columns ->getSelect ($ table , $ columnNames );
1947- $ tableName = $ table ->getName ();
1948- $ condition = $ this ->addMiddlewareConditions ($ tableName , $ condition );
1949- $ parameters = array ();
1950- $ whereClause = $ this ->conditions ->getWhereClause ($ condition , $ parameters );
1951- $ sql = 'SELECT ' . $ selectColumns . ' FROM " ' . $ tableName . '" ' . $ whereClause ;
1952- $ stmt = $ this ->query ($ sql , $ parameters );
1953- $ records = $ stmt ->fetchAll ();
1954- $ this ->converter ->convertRecords ($ table , $ columnNames , $ records );
1955- return $ records ;
1956- }
1957-
19581947 public function selectAll (ReflectedTable $ table , array $ columnNames , Condition $ condition , array $ columnOrdering , int $ offset , int $ limit ): array
19591948 {
19601949 if ($ limit == 0 ) {
@@ -1967,7 +1956,7 @@ public function selectAll(ReflectedTable $table, array $columnNames, Condition $
19671956 $ whereClause = $ this ->conditions ->getWhereClause ($ condition , $ parameters );
19681957 $ orderBy = $ this ->columns ->getOrderBy ($ table , $ columnOrdering );
19691958 $ offsetLimit = $ this ->columns ->getOffsetLimit ($ offset , $ limit );
1970- $ sql = 'SELECT ' . $ selectColumns . ' FROM " ' . $ tableName . '" ' . $ whereClause . ' ORDER BY ' . $ orderBy . ' ' . $ offsetLimit ;
1959+ $ sql = 'SELECT ' . $ selectColumns . ' FROM " ' . $ tableName . '" ' . $ whereClause . $ orderBy . $ offsetLimit ;
19711960 $ stmt = $ this ->query ($ sql , $ parameters );
19721961 $ records = $ stmt ->fetchAll ();
19731962 $ this ->converter ->convertRecords ($ table , $ columnNames , $ records );
@@ -5032,7 +5021,7 @@ private function addPkRecords(ReflectedTable $t1, ReflectedTable $t2, array $pkV
50325021 $ conditions [] = new ColumnCondition ($ fk , 'in ' , $ pkValueKeys );
50335022 }
50345023 $ condition = OrCondition::fromArray ($ conditions );
5035- foreach ($ db ->selectAllUnordered ($ t2 , $ columnNames , $ condition ) as $ record ) {
5024+ foreach ($ db ->selectAll ($ t2 , $ columnNames , $ condition, array (), 0 , - 1 ) as $ record ) {
50365025 $ records [] = $ record ;
50375026 }
50385027 }
@@ -5078,7 +5067,7 @@ private function getHabtmEmptyValues(ReflectedTable $t1, ReflectedTable $t2, Ref
50785067 $ pkIds = implode (', ' , array_keys ($ pkValues ));
50795068 $ condition = new ColumnCondition ($ t3 ->getColumn ($ fk1Name ), 'in ' , $ pkIds );
50805069
5081- $ records = $ db ->selectAllUnordered ($ t3 , $ columnNames , $ condition );
5070+ $ records = $ db ->selectAll ($ t3 , $ columnNames , $ condition, array (), 0 , - 1 );
50825071 foreach ($ records as $ record ) {
50835072 $ val1 = $ record [$ fk1Name ];
50845073 $ val2 = $ record [$ fk2Name ];
0 commit comments