]> granicus.if.org Git - php/commitdiff
Support for native nulls, bools and ints
authorEdin Kadribasic <edink@php.net>
Sat, 22 Jan 2005 23:31:19 +0000 (23:31 +0000)
committerEdin Kadribasic <edink@php.net>
Sat, 22 Jan 2005 23:31:19 +0000 (23:31 +0000)
ext/pdo_pgsql/pgsql_statement.c

index fe29c6b797665261a165a667bb2c15f1ea8695d0..d9b7de425684f67a22c1646708a5e5b6b2486eb3 100644 (file)
 #include "php_pdo_pgsql.h"
 #include "php_pdo_pgsql_int.h"
 
+/* from postgresql/src/include/catalog/pg_type.h */
+#define BOOLOID                        16
+#define INT8OID                        20
+#define INT2OID                        21
+#define INT4OID                        23
+
 
 static int pgsql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC)
 {
@@ -158,7 +164,7 @@ static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
 {
        pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
        struct pdo_column_data *cols = stmt->columns;
-
+       
        if (!S->result) {
                return 0;
        }
@@ -167,7 +173,27 @@ static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
        cols[colno].namelen = strlen(cols[colno].name);
        cols[colno].maxlen = PQfsize(S->result, colno);
        cols[colno].precision = PQfmod(S->result, colno);
-       cols[colno].param_type = PDO_PARAM_STR;
+
+       switch(PQftype(S->result, colno)) {
+
+               case BOOLOID:
+                       cols[colno].param_type = PDO_PARAM_BOOL;
+                       break;
+
+               case INT2OID:
+               case INT4OID:
+                       cols[colno].param_type = PDO_PARAM_INT;
+                       break;
+
+               case INT8OID:
+                       if (sizeof(long)>=8) {
+                               cols[colno].param_type = PDO_PARAM_INT;
+                       }
+                       break;
+
+               default:
+                       cols[colno].param_type = PDO_PARAM_STR;
+       }
 
        return 1;
 }
@@ -175,14 +201,38 @@ static int pgsql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC)
 static int pgsql_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, unsigned long *len TSRMLS_DC)
 {
        pdo_pgsql_stmt *S = (pdo_pgsql_stmt*)stmt->driver_data;
+       struct pdo_column_data *cols = stmt->columns;
+       long intval;
+       zend_bool boolval;
 
        if (!S->result) {
                return 0;
        }
 
        /* We have already increased count by 1 in pgsql_stmt_fetch() */
-       *ptr = PQgetvalue(S->result, S->current_row - 1, colno);
-       *len = PQgetlength(S->result, S->current_row - 1, colno);
+       if (PQgetisnull(S->result, S->current_row - 1, colno)) { /* Check if we got NULL */
+               *ptr = NULL;
+               *len = 0;
+       } else {
+               *ptr = PQgetvalue(S->result, S->current_row - 1, colno);
+               *len = PQgetlength(S->result, S->current_row - 1, colno);
+               
+               switch(cols[colno].param_type) {
+
+                       case PDO_PARAM_INT:
+                               intval = atol(*ptr);
+                               printf ("Here %d %s\n", intval, *ptr);
+                               *ptr = &intval;
+                               *len = sizeof(long);
+                               break;
+
+                       case PDO_PARAM_BOOL:
+                               boolval = **ptr == 't' ? 1: 0;
+                               *ptr = &boolval;
+                               *len = sizeof(zend_bool);
+                               break;
+               }
+       }
 
        return 1;
 }