List:Commits« Previous MessageNext Message »
From:ahristov Date:March 21 2007 2:04pm
Subject:PHP mysqlnd svn commit: r238 - in trunk/ext/mysqli: . mysqlnd
View as plain text  
Author: ahristov
Date: 2007-03-21 15:04:32 +0100 (Wed, 21 Mar 2007)
New Revision: 238

Modified:
   trunk/ext/mysqli/mysqli.c
   trunk/ext/mysqli/mysqli_libmysql.h
   trunk/ext/mysqli/mysqlnd/mysqlnd.c
   trunk/ext/mysqli/mysqlnd/mysqlnd.h
   trunk/ext/mysqli/mysqlnd/mysqlnd_priv.h
   trunk/ext/mysqli/mysqlnd/mysqlnd_ps_codec.c
   trunk/ext/mysqli/mysqlnd/mysqlnd_wireprotocol.c
Log:
Add an option, which when enabled forces mysqlnd to
convert strings which represent overflowed intergers (unsigned int
on 32b and unsigned long on 32 and 64 bit) to unicode strings instead
of binary such. By default binary is created as it consumes less memory.
This option affects
- int32 (unsigned int)
- int64 (on 32 bit in all cases, on 64bit unsigned int)
- date
- time
- datetime


Modified: trunk/ext/mysqli/mysqli.c
===================================================================
--- trunk/ext/mysqli/mysqli.c	2007-03-21 13:37:22 UTC (rev 237)
+++ trunk/ext/mysqli/mysqli.c	2007-03-21 14:04:32 UTC (rev 238)
@@ -613,6 +613,7 @@
 	REGISTER_LONG_CONSTANT("MYSQLI_OPT_CONNECT_TIMEOUT", MYSQL_OPT_CONNECT_TIMEOUT, CONST_CS
| CONST_PERSISTENT);
 	REGISTER_LONG_CONSTANT("MYSQLI_OPT_LOCAL_INFILE", MYSQL_OPT_LOCAL_INFILE, CONST_CS |
CONST_PERSISTENT);
 	REGISTER_LONG_CONSTANT("MYSQLI_INIT_COMMAND", MYSQL_INIT_COMMAND, CONST_CS |
CONST_PERSISTENT);
+	REGISTER_LONG_CONSTANT("MYSQLI_OPT_NUMERIC_AND_DATETIME_AS_UNICODE",
MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE, CONST_CS | CONST_PERSISTENT);
 
 	/* mysqli_real_connect flags */	
 	REGISTER_LONG_CONSTANT("MYSQLI_CLIENT_SSL", CLIENT_SSL, CONST_CS | CONST_PERSISTENT);

Modified: trunk/ext/mysqli/mysqli_libmysql.h
===================================================================
--- trunk/ext/mysqli/mysqli_libmysql.h	2007-03-21 13:37:22 UTC (rev 237)
+++ trunk/ext/mysqli/mysqli_libmysql.h	2007-03-21 14:04:32 UTC (rev 238)
@@ -23,6 +23,7 @@
 #define MYSQLI_CLOSE_EXPLICIT
 #define MYSQLI_CLOSE_IMPLICIT
 #define MYSQLI_CLOSE_DISCONNECTED
+#define MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE	100
 
 #define mysqli_result_is_unbuffered(r)		((r)->handle &&
(r)->handle->status == MYSQL_STATUS_USE_RESULT)
 #define mysqli_server_status(c)				(c)->server_status

Modified: trunk/ext/mysqli/mysqlnd/mysqlnd.c
===================================================================
--- trunk/ext/mysqli/mysqlnd/mysqlnd.c	2007-03-21 13:37:22 UTC (rev 237)
+++ trunk/ext/mysqli/mysqlnd/mysqlnd.c	2007-03-21 14:04:32 UTC (rev 238)
@@ -2305,6 +2305,9 @@
 _mysqlnd_set_client_option(MYSQLND * const conn, enum mysqlnd_option option, const char *
const value)
 {
 	switch (option) {
+		case MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE:
+			conn->options.numeric_and_datetime_as_unicode = *(uint*) value;
+			break;
 		case MYSQL_OPT_CONNECT_TIMEOUT:
 			conn->options.timeout_connect = *(uint*) value;
 			break;

Modified: trunk/ext/mysqli/mysqlnd/mysqlnd.h
===================================================================
--- trunk/ext/mysqli/mysqlnd/mysqlnd.h	2007-03-21 13:37:22 UTC (rev 237)
+++ trunk/ext/mysqli/mysqlnd/mysqlnd.h	2007-03-21 14:04:32 UTC (rev 238)
@@ -155,7 +155,8 @@
 	MYSQL_SECURE_AUTH,
 	MYSQL_REPORT_DATA_TRUNCATION,
 	MYSQL_OPT_RECONNECT,
-	MYSQL_OPT_SSL_VERIFY_SERVER_CERT
+	MYSQL_OPT_SSL_VERIFY_SERVER_CERT,
+	MYSQLND_OPT_NUMERIC_AND_DATETIME_AS_UNICODE = 100,
 } enum_mysqlnd_option;
 
 
@@ -462,6 +463,8 @@
 
 	/* maximum allowed packet size for communication */
 	ulong	max_allowed_packet;
+
+	zend_bool	numeric_and_datetime_as_unicode;
 } MYSQLND_OPTION;
 
 

