summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2018-08-09 17:36:23 +0200
committerUrban Müller2018-08-09 17:36:23 +0200
commitf8aabe317e7a7997594bc124aa17fd4d6442dfd1 (patch)
treeed7d384ba76443d86a5ab2bf87471d082d63b90f
parent8c399fb12571ae5950a1e3fe186e999abdc0b504 (diff)
downloaditools-f8aabe317e7a7997594bc124aa17fd4d6442dfd1.tar.gz
itools-f8aabe317e7a7997594bc124aa17fd4d6442dfd1.tar.bz2
itools-f8aabe317e7a7997594bc124aa17fd4d6442dfd1.zip
iterator should clear dynfields from previous iteration, may be missing in current one
-rw-r--r--it_dbi.class3
-rwxr-xr-xtest/it_dbi.t11
2 files changed, 14 insertions, 0 deletions
diff --git a/it_dbi.class b/it_dbi.class
index 426e653..be802b7 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -680,6 +680,9 @@ function iterate()
foreach ($localizedfields as $field => $dummy)
unset($this->$field);
+ foreach ((array)$this->_dyndata as $field => $dummy)
+ unset($this->$field);
+
foreach (($t = $this->_data['dyncols']) ? ($this->_dyndata = (array)json_decode($t, true)) : [] as $field => $value)
$this->_data[$field] = $value;
unset($this->_data['dyncols']);
diff --git a/test/it_dbi.t b/test/it_dbi.t
index 70d7f6f..89df3b8 100755
--- a/test/it_dbi.t
+++ b/test/it_dbi.t
@@ -349,6 +349,17 @@ $r->update(['key4' => "val4'"]); is($r->_writes, 0); is($r-
$r->update(['key4' => "val4'", 'key5' => "val5'"]); is($r->_writes, 1); is($r->key4, "val4'"); is($r->key5, "val5'");
$r->update(['key4' => "val4'", 'key5' => "val5'"]); is($r->_writes, 1); is($r->key4, "val4'"); is($r->key5, "val5'");
+# Check if iterator clears dynfields left over from previous record
+$r->delete(["WHERE 1"]);
+$r->replace(['ID' => 1, 'key1' => "a"]);
+$r->replace(['ID' => 2, 'key2' => "b"]);
+$r->clear(false);
+$r->select("WHERE 1 ORDER BY ID");
+$r->iterate();
+is($r->key1, "a"); is($r->key2, null);
+$r->iterate();
+is($r->key1, null); is($r->key2, "b");
+
#
# Test tracked update
#