Skip to content

Commit 8487806

Browse files
author
ULF WENDEL
committed
Fix for bug #62820 well hidden beneath a ton of whitespace changes. Do not use this pdo factory stuff - you get a line with an error on it, use the mysql stuff in the tests
1 parent bac9d11 commit 8487806

File tree

2 files changed

+71
-59
lines changed

2 files changed

+71
-59
lines changed

ext/pdo_mysql/mysql_statement.c

Lines changed: 65 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
8080
#endif /* PDO_USE_MYSQLND */
8181

8282
#ifdef HAVE_MYSQL_STMT_PREPARE
83-
if (S->bound_result)
83+
if (S->bound_result)
8484
{
8585
int i;
8686
for (i = 0; i < stmt->column_count; i++) {
8787
pdo_free_bound_result(S->bound_result[i]);
8888
}
89-
89+
9090
efree(S->bound_result);
9191
efree(S->out_null);
9292
efree(S->out_length);
@@ -101,13 +101,13 @@ static int pdo_mysql_stmt_dtor(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
101101
if (mysql_next_result(S->H->server) != 0) {
102102
break;
103103
}
104-
104+
105105
res = mysql_store_result(S->H->server);
106106
if (res) {
107107
mysql_free_result(res);
108108
}
109109
}
110-
}
110+
}
111111
#endif /* HAVE_MYSQL_NEXT_RESULT || PDO_USE_MYSQLND */
112112
#if PDO_USE_MYSQLND
113113
if (!S->stmt && S->current_data) {
@@ -186,23 +186,23 @@ static int pdo_mysql_stmt_execute_prepared_libmysql(pdo_stmt_t *stmt TSRMLS_DC)
186186
}
187187

188188
if (!S->result) {
189-
int i;
190-
191-
/* figure out the result set format, if any */
192-
S->result = mysql_stmt_result_metadata(S->stmt);
193-
if (S->result) {
194-
int calc_max_length = H->buffered && S->max_length == 1;
195-
S->fields = mysql_fetch_fields(S->result);
196-
if (S->bound_result) {
197-
int i;
198-
for (i = 0; i < stmt->column_count; i++) {
199-
efree(S->bound_result[i].buffer);
200-
}
201-
efree(S->bound_result);
202-
efree(S->out_null);
203-
efree(S->out_length);
189+
int i;
190+
191+
/* figure out the result set format, if any */
192+
S->result = mysql_stmt_result_metadata(S->stmt);
193+
if (S->result) {
194+
int calc_max_length = H->buffered && S->max_length == 1;
195+
S->fields = mysql_fetch_fields(S->result);
196+
if (S->bound_result) {
197+
int i;
198+
for (i = 0; i < stmt->column_count; i++) {
199+
efree(S->bound_result[i].buffer);
200+
}
201+
efree(S->bound_result);
202+
efree(S->out_null);
203+
efree(S->out_length);
204204
}
205-
205+
206206
stmt->column_count = (int)mysql_num_fields(S->result);
207207
S->bound_result = ecalloc(stmt->column_count, sizeof(MYSQL_BIND));
208208
S->out_null = ecalloc(stmt->column_count, sizeof(my_bool));
@@ -268,7 +268,7 @@ static int pdo_mysql_stmt_execute_prepared_libmysql(pdo_stmt_t *stmt TSRMLS_DC)
268268
}
269269
}
270270
}
271-
271+
272272
pdo_mysql_stmt_set_row_count(stmt TSRMLS_CC);
273273
PDO_DBG_RETURN(1);
274274
}
@@ -281,9 +281,9 @@ static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo_stmt_t *stmt TSRMLS_DC) /
281281
pdo_mysql_stmt *S = stmt->driver_data;
282282
pdo_mysql_db_handle *H = S->H;
283283
int i;
284-
284+
285285
PDO_DBG_ENTER("pdo_mysql_stmt_execute_prepared_mysqlnd");
286-
286+
287287
if (mysql_stmt_execute(S->stmt)) {
288288
pdo_mysql_error_stmt(stmt);
289289
PDO_DBG_RETURN(0);
@@ -311,7 +311,7 @@ static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo_stmt_t *stmt TSRMLS_DC) /
311311
}
312312
}
313313
}
314-
314+
315315
pdo_mysql_stmt_set_row_count(stmt TSRMLS_CC);
316316
PDO_DBG_RETURN(1);
317317
}
@@ -330,7 +330,7 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
330330
PDO_DBG_RETURN(pdo_mysql_stmt_execute_prepared(stmt));
331331
}
332332
#endif
333-
333+
334334
/* ensure that we free any previous unfetched results */
335335
if (S->result) {
336336
mysql_free_result(S->result);
@@ -366,8 +366,8 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
366366
}
367367

