@@ -1005,8 +1005,8 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
10051005 {$ sqlLimit };
10061006 " ;
10071007
1008- if ($ timeout ) {
1009- $ sql = $ this ->setTimeout ($ sql , $ timeout );
1008+ if ($ timeout || static :: $ timeout ) {
1009+ $ sql = $ this ->setTimeout ($ sql , $ timeout ? $ timeout : static :: $ timeout );
10101010 }
10111011
10121012 $ stmt = $ this ->getPDO ()->prepare ($ sql );
@@ -1078,7 +1078,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
10781078 * @throws Exception
10791079 * @throws PDOException
10801080 */
1081- public function count (string $ collection , array $ queries = [], ?int $ max = null ): int
1081+ public function count (string $ collection , array $ queries = [], ?int $ max = null , ? int $ timeout = null ): int
10821082 {
10831083 $ name = $ this ->filter ($ collection );
10841084 $ roles = Authorization::getRoles ();
@@ -1103,6 +1103,10 @@ public function count(string $collection, array $queries = [], ?int $max = null)
11031103 {$ limit }
11041104 ) table_count
11051105 " ;
1106+ if ($ timeout || self ::$ timeout ) {
1107+ $ sql = $ this ->setTimeout ($ sql , $ timeout ? $ timeout : self ::$ timeout );
1108+ }
1109+
11061110 $ stmt = $ this ->getPDO ()->prepare ($ sql );
11071111 foreach ($ queries as $ query ) {
11081112 $ this ->bindConditionValue ($ stmt , $ query );
@@ -1130,7 +1134,7 @@ public function count(string $collection, array $queries = [], ?int $max = null)
11301134 * @throws Exception
11311135 * @throws PDOException
11321136 */
1133- public function sum (string $ collection , string $ attribute , array $ queries = [], ?int $ max = null ): int |float
1137+ public function sum (string $ collection , string $ attribute , array $ queries = [], ?int $ max = null , ? int $ timeout = null ): int |float
11341138 {
11351139 $ name = $ this ->filter ($ collection );
11361140 $ roles = Authorization::getRoles ();
@@ -1146,16 +1150,20 @@ public function sum(string $collection, string $attribute, array $queries = [],
11461150 }
11471151
11481152 $ sqlWhere = !empty ($ where ) ? 'where ' . implode (' AND ' , $ where ) : '' ;
1153+ $ sql = "SELECT SUM( {$ attribute }) as sum
1154+ FROM
1155+ (
1156+ SELECT {$ attribute }
1157+ FROM {$ this ->getSQLTable ($ name )} table_main
1158+ " . $ sqlWhere . "
1159+ {$ limit }
1160+ ) table_count
1161+ " ;
1162+ if ($ timeout || self ::$ timeout ) {
1163+ $ sql = $ this ->setTimeout ($ sql , $ timeout ? $ timeout : self ::$ timeout );
1164+ }
11491165
1150- $ stmt = $ this ->getPDO ()->prepare ("
1151- SELECT SUM( {$ attribute }) as sum
1152- FROM (
1153- SELECT {$ attribute }
1154- FROM {$ this ->getSQLTable ($ name )} table_main
1155- " . $ sqlWhere . "
1156- {$ limit }
1157- ) table_count
1158- " );
1166+ $ stmt = $ this ->getPDO ()->prepare ($ sql );
11591167
11601168 foreach ($ queries as $ query ) {
11611169 $ this ->bindConditionValue ($ stmt , $ query );
@@ -1224,7 +1232,7 @@ protected function getSQLCondition(Query $query): string
12241232 default => $ query ->getAttribute ()
12251233 });
12261234
1227- $ attribute = "` {$ query ->getAttribute ()}` " ;
1235+ $ attribute = "` {$ query ->getAttribute ()}` " ;
12281236 $ placeholder = $ this ->getSQLPlaceholder ($ query );
12291237
12301238 switch ($ query ->getMethod ()) {
@@ -1241,7 +1249,7 @@ protected function getSQLCondition(Query $query): string
12411249 default :
12421250 $ conditions = [];
12431251 foreach ($ query ->getValues () as $ key => $ value ) {
1244- $ conditions [] = $ attribute. ' ' . $ this ->getSQLOperator ($ query ->getMethod ()). ' : ' . $ placeholder. '_ ' . $ key ;
1252+ $ conditions [] = $ attribute . ' ' . $ this ->getSQLOperator ($ query ->getMethod ()) . ' : ' . $ placeholder . '_ ' . $ key ;
12451253 }
12461254 $ condition = implode (' OR ' , $ conditions );
12471255 return empty ($ condition ) ? '' : '( ' . $ condition . ') ' ;
0 commit comments