Modified: trunk/ext/mysqli/mysqlnd/mysqlnd_priv.h
===================================================================
--- trunk/ext/mysqli/mysqlnd/mysqlnd_priv.h	2007-03-21 13:37:22 UTC (rev 237)
+++ trunk/ext/mysqli/mysqlnd/mysqlnd_priv.h	2007-03-21 14:04:32 UTC (rev 238)
@@ -136,7 +136,8 @@
 
 /* PS stuff */
 typedef void (*ps_field_fetch_func)(zval *zv, const MYSQLND_FIELD * const field,
-									uint pack_len, zend_uchar **row TSRMLS_DC);
+									uint pack_len, zend_uchar **row,
+									zend_bool everything_as_unicode TSRMLS_DC);
 struct st_mysqlnd_perm_bind {
 	ps_field_fetch_func func;
 	/* should be signed int */

Modified: trunk/ext/mysqli/mysqlnd/mysqlnd_ps_codec.c
===================================================================
--- trunk/ext/mysqli/mysqlnd/mysqlnd_ps_codec.c	2007-03-21 13:37:22 UTC (rev 237)
+++ trunk/ext/mysqli/mysqlnd/mysqlnd_ps_codec.c	2007-03-21 14:04:32 UTC (rev 238)
@@ -69,7 +69,8 @@
 /* {{{ ps_fetch_null */
 static
 void ps_fetch_null(zval *zv, const MYSQLND_FIELD * const field,
-				   uint pack_len, zend_uchar **row TSRMLS_DC)
+				   uint pack_len, zend_uchar **row,
+				   zend_bool as_unicode TSRMLS_DC)
 {
 	ZVAL_NULL(zv);
 }
