Skip to content

Commit 5795b9e

Browse files
committed
Alternative solution, remove temporary PS
1 parent 1b34738 commit 5795b9e

File tree

2 files changed

+16
-41
lines changed

2 files changed

+16
-41
lines changed

ext/mysqli/tests/mysqli_stmt_affected_rows.phpt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,15 @@ require_once('skipifconnectfailure.inc');
194194

195195
/* try to use stmt_affected_rows like stmt_num_rows */
196196
/* stmt_affected_rows is not really meant for SELECT! */
197-
if (mysqli_stmt_prepare($stmt, 'SELECT unknown_column FROM this_table_does_not_exist') &&
197+
if (mysqli_stmt_prepare($stmt, 'SELECT unknown_column FROM this_table_does_not_exist') ||
198198
mysqli_stmt_execute($stmt))
199199
printf("[041] Expecting SELECT statement to fail on purpose\n");
200200

201201
if (-1 !== ($tmp = mysqli_stmt_affected_rows($stmt)))
202202
printf("[042] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp);
203203

204-
if ($IS_MYSQLND) {
205-
if (false !== ($tmp = mysqli_stmt_store_result($stmt)))
206-
printf("[043] Expecting boolean/false, got %s\%s\n", gettype($tmp), $tmp);
207-
} else {
208-
if (true !== ($tmp = mysqli_stmt_store_result($stmt)))
209-
printf("[043] Libmysql does not care if the previous statement was bogus, expecting boolean/true, got %s\%s\n", gettype($tmp), $tmp);
210-
}
204+
if (true !== ($tmp = mysqli_stmt_store_result($stmt)))
205+
printf("[043] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
211206

212207
if (0 !== ($tmp = mysqli_stmt_num_rows($stmt)))
213208
printf("[044] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);

ext/mysqlnd/mysqlnd_ps.c

Lines changed: 13 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,10 @@ mysqlnd_stmt_prepare_read_eof(MYSQLND_STMT * s)
391391

392392
/* {{{ mysqlnd_stmt::prepare */
393393
static enum_func_status
394-
MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const s, const char * const query, const size_t query_len)
394+
MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * s, const char * const query, const size_t query_len)
395395
{
396396
MYSQLND_STMT_DATA * stmt = s? s->data : NULL;
397397
MYSQLND_CONN_DATA * conn = stmt? stmt->conn : NULL;
398-
MYSQLND_STMT * s_to_prepare = s;
399-
MYSQLND_STMT_DATA * stmt_to_prepare = stmt;
400398

401399
DBG_ENTER("mysqlnd_stmt::prepare");
402400
if (!stmt || !conn) {
@@ -426,11 +424,12 @@ MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const s, const char * const
426424
Create a new test statement, which we will prepare, but if anything
427425
fails, we will scrap it.
428426
*/
429-
s_to_prepare = conn->m->stmt_init(conn);
430-
if (!s_to_prepare) {
427+
s->m->dtor(s, TRUE);
428+
s = conn->m->stmt_init(conn);
429+
if (!s) {
431430
goto fail;
432431
}
433-
stmt_to_prepare = s_to_prepare->data;
432+
stmt = s->data;
434433
}
435434

436435
{
@@ -444,13 +443,13 @@ MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const s, const char * const
444443
}
445444
}
446445

447-
if (FAIL == mysqlnd_stmt_read_prepare_response(s_to_prepare)) {
446+
if (FAIL == mysqlnd_stmt_read_prepare_response(s)) {
448447
goto fail;
449448
}
450449

451-
if (stmt_to_prepare->param_count) {
452-
if (FAIL == mysqlnd_stmt_skip_metadata(s_to_prepare) ||
453-
FAIL == mysqlnd_stmt_prepare_read_eof(s_to_prepare))
450+
if (stmt->param_count) {
451+
if (FAIL == mysqlnd_stmt_skip_metadata(s) ||
452+
FAIL == mysqlnd_stmt_prepare_read_eof(s))
454453
{
455454
goto fail;
456455
}
@@ -461,50 +460,31 @@ MYSQLND_METHOD(mysqlnd_stmt, prepare)(MYSQLND_STMT * const s, const char * const
461460
Beware that SHOW statements bypass the PS framework and thus they send
462461
no metadata at prepare.
463462
*/
464-
if (stmt_to_prepare->field_count) {
465-
MYSQLND_RES * result = conn->m->result_init(stmt_to_prepare->field_count);
463+
if (stmt->field_count) {
464+
MYSQLND_RES * result = conn->m->result_init(stmt->field_count);
466465
if (!result) {
467466
SET_OOM_ERROR(conn->error_info);
468467
goto fail;
469468
}
470469
/* Allocate the result now as it is needed for the reading of metadata */
471-
stmt_to_prepare->result = result;
470+
stmt->result = result;
472471

473472
result->conn = conn->m->get_reference(conn);
474473

475474
result->type = MYSQLND_RES_PS_BUF;
476475

477476
if (FAIL == result->m.read_result_metadata(result, conn) ||
478-
FAIL == mysqlnd_stmt_prepare_read_eof(s_to_prepare))
477+
FAIL == mysqlnd_stmt_prepare_read_eof(s))
479478
{
480479
goto fail;
481480
}
482481
}
483482

484-
if (stmt_to_prepare != stmt) {
485-
/* swap */
486-
size_t real_size = sizeof(MYSQLND_STMT) + mysqlnd_plugin_count() * sizeof(void *);
487-
char * tmp_swap = mnd_malloc(real_size);
488-
memcpy(tmp_swap, s, real_size);
489-
memcpy(s, s_to_prepare, real_size);
490-
memcpy(s_to_prepare, tmp_swap, real_size);
491-
mnd_free(tmp_swap);
492-
{
493-
MYSQLND_STMT_DATA * tmp_swap_data = stmt_to_prepare;
494-
stmt_to_prepare = stmt;
495-
stmt = tmp_swap_data;
496-
}
497-
s_to_prepare->m->dtor(s_to_prepare, TRUE);
498-
}
499483
stmt->state = MYSQLND_STMT_PREPARED;
500484
DBG_INF("PASS");
501485
DBG_RETURN(PASS);
502486

503487
fail:
504-
if (stmt_to_prepare != stmt && s_to_prepare) {
505-
COPY_CLIENT_ERROR(stmt->error_info, *stmt_to_prepare->error_info);
506-
s_to_prepare->m->dtor(s_to_prepare, TRUE);
507-
}
508488

509489
DBG_INF("FAIL");
510490
DBG_RETURN(FAIL);

0 commit comments

Comments
 (0)