# Concern over ext/pgsql API

- Thread: https://externals.io/message/15697
- Original archive: https://news-web.php.net/php.internals/15697
- Started by Christopher Kings-Lynne on 2005-03-31T07:07:24+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #15697 — Christopher Kings-Lynne — 2005-03-31T07:07:24+00:00

URL: https://externals.io/message/15697#15697

Hi,

There is a nasty problem with using the new sqlstate codes in the 
PostgreSQL extension.

Say you want to find the sqlstate error code of a query that fails, the 
function prototype is:

$sqlstate = pg_result_error_field($result, PGSQL_DIAG_SQLSTATE);

HOWEVER, it is not possible to get a result resource from a failed 
pg_query!  pg_query() returns `FALSE` on failure, not a result.

The only way to get the result is to use the asynchronous interface, 
which basically no-one does.

What should we do?

I can perhaps store a per-connection sqlstate after each query, but what 
about all the other error fields:

PGSQL_DIAG_SEVERITY, PGSQL_DIAG_MESSAGE_PRIMARY, 
PGSQL_DIAG_MESSAGE_DETAIL, PGSQL_DIAG_MESSAGE_HINT, 
PGSQL_DIAG_STATEMENT_POSITION, PGSQL_DIAG_INTERNAL_POSITION (PostgreSQL 
8.0+ only), PGSQL_DIAG_INTERNAL_QUERY (PostgreSQL 8.0+ only), 
PGSQL_DIAG_CONTEXT, PGSQL_DIAG_SOURCE_FILE, PGSQL_DIAG_SOURCE_LINE or 
PGSQL_DIAG_SOURCE_FUNCTION

???

Chris

---

## #15699 — Kouber Saparev — 2005-03-31T15:00:02+00:00

URL: https://externals.io/message/15697#15699 · In reply to: #15697

> HOWEVER, it is not possible to get a result resource from a failed
> pg_query!  pg_query() returns `FALSE` on failure, not a result.

You could call pg_last_error(), or pg_last_notice(). Although the last one
is currently somehow broken: http://bugs.php.net/bug.php?id=32223

Kouber

---

## #15709 — Christopher Kings-Lynne — 2005-04-01T02:04:13+00:00

URL: https://externals.io/message/15697#15709 · In reply to: #15699

> > […]
> 
> 
> You could call pg_last_error(), or pg_last_notice(). Although the last one
> is currently somehow broken: http://bugs.php.net/bug.php?id=32223

Those functions are basically useless - they just return a string. 
Everyone's PHP/Pgsql apps at the moment have to to regexes on those 
strings to figure out what the error was.

Chris