@@ -79,7 +80,8 @@
 /* {{{ ps_fetch_int8 */
 static
 void ps_fetch_int8(zval *zv, const MYSQLND_FIELD * const field,
-				   uint pack_len, zend_uchar **row TSRMLS_DC)
+				   uint pack_len, zend_uchar **row,
+				   zend_bool as_unicode TSRMLS_DC)
 {
 
 	if (field->flags & UNSIGNED_FLAG) {
@@ -95,7 +97,8 @@
 /* {{{ ps_fetch_int16 */
 static
 void ps_fetch_int16(zval *zv, const MYSQLND_FIELD * const field,
-					uint pack_len, zend_uchar **row TSRMLS_DC)
+					uint pack_len, zend_uchar **row,
+					zend_bool as_unicode TSRMLS_DC)
 {
 	if (field->flags & UNSIGNED_FLAG) {
 		ZVAL_LONG(zv, (my_uint16) sint2korr(*row));
@@ -110,7 +113,8 @@
 /* {{{ ps_fetch_int32 */
 static
 void ps_fetch_int32(zval *zv, const MYSQLND_FIELD * const field,
-					uint pack_len, zend_uchar **row TSRMLS_DC)
+					uint pack_len, zend_uchar **row,
+					zend_bool as_unicode TSRMLS_DC)
 {
 	if (field->flags & UNSIGNED_FLAG) {
 		my_uint32 uval;
@@ -129,11 +133,15 @@
 			} while (--j > 0);
 			tmp[10]= '\0';
 			/* unsigned int > INT_MAX is 10 digits - ALWAYS */
-#if PHP_MAJOR_VERSION < 6
-			ZVAL_STRING(zv, tmp, 0);
-#else
-			ZVAL_UTF8_STRINGL(zv, tmp, 10, ZSTR_AUTOFREE);
-#endif /* PHP_MAJOR_VERSION < 6 */
+#if PHP_MAJOR_VERSION >= 6
+			if (!as_unicode) {
+#endif
+				ZVAL_STRING(zv, tmp, 0);
+#if PHP_MAJOR_VERSION >= 6
+			} else {
+				ZVAL_UTF8_STRINGL(zv, tmp, 10, ZSTR_AUTOFREE);
+			}
+#endif /* PHP_MAJOR_VERSION >= 6 */
 		} else 
 #endif /* #if SIZEOF_LONG==4 */
 		{
@@ -150,7 +158,8 @@
 /* {{{ ps_fetch_int64 */
 static
 void ps_fetch_int64(zval *zv, const MYSQLND_FIELD * const field,
-					uint pack_len, zend_uchar **row TSRMLS_DC)
+					uint pack_len, zend_uchar **row,
+					zend_bool as_unicode TSRMLS_DC)
 {
 	my_uint64 llval = (my_uint64) sint8korr(*row);
 	zend_bool uns = field->flags & UNSIGNED_FLAG? TRUE:FALSE;
@@ -169,13 +178,13 @@
 		 * use MYSQLND_LL_SPEC.
 		 */
 		sprintf((char *)&tmp, uns == TRUE? MYSQLND_LLU_SPEC : MYSQLND_LL_SPEC, llval);
-#if PHP_MAJOR_VERSION < 6
-		ZVAL_STRING(zv, tmp, 1);
-#else
-		if (UG(unicode)) {
+#if PHP_MAJOR_VERSION >= 6
+		if (!as_unicode) {
+#endif		
+			ZVAL_STRING(zv, tmp, 1);
+#if PHP_MAJOR_VERSION >= 6
+		} else {
 			ZVAL_UTF8_STRING(zv, tmp, ZSTR_DUPLICATE);
-		} else {
-			ZVAL_STRING(zv, tmp, 1);	
 		}
 #endif
 	} else {
@@ -189,7 +198,8 @@
 /* {{{ ps_fetch_float */
 static
 void ps_fetch_float(zval *zv, const MYSQLND_FIELD * const field,
-					uint pack_len, zend_uchar **row TSRMLS_DC)
+					uint pack_len, zend_uchar **row,
+					zend_bool as_unicode TSRMLS_DC)
 {
 	float value;
 	float4get(value, *row);
@@ -202,7 +212,8 @@
 /* {{{ ps_fetch_double */
 static
 void ps_fetch_double(zval *zv, const MYSQLND_FIELD * const field,
-					 uint pack_len, zend_uchar **row TSRMLS_DC)
+					uint pack_len, zend_uchar **row,
+					zend_bool as_unicode TSRMLS_DC)
 {
 	double value;
 	float8get(value, *row);
@@ -215,7 +226,8 @@
 /* {{{ ps_fetch_time */
 static
 void ps_fetch_time(zval *zv, const MYSQLND_FIELD * const field,
-					uint pack_len, zend_uchar **row TSRMLS_DC)
+				   uint pack_len, zend_uchar **row,
+				   zend_bool as_unicode TSRMLS_DC)
 {
 	struct st_mysqlnd_time t;
 	unsigned int length; /* First byte encodes the length*/
@@ -252,12 +264,16 @@
 	length = spprintf(&to, 0, "%s%02u:%02u:%02u",
 					 (t.neg ? "-" : ""), t.hour, t.minute, t.second);
 
-#if PHP_MAJOR_VERSION < 6
-	ZVAL_STRINGL(zv, to, length, 1);
-	efree(to);
-#else
-	ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);
+#if PHP_MAJOR_VERSION >= 6
+	if (!as_unicode) {
 #endif
+		ZVAL_STRINGL(zv, to, length, 1);
+		efree(to);
+#if PHP_MAJOR_VERSION >= 6
+	} else {
+		ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);	
+	}
+#endif
 }
 /* }}} */
 
@@ -265,7 +281,8 @@
 /* {{{ ps_fetch_date */
 static
 void ps_fetch_date(zval *zv, const MYSQLND_FIELD * const field,
-					uint pack_len, zend_uchar **row TSRMLS_DC)
+				   uint pack_len, zend_uchar **row,
+				   zend_bool as_unicode TSRMLS_DC)
 {
 	struct st_mysqlnd_time t = {0};
 	unsigned int length; /* First byte encodes the length*/
@@ -295,12 +312,16 @@
 	*/
 	length = spprintf(&to, 0, "%04u-%02u-%02u", t.year, t.month, t.day);
 
-#if PHP_MAJOR_VERSION < 6
-	ZVAL_STRINGL(zv, to, length, 1);
-	efree(to);
-#else
-	ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);
+#if PHP_MAJOR_VERSION >= 6
+	if (!as_unicode) {
 #endif
+		ZVAL_STRINGL(zv, to, length, 1);
+		efree(to);
+#if PHP_MAJOR_VERSION >= 6
+	} else {
+		ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);	
+	}
+#endif
 }
 /* }}} */
 
