diff options
author | Edin Kadribasic <edink@php.net> | 2005-01-23 14:50:06 +0000 |
---|---|---|
committer | Edin Kadribasic <edink@php.net> | 2005-01-23 14:50:06 +0000 |
commit | 60f5e66aa94afc7d1c26c4613781a55e2477e5e7 (patch) | |
tree | ed84d1bf2a502186362d1801c91b49debbf9b2ed /ext/pdo_pgsql/pgsql_statement.c | |
parent | d8aa131ca088ef9b68e62547f44c3d20355366bd (diff) | |
download | php-git-60f5e66aa94afc7d1c26c4613781a55e2477e5e7.tar.gz |
Add support for fetching meta data
Diffstat (limited to 'ext/pdo_pgsql/pgsql_statement.c')
-rw-r--r-- | ext/pdo_pgsql/pgsql_statement.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c index 5f7a40c98e..2e38b1f941 100644 --- a/ext/pdo_pgsql/pgsql_statement.c +++ b/ext/pdo_pgsql/pgsql_statement.c @@ -235,13 +235,63 @@ static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned return 1; } +static int pgsql_stmt_get_column_meta(pdo_stmt_t *stmt, long colno, zval *return_value TSRMLS_DC) +{ + pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data; + PGresult *res; + char *q=NULL; + ExecStatusType status; + int i; + + if (!S->result) { + return FAILURE; + } + + if (colno >= stmt->column_count) { + return FAILURE; + } + + array_init(return_value); + add_assoc_long(return_value, "pgsql:oid", S->cols[colno].pgsql_type); + + /* Fetch metadata from Postgres system catalogue */ + spprintf(&q, 0, "SELECT TYPNAME FROM PG_TYPE WHERE OID=%d", S->cols[colno].pgsql_type); + res = PQexec(S->H->server, q); + efree(q); + + status = PQresultStatus(res); + + if (status != PGRES_TUPLES_OK) { + /* Failed to get system catalogue, but return success + * with the data we have collected so far + */ + PQclear(res); + return 1; + } + + /* We want exactly one row returned */ + if (1 != PQntuples(res)) { + PQclear(res); + return 1; + } + + add_assoc_string(return_value, "native_type", PQgetvalue(res, 0, 0), 1); + + PQclear(res); + return 1; +} + struct pdo_stmt_methods pgsql_stmt_methods = { pgsql_stmt_dtor, pgsql_stmt_execute, pgsql_stmt_fetch, pgsql_stmt_describe, pgsql_stmt_get_col, - pgsql_stmt_param_hook + pgsql_stmt_param_hook, + NULL, /* set_attr */ + NULL, /* get_attr */ + pgsql_stmt_get_column_meta, + NULL /* next_rowset */ }; /* |