summaryrefslogtreecommitdiff
path: root/ext/pdo_pgsql/pgsql_statement.c
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2016-04-07 13:58:00 +0800
committerXinchen Hui <laruence@gmail.com>2016-04-07 13:58:00 +0800
commit079239a7cececfca9344b24f5bb1cca127d4bcc9 (patch)
treec02a94788db9aac4f3834a7029ce6af28e905b29 /ext/pdo_pgsql/pgsql_statement.c
parent7e042224a26282938b866a49ca3d4af1b368c0cc (diff)
parent5ab950cb2ca362af3f718179f1da430922c1e0dd (diff)
downloadphp-git-079239a7cececfca9344b24f5bb1cca127d4bcc9.tar.gz
Merge branch 'PHP-7.0' of git.php.net:/php-src into PHP-7.0
* 'PHP-7.0' of git.php.net:/php-src: Remove __halt_compiler from semi-reserved tokens Fixed Bug #71974 Trans sid will always be send, even if cookies are available Optimized array_fill(). This is a perfect function for fast creation of packed arrays. Fixed build fix merge mistake fix tests PostgreSQL's PDOStatement::getColumnMeta() fills in table's name. fix indent Fixed bug #71978 (Existence of return type hint affects other compatibility rules) fix test fix bug #71667 (emulate how mssql extension names "computed" columns) update NEWS add 32-bit specific variont for #62498 skip test on 32-bit make opcache lockfile path configurable return zvals instead of strings, cast or not based on stringify attribute fix test add skip slow test
Diffstat (limited to 'ext/pdo_pgsql/pgsql_statement.c')
-rw-r--r--ext/pdo_pgsql/pgsql_statement.c115
1 files changed, 75 insertions, 40 deletions
diff --git a/ext/pdo_pgsql/pgsql_statement.c b/ext/pdo_pgsql/pgsql_statement.c
index 6a18d6dfb0..a6a69ac3d0 100644
--- a/ext/pdo_pgsql/pgsql_statement.c
+++ b/ext/pdo_pgsql/pgsql_statement.c
@@ -587,12 +587,40 @@ static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, zend_ulon
return 1;
}
+static zend_always_inline char * pdo_pgsql_translate_oid_to_table(Oid oid, PGconn *conn)
+{
+ char *table_name = NULL;
+ PGresult *tmp_res;
+ char *querystr = NULL;
+
+ spprintf(&querystr, 0, "SELECT RELNAME FROM PG_CLASS WHERE OID=%d", oid);
+
+ if ((tmp_res = PQexec(conn, querystr)) == NULL || PQresultStatus(tmp_res) != PGRES_TUPLES_OK) {
+ if (tmp_res) {
+ PQclear(tmp_res);
+ }
+ efree(querystr);
+ return 0;
+ }
+ efree(querystr);
+
+ if ((table_name = PQgetvalue(tmp_res, 0, 0)) == NULL) {
+ PQclear(tmp_res);
+ return 0;
+ }
+
+ PQclear(tmp_res);
+ return table_name;
+}
+
static int pgsql_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zval *return_value)
{
pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
PGresult *res;
char *q=NULL;
ExecStatusType status;
+ Oid table_oid;
+ char *table_name=NULL;
if (!S->result) {
return FAILURE;
@@ -605,46 +633,53 @@ static int pgsql_stmt_get_column_meta(pdo_stmt_t *stmt, zend_long colno, zval *r
array_init(return_value);
add_assoc_long(return_value, "pgsql:oid", S->cols[colno].pgsql_type);
- switch (S->cols[colno].pgsql_type) {
- case BOOLOID:
- add_assoc_string(return_value, "native_type", BOOLLABEL);
- break;
- case BYTEAOID:
- add_assoc_string(return_value, "native_type", BYTEALABEL);
- break;
- case INT8OID:
- add_assoc_string(return_value, "native_type", INT8LABEL);
- break;
- case INT2OID:
- add_assoc_string(return_value, "native_type", INT2LABEL);
- break;
- case INT4OID:
- add_assoc_string(return_value, "native_type", INT4LABEL);
- break;
- case TEXTOID:
- add_assoc_string(return_value, "native_type", TEXTLABEL);
- break;
- case VARCHAROID:
- add_assoc_string(return_value, "native_type", VARCHARLABEL);
- break;
- case DATEOID:
- add_assoc_string(return_value, "native_type", DATELABEL);
- break;
- case TIMESTAMPOID:
- add_assoc_string(return_value, "native_type", TIMESTAMPLABEL);
- break;
- default:
- /* Fetch metadata from Postgres system catalogue */
- spprintf(&q, 0, "SELECT TYPNAME FROM PG_TYPE WHERE OID=%u", S->cols[colno].pgsql_type);
- res = PQexec(S->H->server, q);
- efree(q);
- status = PQresultStatus(res);
- if (status == PGRES_TUPLES_OK && 1 == PQntuples(res)) {
- add_assoc_string(return_value, "native_type", PQgetvalue(res, 0, 0));
- }
- PQclear(res);
- }
- return 1;
+ table_oid = PQftable(S->result, colno);
+ add_assoc_long(return_value, "pgsql:table_oid", table_oid);
+ table_name = pdo_pgsql_translate_oid_to_table(table_oid, S->H->server);
+ if (table_name) {
+ add_assoc_string(return_value, "table", table_name);
+ }
+
+ switch (S->cols[colno].pgsql_type) {
+ case BOOLOID:
+ add_assoc_string(return_value, "native_type", BOOLLABEL);
+ break;
+ case BYTEAOID:
+ add_assoc_string(return_value, "native_type", BYTEALABEL);
+ break;
+ case INT8OID:
+ add_assoc_string(return_value, "native_type", INT8LABEL);
+ break;
+ case INT2OID:
+ add_assoc_string(return_value, "native_type", INT2LABEL);
+ break;
+ case INT4OID:
+ add_assoc_string(return_value, "native_type", INT4LABEL);
+ break;
+ case TEXTOID:
+ add_assoc_string(return_value, "native_type", TEXTLABEL);
+ break;
+ case VARCHAROID:
+ add_assoc_string(return_value, "native_type", VARCHARLABEL);
+ break;
+ case DATEOID:
+ add_assoc_string(return_value, "native_type", DATELABEL);
+ break;
+ case TIMESTAMPOID:
+ add_assoc_string(return_value, "native_type", TIMESTAMPLABEL);
+ break;
+ default:
+ /* Fetch metadata from Postgres system catalogue */
+ spprintf(&q, 0, "SELECT TYPNAME FROM PG_TYPE WHERE OID=%u", S->cols[colno].pgsql_type);
+ res = PQexec(S->H->server, q);
+ efree(q);
+ status = PQresultStatus(res);
+ if (status == PGRES_TUPLES_OK && 1 == PQntuples(res)) {
+ add_assoc_string(return_value, "native_type", PQgetvalue(res, 0, 0));
+ }
+ PQclear(res);
+ }
+ return 1;
}
static int pdo_pgsql_stmt_cursor_closer(pdo_stmt_t *stmt)