@@ -301,7 +301,9 @@ public function delete(bool $allowDeleteAll = false) : static
301
301
$ this ->lastInput = [];
302
302
$ where = $ this ->getWhere ($ this ->lastInput );
303
303
$ limit = $ this ->getLimitClause ();
304
- $ this ->lastSql = "DELETE FROM ` {$ table }` {$ where }{$ limit }" ;
304
+ $ orderBy = $ this ->getOrderBy ();
305
+
306
+ $ this ->lastSql = "DELETE FROM ` {$ table }` {$ where }{$ orderBy }{$ limit }" ;
305
307
\PHPFUI \ORM ::execute ($ this ->lastSql , $ this ->lastInput );
306
308
307
309
return $ this ;
@@ -378,7 +380,7 @@ public static function getAllTables(array $skipTables = []) : array
378
380
public function getArrayCursor () : \PHPFUI \ORM \ArrayCursor
379
381
{
380
382
$ this ->lastInput = [];
381
- $ this ->lastSql = $ this ->getSQL ($ this ->lastInput );
383
+ $ this ->lastSql = $ this ->getSelectSQL ($ this ->lastInput );
382
384
383
385
$ totalInput = [];
384
386
@@ -391,7 +393,7 @@ public function getArrayCursor() : \PHPFUI\ORM\ArrayCursor
391
393
public function getDataObjectCursor () : \PHPFUI \ORM \DataObjectCursor
392
394
{
393
395
$ this ->lastInput = [];
394
- $ this ->lastSql = $ this ->getSQL ($ this ->lastInput );
396
+ $ this ->lastSql = $ this ->getSelectSQL ($ this ->lastInput );
395
397
$ totalInput = [];
396
398
397
399
return \PHPFUI \ORM ::getDataObjectCursor ($ this ->lastSql , $ this ->lastInput )->setCountSQL ($ this ->getCountSQL ($ totalInput ))->setTotalCountSQL ($ this ->getTotalSQL ($ totalInput ));
@@ -405,7 +407,7 @@ public function getDataObjectCursor() : \PHPFUI\ORM\DataObjectCursor
405
407
public function getExplainRows () : array
406
408
{
407
409
$ this ->lastInput = [];
408
- $ this ->lastSql = 'explain ' . $ this ->getSQL ($ this ->lastInput );
410
+ $ this ->lastSql = 'explain ' . $ this ->getSelectSQL ($ this ->lastInput );
409
411
410
412
return \PHPFUI \ORM ::getRows ($ this ->lastSql , $ this ->lastInput );
411
413
}
@@ -585,7 +587,7 @@ public function getRecord() : \PHPFUI\ORM\Record
585
587
public function getRecordCursor () : \PHPFUI \ORM \RecordCursor
586
588
{
587
589
$ this ->lastInput = [];
588
- $ this ->lastSql = $ this ->getSQL ($ this ->lastInput );
590
+ $ this ->lastSql = $ this ->getSelectSQL ($ this ->lastInput );
589
591
590
592
$ totalInput = [];
591
593
@@ -598,15 +600,15 @@ public function getRecordCursor() : \PHPFUI\ORM\RecordCursor
598
600
public function getRows () : array
599
601
{
600
602
$ this ->lastInput = [];
601
- $ this ->lastSql = $ this ->getSQL ($ this ->lastInput );
603
+ $ this ->lastSql = $ this ->getSelectSQL ($ this ->lastInput );
602
604
603
605
return \PHPFUI \ORM ::getRows ($ this ->lastSql , $ this ->lastInput );
604
606
}
605
607
606
608
/**
607
609
* @return string the current select string, '*' if nothing specified, or a comma delimited field list
608
610
*/
609
- public function getSelect () : string
611
+ public function getSelectFields () : string
610
612
{
611
613
$ sql = '' ;
612
614
$ comma = '' ;
@@ -676,10 +678,10 @@ public function getSelect() : string
676
678
*
677
679
* Sets up lastSql and lastInput variable for use in returning cursors
678
680
*/
679
- public function getSQL (array &$ input , bool $ limited = true ) : string
681
+ public function getSelectSQL (array &$ input , bool $ limited = true ) : string
680
682
{
681
683
$ table = $ this ->instance ->getTableName ();
682
- $ select = $ this ->getSelect ();
684
+ $ select = $ this ->getSelectFields ();
683
685
$ joins = $ this ->getJoins ($ input );
684
686
$ where = $ this ->getWhere ($ input );
685
687
$ groupBy = $ this ->getGroupBy ();
@@ -699,7 +701,7 @@ public function getSQL(array &$input, bool $limited = true) : string
699
701
{
700
702
$ sql .= 'ANY ' ;
701
703
}
702
- $ sql .= ' ' . $ table ->getSQL ($ input , $ limited ) . ' ' ;
704
+ $ sql .= ' ' . $ table ->getSelectSQL ($ input , $ limited ) . ' ' ;
703
705
}
704
706
}
705
707
$ sql .= $ orderBy ;
@@ -830,7 +832,7 @@ public function setFullJoinSelects(bool $fullSelects = true) : static
830
832
*
831
833
* @param bool $rollup can be applied to any group by field, but affects the entire group by clause
832
834
*/
833
- public function setGroupBy (string $ field , bool $ rollup = false ) : self
835
+ public function setGroupBy (string $ field , bool $ rollup = false ) : static
834
836
{
835
837
$ this ->groupBys = [];
836
838
@@ -862,7 +864,7 @@ public function setOffset(int $offset) : static
862
864
return $ this ;
863
865
}
864
866
865
- public function setOrderBy (string $ field , string $ ascending = 'ASC ' ) : self
867
+ public function setOrderBy (string $ field , string $ ascending = 'ASC ' ) : static
866
868
{
867
869
$ this ->orderBys = [];
868
870
@@ -983,9 +985,10 @@ public function update(array $variables) : static
983
985
}
984
986
985
987
$ where = $ this ->getWhere ($ this ->lastInput );
988
+ $ orderBy = $ this ->getOrderBy ();
986
989
$ limit = $ this ->getLimitClause ();
987
990
988
- $ this ->lastSql .= $ where . $ limit ;
991
+ $ this ->lastSql .= $ where . $ orderBy . $ limit ;
989
992
\PHPFUI \ORM ::execute ($ this ->lastSql , $ this ->lastInput );
990
993
991
994
return $ this ;
@@ -1011,6 +1014,7 @@ public function updateFromTable(array $request) : bool
1011
1014
$ data = [];
1012
1015
1013
1016
$ record = new static::$ className ($ existingKey );
1017
+
1014
1018
foreach ($ fields as $ field => $ typeInfo )
1015
1019
{
1016
1020
if (isset ($ request [$ field ]))
@@ -1056,7 +1060,7 @@ private function doTranslation(string $text) : string
1056
1060
*/
1057
1061
private function getCountSQL (array &$ input ) : string
1058
1062
{
1059
- return 'SELECT COUNT(*) from ( ' . $ this ->getSql ($ input ) . ') countAlias ' ;
1063
+ return 'SELECT COUNT(*) from ( ' . $ this ->getSelectSQL ($ input ) . ') countAlias ' ;
1060
1064
}
1061
1065
1062
1066
/**
@@ -1090,6 +1094,6 @@ private function getTotalSQL(array &$input) : string
1090
1094
{
1091
1095
$ input = [];
1092
1096
1093
- return 'SELECT COUNT(*) from ( ' . $ this ->getSql ($ input , false ) . ') countAlias ' ;
1097
+ return 'SELECT COUNT(*) from ( ' . $ this ->getSelectSQL ($ input , false ) . ') countAlias ' ;
1094
1098
}
1095
1099
}
0 commit comments