From 3bc45983207d43f9c80ef08e2ef28064f57e19e9 Mon Sep 17 00:00:00 2001 From: Nathan Gass Date: Wed, 6 Jan 2021 17:39:41 +0100 Subject: add special handling of numeric keys to _set and _values consistent with _where --- it_dbi.class | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'it_dbi.class') diff --git a/it_dbi.class b/it_dbi.class index e51b23e..ace10ba 100644 --- a/it_dbi.class +++ b/it_dbi.class @@ -248,6 +248,11 @@ function _expressions($tags, $force = false) foreach((array)$tags as $field => $value) { + if (is_int($field)) { /* no key specified; pass on unchanged */ + $result[$field] = $value; + continue; + } + $f = trim($field, "-"); if (!$this->_fields[$f] && it::match(",$f,", $this->_fieldnames)) it::error("case mismatch on field $f, valid fields $this->_fieldnames"); @@ -305,10 +310,15 @@ 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"; + $append = []; + foreach ((array)$expressions as $k => $v) { + if (is_int($k)) /* no key specified; just append */ + $append[] = $v; + else + $strings[] = $this->escape_name($k) . "=$v"; + } - return $strings ? 'SET ' . implode(', ', $strings) : ''; + return $strings ? 'SET ' . implode(', ', $strings) . implode(' ', $append) : ''; } /** @@ -318,12 +328,16 @@ function _set($tags, $force = false) function _values($tags, $force = false) { $expressions = $this->_expressions($tags, $force); - + $append = []; foreach ((array)$expressions as $k => $v) { - $keys[] = $this->escape_name($k); - $vals[] = $v; + if (is_int($k)) /* no key specified; just append */ + $append[] = $v; + else { + $keys[] = $this->escape_name($k); + $vals[] = $v; + } } - return $expressions ? '(' . implode(', ', $keys) . ') VALUES (' . implode(', ', $vals) . ')' : ''; + return $expressions ? '(' . implode(', ', $keys) . ') VALUES (' . implode(', ', $vals) . ')' . implode(' ', $append) : ''; } /** -- cgit v1.2.3