m6w6 / ext-pq

PostgreSQL client library (libpq) binding
BSD 2-Clause "Simplified" License
39 stars 7 forks source link

How to get detail error code? #14

Closed ParkFramework closed 8 years ago

ParkFramework commented 8 years ago

We need to know specifically error code, to create specific exception classes.

The documents have a table of detailed error codes: http://www.postgresql.org/docs/current/static/errcodes-appendix.html

How to get them in pq\Result?

Thank.

m6w6 commented 8 years ago

Check the sqlstate property of pq\Exception\DomainException: https://mdref.m6w6.name/pq/Exception/DomainException#$sqlstate

m6w6 commented 8 years ago

Oh, from pq\Result? Let me check :)

m6w6 commented 8 years ago

Looks like we're missing the complete PQresultErrorField() API :-/

m6w6 commented 8 years ago

How about a public (readonly) property pq\Result::$diag which returns

array(
  "severity" => "ERROR",
  "sqlstate" => "A00A00",
  "message_primary" => "...",
  ...
)

?

m6w6 commented 8 years ago

Basically everything that's available from PQresultErrorField: http://www.postgresql.org/docs/current/static/libpq-exec.html#LIBPQ-PQRESULTERRORFIELD

ParkFramework commented 8 years ago

Great, thank you! :+1:

We are waiting for the new version :)