diff options
Diffstat (limited to 'it_dbi_postgres.class')
-rw-r--r-- | it_dbi_postgres.class | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/it_dbi_postgres.class b/it_dbi_postgres.class index 2f8eadb..b7b8851 100644 --- a/it_dbi_postgres.class +++ b/it_dbi_postgres.class @@ -35,7 +35,11 @@ function _where($params) function replace($tags = []) { - $this->insert($tags, "INSERT", ' ON CONFLICT (' . $this->escape_name($this->_p['keyfield']) . ') DO UPDATE SET ' . implode(', ', it::map(fn ($k) => ($esc = $this->escape_name($k)) . " = EXCLUDED." . $esc, $this->_fields))); + foreach (array_keys($this->_fields) as $k) { + $escaped = $this->escape_name($k); + $strings[] = $escaped . '= EXCLUDED.' . $escaped; + } + $this->insert($tags, "INSERT", ' ON CONFLICT (' . $this->escape_name($this->_p['keyfield']) . ') DO UPDATE SET ' . implode(', ', $strings)); } function _tables($p = array()) @@ -137,7 +141,9 @@ function _json_extract($col, $field) function _json_object($tags) { - return "JSONB_BUILD_OBJECT(" . implode(', ', it::map(fn ($f, $v) => "'$f', $v", (array)$tags)) . ")"; + foreach ((array)$tags as $f => $v) + $strings[] = $this->escape_string($f) . ', ' . $v; + return "JSONB_BUILD_OBJECT(" . implode(', ', $strings) . ")"; } function _json_set($source, $tags) @@ -147,7 +153,9 @@ function _json_set($source, $tags) function _json_remove($source, $fields) { - return "($source - " . implode(" - ", it::map(fn ($dummy, $f) => $this->escape_string($f), (array)$fields)) . ")"; + foreach ((array)$fields as $f) + $strings[] = $this->escape_string($f); + return "($source - " . implode(" - ", $strings) . ")"; } function _fetch_assoc($res) |