@@ -308,7 +329,8 @@
 /* {{{ ps_fetch_datetime */
 static
 void ps_fetch_datetime(zval *zv, const MYSQLND_FIELD * const field,
-						uint pack_len, zend_uchar **row TSRMLS_DC)
+					   uint pack_len, zend_uchar **row,
+					   zend_bool as_unicode TSRMLS_DC)
 {
 	struct st_mysqlnd_time t;
 	unsigned int length; /* First byte encodes the length*/
@@ -346,12 +368,16 @@
 	length = spprintf(&to, 0, "%04u-%02u-%02u %02u:%02u:%02u",
 					  t.year, t.month, t.day, t.hour, t.minute, t.second);
 
-#if PHP_MAJOR_VERSION < 6
-	ZVAL_STRINGL(zv, to, length, 1);
-	efree(to);
-#else
-	ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);
+#if PHP_MAJOR_VERSION >= 6
+	if (!as_unicode) {
 #endif
+		ZVAL_STRINGL(zv, to, length, 1);
+		efree(to);
+#if PHP_MAJOR_VERSION >= 6
+	} else {
+		ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);	
+	}
+#endif
 }
 /* }}} */
 
@@ -359,7 +385,8 @@
 /* {{{ ps_fetch_string */
 static
 void ps_fetch_string(zval *zv, const MYSQLND_FIELD * const field,
-					 uint pack_len, zend_uchar **row TSRMLS_DC)
+					 uint pack_len, zend_uchar **row,
+					 zend_bool as_unicode TSRMLS_DC)
 {
 	/*
 	  For now just copy, before we make it possible
@@ -368,11 +395,7 @@
 	unsigned long length= php_mysqlnd_net_field_length(row);
 
 #if PHP_MAJOR_VERSION < 6
-	if (field->type != MYSQL_TYPE_BIT) {
-		ZVAL_STRINGL(zv, (char *)*row, length, 1);	
-	} else {
-		/* Handle BIT here */
-	}
+	ZVAL_STRINGL(zv, (char *)*row, length, 1);	
 #else
 	if (field->charsetnr == MYSQLND_BINARY_CHARSET_NR) {
 		ZVAL_STRINGL(zv, (char *)*row, length, 1);
@@ -386,7 +409,22 @@
 /* }}} */
 
 
+/* {{{ ps_fetch_bit */
+static
+void ps_fetch_bit(zval *zv, const MYSQLND_FIELD * const field,
+					 uint pack_len, zend_uchar **row,
+					 zend_bool as_unicode TSRMLS_DC)
+{
+	unsigned long length= php_mysqlnd_net_field_length(row);
 
+	/* Handle BIT here */
+	ZVAL_STRINGL(zv, (char *)*row, length, 1);	
+
+	(*row) += length;
+}
+/* }}} */
+
+
 /* {{{ _mysqlnd_init_ps_subsystem */
 void _mysqlnd_init_ps_subsystem()
 {
@@ -463,7 +501,7 @@
 	mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG_BLOB].php_type	= IS_STRING;
 	mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG_BLOB].is_possibly_blob = TRUE;
 
-	mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].func			= ps_fetch_string;
+	mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].func			= ps_fetch_bit;
 	mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].pack_len		= MYSQLND_PS_SKIP_RESULT_STR;
 	mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].php_type		= IS_STRING;
 

Modified: trunk/ext/mysqli/mysqlnd/mysqlnd_wireprotocol.c
===================================================================
--- trunk/ext/mysqli/mysqlnd/mysqlnd_wireprotocol.c	2007-03-21 13:37:22 UTC (rev 237)
+++ trunk/ext/mysqli/mysqlnd/mysqlnd_wireprotocol.c	2007-03-21 14:04:32 UTC (rev 238)
@@ -1124,6 +1124,7 @@
 	int i;
 	zend_uchar *null_ptr, bit;
 	zval **current_field, **end_field, **start_field;
+	zend_bool as_unicode = conn->options.numeric_and_datetime_as_unicode;
 
 	end_field = (current_field = start_field = packet->fields) + packet->field_count;
 
@@ -1140,7 +1141,8 @@
 			ZVAL_NULL(*current_field);
 		} else {
 			mysqlnd_ps_fetch_functions[packet->fields_metadata[i].type].
-				func(*current_field, &packet->fields_metadata[i], 0, &p TSRMLS_CC);
+				func(*current_field, &packet->fields_metadata[i], 0, &p,
+					 as_unicode TSRMLS_CC);
 		}
 	    if (!((bit<<=1) & 255)) {
 			bit= 1;					/* To next byte */

Thread
PHP mysqlnd svn commit: r238 - in trunk/ext/mysqli: . mysqlndahristov21 Mar