]> granicus.if.org Git - php/commitdiff
Added pg_field_type_oid() function
authorEdin Kadribasic <edink@php.net>
Mon, 14 Feb 2005 23:36:16 +0000 (23:36 +0000)
committerEdin Kadribasic <edink@php.net>
Mon, 14 Feb 2005 23:36:16 +0000 (23:36 +0000)
NEWS
ext/pgsql/pgsql.c
ext/pgsql/php_pgsql.h

diff --git a/NEWS b/NEWS
index 157c336c17144e6996c48f9bde87e811f5fd9428..9b88a9c150f4abe698fa34453663282cc2bcd0ed 100644 (file)
--- 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:
index 786be839fc7b0af9b0a92bcaf1e2997d0eaa984c..b442f8ab40678b6470f9dad6094996cf7e6671e3 100644 (file)
@@ -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)
index f25acc9072b9ff747faa44d3c703395c7c4fc23f..835219d983ee3708984560f0571ef71db0be7238 100644 (file)
@@ -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 */