Skip to content
Permalink
Browse files

MDL-17491 oci native driver - improve exception/error handling to kno…

…w what the hell is happening. ;-)
  • Loading branch information...
stronk7
stronk7 committed Sep 11, 2009
1 parent d755d8c commit 7cfaef13aa707d709d3ac49939b22c30c26ebd64
Showing with 19 additions and 9 deletions.
  1. +19 −9 lib/dml/oci_native_moodle_database.php
@@ -36,7 +36,7 @@ class oci_native_moodle_database extends moodle_database {
protected $oci = null;
protected $bytea_oid = null;
protected $last_debug;
private $last_stmt_error = null; // To store stmt errors and enable get_last_error() to detect them
/**
* Detects if all needed PHP stuff installed.
@@ -196,8 +196,6 @@ public function dispose() {
*/
protected function query_start($sql, array $params=null, $type, $extrainfo=null) {
parent::query_start($sql, $params, $type, $extrainfo);
// oci driver tents to send debug to output, we do not need that ;-)
//$this->last_debug = error_reporting(0);
}
/**
@@ -206,9 +204,14 @@ protected function query_start($sql, array $params=null, $type, $extrainfo=null)
* @return void
*/
protected function query_end($result, $stmt=null) {
//reset original debug level
//error_reporting($this->last_debug);
if ($stmt and $result === false) {
// Look for stmt error and store it
if (is_resource($stmt)) {
$e = oci_error($stmt);
if ($e !== false) {
$this->last_stmt_error = $e['message'];
}
}
oci_free_statement($stmt);
}
parent::query_end($result);
@@ -250,11 +253,18 @@ protected function allowed_param_types() {
* Returns last error reported by database engine.
*/
public function get_last_error() {
$e = oci_error($this->oci);
if (isset($e['message'])) {
return $e['message'];
$error = false;
// First look for any previously saved stmt error
if (!empty($this->last_stmt_error)) {
$error = $this->last_stmt_error;
$this->last_stmt_error = null;
} else { // Now try connection error
$e = oci_error($this->oci);
if ($e !== false) {
$error = $e['message'];
}
}
return false;
return $error;
}
protected function parse_query($sql) {

0 comments on commit 7cfaef1

Please sign in to comment.
You can’t perform that action at this time.