]> granicus.if.org Git - php/commitdiff
fix misinterpretation of data when overriding types via bindColumn.
authorWez Furlong <wez@php.net>
Mon, 31 Oct 2005 03:23:38 +0000 (03:23 +0000)
committerWez Furlong <wez@php.net>
Mon, 31 Oct 2005 03:23:38 +0000 (03:23 +0000)
Very slightly modified patch from Marcus.

ext/pdo/pdo_stmt.c

index f251db919f80ba4de38d4e5306e14ea50de4dd34..bf83c703acbd6c84f1859dd604042eb868187207 100755 (executable)
@@ -443,10 +443,11 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *typ
        char *value = NULL;
        unsigned long value_len = 0;
        int caller_frees = 0;
-       int type;
+       int type, new_type;
 
        col = &stmt->columns[colno];
-       type = type_override ? PDO_PARAM_TYPE(*type_override) : PDO_PARAM_TYPE(col->param_type);
+       type = PDO_PARAM_TYPE(col->param_type);
+       new_type =  type_override ? PDO_PARAM_TYPE(*type_override) : type;
 
        value = NULL;
        value_len = 0;
@@ -474,7 +475,7 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *typ
                        if (value == NULL) {
                                ZVAL_NULL(dest);
                        } else if (value_len == 0) {
-                               if (stmt->dbh->stringify) {
+                               if (stmt->dbh->stringify || new_type == PDO_PARAM_STR) {
                                        char *buf = NULL;
                                        size_t len;
                                        len = php_stream_copy_to_mem((php_stream*)value, &buf, PHP_STREAM_COPY_ALL, 0);
@@ -483,7 +484,7 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *typ
                                } else {
                                        php_stream_to_zval((php_stream*)value, dest);
                                }
-                       } else if (!stmt->dbh->stringify) {
+                       } else if (!stmt->dbh->stringify && new_type != PDO_PARAM_STR) {
                                /* they gave us a string, but LOBs are represented as streams in PDO */
                                php_stream *stm;
 #ifdef TEMP_STREAM_TAKE_BUFFER
@@ -517,6 +518,25 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *typ
                        ZVAL_NULL(dest);
        }
 
+       if (type != new_type) {
+               switch (new_type) {
+                       case PDO_PARAM_INT:
+                               convert_to_long_ex(&dest);
+                               break;
+                       case PDO_PARAM_BOOL:
+                               convert_to_boolean_ex(&dest);
+                               break;
+                       case PDO_PARAM_STR:
+                               convert_to_string_ex(&dest);
+                               break;
+                       case PDO_PARAM_NULL:
+                               convert_to_null_ex(&dest);
+                               break;
+                       default:
+                               ;
+               }
+       }
+       
        if (caller_frees && value) {
                efree(value);
        }