yajra / pdo-via-oci8

PHP PDO_OCI functions via OCI8 extension
Other
88 stars 61 forks source link

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

Open cartbeforehorse opened 6 years ago

cartbeforehorse commented 6 years ago

As per request for a Pull Request, I'm now submitting changes that I've applied.

The objective is to build better Oracle debugging support into the Oci8Exception class, so that (for example) user-facing error-messages are easier to extract.

These changes are slightly different than the original suggestions documented in the original thread. Rather than allow Exception-throwing code in Statement.php to build a lengthy message string to pass to the Exception object, I've decided to simply pass the PDO exception-array to the Exception class instead, so that the Exception class itself can do the legwork. This reduces the overhead of constructing and de-constructing the message string to find the necessary debug info.

mstaack commented 6 years ago

@cartbeforehorse really like the idea, could you refomat & cleanup your variables & functions?

cartbeforehorse commented 6 years ago

@mstaack I'm not clear what I need to do. What is it that needs tidying?

yajra commented 6 years ago

Reviewing this and this is the difference when doing a tinker session in Laravel:

With this PR, the console log is:

Psy Shell v0.9.7 (PHP 7.1.19 — cli) by Justin Hileman
>>> factory("App\User")->create()
PHP Warning:  oci_execute(): ORA-01400: cannot insert NULL into ("LARAVEL57"."USERS"."REMARKS") in /www/yajra/oci8/pdo-via-oci8/src/Pdo/Oci8/Statement.php on line 158
Yajra/Pdo/Oci8/Exceptions/Oci8Exception with message 'ORA-01400: cannot insert NULL into ("LARAVEL57"."USERS"."REMARKS")'

This is how it currently looks:

Psy Shell v0.9.7 (PHP 7.1.19 — cli) by Justin Hileman
>>> factory("App\User")->create()
PHP Warning:  oci_execute(): ORA-01400: cannot insert NULL into ("LARAVEL57"."USERS"."REMARKS") in /www/yajra/oci8/pdo-via-oci8/src/Pdo/Oci8/Statement.php on line 158
Yajra/Pdo/Oci8/Exceptions/Oci8Exception with message 'Error Code    : 1400
Error Message : ORA-01400: cannot insert NULL into ("LARAVEL57"."USERS"."REMARKS")
Position      : 0
Statement     : insert into "USERS" ("NAME", "EMAIL", "PASSWORD", "REMEMBER_TOKEN", "UPDATED_AT", "CREATED_AT") values (:p0, :p1, :p2, :p3, :p4, :p5) returning "ID" into :p6
Bindings      : [Prof. Zita Ryan Sr.,rosamond98@example.com,$2y$10$TKh8H1.PfQx37YgCzwiKb.KjNyWgaHb9cbcoQgdIVFlYg7B77UdFm,JUanCgKavf,2018-09-05 03:15:34,2018-09-05 03:15:34,0]
'

In this regard, I guess we could retain the original error display but we can add a chain of error that the user can use to fit their requirements. What do you think? Thanks!