@@ -1402,9 +1402,9 @@ public function getOffsetLimit(int $offset, int $limit): String
1402
1402
return '' ;
1403
1403
}
1404
1404
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 " ;
1408
1408
}
1409
1409
}
1410
1410
@@ -1415,13 +1415,16 @@ private function quoteColumnName(ReflectedColumn $column): String
1415
1415
1416
1416
public function getOrderBy (ReflectedTable $ table , array $ columnOrdering ): String
1417
1417
{
1418
+ if (count ($ columnOrdering )==0 ) {
1419
+ return '' ;
1420
+ }
1418
1421
$ results = array ();
1419
1422
foreach ($ columnOrdering as $ i => list ($ columnName , $ ordering )) {
1420
1423
$ column = $ table ->getColumn ($ columnName );
1421
1424
$ quotedColumnName = $ this ->quoteColumnName ($ column );
1422
1425
$ results [] = $ quotedColumnName . ' ' . $ ordering ;
1423
1426
}
1424
- return implode (', ' , $ results );
1427
+ return ' ORDER BY ' . implode (', ' , $ results );
1425
1428
}
1426
1429
1427
1430
public function getSelect (ReflectedTable $ table , array $ columnNames ): String
@@ -1941,20 +1944,6 @@ public function selectCount(ReflectedTable $table, Condition $condition): int
1941
1944
return $ stmt ->fetchColumn (0 );
1942
1945
}
1943
1946
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
-
1958
1947
public function selectAll (ReflectedTable $ table , array $ columnNames , Condition $ condition , array $ columnOrdering , int $ offset , int $ limit ): array
1959
1948
{
1960
1949
if ($ limit == 0 ) {
@@ -1967,7 +1956,7 @@ public function selectAll(ReflectedTable $table, array $columnNames, Condition $
1967
1956
$ whereClause = $ this ->conditions ->getWhereClause ($ condition , $ parameters );
1968
1957
$ orderBy = $ this ->columns ->getOrderBy ($ table , $ columnOrdering );
1969
1958
$ 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 ;
1971
1960
$ stmt = $ this ->query ($ sql , $ parameters );
1972
1961
$ records = $ stmt ->fetchAll ();
1973
1962
$ this ->converter ->convertRecords ($ table , $ columnNames , $ records );
@@ -5032,7 +5021,7 @@ private function addPkRecords(ReflectedTable $t1, ReflectedTable $t2, array $pkV
5032
5021
$ conditions [] = new ColumnCondition ($ fk , 'in ' , $ pkValueKeys );
5033
5022
}
5034
5023
$ 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 ) {
5036
5025
$ records [] = $ record ;
5037
5026
}
5038
5027
}
@@ -5078,7 +5067,7 @@ private function getHabtmEmptyValues(ReflectedTable $t1, ReflectedTable $t2, Ref
5078
5067
$ pkIds = implode (', ' , array_keys ($ pkValues ));
5079
5068
$ condition = new ColumnCondition ($ t3 ->getColumn ($ fk1Name ), 'in ' , $ pkIds );
5080
5069
5081
- $ records = $ db ->selectAllUnordered ($ t3 , $ columnNames , $ condition );
5070
+ $ records = $ db ->selectAll ($ t3 , $ columnNames , $ condition, array (), 0 , - 1 );
5082
5071
foreach ($ records as $ record ) {
5083
5072
$ val1 = $ record [$ fk1Name ];
5084
5073
$ val2 = $ record [$ fk2Name ];
0 commit comments