diff options
author | Nathan Gass | 2020-09-03 15:52:06 +0200 |
---|---|---|
committer | Nathan Gass | 2020-09-03 15:52:06 +0200 |
commit | d3f0a6e4f822607b41d138afaa77081cab6afe5e (patch) | |
tree | c592e1e7b5101e77e8b3ca8b20f5d8d286b5a903 | |
parent | 0a1feb7c54e7167b0479fe116e0062017d9496b8 (diff) | |
download | itools-d3f0a6e4f822607b41d138afaa77081cab6afe5e.tar.gz itools-d3f0a6e4f822607b41d138afaa77081cab6afe5e.tar.bz2 itools-d3f0a6e4f822607b41d138afaa77081cab6afe5e.zip |
avoid arrow functions as we support php 7.0
-rw-r--r-- | it_dbi.class | 26 | ||||
-rw-r--r-- | it_dbi_postgres.class | 14 |
2 files changed, 28 insertions, 12 deletions
diff --git a/it_dbi.class b/it_dbi.class index ee6ce08..5d86f12 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -305,8 +305,10 @@ function _expressions($tags, $force = false) function _set($tags, $force = false) { $expressions = $this->_expressions($tags, $force); + foreach ((array)$expressions as $k => $v) + $strings[] = $this->escape_name($k) . "=$v"; - return $expressions ? 'SET ' . implode(', ', it::map(fn ($k, $v) => $this->escape_name($k) . "=$v", $expressions)) : ''; + return $strings ? 'SET ' . implode(', ', $strings) : ''; } /** @@ -317,11 +319,11 @@ function _values($tags, $force = false) { $expressions = $this->_expressions($tags, $force); - $result = ''; - if ($expressions) - $result = '(' . implode(', ', it::map(fn ($k) => $this->escape_name($k), $expressions)) . ') VALUES (' . implode(', ', array_values($expressions)) . ')'; - - return $result; + foreach ((array)$expressions as $k => $v) { + $keys[] = $this->escape_name($k); + $vals[] = $v; + } + return $expressions ? '(' . implode(', ', $keys) . ') VALUES (' . implode(', ', $vals) . ')' : ''; } /** @@ -1138,17 +1140,23 @@ function _json_extract($col, $field) function _json_object($tags) { - return "JSON_OBJECT(" . implode(', ', it::map(fn ($f, $v) => "'$f', $v", (array)$tags)) . ")"; + foreach ((array)$tags as $f => $v) + $strings[] = $this->escape_string($f) . ', ' . $v; + return "JSON_OBJECT(" . implode(', ', $strings) . ")"; } function _json_set($source, $tags) { - return "JSON_SET($source, " . implode(", ", it::map(fn ($f, $v) => "'\$.$f', $v", (array)$tags)) . ')'; + foreach ((array)$tags as $f => $v) + $strings[] = $this->escape_string('$.' . $f) . ', ' . $v; + return "JSON_SET($source, " . implode(", ", $strings) . ')'; } function _json_remove($source, $fields) { - return "JSON_REMOVE($source, " . implode(", ", it::map(fn ($dummy, $f) => "'\$.$f'", (array)$fields)) . ')'; + foreach ((array)$fields as $f) + $strings[] = $this->escape_string('$.' . $f); + return "JSON_REMOVE($source, " . implode(", ", $strings) . ')'; } function _fetch_assoc($res) 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) |