php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #52686
Patch rein-mysql_fetch_hash revision 2010-08-24 11:39 UTC by rein at basefarm dot no

Patch rein-mysql_fetch_hash for MySQLi related Bug #52686

Patch version 2010-08-24 11:39 UTC

Return to Bug #52686 | Download this patch
Patch Revisions:

Developer: rein@basefarm.no

Index: ext/mysqli/mysqli_api.c
===================================================================
RCS file: /f/CVSROOT/drift/www/php/ext/mysqli/mysqli_api.c,v
retrieving revision 1.1.1.14
retrieving revision 1.7
diff -u -u -r1.1.1.14 -r1.7
--- ext/mysqli/mysqli_api.c	16 Aug 2010 17:59:17 -0000	1.1.1.14
+++ ext/mysqli/mysqli_api.c	24 Aug 2010 11:20:04 -0000	1.7
@@ -379,11 +379,11 @@
 			case MYSQL_TYPE_NEWDECIMAL:
 #endif
 			{
-#if MYSQL_VERSION_ID > 50099
+#if MYSQL_VERSION_ID >= 50107
 				/* Changed to my_bool in MySQL 5.1. See MySQL Bug #16144 */
 				my_bool tmp;
 #else
-				ulong tmp = 0;
+				uint tmp = 0;
 #endif
 				stmt->result.buf[ofs].type = IS_STRING;
 				/*
@@ -2224,8 +2224,10 @@
 	MY_STMT	*stmt;
 	zval	*mysql_stmt;
 	long	mode_in;
+	my_bool	mode_b;
 	ulong	mode;
 	ulong	attr;
+	void	*mode_p;
 
 	if (zend_parse_method_parameters(ZEND_NUM_ARGS() TSRMLS_CC, getThis(), "Oll", &mysql_stmt, mysqli_stmt_class_entry, &attr, &mode_in) == FAILURE) {
 		return;
@@ -2237,11 +2239,22 @@
 		RETURN_FALSE;
 	}
 
-	mode = mode_in;
+	switch (attr) {
+#if MYSQL_VERSION_ID >= 50107
+	case STMT_ATTR_UPDATE_MAX_LENGTH:
+		mode_b = (my_bool) mode_in;
+		mode_p = &mode_b;
+		break;
+#endif
+	default:
+		mode = mode_in;
+		mode_p = &mode;
+		break;
+	}
 #if !defined(MYSQLI_USE_MYSQLND)
-	if (mysql_stmt_attr_set(stmt->stmt, attr, (void *)&mode)) {
+	if (mysql_stmt_attr_set(stmt->stmt, attr, mode_p)) {
 #else
-	if (FAIL == mysql_stmt_attr_set(stmt->stmt, attr, (void *)&mode)) {
+	if (FAIL == mysql_stmt_attr_set(stmt->stmt, attr, mode_p)) {
 #endif
 		RETURN_FALSE;
 	}
@@ -2255,11 +2268,7 @@
 {
 	MY_STMT	*stmt;
 	zval	*mysql_stmt;
-#if !defined(MYSQLI_USE_MYSQLND) && MYSQL_VERSION_ID > 50099
-	my_bool value;
-#else
 	ulong	value = 0;
-#endif
 	ulong	attr;
 	int		rc;
 
@@ -2271,6 +2280,11 @@
 	if ((rc = mysql_stmt_attr_get(stmt->stmt, attr, &value))) {
 		RETURN_FALSE;
 	}
+
+#if MYSQL_VERSION_ID >= 50107
+	if (attr == STMT_ATTR_UPDATE_MAX_LENGTH)
+		value = *((my_bool *)&value);
+#endif
 	RETURN_LONG((long)value);
 }
 /* }}} */
@@ -2416,7 +2430,11 @@
 				stmt->stmt->fields[i].type == MYSQL_TYPE_LONG_BLOB ||
 				stmt->stmt->fields[i].type == MYSQL_TYPE_GEOMETRY))
 			{
+#if MYSQL_VERSION_ID >= 50107
 				my_bool	tmp=1;
+#else
+				uint tmp=1;
+#endif
 				mysql_stmt_attr_set(stmt->stmt, STMT_ATTR_UPDATE_MAX_LENGTH, &tmp);
 				break;
 			}
Index: ext/mysqli/tests/mysqli_stmt_attr_set.phpt
===================================================================
RCS file: /f/CVSROOT/drift/www/php/ext/mysqli/tests/mysqli_stmt_attr_set.phpt,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -u -r1.1.1.1 -r1.2
--- ext/mysqli/tests/mysqli_stmt_attr_set.phpt	16 Aug 2010 17:59:18 -0000	1.1.1.1
+++ ext/mysqli/tests/mysqli_stmt_attr_set.phpt	24 Aug 2010 11:20:53 -0000	1.2
@@ -92,6 +92,9 @@
 	$stmt = mysqli_stmt_init($link);
 	$stmt->prepare("SELECT label FROM test");
 	$stmt->attr_set(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, 1);
+	$res = $stmt->attr_get(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH);
+	if ($res !== 1)
+		printf("[007.1] max_length should be 1, got %s\n", $res);
 	$stmt->execute();
 	$stmt->store_result();
 	$res = $stmt->result_metadata();
@@ -109,6 +112,9 @@
 	$stmt = mysqli_stmt_init($link);
 	$stmt->prepare("SELECT label FROM test");
 	$stmt->attr_set(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH, 0);
+	$res = $stmt->attr_get(MYSQLI_STMT_ATTR_UPDATE_MAX_LENGTH);
+	if ($res !== 0)
+		printf("[008.1] max_length should be 0, got %s\n", $res);
 	$stmt->execute();
 	$stmt->store_result();
 	$res = $stmt->result_metadata();
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC