summaryrefslogtreecommitdiff
path: root/ext/mysqlnd/mysqlnd_ps_codec.c
diff options
context:
space:
mode:
authorDmitry Stogov <dmitry@zend.com>2014-04-26 00:32:51 +0400
committerDmitry Stogov <dmitry@zend.com>2014-04-26 00:32:51 +0400
commitf9927a6c97208c60d922f9a4e98feb8079c57d1f (patch)
tree35815b69d1bf7d47fb41e857ff8d2b024ddac153 /ext/mysqlnd/mysqlnd_ps_codec.c
parent4e7cbf3f5842abe6688c11ce3cc11d2eabf0695f (diff)
parentb82d077f988606580e5c06a9da18fe4f60ddb7cb (diff)
downloadphp-git-f9927a6c97208c60d922f9a4e98feb8079c57d1f.tar.gz
Merge mainstream 'master' branch into refactoring
During merge I had to revert: Nikita's patch for php_splice() (it probably needs to be applyed again) Bob Weinand's patches related to constant expression handling (we need to review them carefully) I also reverted all our attempts to support sapi/phpdbg (we didn't test it anyway) Conflicts: Zend/zend.h Zend/zend_API.c Zend/zend_ast.c Zend/zend_compile.c Zend/zend_compile.h Zend/zend_constants.c Zend/zend_exceptions.c Zend/zend_execute.c Zend/zend_execute.h Zend/zend_execute_API.c Zend/zend_hash.c Zend/zend_highlight.c Zend/zend_language_parser.y Zend/zend_language_scanner.c Zend/zend_language_scanner_defs.h Zend/zend_variables.c Zend/zend_vm_def.h Zend/zend_vm_execute.h ext/date/php_date.c ext/dom/documenttype.c ext/hash/hash.c ext/iconv/iconv.c ext/mbstring/tests/zend_multibyte-10.phpt ext/mbstring/tests/zend_multibyte-11.phpt ext/mbstring/tests/zend_multibyte-12.phpt ext/mysql/php_mysql.c ext/mysqli/mysqli.c ext/mysqlnd/mysqlnd_reverse_api.c ext/mysqlnd/php_mysqlnd.c ext/opcache/ZendAccelerator.c ext/opcache/zend_accelerator_util_funcs.c ext/opcache/zend_persist.c ext/opcache/zend_persist_calc.c ext/pcre/php_pcre.c ext/pdo/pdo_dbh.c ext/pdo/pdo_stmt.c ext/pdo_pgsql/pgsql_driver.c ext/pgsql/pgsql.c ext/reflection/php_reflection.c ext/session/session.c ext/spl/spl_array.c ext/spl/spl_observer.c ext/standard/array.c ext/standard/basic_functions.c ext/standard/html.c ext/standard/mail.c ext/standard/php_array.h ext/standard/proc_open.c ext/standard/streamsfuncs.c ext/standard/user_filters.c ext/standard/var_unserializer.c ext/standard/var_unserializer.re main/php_variables.c sapi/phpdbg/phpdbg.c sapi/phpdbg/phpdbg_bp.c sapi/phpdbg/phpdbg_frame.c sapi/phpdbg/phpdbg_help.c sapi/phpdbg/phpdbg_list.c sapi/phpdbg/phpdbg_print.c sapi/phpdbg/phpdbg_prompt.c
Diffstat (limited to 'ext/mysqlnd/mysqlnd_ps_codec.c')
-rw-r--r--ext/mysqlnd/mysqlnd_ps_codec.c105
1 files changed, 26 insertions, 79 deletions
diff --git a/ext/mysqlnd/mysqlnd_ps_codec.c b/ext/mysqlnd/mysqlnd_ps_codec.c
index 1af4912d91..d96a57721c 100644
--- a/ext/mysqlnd/mysqlnd_ps_codec.c
+++ b/ext/mysqlnd/mysqlnd_ps_codec.c
@@ -569,6 +569,7 @@ mysqlnd_stmt_execute_prepare_param_types(MYSQLND_STMT_DATA * stmt, zval *** copi
DBG_ENTER("mysqlnd_stmt_execute_prepare_param_types");
for (i = 0; i < stmt->param_count; i++) {
short current_type = stmt->param_bind[i].type;
+
if (Z_TYPE_P(stmt->param_bind[i].zv) != IS_NULL && (current_type == MYSQL_TYPE_LONG || current_type == MYSQL_TYPE_LONGLONG)) {
zval ** copies;
/* always copy the var, because we do many conversions */
@@ -668,9 +669,8 @@ mysqlnd_stmt_execute_calculate_param_values_size(MYSQLND_STMT_DATA * stmt, zval
{
unsigned int i;
DBG_ENTER("mysqlnd_stmt_execute_calculate_param_values_size");
-
for (i = 0; i < stmt->param_count; i++) {
- zval ** copies = NULL;
+ unsigned short is_longlong = 0;
unsigned int j;
zval *the_var = stmt->param_bind[i].zv;
@@ -680,23 +680,21 @@ mysqlnd_stmt_execute_calculate_param_values_size(MYSQLND_STMT_DATA * stmt, zval
for (j = i + 1; j < stmt->param_count; j++) {
if (stmt->param_bind[j].zv == the_var) {
/* Double binding of the same zval, make a copy */
- if (!copies || !copies[i]) {
+ if (!*copies_param || !(*copies_param)[i]) {
if (PASS != mysqlnd_stmt_copy_it(copies_param, the_var, stmt->param_count, i TSRMLS_CC)) {
SET_OOM_ERROR(*stmt->error_info);
goto end;
}
}
- break;
+ break;
}
}
- copies = *copies_param;
-
switch (stmt->param_bind[i].type) {
case MYSQL_TYPE_DOUBLE:
*data_size += 8;
if (Z_TYPE_P(the_var) != IS_DOUBLE) {
- if (!copies || !copies[i]) {
+ if (!*copies_param || !(*copies_param)[i]) {
if (PASS != mysqlnd_stmt_copy_it(copies_param, the_var, stmt->param_count, i TSRMLS_CC)) {
SET_OOM_ERROR(*stmt->error_info);
goto end;
@@ -705,24 +703,17 @@ mysqlnd_stmt_execute_calculate_param_values_size(MYSQLND_STMT_DATA * stmt, zval
}
break;
case MYSQL_TYPE_LONGLONG:
- {
- zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv;
- if (Z_TYPE_P(tmp_data) == IS_STRING) {
- goto use_string;
- }
- convert_to_long_ex(&tmp_data);
- }
- *data_size += 8;
- break;
+ is_longlong = 4;
+ /* fall-through */
case MYSQL_TYPE_LONG:
{
- zval *tmp_data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv;
+ zval *tmp_data = (*copies_param && (*copies_param)[i])? (*copies_param)[i]: stmt->param_bind[i].zv;
if (Z_TYPE_P(tmp_data) == IS_STRING) {
goto use_string;
}
convert_to_long_ex(&tmp_data);
}
- *data_size += 4;
+ *data_size += 4 + is_longlong;
break;
case MYSQL_TYPE_LONG_BLOB:
if (!(stmt->param_bind[i].flags & MYSQLND_PARAM_BIND_BLOB_USED)) {
@@ -738,14 +729,13 @@ mysqlnd_stmt_execute_calculate_param_values_size(MYSQLND_STMT_DATA * stmt, zval
use_string:
*data_size += 8; /* max 8 bytes for size */
if (Z_TYPE_P(the_var) != IS_STRING) {
- if (!copies || !copies[i]) {
+ if (!*copies_param || !(*copies_param)[i]) {
if (PASS != mysqlnd_stmt_copy_it(copies_param, the_var, stmt->param_count, i TSRMLS_CC)) {
SET_OOM_ERROR(*stmt->error_info);
goto end;
}
}
- copies = *copies_param;
- the_var = copies[i];
+ the_var = (*copies_param)[i];
}
convert_to_string_ex(&the_var);
*data_size += Z_STRLEN_P(the_var);
@@ -761,14 +751,14 @@ end:
/* {{{ mysqlnd_stmt_execute_store_param_values */
static void
-mysqlnd_stmt_execute_store_param_values(MYSQLND_STMT_DATA * stmt, zval ** copies, zend_uchar ** buf, zend_uchar ** p, size_t null_byte_offset)
+mysqlnd_stmt_execute_store_param_values(MYSQLND_STMT_DATA * stmt, zval ** copies, zend_uchar * buf, zend_uchar ** p, size_t null_byte_offset)
{
unsigned int i;
for (i = 0; i < stmt->param_count; i++) {
zval * data = (copies && copies[i])? copies[i]: stmt->param_bind[i].zv;
/* Handle long data */
if (stmt->param_bind[i].zv && Z_TYPE_P(data) == IS_NULL) {
- (*buf + null_byte_offset)[i/8] |= (zend_uchar) (1 << (i & 7));
+ (buf + null_byte_offset)[i/8] |= (zend_uchar) (1 << (i & 7));
} else {
switch (stmt->param_bind[i].type) {
case MYSQL_TYPE_DOUBLE:
@@ -803,7 +793,7 @@ mysqlnd_stmt_execute_store_param_values(MYSQLND_STMT_DATA * stmt, zval ** copies
case MYSQL_TYPE_VAR_STRING:
send_string:
{
- unsigned int len = Z_STRLEN_P(data);
+ size_t len = Z_STRLEN_P(data);
/* to is after p. The latter hasn't been moved */
*p = php_mysqlnd_net_store_length(*p, len);
memcpy(*p, Z_STRVAL_P(data), len);
@@ -812,7 +802,7 @@ send_string:
break;
default:
/* Won't happen, but set to NULL */
- (*buf + null_byte_offset)[i/8] |= (zend_uchar) (1 << (i & 7));
+ (buf + null_byte_offset)[i/8] |= (zend_uchar) (1 << (i & 7));
break;
}
}
@@ -823,12 +813,13 @@ send_string:
/* {{{ mysqlnd_stmt_execute_store_params */
static enum_func_status
-mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar ** buf, zend_uchar ** p, size_t * buf_len TSRMLS_DC)
+mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar **buf, zend_uchar **p, size_t *buf_len TSRMLS_DC)
{
MYSQLND_STMT_DATA * stmt = s->data;
+ unsigned int i = 0;
zend_uchar * provided_buffer = *buf;
size_t data_size = 0;
- zval ** copies = NULL;/* if there are different types */
+ zval **copies = NULL;/* if there are different types */
enum_func_status ret = FAIL;
int resend_types_next_time = 0;
size_t null_byte_offset;
@@ -839,7 +830,7 @@ mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar ** buf, zend_ucha
unsigned int null_count = (stmt->param_count + 7) / 8;
if (FAIL == mysqlnd_stmt_execute_check_n_enlarge_buffer(buf, p, buf_len, provided_buffer, null_count TSRMLS_CC)) {
SET_OOM_ERROR(*stmt->error_info);
- goto end;
+ goto end;
}
/* put `null` bytes */
null_byte_offset = *p - *buf;
@@ -859,19 +850,20 @@ mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar ** buf, zend_ucha
goto end;
}
- int1store(*p, stmt->send_types_to_server);
+ int1store(*p, stmt->send_types_to_server);
(*p)++;
if (stmt->send_types_to_server) {
if (FAIL == mysqlnd_stmt_execute_check_n_enlarge_buffer(buf, p, buf_len, provided_buffer, stmt->param_count * 2 TSRMLS_CC)) {
SET_OOM_ERROR(*stmt->error_info);
- goto end;
+ goto end;
}
mysqlnd_stmt_execute_store_types(stmt, copies, p);
}
+
stmt->send_types_to_server = resend_types_next_time;
-/* 2. Store actual data */
+/* 2. Store data */
/* 2.1 Calculate how much space we need */
if (FAIL == mysqlnd_stmt_execute_calculate_param_values_size(stmt, &copies, &data_size TSRMLS_CC)) {
goto end;
@@ -880,11 +872,11 @@ mysqlnd_stmt_execute_store_params(MYSQLND_STMT * s, zend_uchar ** buf, zend_ucha
/* 2.2 Enlarge the buffer, if needed */
if (FAIL == mysqlnd_stmt_execute_check_n_enlarge_buffer(buf, p, buf_len, provided_buffer, data_size TSRMLS_CC)) {
SET_OOM_ERROR(*stmt->error_info);
- goto end;
+ goto end;
}
/* 2.3 Store the actual data */
- mysqlnd_stmt_execute_store_param_values(stmt, copies, buf, p, null_byte_offset);
+ mysqlnd_stmt_execute_store_param_values(stmt, copies, *buf, p, null_byte_offset);
ret = PASS;
end:
@@ -898,7 +890,7 @@ end:
/* {{{ mysqlnd_stmt_execute_generate_request */
enum_func_status
-mysqlnd_stmt_execute_generate_request(MYSQLND_STMT * const s, zend_uchar ** request, size_t * request_len, zend_bool * free_buffer TSRMLS_DC)
+mysqlnd_stmt_execute_generate_request(MYSQLND_STMT * const s, zend_uchar ** request, size_t *request_len, zend_bool * free_buffer TSRMLS_DC)
{
MYSQLND_STMT_DATA * stmt = s->data;
zend_uchar *p = stmt->execute_cmd_buffer.buffer,
@@ -931,51 +923,6 @@ mysqlnd_stmt_execute_generate_request(MYSQLND_STMT * const s, zend_uchar ** requ
}
/* }}} */
-
-/* {{{ mysqlnd_stmt_execute_batch_generate_request */
-enum_func_status
-mysqlnd_stmt_execute_batch_generate_request(MYSQLND_STMT * const s, zend_uchar ** request, size_t *request_len, zend_bool * free_buffer TSRMLS_DC)
-{
- MYSQLND_STMT_DATA * stmt = s->data;
- zend_uchar *p = stmt->execute_cmd_buffer.buffer;
- enum_func_status ret;
-
- DBG_ENTER("mysqlnd_stmt_execute_batch_generate_request");
-
- int4store(p, stmt->stmt_id);
- p += 4;
-
- /* flags is 4 bytes, we store just 1 */
- int1store(p, (zend_uchar) stmt->flags);
- p++;
-
- int2store(p, stmt->param_count);
- p+= 2;
-
- int2store(p, 0); /* reserved */
- p+= 2;
-
- {
- zend_uchar * provided_buffer = stmt->execute_cmd_buffer.buffer;
- size_t provided_buffer_length = stmt->execute_cmd_buffer.length;
- uint i= 0;
- for (;i < 5; i++) {
- ret = mysqlnd_stmt_execute_store_params(s, &provided_buffer, &p, &provided_buffer_length TSRMLS_CC);
- if (ret == FAIL) {
- break;
- }
-
- *free_buffer = (provided_buffer != stmt->execute_cmd_buffer.buffer);
- *request_len = (p - provided_buffer);
- *request = provided_buffer;
- }
- }
- DBG_INF_FMT("ret=%s", ret == PASS? "PASS":"FAIL");
- DBG_RETURN(ret);
-}
-/* }}} */
-
-
/*
* Local variables:
* tab-width: 4