368368
if (!mysqlnd_stmt_more_results(S->stmt)) {
369-
/*
370-
MySQL gives us n + 1 result sets for
369+
/*
370+
MySQL gives us n + 1 result sets for
371371
CALL proc() and n result sets returned by the proc itself.
372372
Result set n + 1 is about the procedure call itself.
373373
As the PDO emulation does not return it, we skip it as well
@@ -422,7 +422,19 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
422422
}
423423

424424
ret = mysql_next_result(H->server);
425-
425+
#if PDO_USE_MYSQLND
426+
/* for whatever reason mysqlnd breaks with libmysql compatibility at the C level, no -1 */
427+
if (PASS != ret) {
428+
pdo_mysql_error_stmt(stmt);
429+
PDO_DBG_RETURN(0);
430+
}
431+
if (mysql_more_results(H->server)) {
432+
PDO_DBG_RETURN(pdo_mysql_fill_stmt_from_result(stmt TSRMLS_CC));
433+
} else {
434+
/* No more results */
435+
PDO_DBG_RETURN(0);
436+
}
437+
#else
426438
if (ret > 0) {
427439
pdo_mysql_error_stmt(stmt);
428440
PDO_DBG_RETURN(0);
@@ -432,6 +444,8 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
432444
} else {
433445
PDO_DBG_RETURN(pdo_mysql_fill_stmt_from_result(stmt TSRMLS_CC));
434446
}
447+
#endif
448+
435449
#else
436450
strcpy(stmt->error_code, "HYC00");
437451
PDO_DBG_RETURN(0);
@@ -458,7 +472,7 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
458472
PDO_MYSQL_PARAM_BIND *b;
459473
#endif
460474
#if HAVE_MYSQL_STMT_PREPARE || PDO_USE_MYSQLND
461-
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
475+
pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data;
462476

463477
PDO_DBG_ENTER("pdo_mysql_stmt_param_hook");
464478
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
@@ -498,18 +512,18 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
498512
}
499513
#else
500514
b = (PDO_MYSQL_PARAM_BIND*)param->driver_data;
501-
*b->is_null = 0;
502-
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_NULL ||
503-
Z_TYPE_P(param->parameter) == IS_NULL) {
504-
*b->is_null = 1;
505-
b->buffer_type = MYSQL_TYPE_STRING;
506-
b->buffer = NULL;
507-
b->buffer_length = 0;
508-
*b->length = 0;
515+
*b->is_null = 0;
516+
if (PDO_PARAM_TYPE(param->param_type) == PDO_PARAM_NULL ||
517+
Z_TYPE_P(param->parameter) == IS_NULL) {
518+
*b->is_null = 1;
519+
b->buffer_type = MYSQL_TYPE_STRING;
520+
b->buffer = NULL;
521+
b->buffer_length = 0;
522+
*b->length = 0;
509523
PDO_DBG_RETURN(1);
510-
}
524+
}
511525
#endif /* PDO_USE_MYSQLND */
512-
526+
513527
switch (PDO_PARAM_TYPE(param->param_type)) {
514528
case PDO_PARAM_STMT:
515529
PDO_DBG_RETURN(0);
@@ -533,7 +547,7 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
533547
default:
534548
;
535549
}
536-
550+
537551
#if PDO_USE_MYSQLND
538552
/* Is it really correct to check the zval's type? - But well, that's what the old code below does, too */
539553
PDO_DBG_INF_FMT("param->parameter->type=%d", Z_TYPE_P(param->parameter));
@@ -554,9 +568,9 @@ static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_da
554568
default:
555569
PDO_DBG_RETURN(0);
556570
}
557-
571+
558572
PDO_DBG_RETURN(1);
559-
#else
573+
#else
560574
PDO_DBG_INF_FMT("param->parameter->type=%d", Z_TYPE_P(param->parameter));
561575
switch (Z_TYPE_P(param->parameter)) {
562576
case IS_STRING:
@@ -612,7 +626,7 @@ static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori
612626
#else
613627
# if HAVE_MYSQL_STMT_PREPARE
614628
int ret;
615-
629+
616630
if (S->stmt) {
617631
ret = mysql_stmt_fetch(S->stmt);
618632

@@ -633,7 +647,7 @@ static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori
633647
}
634648
# endif /* HAVE_MYSQL_STMT_PREPARE */
635649
#endif /* PDO_USE_MYSQLND */
636-
650+
637651
if (!S->result) {
638652
strcpy(stmt->error_code, "HY000");
639653
PDO_DBG_RETURN(0);
@@ -653,7 +667,7 @@ static int pdo_mysql_stmt_fetch(pdo_stmt_t *stmt, enum pdo_fetch_orientation ori
653667
pdo_mysql_error_stmt(stmt);
654668
}
655669
PDO_DBG_RETURN(0);
656-
}
670+
}
657671

