Skip to content

Commit 2d2d1c7

Browse files
committed
new function/methods - mysqlnd_stmt_flush. Removing
code duplication
1 parent ca5df2a commit 2d2d1c7

File tree

3 files changed

+46
-37
lines changed

3 files changed

+46
-37
lines changed

ext/mysqlnd/mysqlnd.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ PHPAPI ulong mysqlnd_old_escape_string(char *newstr, const char *escapestr, size
261261
#define mysqlnd_stmt_free_result(stmt) (stmt)->m->free_result((stmt) TSRMLS_CC)
262262
#define mysqlnd_stmt_close(stmt, implicit) (stmt)->m->dtor((stmt), (implicit) TSRMLS_CC)
263263
#define mysqlnd_stmt_reset(stmt) (stmt)->m->reset((stmt) TSRMLS_CC)
264+
#define mysqlnd_stmt_flush(stmt) (stmt)->m->flush((stmt) TSRMLS_CC)
264265

265266

266267
#define mysqlnd_stmt_attr_get(stmt, attr, value) (stmt)->m->get_attribute((stmt), (attr), (value) TSRMLS_CC)

ext/mysqlnd/mysqlnd_ps.c

Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -628,27 +628,7 @@ MYSQLND_METHOD(mysqlnd_stmt, execute)(MYSQLND_STMT * const s TSRMLS_DC)
628628
}
629629
#endif
630630

631-
/*
632-
If right after execute() we have to call the appropriate
633-
use_result() or store_result() and clean.
634-
*/
635-
if (stmt->state == MYSQLND_STMT_WAITING_USE_OR_STORE) {
636-
DBG_INF("fetching result set header");
637-
/* Do implicit use_result and then flush the result */
638-
stmt->default_rset_handler = s->m->use_result;
639-
stmt->default_rset_handler(s TSRMLS_CC);
640-
}
641-
642-
if (stmt->state > MYSQLND_STMT_WAITING_USE_OR_STORE) {
643-
DBG_INF("skipping result");
644-
/* Flush if anything is left and unbuffered set */
645-
stmt->result->m.skip_result(stmt->result TSRMLS_CC);
646-
}
647-
648-
if (stmt->state > MYSQLND_STMT_PREPARED) {
649-
/* As the buffers have been freed, we should go back to PREPARED */
650-
stmt->state = MYSQLND_STMT_PREPARED;
651-
}
631+
s->m->flush(s TSRMLS_CC);
652632

