|
|||||||||||
|
PHP mysqlnd svn commit: r824 - in trunk: mysqlnd tests/ext/mysqli
From: <ahristov(at)mysql.com>
Date: Fri Jul 20 2007 - 19:54:52 EDT
Modified: trunk/mysqlnd/mysqlnd.h trunk/mysqlnd/mysqlnd_palloc.c trunk/mysqlnd/mysqlnd_priv.h trunk/mysqlnd/mysqlnd_ps.c trunk/mysqlnd/mysqlnd_ps_codec.c trunk/mysqlnd/mysqlnd_result.c trunk/mysqlnd/mysqlnd_result_meta.c trunk/mysqlnd/mysqlnd_wireprotocol.c trunk/mysqlnd/mysqlnd_wireprotocol.h trunk/mysqlnd/portability.h trunk/tests/ext/mysqli/mysqli_fetch_assoc_bit.phpt trunk/tests/ext/mysqli/mysqli_stmt_fetch_bit.phpt trunk/tests/ext/mysqli/mysqli_stmt_get_result_bit.phptLog: Eventually BIT handing is solved. Strangely BIT is sent in different order, on the wire, than typical 1, 2, 3, 4, 8 byte types. This confuses a lot. Down to 16 failures in Unicode, mysql+mysqli@mysqlnd, 5.1 Server Modified: trunk/mysqlnd/mysqlnd.h
struct st_mysqlnd_res_meta_methods *m; }; Modified: trunk/mysqlnd/mysqlnd_palloc.c
Modified: trunk/mysqlnd/mysqlnd_priv.h
+void ps_fetch_from_1_to_8_bytes(zval *zv, const MYSQLND_FIELD * const field, + uint pack_len, zend_uchar **row, zend_bool as_unicode, + unsigned int byte_count, zend_bool is_bit TSRMLS_DC);
+
Modified: trunk/mysqlnd/mysqlnd_ps.c
stmt->state = MYSQLND_STMT_USE_OR_STORE_CALLED; Modified: trunk/mysqlnd/mysqlnd_ps_codec.c
+/* {{{ ps_fetch_from_1_to_8_bytes */
+void ps_fetch_from_1_to_8_bytes(zval *zv, const MYSQLND_FIELD * const field,
+ uint pack_len, zend_uchar **row, zend_bool as_unicode,
+ unsigned int byte_count, zend_bool is_bit TSRMLS_DC)
+{
+ char tmp[22];
+ size_t tmp_len = 0;
+ if (field->flags & UNSIGNED_FLAG) {
+ my_uint64 uval = 0;
+ switch (byte_count) {
+ case 8:uval = is_bit? (my_uint64) bit_uint8korr(*row):(my_uint64) uint8korr(*row);break;
+ case 7:uval = bit_uint7korr(*row);break;
+ case 6:uval = bit_uint6korr(*row);break;
+ case 5:uval = bit_uint5korr(*row);break;
+ case 4:uval = is_bit? (my_uint64) bit_uint4korr(*row):(my_uint64) uint4korr(*row);break;
+ case 3:uval = is_bit? (my_uint64) bit_uint3korr(*row):(my_uint64) uint3korr(*row);break;
+ case 2:uval = is_bit? (my_uint64) bit_uint2korr(*row):(my_uint64) uint2korr(*row);break;
+ case 1:uval = (my_uint64) uint1korr(*row);break;
+ }
+#if SIZEOF_LONG==4
+ if (uval > INT_MAX) {
+ tmp_len = sprintf((char *)&tmp, MYSQLND_LLU_SPEC, uval);
+ } else
+#endif /* #if SIZEOF_LONG==4 */
+ {
+ if (byte_count < 8 || uval <= L64(9223372036854775807)) {
+ ZVAL_LONG(zv, uval);
+ } else {
+ tmp_len = sprintf((char *)&tmp, MYSQLND_LLU_SPEC, uval);
+ }
+ }
+ } else {
+ /* SIGNED */
+ my_int64 lval = 0;
+ switch (byte_count) {
+ case 8:lval = (my_int64) sint8korr(*row);break;
+ /*
+ 7, 6 and 5 are not possible.
+ BIT is only unsigned, thus only uint5|6|7 macroses exist
+ */
+ case 4:lval = (my_int64) sint4korr(*row);break;
+ case 3:lval = (my_int64) sint3korr(*row);break;
+ case 2:lval = (my_int64) sint2korr(*row);break;
+ case 1:lval = (my_int64) *(my_int8*)*row;break;
+ }
+
+#if SIZEOF_LONG==4
+ if ((L64(2147483647) < (my_int64) lval) || (L64(-2147483648) > (my_int64) lval)) {
+ tmp_len = sprintf((char *)&tmp, MYSQLND_LL_SPEC, lval);
+ } else
+#endif /* SIZEOF */
+ {
+ ZVAL_LONG(zv, lval);
+ }
+ }
+
+ if (tmp_len) {
+#if PHP_MAJOR_VERSION >= 6
+ if (as_unicode) {
+ ZVAL_UTF8_STRINGL(zv, tmp, tmp_len, ZSTR_DUPLICATE);
+ } else
+#endif
+ {
+ ZVAL_STRINGL(zv, tmp, tmp_len, 1);
+ }
+ }
+ (*row)+= byte_count;
+}
+/* }}} */
+ + /* {{{ ps_fetch_null */ static void ps_fetch_null(zval *zv, const MYSQLND_FIELD * const field, @@ -83,13 +154,15 @@ uint pack_len, zend_uchar **row, zend_bool as_unicode TSRMLS_DC) { - + ps_fetch_from_1_to_8_bytes(zv, field, pack_len, row, as_unicode, 1, FALSE TSRMLS_CC); +#if 0
if (field->flags & UNSIGNED_FLAG) {
ZVAL_LONG(zv, *(my_uint8*)*row);
} else {
ZVAL_LONG(zv, *(my_int8*)*row);
}
(*row)++;
+#endif } /* }}} */ @@ -100,12 +173,15 @@
uint pack_len, zend_uchar **row,
zend_bool as_unicode TSRMLS_DC)
{
+ ps_fetch_from_1_to_8_bytes(zv, field, pack_len, row, as_unicode, 2, FALSE TSRMLS_CC);
+#if 0
if (field->flags & UNSIGNED_FLAG) {
ZVAL_LONG(zv, (my_uint16) sint2korr(*row));
} else {
ZVAL_LONG(zv, (my_int16) sint2korr(*row));
}
(*row)+= 2;
+#endif } /* }}} */ @@ -116,6 +192,9 @@
uint pack_len, zend_uchar **row,
zend_bool as_unicode TSRMLS_DC)
{
+ ps_fetch_from_1_to_8_bytes(zv, field, pack_len, row, as_unicode, 4, FALSE TSRMLS_CC);
+#if 0
+
if (field->flags & UNSIGNED_FLAG) {
my_uint32 uval;
+#endif /* 0 */ } /* }}} */ @@ -161,6 +241,9 @@
uint pack_len, zend_uchar **row,
zend_bool as_unicode TSRMLS_DC)
{
+ ps_fetch_from_1_to_8_bytes(zv, field, pack_len, row, as_unicode, 8, FALSE TSRMLS_CC);
+#if 0
+ my_uint64 llval = (my_uint64) sint8korr(*row); zend_bool uns = field->flags & UNSIGNED_FLAG? TRUE:FALSE; +#endif /* 0 */ } /* }}} */ @@ -413,38 +497,11 @@
- uint pack_len, zend_uchar **row,
- zend_bool as_unicode TSRMLS_DC)
+ uint pack_len, zend_uchar **row,
+ zend_bool as_unicode TSRMLS_DC)
{
unsigned long length= php_mysqlnd_net_field_length(row);
- ps_field_fetch_func func = NULL;
- switch (length) {
- case 8:
- func = ps_fetch_int64;
- break;
- case 4:
- case 3:
- func = ps_fetch_int32;
- break;
- case 2:
- func = ps_fetch_int16;
- break;
- case 1:
- func = ps_fetch_int8;
- break;
- default:
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "Serious error. Length is %llu", length);
- break;
- }
- if (func) {
- func(zv, field, length, row, as_unicode TSRMLS_CC);
- }
-#if 0
- /* Handle BIT here */
- ZVAL_STRINGL(zv, (char *)*row, length, 1);
-#endif
-
- (*row) += length;
+ ps_fetch_from_1_to_8_bytes(zv, field, pack_len, row, as_unicode, length, TRUE TSRMLS_CC);
}
/* }}} */ @@ -547,10 +604,10 @@ mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG_BLOB].is_possibly_blob = TRUE; mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG_BLOB].can_ret_as_str_in_uni = TRUE; - 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; - mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].is_possibly_blob = TRUE; + mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].func = ps_fetch_bit; + mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].pack_len = 8; + mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].php_type = IS_LONG; + mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].can_ret_as_str_in_uni = TRUE; mysqlnd_ps_fetch_functions[MYSQL_TYPE_VAR_STRING].func = ps_fetch_string; mysqlnd_ps_fetch_functions[MYSQL_TYPE_VAR_STRING].pack_len = MYSQLND_PS_SKIP_RESULT_STR; Modified: trunk/mysqlnd/mysqlnd_result.c
/* No multithreading issues as we don't share the connection :) */
row_packet.field_count = meta->field_count;
row_packet.binary_protocol = binary_protocol;
row_packet.fields_metadata = meta->fields;
+ row_packet.bit_fields_count = meta->bit_fields_count;
+ row_packet.bit_fields_total_len = meta->bit_fields_total_len;
/* Let the row packet fill our buffer and skip additional malloc + memcpy */
while (FAIL != (ret = PACKET_READ_ALLOCA(row_packet, conn)) && !row_packet.eof) {
int i;
Modified: trunk/mysqlnd/mysqlnd_result_meta.c
-
if (UG(unicode)) {
UChar *ustr;
Modified: trunk/mysqlnd/mysqlnd_wireprotocol.c
static enum_func_status
- size_t *data_size, zend_bool persistent_alloc TSRMLS_DC)
+ size_t *data_size, zend_bool persistent_alloc,
+ unsigned int prealloc_more_bytes TSRMLS_DC)
{
enum_func_status ret = PASS;
mysqlnd_packet_header header;
} @@ -1256,6 +1258,7 @@ int i; zend_bool last_field_was_string; zval **current_field, **end_field, **start_field; + zend_uchar *bit_area = packet->row_buffer + data_size + 1; /* we allocate from here */ zend_bool as_unicode = conn->options.numeric_and_datetime_as_unicode; #ifdef MYSQLND_STRING_TO_INT_CONVERSION zend_bool as_int = conn->options.int_and_year_as_int;-#endif +#endif /* SIZEOF */
{
ZVAL_STRINGL(*current_field, (char *)p, len, 0);
} else {
@@ -1358,6 +1394,7 @@ XXX: Keep in mind that up there there is an open `else` in #ifdef MYSQLND_STRING_TO_INT_CONVERSION + which will make with this `if` an `else if`. */ if ((perm_bind.is_possibly_blob == TRUE && packet->fields_metadata[i].charsetnr == MYSQLND_BINARY_CHARSET_NR) || Modified: trunk/mysqlnd/mysqlnd_wireprotocol.h
/* If error packet, we use these */ mysqlnd_error_info error_info; Modified: trunk/mysqlnd/portability.h
#define int1store(T,A) do { *((zend_uchar*) (T)) = (A); } while(0)
-#define uint1korr(A) (*(((zend_uchar*)(A))))
+#define uint1korr(A) (*(((uint8*)(A))))
+/* Bit values are sent in reverted order of bytes, compared to normal !!! */
+#define bit_uint2korr(A) ((uint16) (((uint16) (((uchar*) (A))[1])) +\
+ ((uint16) (((uchar*) (A))[0]) << 8)))
+#define bit_uint3korr(A) ((uint32) (((uint32) (((uchar*) (A))[2])) +\
+ (((uint32) (((uchar*) (A))[1])) << 8) +\
+ (((uint32) (((uchar*) (A))[0])) << 16)))
+
+#define bit_uint4korr(A) ((uint32) (((uint32) (((uchar*) (A))[3])) +\
+ (((uint32) (((uchar*) (A))[2])) << 8) +\
+ (((uint32) (((uchar*) (A))[1])) << 16) +\
+ (((uint32) (((uchar*) (A))[0])) << 24)))
+
+#define bit_uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
+ (((uint32) ((uchar) (A)[1])) << 8) +\
+ (((uint32) ((uchar) (A)[2])) << 16) +\
+ (((uint32) ((uchar) (A)[3])) << 24)) +\
+ (((ulonglong) ((uchar) (A)[4])) << 32))
+
+#define bit_uint6korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[5])) +\
+ (((uint32) (((uchar*) (A))[4])) << 8) +\
+ (((uint32) (((uchar*) (A))[3])) << 16) +\
+ (((uint32) (((uchar*) (A))[2])) << 24)) +\
+ (((ulonglong) (((uint32) (((uchar*) (A))[1])) +\
+ (((uint32) (((uchar*) (A))[0]) << 8)))) << 32))
+
+#define bit_uint7korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[6])) +\
+ (((uint32) (((uchar*) (A))[5])) << 8) +\
+ (((uint32) (((uchar*) (A))[4])) << 16) +\
+ (((uint32) (((uchar*) (A))[3])) << 24)) +\
+ (((ulonglong) (((uint32) (((uchar*) (A))[2])) +\
+ (((uint32) (((uchar*) (A))[1])) << 8) +\
+ (((uint32) (((uchar*) (A))[0])) << 16))) << 32))
+
+
+#define bit_uint8korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[7])) +\
+ (((uint32) (((uchar*) (A))[6])) << 8) +\
+ (((uint32) (((uchar*) (A))[5])) << 16) +\
+ (((uint32) (((uchar*) (A))[4])) << 24)) +\
+ (((ulonglong) (((uint32) (((uchar*) (A))[3])) +\
+ (((uint32) (((uchar*) (A))[2])) << 8) +\
+ (((uint32) (((uchar*) (A))[1])) << 16) +\
+ (((uint32) (((uchar*) (A))[0])) << 24))) << 32))
+
+ /* ** Define-funktions for reading and storing in machine independent format ** (low byte first)#define sint4korr(A) (*((long *) (A))) +
#define uint2korr(A) (*((uint16 *) (A)))
#define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
(((uint32) ((uchar) (A)[1])) << 8) +\
(((uint32) ((uchar) (A)[2])) << 16))
#define uint4korr(A) (*((unsigned long *) (A)))
-#define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ - (((uint32) ((uchar) (A)[1])) << 8) +\ - (((uint32) ((uchar) (A)[2])) << 16) +\ - (((uint32) ((uchar) (A)[3])) << 24)) +\ - (((ulonglong) ((uchar) (A)[4])) << 32)) -/* From Andrey Hristov, based on uint5korr() */ -#define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ - (((uint32) ((uchar) (A)[1])) << 8) +\ - (((uint32) ((uchar) (A)[2])) << 16) +\ - (((uint32) ((uchar) (A)[3])) << 24)) +\ - (((ulonglong) ((uchar) (A)[4])) << 32)) +\ - (((ulonglong) ((uchar) (A)[5])) << 40)) + + + #define uint8korr(A) (*((ulonglong *) (A))) #define sint8korr(A) (*((longlong *) (A))) #define int2store(T,A) *((uint16*) (T))= (uint16) (A)+
#define sint8korr(A) (longlong) uint8korr(A)
#define uint2korr(A) (uint16) (((uint16) ((uchar) (A)[0])) +\
((uint16) ((uchar) (A)[1]) << 8))
/* From Andrey Hristov, based on uint5korr */
-#define uint6korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ - (((uint32) ((uchar) (A)[1])) << 8) +\ - (((uint32) ((uchar) (A)[2])) << 16) +\ - (((uint32) ((uchar) (A)[3])) << 24)) +\ - (((ulonglong) ((uchar) (A)[4])) << 32)) +\ - (((ulonglong) ((uchar) (A)[5])) << 40)) -#define uint8korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ - (((uint32) ((uchar) (A)[1])) << 8) +\ - (((uint32) ((uchar) (A)[2])) << 16) +\ - (((uint32) ((uchar) (A)[3])) << 24)) +\ - (((ulonglong) (((uint32) ((uchar) (A)[4])) +\ - (((uint32) ((uchar) (A)[5])) << 8) +\ - (((uint32) ((uchar) (A)[6])) << 16) +\ - (((uint32) ((uchar) (A)[7])) << 24))) << 32)) +#define bit_uint6korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[5])) +\ + (((uint32) (((uchar*) (A))[4])) << 8) +\ + (((uint32) (((uchar*) (A))[3])) << 16) +\ + (((uint32) (((uchar*) (A))[2])) << 24)) +\ + (((ulonglong) (((uint32) (((uchar*) (A))[1])) +\ + (((uint32) (((uchar*) (A))[0]) << 8)))) << 32)) + +#define bit_uint7korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[6])) +\ + (((uint32) (((uchar*) (A))[5])) << 8) +\ + (((uint32) (((uchar*) (A))[4])) << 16) +\ + (((uint32) (((uchar*) (A))[3])) << 24)) +\ + (((ulonglong) (((uint32) (((uchar*) (A))[2])) +\ + (((uint32) (((uchar*) (A))[1])) << 8) +\ + (((uint32) (((uchar*) (A))[0])) << 16))) << 32)) + + +#define bit_uint8korr(A) ((ulonglong)(((uint32) (((uchar*) (A))[7])) +\ + (((uint32) (((uchar*) (A))[6])) << 8) +\ + (((uint32) (((uchar*) (A))[5])) << 16) +\ + (((uint32) (((uchar*) (A))[4])) << 24)) +\ + (((ulonglong) (((uint32) (((uchar*) (A))[3])) +\ + (((uint32) (((uchar*) (A))[2])) << 8) +\ + (((uint32) (((uchar*) (A))[1])) << 16) +\ + (((uint32) (((uchar*) (A))[0])) << 24))) << 32)) + +#define uint8korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\ + (((uint32) ((uchar) (A)[1])) << 8) +\ + (((uint32) ((uchar) (A)[2])) << 16) +\ + (((uint32) ((uchar) (A)[3])) << 24)) +\ + (((ulonglong) (((uint32) ((uchar) (A)[4])) +\ + (((uint32) ((uchar) (A)[5])) << 8) +\ + (((uint32) ((uchar) (A)[6])) << 16) +\ + (((uint32) ((uchar) (A)[7])) << 24))) << 32))+ + #define int2store(T,A) do { uint def_temp= (uint) (A) ;\
*((uchar*) (T)) = (uchar)(def_temp); \
*((uchar*) (T+1)) = (uchar)((def_temp >> 8)); } while (0)
Modified: trunk/tests/ext/mysqli/mysqli_fetch_assoc_bit.phpt
mysqli_close($link); print "done!"; ?> --EXPECTF-- -done! \ No newline at end of file +done! Modified: trunk/tests/ext/mysqli/mysqli_stmt_fetch_bit.phpt
Modified: trunk/tests/ext/mysqli/mysqli_stmt_get_result_bit.phpt
-- MySQL Code Commits Mailing List For list archives: http://lists.mysql.com/commits To unsubscribe: http://lists.mysql.com/commits?unsub=lists@pantek.comReceived on Fri Jul 20 19:55:00 2007 This archive was generated by hypermail 2.1.8 : Thu Aug 09 2007 - 19:10:52 EDT |
||||||||||
|
|||||||||||