summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorULF WENDEL <uw@php.net>2012-10-23 15:13:57 +0200
committerULF WENDEL <uw@php.net>2012-10-23 15:13:57 +0200
commit0737be7e7baf1fece1683ca9f33064733d8b3514 (patch)
treee09080e18f3c27e90ecd392dc9a4003a5b4e57db
parent38b632dd7c1d6a935f859e53d69cc3ce3c373c94 (diff)
downloadphp-git-0737be7e7baf1fece1683ca9f33064733d8b3514.tar.gz
Fix for bug #62820
-rw-r--r--ext/pdo_mysql/mysql_statement.c113
1 files changed, 63 insertions, 50 deletions
diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c
index fc5ec5135b..7bfbef015c 100644
--- a/ext/pdo_mysql/mysql_statement.c
+++ b/ext/pdo_mysql/mysql_statement.c
@@ -75,13 +75,13 @@ static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
efree(S->in_length);
}
- if (S->bound_result)
+ if (S->bound_result)
{
int i;
for (i = 0; i < stmt->column_count; i++) {
pdo_free_bound_result(S->bound_result[i]);
}
-
+
efree(S->bound_result);
efree(S->out_null);
efree(S->out_length);
@@ -95,7 +95,7 @@ static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
if (mysql_next_result(S->H->server) != 0) {
break;
}
-
+
res = mysql_store_result(S->H->server);
if (res) {
mysql_free_result(res);
@@ -180,23 +180,23 @@ static int pdo_mysql_stmt_execute_prepared_libmysql(pdo_stmt_t *stmt TSRMLS_DC)
}
if (!S->result) {
- int i;
-
- /* figure out the result set format, if any */
- S->result = mysql_stmt_result_metadata(S->stmt);
- if (S->result) {
- int calc_max_length = H->buffered && S->max_length == 1;
- S->fields = mysql_fetch_fields(S->result);
- if (S->bound_result) {
- int i;
- for (i = 0; i < stmt->column_count; i++) {
- efree(S->bound_result[i].buffer);
- }
- efree(S->bound_result);
- efree(S->out_null);
- efree(S->out_length);
+ int i;
+
+ /* figure out the result set format, if any */
+ S->result = mysql_stmt_result_metadata(S->stmt);
+ if (S->result) {
+ int calc_max_length = H->buffered && S->max_length == 1;
+ S->fields = mysql_fetch_fields(S->result);
+ if (S->bound_result) {
+ int i;
+ for (i = 0; i < stmt->column_count; i++) {
+ efree(S->bound_result[i].buffer);
+ }
+ efree(S->bound_result);
+ efree(S->out_null);
+ efree(S->out_length);
}
-
+
stmt->column_count = (int)mysql_num_fields(S->result);
S->bound_result = ecalloc(stmt->column_count, sizeof(MYSQL_BIND));
S->out_null = ecalloc(stmt->column_count, sizeof(my_bool));
@@ -262,7 +262,7 @@ static int pdo_mysql_stmt_execute_prepared_libmysql(pdo_stmt_t *stmt TSRMLS_DC)
}
}
}
-
+
pdo_mysql_stmt_set_row_count(stmt TSRMLS_CC);
PDO_DBG_RETURN(1);
}
@@ -275,9 +275,9 @@ static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo_stmt_t *stmt TSRMLS_DC) /
pdo_mysql_stmt *S = stmt->driver_data;
pdo_mysql_db_handle *H = S->H;
int i;
-
+
PDO_DBG_ENTER("pdo_mysql_stmt_execute_prepared_mysqlnd");
-
+
if (mysql_stmt_execute(S->stmt)) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
@@ -305,7 +305,7 @@ static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo_stmt_t *stmt TSRMLS_DC) /
}
}
}
-
+
pdo_mysql_stmt_set_row_count(stmt TSRMLS_CC);
PDO_DBG_RETURN(1);
}
@@ -322,7 +322,7 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
if (S->stmt) {
PDO_DBG_RETURN(pdo_mysql_stmt_execute_prepared(stmt));
}
-
+
/* ensure that we free any previous unfetched results */
if (S->result) {
mysql_free_result(S->result);
@@ -357,8 +357,8 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
}
if (!mysqlnd_stmt_more_results(S->stmt)) {
- /*
- MySQL gives us n + 1 result sets for
+ /*
+ MySQL gives us n + 1 result sets for
CALL proc() and n result sets returned by the proc itself.
Result set n + 1 is about the procedure call itself.
As the PDO emulation does not return it, we skip it as well
@@ -413,7 +413,19 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
}
ret = mysql_next_result(H->server);
-
+#if PDO_USE_MYSQLND
+ /* for whatever reason mysqlnd breaks with libmysql compatibility at the C level, no -1 */
+ if (PASS != ret) {
+ pdo_mysql_error_stmt(stmt);
+ PDO_DBG_RETURN(0);
+ }
+ if (mysql_more_results(H->server)) {
+ PDO_DBG_RETURN(pdo_mysql_fill_stmt_from_result(stmt TSRMLS_CC));
+ } else {
+ /* No more results */
+ PDO_DBG_RETURN(0);
+ }
+#else
if (ret > 0) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
@@ -423,6 +435,7 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
} else {
PDO_DBG_RETURN(pdo_mysql_fill_stmt_from_result(stmt TSRMLS_CC));
}
+#endif
}
/* }}} */
@@ -444,7 +457,7 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
#ifndef PDO_USE_MYSQLND
PDO_MYSQL_PARAM_BIND *b;
#endif
- pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
+ pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
PDO_DBG_ENTER("pdo_mysql_stmt_param_hook");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
@@ -484,18 +497,18 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
}
#else
b = (PDO_MYSQL_PARAM_BIND*)param->driver_data;
- *b->is_null = 0;
- if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_NULL ||
- Z_TYPE_P(param->parameter) == IS_NULL) {
- *b->is_null = 1;
- b->buffer_type = MYSQL_TYPE_STRING;
- b->buffer = NULL;
- b->buffer_length = 0;
- *b->length = 0;
+ *b->is_null = 0;
+ if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_NULL ||
+ Z_TYPE_P(param->parameter) == IS_NULL) {
+ *b->is_null = 1;
+ b->buffer_type = MYSQL_TYPE_STRING;
+ b->buffer = NULL;
+ b->buffer_length = 0;
+ *b->length = 0;
PDO_DBG_RETURN(1);
- }
+ }
#endif /* PDO_USE_MYSQLND */
-
+
switch (PDO_PARAM_TYPE(param->param_type)) {
case PDO_PARAM_STMT:
PDO_DBG_RETURN(0);
@@ -519,7 +532,7 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
default:
;
}
-
+
#if PDO_USE_MYSQLND
/* Is it really correct to check the zval's type? - But well, that's what the old code below does, too */
PDO_DBG_INF_FMT("param->parameter->type=%d", Z_TYPE_P(param->parameter));
@@ -540,9 +553,9 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
default:
PDO_DBG_RETURN(0);
}
-
+
PDO_DBG_RETURN(1);
-#else
+#else
PDO_DBG_INF_FMT("param->parameter->type=%d", Z_TYPE_P(param->parameter));
switch (Z_TYPE_P(param->parameter)) {
case IS_STRING:
@@ -597,7 +610,7 @@ static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori
}
#else
int ret;
-
+
if (S->stmt) {
ret = mysql_stmt_fetch(S->stmt);
@@ -617,7 +630,7 @@ static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori
PDO_DBG_RETURN(1);
}
#endif /* PDO_USE_MYSQLND */
-
+
if (!S->result) {
strcpy(stmt->error_code, "HY000");
PDO_DBG_RETURN(0);
@@ -637,7 +650,7 @@ static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori
pdo_mysql_error_stmt(stmt);
}
PDO_DBG_RETURN(0);
- }
+ }
S->current_lengths = mysql_fetch_lengths(S->result);
PDO_DBG_RETURN(1);
@@ -661,8 +674,8 @@ static int pdo_mysql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC) /* {{{
PDO_DBG_RETURN(0);
}
- /* fetch all on demand, this seems easiest
- ** if we've been here before bail out
+ /* fetch all on demand, this seems easiest
+ ** if we've been here before bail out
*/
if (cols[0].name) {
PDO_DBG_RETURN(1);
@@ -678,10 +691,10 @@ static int pdo_mysql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC) /* {{{
cols[i].namelen = namelen;
cols[i].name = estrndup(S->fields[i].name, namelen);
}
-
+
cols[i].precision = S->fields[i].decimals;
cols[i].maxlen = S->fields[i].length;
-
+
#ifdef PDO_USE_MYSQLND
if (S->stmt) {
cols[i].param_type = PDO_PARAM_ZVAL;
@@ -799,7 +812,7 @@ static int pdo_mysql_stmt_col_meta(pdo_stmt_t *stmt, long colno, zval *return_va
const MYSQL_FIELD *F;
zval *flags;
char *str;
-
+
PDO_DBG_ENTER("pdo_mysql_stmt_col_meta");
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
if (!S->result) {
@@ -857,7 +870,7 @@ static int pdo_mysql_stmt_col_meta(pdo_stmt_t *stmt, long colno, zval *return_va
break;
}
#endif
-
+
add_assoc_zval(return_value, "flags", flags);
add_assoc_string(return_value, "table", (char *) (F->table?F->table:""), 1);
PDO_DBG_RETURN(SUCCESS);