From: Edin Kadribasic Date: Mon, 14 Feb 2005 23:36:16 +0000 (+0000) Subject: Added pg_field_type_oid() function X-Git-Tag: RELEASE_0_2_4~44 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=70e084941665ff8483063792b6ff40828a3210d1;p=php Added pg_field_type_oid() function --- diff --git a/NEWS b/NEWS index 157c336c17..9b88a9c150 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2004, PHP 5.1.0 +- Added pg_field_type_oid() PostgreSQL function. (mauroi at digbang dot com) - Added zend_declare_property_...() and zend_update_property_...() API functions for bool, double and binary safe strings. (Hartmut) - Moved extensions to PECL: diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 786be839fc..b442f8ab40 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -117,6 +117,7 @@ function_entry pgsql_functions[] = { PHP_FE(pg_field_num, NULL) PHP_FE(pg_field_size, NULL) PHP_FE(pg_field_type, NULL) + PHP_FE(pg_field_type_oid, NULL) PHP_FE(pg_field_prtlen, NULL) PHP_FE(pg_field_is_null,NULL) /* async message function */ @@ -1251,6 +1252,7 @@ static char *get_field_name(PGconn *pgsql, Oid oid, HashTable *list TSRMLS_DC) #define PHP_PG_FIELD_NAME 1 #define PHP_PG_FIELD_SIZE 2 #define PHP_PG_FIELD_TYPE 3 +#define PHP_PG_FIELD_TYPE_OID 4 /* {{{ php_pgsql_get_field_info */ @@ -1259,6 +1261,7 @@ static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_typ zval **result, **field; PGresult *pgsql_result; pgsql_result_handle *pg_result; + Oid oid; if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &result, &field)==FAILURE) { WRONG_PARAM_COUNT; @@ -1290,6 +1293,24 @@ static void php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAMETERS, int entry_typ Z_STRLEN_P(return_value) = strlen(Z_STRVAL_P(return_value)); Z_TYPE_P(return_value) = IS_STRING; break; + case PHP_PG_FIELD_TYPE_OID: + + oid = PQftype(pgsql_result, Z_LVAL_PP(field)); + + if (oid > LONG_MAX) { + smart_str s = {0}; + smart_str_append_unsigned(&s, oid); + smart_str_0(&s); + Z_STRVAL_P(return_value) = s.c; + Z_STRLEN_P(return_value) = s.len; + Z_TYPE_P(return_value) = IS_STRING; + } + else + { + Z_LVAL_P(return_value) = (long)oid; + Z_TYPE_P(return_value) = IS_LONG; + } + break; default: RETURN_FALSE; } @@ -1320,6 +1341,15 @@ PHP_FUNCTION(pg_field_type) } /* }}} */ + +/* {{{ proto string pg_field_type_oid(resource result, int field_number) + Returns the type oid for the given field */ +PHP_FUNCTION(pg_field_type_oid) +{ + php_pgsql_get_field_info(INTERNAL_FUNCTION_PARAM_PASSTHRU,PHP_PG_FIELD_TYPE_OID); +} +/* }}} */ + /* {{{ proto int pg_field_num(resource result, string field_name) Returns the field number of the named field */ PHP_FUNCTION(pg_field_num) diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h index f25acc9072..835219d983 100644 --- a/ext/pgsql/php_pgsql.h +++ b/ext/pgsql/php_pgsql.h @@ -98,6 +98,7 @@ PHP_FUNCTION(pg_field_name); PHP_FUNCTION(pg_field_num); PHP_FUNCTION(pg_field_size); PHP_FUNCTION(pg_field_type); +PHP_FUNCTION(pg_field_type_oid); PHP_FUNCTION(pg_field_prtlen); PHP_FUNCTION(pg_field_is_null); /* async message functions */