diff options
author | Edin Kadribasic <edink@php.net> | 2005-07-01 22:30:55 +0000 |
---|---|---|
committer | Edin Kadribasic <edink@php.net> | 2005-07-01 22:30:55 +0000 |
commit | 7ef1a91508ec876a3c79b9e4da42f3dca6c65b3e (patch) | |
tree | 8d8277095b7b432f3d7594c9cb851feb4a39b370 /ext | |
parent | 5d6578987767e12479f9440fc90622cd1d23be46 (diff) | |
download | php-git-7ef1a91508ec876a3c79b9e4da42f3dca6c65b3e.tar.gz |
Fold PQresultErrorField() into a macro
Diffstat (limited to 'ext')
-rw-r--r-- | ext/pdo_pgsql/pgsql_driver.c | 14 | ||||
-rw-r--r-- | ext/pdo_pgsql/pgsql_statement.c | 15 | ||||
-rw-r--r-- | ext/pdo_pgsql/php_pdo_pgsql_int.h | 7 |
3 files changed, 11 insertions, 25 deletions
diff --git a/ext/pdo_pgsql/pgsql_driver.c b/ext/pdo_pgsql/pgsql_driver.c index c0ec5c9d89..3d283fa188 100644 --- a/ext/pdo_pgsql/pgsql_driver.c +++ b/ext/pdo_pgsql/pgsql_driver.c @@ -160,12 +160,7 @@ static long pgsql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM } else { ExecStatusType qs = PQresultStatus(res); if (qs != PGRES_COMMAND_OK && qs != PGRES_TUPLES_OK) { -#if HAVE_PQRESULTERRORFIELD - char * sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE); - pdo_pgsql_error(dbh, qs, (const char *)sqlstate); -#else - pdo_pgsql_error(dbh, qs, NULL); -#endif + pdo_pgsql_error(dbh, qs, pdo_pgsql_sqlstate(res)); PQclear(res); return -1; } @@ -232,12 +227,7 @@ static char *pdo_pgsql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned id = estrdup((char *)PQgetvalue(res, 0, 0)); *len = PQgetlength(res, 0, 0); } else { -#if HAVE_PQRESULTERRORFIELD - char * sqlstate = PQresultErrorField(res, PG_DIAG_SQLSTATE); - pdo_pgsql_error(dbh, status, (const char *)sqlstate); -#else - pdo_pgsql_error(dbh, status, NULL); -#endif + pdo_pgsql_error(dbh, status, pdo_pgsql_sqlstate(res)); } if (res) { diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index 821a053778..36f11beec0 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -97,13 +97,7 @@ static int pgsql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC) status = PQresultStatus(S->result); if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) { -#if HAVE_PQRESULTERRORFIELD - char * sqlstate = PQresultErrorField(S->result, PG_DIAG_SQLSTATE); - pdo_pgsql_error_stmt(stmt, status, (const char *)sqlstate); -#else - pdo_pgsql_error_stmt(stmt, status, NULL); -#endif - + pdo_pgsql_error_stmt(stmt, status, pdo_pgsql_sqlstate(S->result)); return 0; } @@ -151,12 +145,7 @@ static int pgsql_stmt_fetch(pdo_stmt_t *stmt, status = PQresultStatus(S->result); if (status != PGRES_COMMAND_OK && status != PGRES_TUPLES_OK) { -#if HAVE_PQRESULTERRORFIELD - char * sqlstate = PQresultErrorField(S->result, PG_DIAG_SQLSTATE); - pdo_pgsql_error_stmt(stmt, status, (const char *)sqlstate); -#else - pdo_pgsql_error_stmt(stmt, status, NULL); -#endif + pdo_pgsql_error_stmt(stmt, status, pdo_pgsql_sqlstate(S->result)); return 0; } diff --git a/ext/pdo_pgsql/php_pdo_pgsql_int.h b/ext/pdo_pgsql/php_pdo_pgsql_int.h index 54a06011a7..565638f705 100644 --- a/ext/pdo_pgsql/php_pdo_pgsql_int.h +++ b/ext/pdo_pgsql/php_pdo_pgsql_int.h @@ -22,6 +22,7 @@ #define PHP_PDO_PGSQL_INT_H #include <libpq-fe.h> +#include <php.h> #define PHP_PDO_PGSQL_CONNECTION_FAILURE_SQLSTATE "08006" @@ -71,6 +72,12 @@ extern int _pdo_pgsql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, int errcode, const extern struct pdo_stmt_methods pgsql_stmt_methods; +#ifdef HAVE_PQRESULTERRORFIELD +#define pdo_pgsql_sqlstate(r) PQresultErrorField(r, PG_DIAG_SQLSTATE) +#else +#define pdo_pgsql_sqlstate(r) (const char *)NULL +#endif + #endif /* PHP_PDO_PGSQL_INT_H */ /* |