mysqlnd_ps_codec.c 31 KB

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