andrey Tue, 22 Sep 2009 15:07:39 +0000 Revision: http://svn.php.net/viewvc?view=revision&revision=288579
Log: Fix handling of BIT fields for non-PS. We need macros from mysqlnd to be able to convert a bit stream to a number. BIT is binary data thus the result is a string, and not unicode Changed paths: U php/php-src/trunk/ext/mysqli/mysqli.c Modified: php/php-src/trunk/ext/mysqli/mysqli.c =================================================================== --- php/php-src/trunk/ext/mysqli/mysqli.c 2009-09-22 14:52:47 UTC (rev 288578) +++ php/php-src/trunk/ext/mysqli/mysqli.c 2009-09-22 15:07:39 UTC (rev 288579) @@ -32,6 +32,7 @@ #include "ext/standard/php_string.h" #include "php_mysqli_structs.h" #include "zend_exceptions.h" +#include "ext/mysqlnd/mysqlnd_portability.h" ZEND_DECLARE_MODULE_GLOBALS(mysqli) static PHP_GINIT_FUNCTION(mysqli); @@ -1218,14 +1219,40 @@ zval *res; MAKE_STD_ZVAL(res); - if (!IS_BINARY_DATA(fields[i])) { - UChar *ustr; - int ulen; - zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, row[i], field_len[i] TSRMLS_CC); - ZVAL_UNICODEL(res, ustr, ulen, 0); - } else { - ZVAL_STRINGL(res, row[i], field_len[i], 1); +#if MYSQL_VERSION_ID > 50002 + if (mysql_fetch_field_direct(result, i)->type == MYSQL_TYPE_BIT) { + my_ulonglong llval; + char tmp[22]; + switch (field_len[i]) { + case 8:llval = (my_ulonglong) bit_uint8korr(row[i]);break; + case 7:llval = (my_ulonglong) bit_uint7korr(row[i]);break; + case 6:llval = (my_ulonglong) bit_uint6korr(row[i]);break; + case 5:llval = (my_ulonglong) bit_uint5korr(row[i]);break; + case 4:llval = (my_ulonglong) bit_uint4korr(row[i]);break; + case 3:llval = (my_ulonglong) bit_uint3korr(row[i]);break; + case 2:llval = (my_ulonglong) bit_uint2korr(row[i]);break; + case 1:llval = (my_ulonglong) uint1korr(row[i]);break; + } + /* even though lval is declared as unsigned, the value + * may be negative. Therefor we cannot use MYSQLI_LLU_SPEC and must + * use MYSQLI_LL_SPEC. + */ + snprintf(tmp, sizeof(tmp), (mysql_fetch_field_direct(result, i)->flags & UNSIGNED_FLAG)? MYSQLI_LLU_SPEC : MYSQLI_LL_SPEC, llval); + /* numbers are latin1 and thus utf8, so no need to convert them with zend_string_to_unicode */ + ZVAL_STRING(res, tmp, 1); + } else +#endif + { + if (!IS_BINARY_DATA(fields[i])) { + UChar *ustr; + int ulen; + + zend_string_to_unicode(UG(utf8_conv), &ustr, &ulen, row[i], field_len[i] TSRMLS_CC); + ZVAL_UNICODEL(res, ustr, ulen, 0); + } else { + ZVAL_STRINGL(res, row[i], field_len[i], 1); + } } if (fetchtype & MYSQLI_NUM) {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php