summaryrefslogtreecommitdiff
path: root/tests/it_dbi.t
diff options
context:
space:
mode:
authorChristian Schneider2017-09-26 16:38:14 +0200
committerChristian Schneider2017-09-26 16:38:14 +0200
commit4bf376c1a603caa7bd093a1c36817f8ea21180b1 (patch)
tree95e65ecb254d0bb2f909b068d274730186d3a58f /tests/it_dbi.t
parent4bd3944affdf5464260e076e315a752d0a8e627f (diff)
downloaditools-4bf376c1a603caa7bd093a1c36817f8ea21180b1.tar.gz
itools-4bf376c1a603caa7bd093a1c36817f8ea21180b1.tar.bz2
itools-4bf376c1a603caa7bd093a1c36817f8ea21180b1.zip
Added update/insert/upsert tracking and delete_untouched() to delete rows not touch by one of those functions
Diffstat (limited to 'tests/it_dbi.t')
-rwxr-xr-xtests/it_dbi.t35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/it_dbi.t b/tests/it_dbi.t
index cec097e..b29b164 100755
--- a/tests/it_dbi.t
+++ b/tests/it_dbi.t
@@ -327,3 +327,38 @@ $record->update(['-key3' => "2*2"]); is($record->key1, "val1"); is($
$record->update(['key1' => "val0"]); is($record->key1, "val0"); is($record->key2, "val2"); is($record->key3, 4);
$record->replace(['ID' => 6, 'key4' => "val4"]); is($record->key4, "val4");
$record->select(['key2' => "val2"]); is($record->key2, "val2"); is($record->key4, null, "clear previous fields");
+
+#
+# Test tracked update
+#
+function allrecs()
+{
+ foreach (new it_dbi_test() as $r)
+ $result[] = ['ID' => $r->ID, 'foo' => $r->foo];
+ return json_encode($result);
+}
+
+$record = new it_dbi_test;
+$record->delete(['WHERE 1' ]);
+$record->upsert(['ID' => 1, 'foo' => "a"]);
+$record->upsert(['ID' => 2, 'foo' => "b"]);
+$record->upsert(['ID' => 2, 'foo' => "B"]);
+is($record->delete_untouched(), 0, 'delete_untouched');
+is(allrecs(), '[{"ID":1,"foo":"a"},{"ID":2,"foo":"B"}]', 'data after delete_untouched');
+
+$record->upsert(['ID' => 1, 'foo' => "A"]);
+$record->upsert(['ID' => 3, 'foo' => "c"]);
+is($record->delete_untouched([ 'ID >' => 2 ]), 0, 'delete_untouched with query');
+is(allrecs(), '[{"ID":1,"foo":"A"},{"ID":2,"foo":"B"},{"ID":3,"foo":"c"}]', 'data after delete_untouched with query');
+
+$record->upsert(['ID' => 3, 'foo' => "C"]);
+is($record->delete_untouched(), 2, 'delete_untouched with query');
+is(allrecs(), '[{"ID":3,"foo":"C"}]', 'data after delete_untouched with query');
+
+$record->replace(['ID' => 4, 'foo' => "C"]);
+is($record->delete_untouched(), 1, 'delete_untouched after replace');
+is(allrecs(), '[{"ID":4,"foo":"C"}]', 'data after delete_untouched after replace');
+
+$record->upsert(['ID' => 4, 'foo' => "C"]);
+is($record->delete_untouched(), 0, 'delete_untouched after upsert without changes');
+is(allrecs(), '[{"ID":4,"foo":"C"}]', 'data after delete_untouched after upsert without changes');