summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUrban Müller2010-11-03 17:04:54 +0000
committerUrban Müller2010-11-03 17:04:54 +0000
commit73fd376c51852805a2832896cea33bad9009c6d3 (patch)
treec20ef5c9ee2c7c90bf4a76cdb1ae03317f0023d1
parent82d2d98a11234ee24dafc01e1565cdf1c4584cd7 (diff)
downloaditools-73fd376c51852805a2832896cea33bad9009c6d3.tar.gz
itools-73fd376c51852805a2832896cea33bad9009c6d3.tar.bz2
itools-73fd376c51852805a2832896cea33bad9009c6d3.zip
dbi::update() returns affected rows
-rw-r--r--it_dbi.class3
-rwxr-xr-xtests/it_dbi.t12
2 files changed, 15 insertions, 0 deletions
diff --git a/it_dbi.class b/it_dbi.class
index 0457142..14899d2 100644
--- a/it_dbi.class
+++ b/it_dbi.class
@@ -651,6 +651,7 @@ function replace($tags = array())
* 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)
+ * @return number of updated records (or false on error)
* Does not destroy internal state of last select() call
*/
function update($tags = array(), $where = null)
@@ -668,6 +669,8 @@ function update($tags = array(), $where = null)
if ($result = $this->query("UPDATE {$this->_p['table']} $set " . $this->_where($where, $this->_link)))
{
+ $result = mysql_affected_rows($this->_link);
+
if (array_key_exists($this->_p['keyfield'], $tags)) # Did we just update the key?
$this->_key = $tags[$this->_p['keyfield']];
diff --git a/tests/it_dbi.t b/tests/it_dbi.t
index 3428c0f..3ee2562 100755
--- a/tests/it_dbi.t
+++ b/tests/it_dbi.t
@@ -132,6 +132,18 @@ is(
"update"
);
+is(
+ $record->update(array('x' => 18), array('x' => 17)),
+ 1,
+ "return affected rows",
+);
+
+is(
+ $record->update(array('x' => 18), array('x' => 17)),
+ 0,
+ "return zero affected rows",
+);
+
$record->update(array('-x' => 'RAND() * 10'));
isnt(
array($record->_key, $record->x, $record->foo),