#37671 [NEW]: MySQLi extension fails to recognize BIT colums

From: Date: Fri, 02 Jun 2006 05:01:19 +0000
Subject: #37671 [NEW]: MySQLi extension fails to recognize BIT colums
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-97949@lists.php.net to get a copy of this message
From: squasar at eternalviper dot net Operating system: * PHP version: 5.1.4 PHP Bug Type: MySQLi related Bug description: MySQLi extension fails to recognize BIT colums Description: ------------ When attempting to use MySQLi prepared statements with BIT columns, an "unrecognized column type" error is thrown. Here is a working patch. I do not know if this is an ideal implementation: A working patch: Index: ext/mysqli/mysqli_api.c ============================================================ ======= RCS file: /repository/php-src/ext/mysqli/mysqli_api.c,v retrieving revision 1.118.2.22 diff -u -r1.118.2.22 mysqli_api.c --- ext/mysqli/mysqli_api.c 5 Apr 2006 12:17:08 -0000 1.118.2.22 +++ ext/mysqli/mysqli_api.c 2 Jun 2006 04:59:44 -0000 @@ -303,10 +303,13 @@ break; case MYSQL_TYPE_LONGLONG: +#ifdef FIELD_TYPE_BIT + case MYSQL_TYPE_BIT: +#endif stmt->result.buf[ofs].type = IS_STRING; stmt->result.buf[ofs].buflen = sizeof(my_ulonglong); stmt->result.buf[ofs].val = (char *)emalloc(stmt->result.buf[ofs].buflen); - bind[ofs].buffer_type = MYSQL_TYPE_LONGLONG; + bind[ofs].buffer_type = col_type; bind[ofs].buffer = stmt- >result.buf[ofs].val; bind[ofs].is_null = &stmt- >result.is_null[ofs]; bind[ofs].buffer_length = stmt->result.buf[ofs].buflen; @@ -713,6 +716,11 @@ } else { ZVAL_LONG(stmt->result.vars[i], llval); } +#ifdef FIELD_TYPE_BIT + } else if (stmt->stmt->bind[i].buffer_type == MYSQL_TYPE_BIT) { + llval = *(my_ulonglong *)stmt->result.buf[i].val; + ZVAL_BOOL(stmt->result.vars[i], llval == 0 ? 0 : 1); +#endif } else { ZVAL_STRINGL(stmt->result.vars[i], stmt->result.buf[i].val, stmt->result.buf[i].buflen, 1); } Reproduce code: --------------- <?php // Assume that $DATABASE is an open MySQLi connection to a MySQL 5.0.x database $DATABASE->query( "CREATE TABLE test( test_col BIT NOT NULL )" ); $DATABASE->query( "INSERT INTO test VALUES ( 1, 0, 1, 0 )" ); $statement = $DATABASE->prepare( "SELECT test_col FROM test" ); $statement->execute(); $statement->bind_result( $bits ); while ( $statement->fetch() === TRUE ) debug_zval_dump( $bits ); $statement->close(); ?> Expected result: ---------------- bool(true) refcount(1) bool(false) refcount(1) bool(true) refcount(1) bool(false) refcount(1) Actual result: -------------- Warning: mysqli_stmt::bind_result(): Server returned unknown type 16. Probably your client library is incompatible with the server version you use! in - on line 8 NULL refcount(1) NULL refcount(1) NULL refcount(1) NULL refcount(1) -- Edit bug report at http://bugs.php.net/?id=37671&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=37671&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=37671&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=37671&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=37671&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=37671&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=37671&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=37671&r=needscript Try newer version: http://bugs.php.net/fix.php?id=37671&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=37671&r=support Expected behavior: http://bugs.php.net/fix.php?id=37671&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=37671&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=37671&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=37671&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37671&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=37671&r=dst IIS Stability: http://bugs.php.net/fix.php?id=37671&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=37671&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=37671&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=37671&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=37671&r=mysqlcfg

« previous php.bugs (#97949) next »