Skip to content

Commit 9cf622f

Browse files
committed
Clean Group By and Order By fields since they don't work with placeholders
1 parent 0664e51 commit 9cf622f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/PHPFUI/ORM/Table.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function addGroupBy(string $field, bool $rollup = false) : static
113113
{
114114
if (\strlen($field))
115115
{
116-
$this->groupBys[$field] = $rollup;
116+
$this->groupBys[$this->cleanField($field)] = $rollup;
117117
}
118118

119119
return $this;
@@ -173,11 +173,16 @@ public function addJoin(string $table, string | \PHPFUI\ORM\Condition $on = '',
173173
return $this;
174174
}
175175

176+
public function cleanField(string $fieldName) : string
177+
{
178+
return \preg_replace('/[^[a-zA-Z_][a-zA-Z0-9_.$@-]{0,63}$]/', '', $fieldName); // string invalid characters since we can't use a placeholder in order and group by
179+
}
180+
176181
public function addOrderBy(string $field, string $ascending = 'ASC') : static
177182
{
178183
if (\strlen($field))
179184
{
180-
$this->orderBys[$field] = ! \str_contains(\strtoupper($ascending), 'D') ? 'ASC' : 'DESC';
185+
$this->orderBys[$this->cleanField($field)] = ! \str_contains(\strtoupper($ascending), 'D') ? 'ASC' : 'DESC';
181186
}
182187

183188
return $this;

0 commit comments

Comments
 (0)