658672
S->current_lengths = mysql_fetch_lengths(S->result);
659673
PDO_DBG_RETURN(1);
@@ -677,8 +691,8 @@ static int pdo_mysql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC) /* {{{
677691
PDO_DBG_RETURN(0);
678692
}
679693

680-
/* fetch all on demand, this seems easiest
681-
** if we've been here before bail out
694+
/* fetch all on demand, this seems easiest
695+
** if we've been here before bail out
682696
*/
683697
if (cols[0].name) {
684698
PDO_DBG_RETURN(1);
@@ -694,10 +708,10 @@ static int pdo_mysql_stmt_describe(pdo_stmt_t *stmt, int colno TSRMLS_DC) /* {{{
694708
cols[i].namelen = namelen;
695709
cols[i].name = estrndup(S->fields[i].name, namelen);
696710
}
697-
711+
698712
cols[i].precision = S->fields[i].decimals;
699713
cols[i].maxlen = S->fields[i].length;
700-
714+
701715
#ifdef PDO_USE_MYSQLND
702716
if (S->stmt) {
703717
cols[i].param_type = PDO_PARAM_ZVAL;
@@ -818,7 +832,7 @@ static int pdo_mysql_stmt_col_meta(pdo_stmt_t *stmt, long colno, zval *return_va
818832
const MYSQL_FIELD *F;
819833
zval *flags;
820834
char *str;
821-
835+
822836
PDO_DBG_ENTER("pdo_mysql_stmt_col_meta");
823837
PDO_DBG_INF_FMT("stmt=%p", S->stmt);
824838
if (!S->result) {
@@ -876,7 +890,7 @@ static int pdo_mysql_stmt_col_meta(pdo_stmt_t *stmt, long colno, zval *return_va
876890
break;
877891
}
878892
#endif
879-
893+
880894
add_assoc_zval(return_value, "flags", flags);
881895
add_assoc_string(return_value, "table",(char *) (F->table?F->table:""), 1);
882896
PDO_DBG_RETURN(SUCCESS);

ext/pdo_mysql/tests/bug_41997.phpt

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
PDO MySQL Bug #41997 (stored procedure call returning single rowset blocks future queries)
33
--SKIPIF--
44
<?php
5-
if (!extension_loaded('pdo') || !extension_loaded('pdo_mysql')) die('skip not loaded');
6-
require dirname(__FILE__) . '/config.inc';
7-
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
8-
PDOTest::skip();
5+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'skipif.inc');
6+
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'mysql_pdo_test.inc');
7+
MySQLPDOTest::skip();
98

10-
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
9+
$db = MySQLPDOTest::factory();
1110
$row = $db->query('SELECT VERSION() as _version')->fetch(PDO::FETCH_ASSOC);
1211
$matches = array();
1312
if (!preg_match('/^(\d+)\.(\d+)\.(\d+)/ismU', $row['_version'], $matches))
@@ -20,9 +19,8 @@ if ($version < 50000)
2019
?>
2120
--FILE--
2221
<?php
23-
require dirname(__FILE__) . '/config.inc';
24-
require dirname(__FILE__) . '/../../../ext/pdo/tests/pdo_test.inc';
25-
$db = PDOTest::test_factory(dirname(__FILE__) . '/common.phpt');
22+
require dirname(__FILE__) . '/mysql_pdo_test.inc';
23+
$db = MySQLPDOTest::factory();
2624

2725
$db->exec('DROP PROCEDURE IF EXISTS p');
2826
$db->exec('CREATE PROCEDURE p() BEGIN SELECT 1 AS "one"; END');

0 commit comments

Comments
 (0)