Skip to content

Commit ab5304d

Browse files
committed
Backend: Also escape …FROM user in case of pgsql
Still hacky, but at least the combined str_replace should compensate the preg_replace :D I stopped thinking about a proper fix, as between the time the original quick fix was implemented and now, nothing has fundamentally changed in ipl-orm. fixes #1330
1 parent 9cabfd5 commit ab5304d

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

library/Icingadb/Common/Backend.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,16 @@ public static function getDb(): Connection
7474
// user is a reserved key word in PostgreSQL, so we need to quote it.
7575
// TODO(lippserd): This is pretty hacky,
7676
// reconsider how to properly implement identifier quoting.
77-
$sql = str_replace(' user ', sprintf(' %s ', $quoted), $sql);
78-
$sql = str_replace(' user.', sprintf(' %s.', $quoted), $sql);
79-
$sql = str_replace('(user.', sprintf('(%s.', $quoted), $sql);
77+
$sql = preg_replace('/user$/', sprintf(' %s', $quoted), $sql);
78+
$sql = str_replace(
79+
[' user ', ' user.', '(user.'],
80+
[
81+
sprintf(' %s ', $quoted),
82+
sprintf(' %s.', $quoted),
83+
sprintf('(%s.', $quoted),
84+
],
85+
$sql
86+
);
8087
})
8188
->on(QueryBuilder::ON_ASSEMBLE_SELECT, function (Select $select) {
8289
// For SELECT DISTINCT, all ORDER BY columns must appear in SELECT list.

0 commit comments

Comments
 (0)