From b74698f1357f4cfd62664e517da8bee1eb8339a1 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 31 Oct 2005 03:23:38 +0000 Subject: [PATCH] fix misinterpretation of data when overriding types via bindColumn. Very slightly modified patch from Marcus. --- ext/pdo/pdo_stmt.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index f251db919f..bf83c703ac 100755 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -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); } -- 2.50.1