Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify Oci8Exception object to add access to Oracle debugging detail #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/Pdo/Oci8/Exceptions/Oci8Exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,69 @@

class Oci8Exception extends PDOException
{

protected $oci_err;

/***
* Macig functions to create and output Exception class
*/
public function __construct (string $message ="", int $code =0, PDOException $e =null, $oci_err =[]) {

parent::__construct ($message, $code, $e);

if ( !empty($oci_err) ) {
$this->oci_err = $oci_err;
} else {
$this->oci_err['message'] = $message;
$this->oci_err['code'] = '00000';
$this->oci_err['sqltext'] = '';
$this->oci_err['bindings'] = '[]';
}

}

public function __toString() {
return $this->getOciAllErrorDetail();
}


/***
* Getters for variouis types of information from the returned OCI error array
*/
public function getOciUserFriendlyMsg() {
$msg_arr = explode ("\n", $this->oci_err['message']);
return preg_replace ('/ORA-[0-9]{5}: /', '', $msg_arr[0]);
}

public function getOciErrorCode() {
return $this->oci_err['code'];
}

public function getOriginalSql() {
return $this->oci_err['sqltext'];
}

public function getOciErrorStack() {
return $this->oci_err['message'];
}

public function getOciBindings() {
return $this->oci_err['bindings'];
}

public function getOciAllErrorDetail() {
return
'Error Code : ' . $this->oci_err['code'] . PHP_EOL .
'Position : ' . $this->oci_err['offset'] . PHP_EOL .
'Statement : ' . $this->oci_err['sqltext'] . PHP_EOL .
'Bindings : ' . $this->oci_err['bindings'] . PHP_EOL .
'Error Stack : ' . PHP_EOL . $this->oci_err['message'];
}

public function getHtmlErrorStack() {
$msg = $this->oci_err['message'];
$msg = str_replace (chr(10), '<br />', $msg);
return '<code>' . $msg . '</code>';
}

}
13 changes: 3 additions & 10 deletions src/Pdo/Oci8/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,8 @@ public function execute($inputParams = null)

if ($result != true) {
$e = oci_error($this->sth);

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can retain this message part as it is easier to debug with all this error message displayed by default?

$message = '';
$message = $message . 'Error Code : ' . $e['code'] . PHP_EOL;
$message = $message . 'Error Message : ' . $e['message'] . PHP_EOL;
$message = $message . 'Position : ' . $e['offset'] . PHP_EOL;
$message = $message . 'Statement : ' . $e['sqltext'] . PHP_EOL;
$message = $message . 'Bindings : [' . $this->displayBindings() . ']' . PHP_EOL;

throw new Oci8Exception($message, $e['code']);
$e['bindings'] = $this->displayBindings();
throw new Oci8Exception ($e['message'], $e['code'], null, $e);
}

return $result;
Expand All @@ -198,7 +191,7 @@ private function displayBindings()
}
}

return implode(',', $bindings);
return '[' . implode(',', $bindings) . ']';
}

/**
Expand Down