653633
/*
654634
Executed, but the user hasn't started to fetch
@@ -1228,6 +1208,45 @@ MYSQLND_METHOD(mysqlnd_stmt, reset)(MYSQLND_STMT * const s TSRMLS_DC)
12281208
}
12291209
}
12301210

1211+
s->m->flush(s TSRMLS_CC);
1212+
1213+
/*
1214+
Don't free now, let the result be usable. When the stmt will again be
1215+
executed then the result set will be cleaned, the bound variables will
1216+
be separated before that.
1217+
*/
1218+
1219+
int4store(cmd_buf, stmt->stmt_id);
1220+
if (CONN_GET_STATE(conn) == CONN_READY &&
1221+
FAIL == (ret = conn->m->simple_command(conn, COM_STMT_RESET, cmd_buf,
1222+
sizeof(cmd_buf), PROT_OK_PACKET,
1223+
FALSE, TRUE TSRMLS_CC))) {
1224+
stmt->error_info = conn->error_info;
1225+
}
1226+
stmt->upsert_status = conn->upsert_status;
1227+
1228+
stmt->state = MYSQLND_STMT_PREPARED;
1229+
}
1230+
DBG_INF(ret == PASS? "PASS":"FAIL");
1231+
DBG_RETURN(ret);
1232+
}
1233+
/* }}} */
1234+
1235+
1236+
/* {{{ mysqlnd_stmt::flush */
1237+
static enum_func_status
1238+
MYSQLND_METHOD(mysqlnd_stmt, flush)(MYSQLND_STMT * const s TSRMLS_DC)
1239+
{
1240+
MYSQLND_STMT_DATA * stmt = s? s->data:NULL;
1241+
enum_func_status ret = PASS;
1242+
1243+
DBG_ENTER("mysqlnd_stmt::flush");
1244+
if (!stmt || !stmt->conn) {
1245+
DBG_RETURN(FAIL);
1246+
}
1247+
DBG_INF_FMT("stmt=%lu", stmt->stmt_id);
1248+
1249+
if (stmt->stmt_id) {
12311250
/*
12321251
If the user decided to close the statement right after execute()
12331252
We have to call the appropriate use_result() or store_result() and
@@ -1246,21 +1265,6 @@ MYSQLND_METHOD(mysqlnd_stmt, reset)(MYSQLND_STMT * const s TSRMLS_DC)
12461265
}
12471266
} while (mysqlnd_stmt_more_results(s) && mysqlnd_stmt_next_result(s) == PASS);
12481267

1249-
/*
1250-
Don't free now, let the result be usable. When the stmt will again be
1251-
executed then the result set will be cleaned, the bound variables will
1252-
be separated before that.
1253-
*/
1254-
1255-
int4store(cmd_buf, stmt->stmt_id);
1256-
if (CONN_GET_STATE(conn) == CONN_READY &&
1257-
FAIL == (ret = conn->m->simple_command(conn, COM_STMT_RESET, cmd_buf,
1258-
sizeof(cmd_buf), PROT_OK_PACKET,
1259-
FALSE, TRUE TSRMLS_CC))) {
1260-
stmt->error_info = conn->error_info;
1261-
}
1262-
stmt->upsert_status = conn->upsert_status;
1263-
12641268
stmt->state = MYSQLND_STMT_PREPARED;
12651269
}
12661270
DBG_INF(ret == PASS? "PASS":"FAIL");
@@ -2335,7 +2339,8 @@ MYSQLND_CLASS_METHODS_START(mysqlnd_stmt)
23352339
MYSQLND_METHOD(mysqlnd_stmt, server_status),
23362340
mysqlnd_stmt_execute_generate_request,
23372341
mysqlnd_stmt_execute_parse_response,
2338-
MYSQLND_METHOD(mysqlnd_stmt, free_stmt_content)
2342+
MYSQLND_METHOD(mysqlnd_stmt, free_stmt_content),
2343+
MYSQLND_METHOD(mysqlnd_stmt, flush)
23392344
MYSQLND_CLASS_METHODS_END;
23402345

23412346

ext/mysqlnd/mysqlnd_structs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,7 @@ typedef unsigned int (*func_mysqlnd_stmt__server_status)(const MYSQLND_STMT * c
641641
typedef enum_func_status (*func_mysqlnd_stmt__generate_execute_request)(MYSQLND_STMT * const s, zend_uchar ** request, size_t *request_len, zend_bool * free_buffer TSRMLS_DC);
642642
typedef enum_func_status (*func_mysqlnd_stmt__parse_execute_response)(MYSQLND_STMT * const s TSRMLS_DC);
643643
typedef void (*func_mysqlnd_stmt__free_stmt_content)(MYSQLND_STMT * const s TSRMLS_DC);
644+
typedef enum_func_status (*func_mysqlnd_stmt__flush)(MYSQLND_STMT * const stmt TSRMLS_DC);
644645

645646
struct st_mysqlnd_stmt_methods
646647
{
@@ -694,6 +695,8 @@ struct st_mysqlnd_stmt_methods
694695
func_mysqlnd_stmt__parse_execute_response parse_execute_response;
695696

696697
func_mysqlnd_stmt__free_stmt_content free_stmt_content;
698+
699+
func_mysqlnd_stmt__flush flush;
697700
};
698701

699702

0 commit comments

Comments
 (0)