PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - ext/mysqlnd - mysqlnd_ps_codec.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 400 446 89.7 %
Date: 2014-08-17 Functions: 16 17 94.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   +----------------------------------------------------------------------+
       3             :   | PHP Version 5                                                        |
       4             :   +----------------------------------------------------------------------+
       5             :   | Copyright (c) 2006-2014 The PHP Group                                |
       6             :   +----------------------------------------------------------------------+
       7             :   | This source file is subject to version 3.01 of the PHP license,      |
       8             :   | that is bundled with this package in the file LICENSE, and is        |
       9             :   | available through the world-wide-web at the following url:           |
      10             :   | http://www.php.net/license/3_01.txt                                  |
      11             :   | If you did not receive a copy of the PHP license and are unable to   |
      12             :   | obtain it through the world-wide-web, please send a note to          |
      13             :   | license@php.net so we can mail you a copy immediately.               |
      14             :   +----------------------------------------------------------------------+
      15             :   | Authors: Andrey Hristov <andrey@mysql.com>                           |
      16             :   |          Ulf Wendel <uwendel@mysql.com>                              |
      17             :   |          Georg Richter <georg@mysql.com>                             |
      18             :   +----------------------------------------------------------------------+
      19             : */
      20             : 
      21             : /* $Id$ */
      22             : #include "php.h"
      23             : #include "mysqlnd.h"
      24             : #include "mysqlnd_wireprotocol.h"
      25             : #include "mysqlnd_priv.h"
      26             : #include "mysqlnd_debug.h"
      27             : 
      28             : #define MYSQLND_SILENT
      29             : 
      30             : 
      31             : enum mysqlnd_timestamp_type
      32             : {
      33             :   MYSQLND_TIMESTAMP_NONE= -2,
      34             :   MYSQLND_TIMESTAMP_ERROR= -1,
      35             :   MYSQLND_TIMESTAMP_DATE= 0,
      36             :   MYSQLND_TIMESTAMP_DATETIME= 1,
      37             :   MYSQLND_TIMESTAMP_TIME= 2
      38             : };
      39             : 
      40             : 
      41             : struct st_mysqlnd_time
      42             : {
      43             :   unsigned int  year, month, day, hour, minute, second;
      44             :   unsigned long second_part;
      45             :   zend_bool     neg;
      46             :   enum mysqlnd_timestamp_type time_type;
      47             : };
      48             : 
      49             : 
      50             : struct st_mysqlnd_perm_bind mysqlnd_ps_fetch_functions[MYSQL_TYPE_LAST + 1];
      51             : 
      52             : #define MYSQLND_PS_SKIP_RESULT_W_LEN    -1
      53             : #define MYSQLND_PS_SKIP_RESULT_STR              -2
      54             : 
      55             : /* {{{ ps_fetch_from_1_to_8_bytes */
      56       23191 : void ps_fetch_from_1_to_8_bytes(zval *zv, const MYSQLND_FIELD * const field,
      57             :                                                                 unsigned int pack_len, zend_uchar **row, zend_bool as_unicode,
      58             :                                                                 unsigned int byte_count TSRMLS_DC)
      59             : {
      60             :         char tmp[22];
      61       23191 :         size_t tmp_len = 0;
      62       23191 :         zend_bool is_bit = field->type == MYSQL_TYPE_BIT;
      63       23191 :         DBG_ENTER("ps_fetch_from_1_to_8_bytes");
      64       23191 :         DBG_INF_FMT("zv=%p byte_count=%u", zv, byte_count);
      65       23191 :         if (field->flags & UNSIGNED_FLAG) {
      66        3568 :                 uint64_t uval = 0;
      67             : 
      68        3568 :                 switch (byte_count) {
      69        1525 :                         case 8:uval = is_bit? (uint64_t) bit_uint8korr(*row):(uint64_t) uint8korr(*row);break;
      70           0 :                         case 7:uval = bit_uint7korr(*row);break;
      71         180 :                         case 6:uval = bit_uint6korr(*row);break;
      72         240 :                         case 5:uval = bit_uint5korr(*row);break;
      73         422 :                         case 4:uval = is_bit? (uint64_t) bit_uint4korr(*row):(uint64_t) uint4korr(*row);break;
      74         400 :                         case 3:uval = is_bit? (uint64_t) bit_uint3korr(*row):(uint64_t) uint3korr(*row);break;
      75         436 :                         case 2:uval = is_bit? (uint64_t) bit_uint2korr(*row):(uint64_t) uint2korr(*row);break;
      76         365 :                         case 1:uval = (uint64_t) uint1korr(*row);break;
      77             :                 }
      78             : 
      79             : #if SIZEOF_LONG==4
      80             :                 if (uval > INT_MAX) {
      81             :                         DBG_INF("stringify");
      82             :                         tmp_len = sprintf((char *)&tmp, MYSQLND_LLU_SPEC, uval);
      83             :                 } else 
      84             : #endif /* #if SIZEOF_LONG==4 */
      85             :                 {
      86        7125 :                         if (byte_count < 8 || uval <= L64(9223372036854775807)) {
      87        3557 :                                 ZVAL_LONG(zv, (long) uval); /* the cast is safe, we are in the range */
      88             :                         } else {
      89          11 :                                 DBG_INF("stringify");
      90          11 :                                 tmp_len = sprintf((char *)&tmp, MYSQLND_LLU_SPEC, uval);
      91             :                         }
      92             :                 }
      93             :         } else {
      94             :                 /* SIGNED */
      95       19623 :                 int64_t lval = 0;
      96       19623 :                 switch (byte_count) {
      97         525 :                         case 8:lval = (int64_t) sint8korr(*row);break;
      98             :                         /*
      99             :                           7, 6 and 5 are not possible.
     100             :                           BIT is only unsigned, thus only uint5|6|7 macroses exist
     101             :                         */
     102       19027 :                         case 4:lval = (int64_t) sint4korr(*row);break;
     103           0 :                         case 3:lval = (int64_t) sint3korr(*row);break;
     104          26 :                         case 2:lval = (int64_t) sint2korr(*row);break;
     105          45 :                         case 1:lval = (int64_t) *(int8_t*)*row;break;
     106             :                 }
     107             : 
     108             : #if SIZEOF_LONG==4
     109             :                 if ((L64(2147483647) < (int64_t) lval) || (L64(-2147483648) > (int64_t) lval)) {
     110             :                         DBG_INF("stringify");
     111             :                         tmp_len = sprintf((char *)&tmp, MYSQLND_LL_SPEC, lval);
     112             :                 } else
     113             : #endif /* SIZEOF */
     114             :                 {
     115       19623 :                         ZVAL_LONG(zv, (long) lval); /* the cast is safe, we are in the range */
     116             :                 }
     117             :         }
     118             : 
     119       23191 :         if (tmp_len) {
     120             : #if MYSQLND_UNICODE
     121             :                 if (as_unicode) {
     122             :                         DBG_INF("stringify");
     123             :                         ZVAL_UTF8_STRINGL(zv, tmp, tmp_len, ZSTR_DUPLICATE);
     124             :                 } else
     125             : #endif
     126             :                 {
     127          11 :                         DBG_INF("stringify");
     128          11 :                         ZVAL_STRINGL(zv, tmp, tmp_len, 1);
     129             :                 }
     130             :         }
     131       23191 :         (*row)+= byte_count;
     132       23191 :         DBG_VOID_RETURN;
     133             : }
     134             : /* }}} */
     135             : 
     136             : 
     137             : /* {{{ ps_fetch_null */
     138             : static
     139           0 : void ps_fetch_null(zval *zv, const MYSQLND_FIELD * const field,
     140             :                                    unsigned int pack_len, zend_uchar **row,
     141             :                                    zend_bool as_unicode TSRMLS_DC)
     142             : {
     143           0 :         ZVAL_NULL(zv);
     144           0 : }
     145             : /* }}} */
     146             : 
     147             : 
     148             : /* {{{ ps_fetch_int8 */
     149             : static
     150          60 : void ps_fetch_int8(zval *zv, const MYSQLND_FIELD * const field,
     151             :                                    unsigned int pack_len, zend_uchar **row,
     152             :                                    zend_bool as_unicode TSRMLS_DC)
     153             : {
     154          60 :         ps_fetch_from_1_to_8_bytes(zv, field, pack_len, row, as_unicode, 1 TSRMLS_CC);
     155          60 : }
     156             : /* }}} */
     157             : 
     158             : 
     159             : /* {{{ ps_fetch_int16 */
     160             : static
     161          62 : void ps_fetch_int16(zval *zv, const MYSQLND_FIELD * const field,
     162             :                                         unsigned int pack_len, zend_uchar **row,
     163             :                                         zend_bool as_unicode TSRMLS_DC)
     164             : {
     165          62 :         ps_fetch_from_1_to_8_bytes(zv, field, pack_len, row, as_unicode, 2 TSRMLS_CC);
     166          62 : }
     167             : /* }}} */
     168             : 
     169             : 
     170             : /* {{{ ps_fetch_int32 */
     171             : static
     172       19069 : void ps_fetch_int32(zval *zv, const MYSQLND_FIELD * const field,
     173             :                                         unsigned int pack_len, zend_uchar **row,
     174             :                                         zend_bool as_unicode TSRMLS_DC)
     175             : {
     176       19069 :         ps_fetch_from_1_to_8_bytes(zv, field, pack_len, row, as_unicode, 4 TSRMLS_CC);
     177       19069 : }
     178             : /* }}} */
     179             : 
     180             : 
     181             : /* {{{ ps_fetch_int64 */
     182             : static
     183        2050 : void ps_fetch_int64(zval *zv, const MYSQLND_FIELD * const field,
     184             :                                         unsigned int pack_len, zend_uchar **row,
     185             :                                         zend_bool as_unicode TSRMLS_DC)
     186             : {
     187        2050 :         ps_fetch_from_1_to_8_bytes(zv, field, pack_len, row, as_unicode, 8 TSRMLS_CC);
     188        2050 : }
     189             : /* }}} */
     190             : 
     191             : 
     192             : /* {{{ ps_fetch_float */
     193             : static
     194         131 : void ps_fetch_float(zval *zv, const MYSQLND_FIELD * const field,
     195             :                                         unsigned int pack_len, zend_uchar **row,
     196             :                                         zend_bool as_unicode TSRMLS_DC)
     197             : {
     198             :         float value;
     199         131 :         DBG_ENTER("ps_fetch_float");
     200         131 :         float4get(value, *row);
     201         131 :         ZVAL_DOUBLE(zv, value);
     202         131 :         (*row)+= 4;
     203         131 :         DBG_INF_FMT("value=%f", value);
     204         131 :         DBG_VOID_RETURN;
     205             : }
     206             : /* }}} */
     207             : 
     208             : 
     209             : /* {{{ ps_fetch_double */
     210             : static
     211          60 : void ps_fetch_double(zval *zv, const MYSQLND_FIELD * const field,
     212             :                                         unsigned int pack_len, zend_uchar **row,
     213             :                                         zend_bool as_unicode TSRMLS_DC)
     214             : {
     215             :         double value;
     216          60 :         DBG_ENTER("ps_fetch_double");
     217          60 :         float8get(value, *row);
     218          60 :         ZVAL_DOUBLE(zv, value);
     219          60 :         (*row)+= 8;
     220          60 :         DBG_INF_FMT("value=%f", value);
     221          60 :         DBG_VOID_RETURN;
     222             : }
     223             : /* }}} */
     224             : 
     225             : 
     226             : /* {{{ ps_fetch_time */
     227             : static
     228          19 : void ps_fetch_time(zval *zv, const MYSQLND_FIELD * const field,
     229             :                                    unsigned int pack_len, zend_uchar **row,
     230             :                                    zend_bool as_unicode TSRMLS_DC)
     231             : {
     232             :         struct st_mysqlnd_time t;
     233             :         unsigned int length; /* First byte encodes the length*/
     234             :         char * value;
     235          19 :         DBG_ENTER("ps_fetch_time");
     236             : 
     237          19 :         if ((length = php_mysqlnd_net_field_length(row))) {
     238          19 :                 zend_uchar *to= *row;
     239             : 
     240          19 :                 t.time_type = MYSQLND_TIMESTAMP_TIME;
     241          19 :                 t.neg                   = (zend_bool) to[0];
     242             : 
     243          19 :                 t.day                   = (unsigned long) sint4korr(to+1);
     244          19 :                 t.hour                  = (unsigned int) to[5];
     245          19 :                 t.minute                = (unsigned int) to[6];
     246          19 :                 t.second                = (unsigned int) to[7];
     247          19 :                 t.second_part   = (length > 8) ? (unsigned long) sint4korr(to+8) : 0;
     248          19 :                 t.year                  = t.month= 0;
     249          19 :                 if (t.day) {
     250             :                         /* Convert days to hours at once */
     251           0 :                         t.hour += t.day*24;
     252           0 :                         t.day   = 0;
     253             :                 }
     254             : 
     255          19 :                 (*row) += length;
     256             :         } else {
     257           0 :                 memset(&t, 0, sizeof(t));
     258           0 :                 t.time_type = MYSQLND_TIMESTAMP_TIME;
     259             :         }
     260             : 
     261          19 :         length = mnd_sprintf(&value, 0, "%s%02u:%02u:%02u", (t.neg ? "-" : ""), t.hour, t.minute, t.second);
     262             : 
     263          19 :         DBG_INF_FMT("%s", value);
     264             : #if MYSQLND_UNICODE
     265             :         if (!as_unicode) {
     266             : #endif
     267          19 :                 ZVAL_STRINGL(zv, value, length, 1);
     268          19 :                 mnd_sprintf_free(value);
     269             : #if MYSQLND_UNICODE
     270             :         } else {
     271             :                 ZVAL_UTF8_STRINGL(zv, value, length, ZSTR_AUTOFREE);
     272             :         }
     273             : #endif
     274          19 :         DBG_VOID_RETURN;
     275             : }
     276             : /* }}} */
     277             : 
     278             : 
     279             : /* {{{ ps_fetch_date */
     280             : static
     281          19 : void ps_fetch_date(zval *zv, const MYSQLND_FIELD * const field,
     282             :                                    unsigned int pack_len, zend_uchar **row,
     283             :                                    zend_bool as_unicode TSRMLS_DC)
     284             : {
     285          19 :         struct st_mysqlnd_time t = {0};
     286             :         unsigned int length; /* First byte encodes the length*/
     287             :         char * value;
     288          19 :         DBG_ENTER("ps_fetch_date");
     289             : 
     290          19 :         if ((length = php_mysqlnd_net_field_length(row))) {
     291          19 :                 zend_uchar *to= *row;
     292             : 
     293          19 :                 t.time_type= MYSQLND_TIMESTAMP_DATE;
     294          19 :                 t.neg= 0;
     295             : 
     296          19 :                 t.second_part = t.hour = t.minute = t.second = 0;
     297             : 
     298          19 :                 t.year  = (unsigned int) sint2korr(to);
     299          19 :                 t.month = (unsigned int) to[2];
     300          19 :                 t.day   = (unsigned int) to[3];
     301             : 
     302          19 :                 (*row)+= length;
     303             :         } else {
     304           0 :                 memset(&t, 0, sizeof(t));
     305           0 :                 t.time_type = MYSQLND_TIMESTAMP_DATE;
     306             :         }
     307             : 
     308          19 :         length = mnd_sprintf(&value, 0, "%04u-%02u-%02u", t.year, t.month, t.day);
     309             : 
     310          19 :         DBG_INF_FMT("%s", value);
     311             : #if MYSQLND_UNICODE
     312             :         if (!as_unicode) {
     313             : #endif
     314          19 :                 ZVAL_STRINGL(zv, value, length, 1);
     315          19 :                 mnd_sprintf_free(value);
     316             : #if MYSQLND_UNICODE
     317             :         } else {
     318             :                 ZVAL_UTF8_STRINGL(zv, value, length, ZSTR_AUTOFREE);
     319             :         }
     320             : #endif
     321          19 :         DBG_VOID_RETURN;
     322             : }
     323             : /* }}} */
     324             : 
     325             : 
     326             : /* {{{ ps_fetch_datetime */
     327             : static
     328          36 : void ps_fetch_datetime(zval *zv, const MYSQLND_FIELD * const field,
     329             :                                            unsigned int pack_len, zend_uchar **row,
     330             :                                            zend_bool as_unicode TSRMLS_DC)
     331             : {
     332             :         struct st_mysqlnd_time t;
     333             :         unsigned int length; /* First byte encodes the length*/
     334             :         char * value;
     335          36 :         DBG_ENTER("ps_fetch_datetime");
     336             : 
     337          36 :         if ((length = php_mysqlnd_net_field_length(row))) {
     338          34 :                 zend_uchar *to= *row;
     339             : 
     340          34 :                 t.time_type = MYSQLND_TIMESTAMP_DATETIME;
     341          34 :                 t.neg    = 0;
     342             : 
     343          34 :                 t.year   = (unsigned int) sint2korr(to);
     344          34 :                 t.month = (unsigned int) to[2];
     345          34 :                 t.day    = (unsigned int) to[3];
     346             : 
     347          34 :                 if (length > 4) {
     348          30 :                         t.hour   = (unsigned int) to[4];
     349          30 :                         t.minute = (unsigned int) to[5];
     350          30 :                         t.second = (unsigned int) to[6];
     351             :                 } else {
     352           4 :                         t.hour = t.minute = t.second= 0;
     353             :                 }
     354          34 :                 t.second_part = (length > 7) ? (unsigned long) sint4korr(to+7) : 0;
     355             : 
     356          34 :                 (*row)+= length;
     357             :         } else {
     358           2 :                 memset(&t, 0, sizeof(t));
     359           2 :                 t.time_type = MYSQLND_TIMESTAMP_DATETIME;
     360             :         }
     361             : 
     362          36 :         length = mnd_sprintf(&value, 0, "%04u-%02u-%02u %02u:%02u:%02u", t.year, t.month, t.day, t.hour, t.minute, t.second);
     363             : 
     364          36 :         DBG_INF_FMT("%s", value);
     365             : #if MYSQLND_UNICODE
     366             :         if (!as_unicode) {
     367             : #endif
     368          36 :                 ZVAL_STRINGL(zv, value, length, 1);
     369          36 :                 mnd_sprintf_free(value);
     370             : #if MYSQLND_UNICODE
     371             :         } else {
     372             :                 ZVAL_UTF8_STRINGL(zv, to, length, ZSTR_AUTOFREE);
     373             :         }
     374             : #endif
     375          36 :         DBG_VOID_RETURN;
     376             : }
     377             : /* }}} */
     378             : 
     379             : 
     380             : /* {{{ ps_fetch_string */
     381             : static
     382       19993 : void ps_fetch_string(zval *zv, const MYSQLND_FIELD * const field,
     383             :                                          unsigned int pack_len, zend_uchar **row,
     384             :                                          zend_bool as_unicode TSRMLS_DC)
     385             : {
     386             :         /*
     387             :           For now just copy, before we make it possible
     388             :           to write \0 to the row buffer
     389             :         */
     390       19993 :         unsigned long length = php_mysqlnd_net_field_length(row);
     391       19993 :         DBG_ENTER("ps_fetch_string");
     392       19993 :         DBG_INF_FMT("len = %lu", length);
     393             : #if MYSQLND_UNICODE
     394             :         if (field->charsetnr == MYSQLND_BINARY_CHARSET_NR) {
     395             :                 DBG_INF("Binary charset");
     396             :                 ZVAL_STRINGL(zv, (char *)*row, length, 1);
     397             :         } else {
     398             :                 DBG_INF_FMT("copying from the row buffer");
     399             :                 ZVAL_UTF8_STRINGL(zv, (char*)*row, length, ZSTR_DUPLICATE);
     400             :         }
     401             : #else
     402       19993 :         DBG_INF("copying from the row buffer");
     403       19993 :         ZVAL_STRINGL(zv, (char *)*row, length, 1);
     404             : #endif
     405             : 
     406       19993 :         (*row) += length;
     407       19993 :         DBG_VOID_RETURN;
     408             : }
     409             : /* }}} */
     410             : 
     411             : 
     412             : /* {{{ ps_fetch_bit */
     413             : static
     414        1487 : void ps_fetch_bit(zval *zv, const MYSQLND_FIELD * const field,
     415             :                                   unsigned int pack_len, zend_uchar **row,
     416             :                                   zend_bool as_unicode TSRMLS_DC)
     417             : {
     418        1487 :         unsigned long length= php_mysqlnd_net_field_length(row);
     419        1487 :         ps_fetch_from_1_to_8_bytes(zv, field, pack_len, row, as_unicode, length TSRMLS_CC);
     420        1487 : }
     421             : /* }}} */
     422             : 
     423             : 
     424             : /* {{{ _mysqlnd_init_ps_fetch_subsystem */
     425       20205 : void _mysqlnd_init_ps_fetch_subsystem()
     426             : {
     427       20205 :         memset(mysqlnd_ps_fetch_functions, 0, sizeof(mysqlnd_ps_fetch_functions));
     428       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_NULL].func                = ps_fetch_null;
     429       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_NULL].pack_len    = 0;
     430       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_NULL].php_type    = IS_NULL;
     431       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_NULL].can_ret_as_str_in_uni       = TRUE;
     432             : 
     433       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TINY].func                = ps_fetch_int8;
     434       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TINY].pack_len    = 1;
     435       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TINY].php_type    = IS_LONG;
     436       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TINY].can_ret_as_str_in_uni       = TRUE;
     437             : 
     438       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_SHORT].func               = ps_fetch_int16;
     439       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_SHORT].pack_len   = 2;
     440       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_SHORT].php_type   = IS_LONG;
     441       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_SHORT].can_ret_as_str_in_uni      = TRUE;
     442             : 
     443       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_YEAR].func                = ps_fetch_int16;
     444       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_YEAR].pack_len    = 2;
     445       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_YEAR].php_type    = IS_LONG;
     446       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_YEAR].can_ret_as_str_in_uni       = TRUE;
     447             : 
     448       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_INT24].func               = ps_fetch_int32;
     449       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_INT24].pack_len   = 4;
     450       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_INT24].php_type   = IS_LONG;
     451       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_INT24].can_ret_as_str_in_uni      = TRUE;
     452             : 
     453       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG].func                = ps_fetch_int32;
     454       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG].pack_len    = 4;
     455       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG].php_type    = IS_LONG;
     456       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG].can_ret_as_str_in_uni       = TRUE;
     457             : 
     458       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONGLONG].func    = ps_fetch_int64;
     459       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONGLONG].pack_len= 8;
     460       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONGLONG].php_type= IS_LONG;
     461       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONGLONG].can_ret_as_str_in_uni   = TRUE;
     462             : 
     463       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_FLOAT].func               = ps_fetch_float;
     464       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_FLOAT].pack_len   = 4;
     465       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_FLOAT].php_type   = IS_DOUBLE;
     466       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_FLOAT].can_ret_as_str_in_uni      = TRUE;
     467             : 
     468       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DOUBLE].func              = ps_fetch_double;
     469       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DOUBLE].pack_len  = 8;
     470       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DOUBLE].php_type  = IS_DOUBLE;
     471       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DOUBLE].can_ret_as_str_in_uni     = TRUE;
     472             : 
     473       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TIME].func                = ps_fetch_time;
     474       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TIME].pack_len    = MYSQLND_PS_SKIP_RESULT_W_LEN;
     475       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TIME].php_type    = IS_STRING;
     476       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TIME].can_ret_as_str_in_uni       = TRUE;
     477             : 
     478       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DATE].func                = ps_fetch_date;
     479       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DATE].pack_len    = MYSQLND_PS_SKIP_RESULT_W_LEN;
     480       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DATE].php_type    = IS_STRING;
     481       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DATE].can_ret_as_str_in_uni       = TRUE;
     482             : 
     483       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_NEWDATE].func             = ps_fetch_string;
     484       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_NEWDATE].pack_len = MYSQLND_PS_SKIP_RESULT_W_LEN;
     485       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_NEWDATE].php_type = IS_STRING;
     486       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_NEWDATE].can_ret_as_str_in_uni    = TRUE;
     487             : 
     488       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DATETIME].func    = ps_fetch_datetime;
     489       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DATETIME].pack_len= MYSQLND_PS_SKIP_RESULT_W_LEN;
     490       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DATETIME].php_type= IS_STRING;
     491       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DATETIME].can_ret_as_str_in_uni   = TRUE;
     492             : 
     493       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TIMESTAMP].func   = ps_fetch_datetime;
     494       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TIMESTAMP].pack_len= MYSQLND_PS_SKIP_RESULT_W_LEN;
     495       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TIMESTAMP].php_type= IS_STRING;
     496       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TIMESTAMP].can_ret_as_str_in_uni  = TRUE;
     497             : 
     498       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TINY_BLOB].func   = ps_fetch_string;
     499       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TINY_BLOB].pack_len= MYSQLND_PS_SKIP_RESULT_STR;
     500       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TINY_BLOB].php_type = IS_STRING;
     501       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TINY_BLOB].is_possibly_blob = TRUE;
     502       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_TINY_BLOB].can_ret_as_str_in_uni  = TRUE;
     503             : 
     504       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_BLOB].func                = ps_fetch_string;
     505       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_BLOB].pack_len    = MYSQLND_PS_SKIP_RESULT_STR;
     506       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_BLOB].php_type    = IS_STRING;
     507       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_BLOB].is_possibly_blob = TRUE;
     508       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_BLOB].can_ret_as_str_in_uni       = TRUE;
     509             : 
     510       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_MEDIUM_BLOB].func         = ps_fetch_string;
     511       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_MEDIUM_BLOB].pack_len     = MYSQLND_PS_SKIP_RESULT_STR;
     512       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_MEDIUM_BLOB].php_type     = IS_STRING;
     513       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_MEDIUM_BLOB].is_possibly_blob = TRUE;
     514       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_MEDIUM_BLOB].can_ret_as_str_in_uni        = TRUE;
     515             : 
     516       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG_BLOB].func           = ps_fetch_string;
     517       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG_BLOB].pack_len       = MYSQLND_PS_SKIP_RESULT_STR;
     518       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG_BLOB].php_type       = IS_STRING;
     519       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG_BLOB].is_possibly_blob = TRUE;
     520       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_LONG_BLOB].can_ret_as_str_in_uni  = TRUE;
     521             : 
     522       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].func         = ps_fetch_bit;
     523       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].pack_len     = 8;
     524       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].php_type     = IS_LONG;
     525       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_BIT].can_ret_as_str_in_uni = TRUE;
     526             : 
     527       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_VAR_STRING].func          = ps_fetch_string;
     528       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_VAR_STRING].pack_len      = MYSQLND_PS_SKIP_RESULT_STR;
     529       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_VAR_STRING].php_type = IS_STRING;
     530       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_VAR_STRING].is_possibly_blob = TRUE;
     531             : 
     532       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_VARCHAR].func             = ps_fetch_string;
     533       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_VARCHAR].pack_len = MYSQLND_PS_SKIP_RESULT_STR;
     534       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_VARCHAR].php_type = IS_STRING;
     535       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_VARCHAR].is_possibly_blob = TRUE;
     536             : 
     537       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_STRING].func                      = ps_fetch_string;
     538       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_STRING].pack_len          = MYSQLND_PS_SKIP_RESULT_STR;
     539       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_STRING].php_type  = IS_STRING;
     540       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_STRING].is_possibly_blob = TRUE;
     541             : 
     542       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DECIMAL].func             = ps_fetch_string;
     543       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DECIMAL].pack_len = MYSQLND_PS_SKIP_RESULT_STR;
     544       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DECIMAL].php_type = IS_STRING;
     545       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_DECIMAL].can_ret_as_str_in_uni    = TRUE;
     546             : 
     547       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_NEWDECIMAL].func          = ps_fetch_string;
     548       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_NEWDECIMAL].pack_len      = MYSQLND_PS_SKIP_RESULT_STR;
     549       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_NEWDECIMAL].php_type      = IS_STRING;
     550       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_NEWDECIMAL].can_ret_as_str_in_uni = TRUE;
     551             : 
     552       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_ENUM].func                = ps_fetch_string;
     553       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_ENUM].pack_len    = MYSQLND_PS_SKIP_RESULT_STR;
     554       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_ENUM].php_type    = IS_STRING;
     555             : 
     556       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_SET].func                 = ps_fetch_string;
     557       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_SET].pack_len             = MYSQLND_PS_SKIP_RESULT_STR;
     558       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_SET].php_type             = IS_STRING;
     559             : 
     560       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_GEOMETRY].func    = ps_fetch_string;
     561       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_GEOMETRY].pack_len= MYSQLND_PS_SKIP_RESULT_STR;
     562       20205 :         mysqlnd_ps_fetch_functions[MYSQL_TYPE_GEOMETRY].php_type= IS_STRING;
     563       20205 : }
     564             : /* }}} */
     565             : 
     566             : 
     567             : /* {{{ mysqlnd_stmt_copy_it */
     568             : static enum_func_status
     569       74150 : mysqlnd_stmt_copy_it(zval *** copies, zval *original, unsigned int param_count, unsigned int current TSRMLS_DC)
     570             : {
     571       74150 :         if (!*copies) {
     572         538 :                 *copies = mnd_ecalloc(param_count, sizeof(zval *));
     573             :         }
     574       74150 :         if (*copies) {
     575       74150 :                 MAKE_STD_ZVAL((*copies)[current]);
     576       74150 :                 *(*copies)[current] = *original;
     577       74150 :                 Z_SET_REFCOUNT_P((*copies)[current], 1);
     578       74150 :                 zval_copy_ctor((*copies)[current]);
     579       74150 :                 return PASS;
     580             :         }
     581           0 :         return FAIL;
     582             : }
     583             : /* }}} */
     584             : 
     585             : 
     586             : /* {{{ mysqlnd_stmt_execute_store_params */
     587             : static enum_func_status
     588        4890 : mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar **buf, zend_uchar **p, size_t *buf_len  TSRMLS_DC)
     589             : {
     590        4890 :         MYSQLND_STMT_DATA * stmt = s->data;
     591        4890 :         unsigned int i = 0;
     592        4890 :         zend_uchar * provided_buffer = *buf;
     593        4890 :         size_t left = (*buf_len - (*p - *buf));
     594        4890 :         size_t data_size = 0;
     595        4890 :         zval **copies = NULL;/* if there are different types */
     596        4890 :         enum_func_status ret = FAIL;
     597        4890 :         int resend_types_next_time = 0;
     598             :         size_t null_byte_offset;
     599             : 
     600        4890 :         DBG_ENTER("mysqlnd_stmt_execute_store_params");
     601             : 
     602             :         {
     603        4890 :                 unsigned int null_count = (stmt->param_count + 7) / 8;
     604             :                 /* give it some reserved space - 20 bytes */
     605        4890 :                 if (left < (null_count + 20)) {
     606           2 :                         unsigned int offset = *p - *buf;
     607             :                         zend_uchar *tmp_buf;
     608           2 :                         *buf_len = offset + null_count + 20;
     609           2 :                         tmp_buf = mnd_emalloc(*buf_len);
     610           2 :                         if (!tmp_buf) {
     611           0 :                                 SET_OOM_ERROR(*stmt->error_info);
     612           0 :                                 goto end;
     613             :                         }
     614           2 :                         memcpy(tmp_buf, *buf, offset);
     615           2 :                         if (*buf != provided_buffer) {
     616           0 :                                 mnd_efree(*buf);
     617             :                         }
     618           2 :                         *buf = tmp_buf;
     619             : 
     620             :                         /* Update our pos pointer */
     621           2 :                         *p = *buf + offset;
     622             :                 }
     623             :                 /* put `null` bytes */
     624        4890 :                 null_byte_offset = *p - *buf;
     625        4890 :                 memset(*p, 0, null_count);
     626        4890 :                 *p += null_count;
     627             :         }
     628             : 
     629        4890 :         left = (*buf_len - (*p - *buf));
     630             : /* 1. Store type information */
     631             :         /*
     632             :           check if need to send the types even if stmt->send_types_to_server is 0. This is because
     633             :           if we send "i" (42) then the type will be int and the server will expect int. However, if next
     634             :           time we try to send > LONG_MAX, the conversion to string will send a string and the server
     635             :           won't expect it and interpret the value as 0. Thus we need to resend the types, if any such values
     636             :           occur, and force resend for the next execution.
     637             :         */
     638      140715 :         for (i = 0; i < stmt->param_count; i++) {
     639      135825 :                 short current_type = stmt->param_bind[i].type;
     640      135825 :                 if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_NULL && (current_type == MYSQL_TYPE_LONG || current_type == MYSQL_TYPE_LONGLONG)) {
     641             :                         /* always copy the var, because we do many conversions */
     642      133961 :                         if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_LONG &&
     643           7 :                                 PASS != mysqlnd_stmt_copy_it(&copies, stmt->param_bind[i].zv, stmt->param_count, i TSRMLS_CC))
     644             :                         {
     645           0 :                                 SET_OOM_ERROR(*stmt->error_info);
     646           0 :                                 goto end;
     647             :                         }
     648             :                         /*
     649             :                           if it doesn't fit in a long send it as a string.
     650             :                           Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > LONG_MAX
     651             :                         */
     652      133954 :                         if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_LONG) {
     653           7 :                                 zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv;
     654             :                                 /*
     655             :                                   Because converting to double and back to long can lead
     656             :                                   to losing precision we need second variable. Conversion to double is to see if 
     657             :                                   value is too big for a long. As said, precision could be lost.
     658             :                                 */
     659             :                                 zval *tmp_data_copy;
     660           7 :                                 MAKE_STD_ZVAL(tmp_data_copy);
     661           7 :                                 *tmp_data_copy = *tmp_data;
     662           7 :                                 Z_SET_REFCOUNT_P(tmp_data_copy, 1);
     663           7 :                                 zval_copy_ctor(tmp_data_copy);
     664          21 :                                 convert_to_double_ex(&tmp_data_copy);
     665             : 
     666             :                                 /*
     667             :                                   if it doesn't fit in a long send it as a string.
     668             :                                   Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > LONG_MAX
     669             :                                   We do transformation here, which will be used later when sending types. The code later relies on this.
     670             :                                 */
     671           7 :                                 if (Z_DVAL_P(tmp_data_copy) > LONG_MAX || Z_DVAL_P(tmp_data_copy) < LONG_MIN) {
     672           0 :                                         stmt->send_types_to_server = resend_types_next_time = 1;
     673           0 :                                         convert_to_string_ex(&tmp_data);
     674             :                                 } else {
     675          21 :                                         convert_to_long_ex(&tmp_data);
     676             :                                 }
     677             : 
     678           7 :                                 zval_ptr_dtor(&tmp_data_copy);
     679             :                         }
     680             :                 }
     681             :         }
     682             : 
     683        4890 :         int1store(*p, stmt->send_types_to_server); 
     684        4890 :         (*p)++;
     685             : 
     686        4890 :         if (stmt->send_types_to_server) {
     687             :                 /* 2 bytes per type, and leave 20 bytes for future use */
     688        1065 :                 if (left < ((stmt->param_count * 2) + 20)) {
     689           3 :                         unsigned int offset = *p - *buf;
     690             :                         zend_uchar *tmp_buf;
     691           3 :                         *buf_len = offset + stmt->param_count * 2 + 20;
     692           3 :                         tmp_buf = mnd_emalloc(*buf_len);
     693           3 :                         if (!tmp_buf) {
     694           0 :                                 SET_OOM_ERROR(*stmt->error_info);
     695           0 :                                 goto end;
     696             :                         }
     697           3 :                         memcpy(tmp_buf, *buf, offset);
     698           3 :                         if (*buf != provided_buffer) {
     699           2 :                                 mnd_efree(*buf);
     700             :                         }
     701           3 :                         *buf = tmp_buf;
     702             : 
     703             :                         /* Update our pos pointer */
     704           3 :                         *p = *buf + offset;
     705             :                 }
     706      136145 :                 for (i = 0; i < stmt->param_count; i++) {
     707      135080 :                         short current_type = stmt->param_bind[i].type;
     708             :                         /* our types are not unsigned */
     709             : #if SIZEOF_LONG==8  
     710      135080 :                         if (current_type == MYSQL_TYPE_LONG) {
     711           0 :                                 current_type = MYSQL_TYPE_LONGLONG;
     712             :                         }
     713             : #endif
     714      135080 :                         if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_NULL && (current_type == MYSQL_TYPE_LONG || current_type == MYSQL_TYPE_LONGLONG)) {
     715             :                                 /*
     716             :                                   if it doesn't fit in a long send it as a string.
     717             :                                   Check bug #52891 : Wrong data inserted with mysqli/mysqlnd when using bind_param, value > LONG_MAX
     718             :                                 */
     719      133513 :                                 if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_LONG) {
     720           7 :                                         zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv;
     721             :                                         /*
     722             :                                           In case of IS_LONG we do nothing, it is ok, in case of string, we just need to set current_type.
     723             :                                           The actual transformation has been performed several dozens line above.
     724             :                                         */
     725           7 :                                         if (Z_TYPE_P(tmp_data) == IS_STRING) {
     726           0 :                                                 current_type = MYSQL_TYPE_VAR_STRING;
     727             :                                                 /*
     728             :                                                   don't change stmt->param_bind[i].type to MYSQL_TYPE_VAR_STRING
     729             :                                                   we force convert_to_long_ex in all cases, thus the type will be right in the next switch.
     730             :                                                   if the type is however not long, then we will do a goto in the next switch.
     731             :                                                   We want to preserve the original bind type given by the user. Thus, we do these hacks.
     732             :                                                 */
     733             :                                         }
     734             :                                 }
     735             :                         }
     736      135080 :                         int2store(*p, current_type);
     737      135080 :                         *p+= 2;
     738             :                 }
     739             :         }
     740        4890 :         stmt->send_types_to_server = resend_types_next_time;
     741             : 
     742             : /* 2. Store data */
     743             :         /* 2.1 Calculate how much space we need */
     744      140715 :         for (i = 0; i < stmt->param_count; i++) {
     745             :                 unsigned int j;
     746      135825 :                 zval *the_var = stmt->param_bind[i].zv;
     747             : 
     748      135825 :                 if (!the_var || (stmt->param_bind[i].type != MYSQL_TYPE_LONG_BLOB && Z_TYPE_P(the_var) == IS_NULL)) {
     749         219 :                         continue;
     750             :                 }
     751  1908086381 :                 for (j = i + 1; j < stmt->param_count; j++) {
     752  1908024392 :                         if (stmt->param_bind[j].zv == the_var) {
     753             :                                 /* Double binding of the same zval, make a copy */
     754       73617 :                                 if (!copies || !copies[i]) {
     755       73615 :                                         if (PASS != mysqlnd_stmt_copy_it(&copies, the_var, stmt->param_count, i TSRMLS_CC)) {
     756           0 :                                                 SET_OOM_ERROR(*stmt->error_info);
     757           0 :                                                 goto end;
     758             :                                         }
     759             :                                 }
     760       73617 :                                 break; 
     761             :                         }
     762             :                 }
     763             : 
     764      135606 :                 switch (stmt->param_bind[i].type) {
     765             :                         case MYSQL_TYPE_DOUBLE:
     766         990 :                                 data_size += 8;
     767         990 :                                 if (Z_TYPE_P(the_var) != IS_DOUBLE) {
     768         967 :                                         if (!copies || !copies[i]) {
     769         506 :                                                 if (PASS != mysqlnd_stmt_copy_it(&copies, the_var, stmt->param_count, i TSRMLS_CC)) {
     770           0 :                                                         SET_OOM_ERROR(*stmt->error_info);
     771           0 :                                                         goto end;
     772             :                                                 }
     773             :                                         }
     774             :                                 }
     775         990 :                                 break;
     776             :                         case MYSQL_TYPE_LONGLONG:
     777             :                                 {
     778      133954 :                                         zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv;
     779      133954 :                                         if (Z_TYPE_P(tmp_data) == IS_STRING) {
     780           0 :                                                 goto use_string;
     781             :                                         }
     782      133954 :                                         convert_to_long_ex(&tmp_data);
     783             :                                 }
     784      133954 :                                 data_size += 8;
     785      133954 :                                 break;
     786             :                         case MYSQL_TYPE_LONG:
     787             :                                 {
     788           0 :                                         zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv;
     789           0 :                                         if (Z_TYPE_P(tmp_data) == IS_STRING) {
     790           0 :                                                 goto use_string;
     791             :                                         }
     792           0 :                                         convert_to_long_ex(&tmp_data);
     793             :                                 }
     794           0 :                                 data_size += 4;
     795           0 :                                 break;
     796             :                         case MYSQL_TYPE_LONG_BLOB:
     797          48 :                                 if (!(stmt->param_bind[i].flags & MYSQLND_PARAM_BIND_BLOB_USED)) {
     798             :                                         /*
     799             :                                           User hasn't sent anything, we will send empty string.
     800             :                                           Empty string has length of 0, encoded in 1 byte. No real
     801             :                                           data will follows after it.
     802             :                                         */
     803          45 :                                         data_size++;
     804             :                                 }
     805          48 :                                 break;
     806             :                         case MYSQL_TYPE_VAR_STRING:
     807             : use_string:
     808         614 :                                 data_size += 8; /* max 8 bytes for size */
     809             : #if MYSQLND_UNICODE
     810             :                                 if (Z_TYPE_P(the_var) != IS_STRING || Z_TYPE_P(the_var) == IS_UNICODE)
     811             : #else
     812         614 :                                 if (Z_TYPE_P(the_var) != IS_STRING)
     813             : #endif
     814             :                                 {
     815          23 :                                         if (!copies || !copies[i]) {
     816          22 :                                                 if (PASS != mysqlnd_stmt_copy_it(&copies, the_var, stmt->param_count, i TSRMLS_CC)) {
     817           0 :                                                         SET_OOM_ERROR(*stmt->error_info);
     818           0 :                                                         goto end;
     819             :                                                 }
     820             :                                         }
     821          23 :                                         the_var = copies[i];
     822             : #if MYSQLND_UNICODE
     823             :                                         if (Z_TYPE_P(the_var) == IS_UNICODE) {
     824             :                                                 zval_unicode_to_string_ex(the_var, UG(utf8_conv) TSRMLS_CC);
     825             :                                         }
     826             : #endif
     827             :                                 }
     828         660 :                                 convert_to_string_ex(&the_var);
     829         614 :                                 data_size += Z_STRLEN_P(the_var);
     830             :                                 break;
     831             :                 }
     832             :         }
     833             : 
     834             :         /* 2.2 Enlarge the buffer, if needed */
     835        4890 :         left = (*buf_len - (*p - *buf));
     836        4890 :         if (left < data_size) {
     837          18 :                 unsigned int offset = *p - *buf;
     838             :                 zend_uchar *tmp_buf;
     839          18 :                 *buf_len = offset + data_size + 10; /* Allocate + 10 for safety */
     840          18 :                 tmp_buf = mnd_emalloc(*buf_len);
     841          18 :                 if (!tmp_buf) {
     842           0 :                         SET_OOM_ERROR(*stmt->error_info);
     843           0 :                         goto end;
     844             :                 }
     845          18 :                 memcpy(tmp_buf, *buf, offset);
     846             :                 /*
     847             :                   When too many columns the buffer provided to the function might not be sufficient.
     848             :                   In this case new buffer has been allocated above. When we allocate a buffer and then
     849             :                   allocate a bigger one here, we should free the first one.
     850             :                 */
     851          18 :                 if (*buf != provided_buffer) {
     852           3 :                         mnd_efree(*buf);
     853             :                 }
     854          18 :                 *buf = tmp_buf;
     855             :                 /* Update our pos pointer */
     856          18 :                 *p = *buf + offset;
     857             :         }
     858             : 
     859             :         /* 2.3 Store the actual data */
     860      140715 :         for (i = 0; i < stmt->param_count; i++) {
     861      135825 :                 zval *data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv;
     862             :                 /* Handle long data */
     863      136049 :                 if (stmt->param_bind[i].zv && Z_TYPE_P(data) == IS_NULL) {
     864         224 :                         (*buf + null_byte_offset)[i/8] |= (zend_uchar) (1 << (i & 7));
     865             :                 } else {
     866      135601 :                         switch (stmt->param_bind[i].type) {
     867             :                                 case MYSQL_TYPE_DOUBLE:
     868        2924 :                                         convert_to_double_ex(&data);
     869         990 :                                         float8store(*p, Z_DVAL_P(data));
     870         990 :                                         (*p) += 8;
     871         990 :                                         break;
     872             :                                 case MYSQL_TYPE_LONGLONG:
     873      133954 :                                         if (Z_TYPE_P(data) == IS_STRING) {
     874           0 :                                                 goto send_string;
     875             :                                         }
     876             :                                         /* data has alreade been converted to long */
     877      133954 :                                         int8store(*p, Z_LVAL_P(data));
     878      133954 :                                         (*p) += 8;
     879      133954 :                                         break;
     880             :                                 case MYSQL_TYPE_LONG:
     881           0 :                                         if (Z_TYPE_P(data) == IS_STRING) {
     882           0 :                                                 goto send_string;
     883             :                                         }
     884             :                                         /* data has alreade been converted to long */
     885           0 :                                         int4store(*p, Z_LVAL_P(data));
     886           0 :                                         (*p) += 4;
     887           0 :                                         break;
     888             :                                 case MYSQL_TYPE_LONG_BLOB:
     889          43 :                                         if (stmt->param_bind[i].flags & MYSQLND_PARAM_BIND_BLOB_USED) {
     890           0 :                                                 stmt->param_bind[i].flags &= ~MYSQLND_PARAM_BIND_BLOB_USED;
     891             :                                         } else {
     892             :                                                 /* send_long_data() not called, send empty string */
     893          43 :                                                 *p = php_mysqlnd_net_store_length(*p, 0);
     894             :                                         }
     895          43 :                                         break;
     896             :                                 case MYSQL_TYPE_VAR_STRING:
     897             : send_string:
     898             :                                         {
     899         614 :                                                 unsigned int len = Z_STRLEN_P(data);
     900             :                                                 /* to is after p. The latter hasn't been moved */
     901         614 :                                                 *p = php_mysqlnd_net_store_length(*p, len);
     902         614 :                                                 memcpy(*p, Z_STRVAL_P(data), len);
     903         614 :                                                 (*p) += len;
     904             :                                         }
     905         614 :                                         break;
     906             :                                 default:
     907             :                                         /* Won't happen, but set to NULL */
     908           0 :                                         (*buf + null_byte_offset)[i/8] |= (zend_uchar) (1 << (i & 7));
     909             :                                         break;
     910             :                         }
     911             :                 }
     912             :         }
     913        4890 :         ret = PASS;
     914             : end:
     915        4890 :         if (copies) {
     916      132657 :                 for (i = 0; i < stmt->param_count; i++) {
     917      132119 :                         if (copies[i]) {
     918       74150 :                                 zval_ptr_dtor(&copies[i]);
     919             :                         }
     920             :                 }
     921         538 :                 mnd_efree(copies);
     922             :         }
     923             : 
     924        4890 :         DBG_INF_FMT("ret=%s", ret == PASS? "PASS":"FAIL");
     925        4890 :         DBG_RETURN(ret);
     926             : }
     927             : /* }}} */
     928             : 
     929             : 
     930             : /* {{{ mysqlnd_stmt_execute_generate_request */
     931             : enum_func_status
     932        4890 : mysqlnd_stmt_execute_generate_request(MYSQLND_STMT * const s, zend_uchar ** request, size_t *request_len, zend_bool * free_buffer TSRMLS_DC)
     933             : {
     934        4890 :         MYSQLND_STMT_DATA * stmt = s->data;
     935        4890 :         zend_uchar      *p = stmt->execute_cmd_buffer.buffer,
     936        4890 :                                 *cmd_buffer = stmt->execute_cmd_buffer.buffer;
     937        4890 :         size_t cmd_buffer_length = stmt->execute_cmd_buffer.length;
     938             :         enum_func_status ret;
     939             : 
     940        4890 :         DBG_ENTER("mysqlnd_stmt_execute_generate_request");
     941             : 
     942        4890 :         int4store(p, stmt->stmt_id);
     943        4890 :         p += 4;
     944             : 
     945             :         /* flags is 4 bytes, we store just 1 */
     946        4890 :         int1store(p, (zend_uchar) stmt->flags);
     947        4890 :         p++;
     948             : 
     949             :         /* Make it all zero */
     950        4890 :         int4store(p, 0); 
     951             : 
     952        4890 :         int1store(p, 1); /* and send 1 for iteration count */
     953        4890 :         p+= 4;
     954             : 
     955        4890 :         ret = mysqlnd_stmt_execute_store_params(s, &cmd_buffer, &p, &cmd_buffer_length TSRMLS_CC);
     956             : 
     957        4890 :         *free_buffer = (cmd_buffer != stmt->execute_cmd_buffer.buffer);
     958        4890 :         *request_len = (p - cmd_buffer);
     959        4890 :         *request = cmd_buffer;
     960        4890 :         DBG_INF_FMT("ret=%s", ret == PASS? "PASS":"FAIL");
     961        4890 :         DBG_RETURN(ret);
     962             : }
     963             : /* }}} */
     964             : 
     965             : /*
     966             :  * Local variables:
     967             :  * tab-width: 4
     968             :  * c-basic-offset: 4
     969             :  * End:
     970             :  * vim600: noet sw=4 ts=4 fdm=marker
     971             :  * vim<600: noet sw=4 ts=4
     972             :  */

Generated by: LCOV version 1.10

Generated at Sun, 17 Aug 2014 15:21:54 +0000 (2 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.