Concern over ext/pgsql API

php.internals

Christopher Kings-Lynne

21 years ago
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

Kouber Saparev

21 years ago
> 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

Christopher Kings-Lynne

21 years ago
>>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
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