Skip to content

Commit b9ea8d6

Browse files
committed
PDO MySQL: Extract common code for handling PS results
1 parent fb69c77 commit b9ea8d6

File tree

1 file changed

+28
-46
lines changed

1 file changed

+28
-46
lines changed

ext/pdo_mysql/mysql_statement.c

Lines changed: 28 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,32 @@ static int pdo_mysql_fill_stmt_from_result(pdo_stmt_t *stmt) /* {{{ */
154154
}
155155
/* }}} */
156156

157+
static bool pdo_mysql_stmt_after_execute_prepared(pdo_stmt_t *stmt) {
158+
pdo_mysql_stmt *S = stmt->driver_data;
159+
pdo_mysql_db_handle *H = S->H;
160+
161+
/* For SHOW/DESCRIBE and others the column/field count is not available before execute. */
162+
php_pdo_stmt_set_column_count(stmt, mysql_stmt_field_count(S->stmt));
163+
for (int i = 0; i < stmt->column_count; i++) {
164+
mysqlnd_stmt_bind_one_result(S->stmt, i);
165+
}
166+
167+
S->result = mysqlnd_stmt_result_metadata(S->stmt);
168+
if (S->result) {
169+
S->fields = mysql_fetch_fields(S->result);
170+
/* If buffered, pre-fetch all the data */
171+
if (H->buffered) {
172+
if (mysql_stmt_store_result(S->stmt)) {
173+
pdo_mysql_error_stmt(stmt);
174+
return false;
175+
}
176+
}
177+
}
178+
179+
pdo_mysql_stmt_set_row_count(stmt);
180+
return true;
181+
}
182+
157183
#ifndef PDO_USE_MYSQLND
158184
static int pdo_mysql_stmt_execute_prepared_libmysql(pdo_stmt_t *stmt) /* {{{ */
159185
{
@@ -272,8 +298,6 @@ static int pdo_mysql_stmt_execute_prepared_libmysql(pdo_stmt_t *stmt) /* {{{ */
272298
static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo_stmt_t *stmt) /* {{{ */
273299
{
274300
pdo_mysql_stmt *S = stmt->driver_data;
275-
pdo_mysql_db_handle *H = S->H;
276-
int i;
277301

278302
PDO_DBG_ENTER("pdo_mysql_stmt_execute_prepared_mysqlnd");
279303

@@ -288,26 +312,7 @@ static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo_stmt_t *stmt) /* {{{ */
288312
S->result = NULL;
289313
}
290314

291-
/* for SHOW/DESCRIBE and others the column/field count is not available before execute */
292-
php_pdo_stmt_set_column_count(stmt, mysql_stmt_field_count(S->stmt));
293-
for (i = 0; i < stmt->column_count; i++) {
294-
mysqlnd_stmt_bind_one_result(S->stmt, i);
295-
}
296-
297-
S->result = mysqlnd_stmt_result_metadata(S->stmt);
298-
if (S->result) {
299-
S->fields = mysql_fetch_fields(S->result);
300-
/* if buffered, pre-fetch all the data */
301-
if (H->buffered) {
302-
if (mysql_stmt_store_result(S->stmt)) {
303-
pdo_mysql_error_stmt(stmt);
304-
PDO_DBG_RETURN(0);
305-
}
306-
}
307-
}
308-
309-
pdo_mysql_stmt_set_row_count(stmt);
310-
PDO_DBG_RETURN(1);
315+
PDO_DBG_RETURN(pdo_mysql_stmt_after_execute_prepared(stmt));
311316
}
312317
/* }}} */
313318
#endif
@@ -364,30 +369,7 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt) /* {{{ */
364369
PDO_DBG_RETURN(0);
365370
}
366371

367-
{
368-
/* for SHOW/DESCRIBE and others the column/field count is not available before execute */
369-
int i;
370-
371-
php_pdo_stmt_set_column_count(stmt, mysql_stmt_field_count(S->stmt));
372-
for (i = 0; i < stmt->column_count; i++) {
373-
mysqlnd_stmt_bind_one_result(S->stmt, i);
374-
}
375-
}
376-
377-
S->result = mysqlnd_stmt_result_metadata(S->stmt);
378-
if (S->result) {
379-
S->fields = mysql_fetch_fields(S->result);
380-
381-
/* if buffered, pre-fetch all the data */
382-
if (H->buffered) {
383-
if (mysql_stmt_store_result(S->stmt)) {
384-
pdo_mysql_error_stmt(stmt);
385-
PDO_DBG_RETURN(0);
386-
}
387-
}
388-
}
389-
pdo_mysql_stmt_set_row_count(stmt);
390-
PDO_DBG_RETURN(1);
372+
PDO_DBG_RETURN(pdo_mysql_stmt_after_execute_prepared(stmt));
391373
}
392374
#endif
393375

0 commit comments

Comments
 (0)