summaryrefslogtreecommitdiff
path: root/it_dbi.class
diff options
context:
space:
mode:
authorUrban Müller2012-05-21 16:23:10 +0000
committerUrban Müller2012-05-21 16:23:10 +0000
commit70889fde2ffa8c747b0a11d2712c4642b6c19b83 (patch)
tree02e5cb4ccf000e834305586933da9008f142c573 /it_dbi.class
parent6829130db749903ca012e09bc0ba19aaca000449 (diff)
downloaditools-70889fde2ffa8c747b0a11d2712c4642b6c19b83.tar.gz
itools-70889fde2ffa8c747b0a11d2712c4642b6c19b83.tar.bz2
itools-70889fde2ffa8c747b0a11d2712c4642b6c19b83.zip
add store(), fix comments
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 328e63c..3ec2978 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -237,7 +237,7 @@ function _connect($p = array())
/**
- * INTERNAL: construct SQL SET clause of changed values from member vars and tags array.
+ * INTERNAL: construct SQL SET clause of changed values from tags array.
*/
function _set($tags, $allfields = false)
{
@@ -640,10 +640,10 @@ function iterate()
/**
- * Insert a record into table. Values are taken from member vars and $tags.
+ * Insert a record into table. Values are taken $tags.
* After inserting, all values are valid (record is read back).
* Does not destroy internal state of last select() call
- * @param $tags Additional key => value pairs (these have priority over member vars)
+ * @param $tags key => value pairs to set
*/
function insert($tags = array(), $command = "INSERT")
{
@@ -672,7 +672,7 @@ function insert($tags = array(), $command = "INSERT")
/**
* Replace a record in a table
- * @param $tags Additional key => value pairs (these have priority over member vars)
+ * @param $tags Additional key => value pairs
* Does not destroy internal state of last select() call
* @see insert()
*/
@@ -683,6 +683,16 @@ function replace($tags = array())
/**
+ * Update a record (efficiently) or create it if missing
+ * @param $tags key => value pairs to set
+ */
+function store($tags = array())
+{
+ return $tags[$this->_p['keyfield']] && $this->read($tags[$this->_p['keyfield']]) ? $this->update($tags) : $this->replace($tags);
+}
+
+
+/**
* Update current record or a number of records given by where condition
* @param $tags key => value pairs (these have priority over changes in member vars)
* @param $where condition to select records to be modified (if not current record)