wez             Sun Sep 11 16:32:29 2005 EDT

  Modified files:              (Branch: PHP_5_1)
    /php-src/ext/pdo    pdo_stmt.c 
  Log:
  When populating bound columns, override the returned type with the type
  specified by the user in their bind.
  
  
  
http://cvs.php.net/diff.php/php-src/ext/pdo/pdo_stmt.c?r1=1.118.2.5&r2=1.118.2.6&ty=u
Index: php-src/ext/pdo/pdo_stmt.c
diff -u php-src/ext/pdo/pdo_stmt.c:1.118.2.5 
php-src/ext/pdo/pdo_stmt.c:1.118.2.6
--- php-src/ext/pdo/pdo_stmt.c:1.118.2.5        Sun Sep 11 10:27:10 2005
+++ php-src/ext/pdo/pdo_stmt.c  Sun Sep 11 16:32:28 2005
@@ -18,7 +18,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: pdo_stmt.c,v 1.118.2.5 2005/09/11 14:27:10 wez Exp $ */
+/* $Id: pdo_stmt.c,v 1.118.2.6 2005/09/11 20:32:28 wez Exp $ */
 
 /* The PDO Statement Handle Class */
 
@@ -432,21 +432,23 @@
 }
 /* }}} */
 
-static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno 
TSRMLS_DC) /* {{{ */
+static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int 
*type_override TSRMLS_DC) /* {{{ */
 {
        struct pdo_column_data *col;
        char *value = NULL;
        unsigned long value_len = 0;
        int caller_frees = 0;
+       int type;
 
        col = &stmt->columns[colno];
+       type = type_override ? PDO_PARAM_TYPE(*type_override) : 
PDO_PARAM_TYPE(col->param_type);
 
        value = NULL;
        value_len = 0;
 
        stmt->methods->get_col(stmt, colno, &value, &value_len, &caller_frees 
TSRMLS_CC);
 
-       switch (PDO_PARAM_TYPE(col->param_type)) {
+       switch (type) {
                case PDO_PARAM_INT:
                        if (value && value_len == sizeof(long)) {
                                ZVAL_LONG(dest, *(long*)value);
@@ -554,7 +556,7 @@
                                zval_dtor(param->parameter);
 
                                /* set new value */
-                               fetch_value(stmt, param->parameter, 
param->paramno TSRMLS_CC);
+                               fetch_value(stmt, param->parameter, 
param->paramno, &param->param_type TSRMLS_CC);
 
                                /* TODO: some smart thing that avoids 
duplicating the value in the
                                 * general loop below.  For now, if you're 
binding output columns,
@@ -778,7 +780,7 @@
 
                        case PDO_FETCH_COLUMN:
                                if (stmt->fetch.column >= 0 && 
stmt->fetch.column < stmt->column_count) {
-                                       fetch_value(stmt, return_value, 
stmt->fetch.column TSRMLS_CC);
+                                       fetch_value(stmt, return_value, 
stmt->fetch.column, NULL TSRMLS_CC);
                                        if (!return_all) {
                                                return 1;
                                        } else {
@@ -802,7 +804,7 @@
                                        do_fetch_opt_finish(stmt, 0 TSRMLS_CC);
 
                                        INIT_PZVAL(&val);
-                                       fetch_value(stmt, &val, i++ TSRMLS_CC);
+                                       fetch_value(stmt, &val, i++, NULL 
TSRMLS_CC);
                                        if (Z_TYPE(val) != IS_NULL) {
                                                convert_to_string(&val);
                                                if 
(zend_lookup_class(Z_STRVAL(val), Z_STRLEN(val), &cep TSRMLS_CC) == FAILURE) {
@@ -855,7 +857,7 @@
                
                if (return_all) {
                        INIT_PZVAL(&grp_val);
-                       fetch_value(stmt, &grp_val, i TSRMLS_CC);
+                       fetch_value(stmt, &grp_val, i, NULL TSRMLS_CC);
                        convert_to_string(&grp_val);
                        if (how == PDO_FETCH_COLUMN) {
                                i = stmt->column_count; /* no more data to 
fetch */
@@ -867,7 +869,7 @@
                for (idx = 0; i < stmt->column_count; i++, idx++) {
                        zval *val;
                        MAKE_STD_ZVAL(val);
-                       fetch_value(stmt, val, i TSRMLS_CC);
+                       fetch_value(stmt, val, i, NULL TSRMLS_CC);
 
                        switch (how) {
                                case PDO_FETCH_ASSOC:
@@ -1216,7 +1218,7 @@
                RETURN_FALSE;
        }
 
-       fetch_value(stmt, return_value, col_n TSRMLS_CC);
+       fetch_value(stmt, return_value, col_n, NULL TSRMLS_CC);
 }
 /* }}} */
 
@@ -2223,7 +2225,7 @@
                
        if (Z_TYPE_P(member) == IS_LONG) {
                if (Z_LVAL_P(member) >= 0 && Z_LVAL_P(member) < 
stmt->column_count) {
-                       fetch_value(stmt, return_value, Z_LVAL_P(member) 
TSRMLS_CC);
+                       fetch_value(stmt, return_value, Z_LVAL_P(member), NULL 
TSRMLS_CC);
                }
        } else {
                convert_to_string(member);
@@ -2231,7 +2233,7 @@
                 * numbers */
                for (colno = 0; colno < stmt->column_count; colno++) {
                        if (strcmp(stmt->columns[colno].name, 
Z_STRVAL_P(member)) == 0) {
-                               fetch_value(stmt, return_value, colno 
TSRMLS_CC);
+                               fetch_value(stmt, return_value, colno, NULL 
TSRMLS_CC);
                                break;
                        }
                }
@@ -2288,7 +2290,7 @@
        for (i = 0; i < stmt->column_count; i++) {
                zval *val;
                MAKE_STD_ZVAL(val);
-               fetch_value(stmt, val, i TSRMLS_CC);
+               fetch_value(stmt, val, i, NULL TSRMLS_CC);
 
                add_assoc_zval(tmp, stmt->columns[i].name, val);
        }

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to