summaryrefslogtreecommitdiff
path: root/it_dbi.class
diff options
context:
space:
mode:
authorChristian Schneider2017-09-26 16:38:14 +0200
committerChristian Schneider2017-09-26 16:38:14 +0200
commit4bf376c1a603caa7bd093a1c36817f8ea21180b1 (patch)
tree95e65ecb254d0bb2f909b068d274730186d3a58f /it_dbi.class
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 'it_dbi.class')
-rw-r--r--it_dbi.class20
1 files changed, 18 insertions, 2 deletions
diff --git a/it_dbi.class b/it_dbi.class
index ab132ff..1c30d6f 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -719,6 +719,8 @@ function insert($tags = array(), $command = "INSERT")
$id = ($this->_p['autoincrement'] && !isset($tags[$this->_p['keyfield']])) ? mysqli_insert_id($this->_link) : $tags[$this->_p['keyfield']];
if ($this->_p['keyfield'] && !$this->read($id) && $this->_p['safety'])
$this->_fatal("insert(): can't read record back (key truncated?), id=\"$id\"");
+
+ $this->_touchedids[$this->_key] = true;
}
else
$this->clear(false);
@@ -782,6 +784,8 @@ function update($tags = array(), $where = null)
}
}
+ $this->_touchedids[$this->_key] = true;
+
return $result;
}
@@ -811,6 +815,20 @@ function delete($query = null)
/**
+ * Delete records matching query which were not touched since creation of this object or last call of this func
+ */
+function delete_untouched($query = null)
+{
+ if ($this->select($query))
+ while ($this->iterate())
+ if (($id = $this->_key) && !$this->_touchedids[$id])
+ $result += $this->delete();
+
+ unset($this->_touchedids);
+ return (int)$result;
+}
+
+/**
* Escapes a string for use in a DB query
* @param The string to be quoted
* @return The quoted value
@@ -953,5 +971,3 @@ static function get($id)
}
} /* End class it_dbi */
-
-?>