DBRow.php.patch (2,474 bytes)
--- DBRow.php 2008-09-19 10:23:11.000000000 +0100
+++ DBRow.php.error_checking 2008-09-19 10:22:06.000000000 +0100
@@ -222,6 +222,10 @@
$sql = 'SELECT ' . $this->fieldlist . ' FROM '.$this->table->name . ' WHERE ' . $this->getPrikeyWhereClause();
$res = $this->db->query ($sql);
+ if (PEAR::isError($res)) {
+ throw new Exception ("MDB2 error when fetching row in table '".$this->table->name."': ".$res->getMessage());
+ }
+
if ($res->numRows()> 1) {
throw new Exception ('PHPOF2_DBRow::get() called but primary key value ("' . $prikey_value . '") was not unique in table "' . $this->table->name . '"');
} else if ($res->numRows() > 0) {
@@ -270,6 +274,10 @@
$res = $this->db->query ($sql);
+ if (PEAR::isError($res)) {
+ throw new Exception ("MDB2 error when fetching unique in table '".$this->table->name."': ".$res->getMessage());
+ }
+
if ($res->numRows() > 1) {
// The provided field/value pairs obviously weren't unique
throw new Exception ('More than one record retrieved by PHPOF2_DBRow::getUnique method');
@@ -518,6 +526,10 @@
$res = $this->db->query($SQL);
+ if (PEAR::isError($res)) {
+ throw new Exception ("MDB2 error when inserting row in table '".$this->table->name."': ".$res->getMessage());
+ }
+
// Update the ID if only a single key and the key hasnot been set manualy
if (count($this->pri_keys) == 1 && $this->table->key_auto_increment && !isset($this->{$this->pri_keys[0]})) {
$this->{$this->pri_keys[0]} = $this->db->lastInsertId($this->table->name);
@@ -569,7 +581,12 @@
$insert_values[] = $this->db->quoteIdentifier($field).'='.$value;
}
$SQL = 'UPDATE '.$this->table->name.' SET '.implode(',',$insert_values).' WHERE ' . $this->getPrikeyWhereClause($this->_orig_prikey);
- $this->db->query($SQL);
+ $res = $this->db->query($SQL);
+
+ if (PEAR::isError($res)) {
+ throw new Exception ("MDB2 error when updating row in table '".$this->table->name."': ".$res->getMessage());
+ }
+
} else {
if (count($this->pri_keys) > 0) {
throw new Exception('PHPOF2_DBRow::Update() called, but the primary key is empty');
@@ -617,7 +634,11 @@
}
}
$sql .= implode(' AND ', $clauses);
- $this->db->query($sql);
+ $res = $this->db->query($sql);
+ if (PEAR::isError($res)) {
+ throw new Exception ("MDB2 error when deleting row in table '".$this->table->name."': ".$res->getMessage());
+ }
+
}
$this->clear();