summaryrefslogtreecommitdiff
path: root/it_dbi.class
diff options
context:
space:
mode:
authorDavid Flatz2018-10-08 15:23:07 +0200
committerDavid Flatz2018-10-08 15:24:10 +0200
commit9e9565b9b29696bae8f74e02b0457208380caaef (patch)
tree4c0f8441fe90b9030ca3e3e1734a6865f559fe90 /it_dbi.class
parent51ed968a13e1664bd256e2adafcb1d5e3c4f4095 (diff)
downloaditools-9e9565b9b29696bae8f74e02b0457208380caaef.tar.gz
itools-9e9565b9b29696bae8f74e02b0457208380caaef.tar.bz2
itools-9e9565b9b29696bae8f74e02b0457208380caaef.zip
handle setting a dyncol to null by removing the field in dyncols
Diffstat (limited to 'it_dbi.class')
-rw-r--r--it_dbi.class18
1 files changed, 14 insertions, 4 deletions
diff --git a/it_dbi.class b/it_dbi.class
index d9688cd..004c22d 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -264,8 +264,12 @@ function _set($tags, $force = false)
{
if (substr($field, 0, 1) === "-")
$newdyns[] = "'\$.$f', " . $value;
- else if ($force || isset($value) && isset($dyndata[$f]) ? strval($value) !== strval($dyndata[$f]) : $value !== $dyndata[$f] || !array_key_exists($f, $dyndata))
- $newdyns[] = "'\$.$f', " . $this->escape_string($value);
+ else if ($force || isset($value) && isset($dyndata[$f]) ? strval($value) !== strval($dyndata[$f]) : $value !== $dyndata[$f] || !array_key_exists($f, $dyndata)) {
+ if (is_null($value))
+ $deldyns[] = "'\$.$f'";
+ else
+ $newdyns[] = "'\$.$f', " . $this->escape_string($value);
+ }
$alldyns[] = $this->escape_string($f) . ", " . (substr($field, 0, 1) === "-" ? $value : $this->escape_string($value));
$dyndata[$f] = $value;
@@ -280,8 +284,14 @@ function _set($tags, $force = false)
{
if ($force == "insert") # INSERT/REPLACE
$result[] = "dyncols = JSON_OBJECT(" . join(", ", (array)$alldyns) . ")";
- else if ($newdyns)
- $result[] = "dyncols = JSON_SET(" . ($this->_dyndata ? 'dyncols' : '"{}"') . ", " . join(", ", $newdyns) .")";
+ else if ($newdyns || $deldyns) {
+ $source = $this->_dyndata ? 'dyncols' : '"{}"';
+ if ($newdyns)
+ $source = "JSON_SET($source, " . join(', ', $newdyns) . ')';
+ if ($deldyns)
+ $source = "JSON_REMOVE($source, " . join(', ', $deldyns) . ')';
+ $result[] = "dyncols = $source";
+ }
}
$this->_writes += $result ? 1 : 0;