Skip to content

Commit

Permalink
PDO MySQL: Extract common code for handling PS results
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Dec 9, 2020
1 parent fb69c77 commit b9ea8d6
Showing 1 changed file with 28 additions and 46 deletions.
74 changes: 28 additions & 46 deletions ext/pdo_mysql/mysql_statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,32 @@ static int pdo_mysql_fill_stmt_from_result(pdo_stmt_t *stmt) /* {{{ */
}
/* }}} */

static bool pdo_mysql_stmt_after_execute_prepared(pdo_stmt_t *stmt) {
pdo_mysql_stmt *S = stmt->driver_data;
pdo_mysql_db_handle *H = S->H;

/* For SHOW/DESCRIBE and others the column/field count is not available before execute. */
php_pdo_stmt_set_column_count(stmt, mysql_stmt_field_count(S->stmt));
for (int i = 0; i < stmt->column_count; i++) {
mysqlnd_stmt_bind_one_result(S->stmt, i);
}

S->result = mysqlnd_stmt_result_metadata(S->stmt);
if (S->result) {
S->fields = mysql_fetch_fields(S->result);
/* If buffered, pre-fetch all the data */
if (H->buffered) {
if (mysql_stmt_store_result(S->stmt)) {
pdo_mysql_error_stmt(stmt);
return false;
}
}
}

pdo_mysql_stmt_set_row_count(stmt);
return true;
}

#ifndef PDO_USE_MYSQLND
static int pdo_mysql_stmt_execute_prepared_libmysql(pdo_stmt_t *stmt) /* {{{ */
{
Expand Down Expand Up @@ -272,8 +298,6 @@ static int pdo_mysql_stmt_execute_prepared_libmysql(pdo_stmt_t *stmt) /* {{{ */
static int pdo_mysql_stmt_execute_prepared_mysqlnd(pdo_stmt_t *stmt) /* {{{ */
{
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");

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

/* for SHOW/DESCRIBE and others the column/field count is not available before execute */
php_pdo_stmt_set_column_count(stmt, mysql_stmt_field_count(S->stmt));
for (i = 0; i < stmt->column_count; i++) {
mysqlnd_stmt_bind_one_result(S->stmt, i);
}

S->result = mysqlnd_stmt_result_metadata(S->stmt);
if (S->result) {
S->fields = mysql_fetch_fields(S->result);
/* if buffered, pre-fetch all the data */
if (H->buffered) {
if (mysql_stmt_store_result(S->stmt)) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
}
}
}

pdo_mysql_stmt_set_row_count(stmt);
PDO_DBG_RETURN(1);
PDO_DBG_RETURN(pdo_mysql_stmt_after_execute_prepared(stmt));
}
/* }}} */
#endif
Expand Down Expand Up @@ -364,30 +369,7 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt) /* {{{ */
PDO_DBG_RETURN(0);
}

{
/* for SHOW/DESCRIBE and others the column/field count is not available before execute */
int i;

php_pdo_stmt_set_column_count(stmt, mysql_stmt_field_count(S->stmt));
for (i = 0; i < stmt->column_count; i++) {
mysqlnd_stmt_bind_one_result(S->stmt, i);
}
}

S->result = mysqlnd_stmt_result_metadata(S->stmt);
if (S->result) {
S->fields = mysql_fetch_fields(S->result);

/* if buffered, pre-fetch all the data */
if (H->buffered) {
if (mysql_stmt_store_result(S->stmt)) {
pdo_mysql_error_stmt(stmt);
PDO_DBG_RETURN(0);
}
}
}
pdo_mysql_stmt_set_row_count(stmt);
PDO_DBG_RETURN(1);
PDO_DBG_RETURN(pdo_mysql_stmt_after_execute_prepared(stmt));
}
#endif

Expand Down

0 comments on commit b9ea8d6

Please sign in to comment.