From 1bbab254554a63dfc8d1507883323f29349dd850 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 2 Jul 2005 21:01:38 +0000 Subject: [PATCH] Experimental support for queries returning multiple rowsets under mysql 5.0. Patch from Guy Harrison (guy dot a dot harrison (at) gmail dot com) --- ext/pdo_mysql/config.m4 | 2 +- ext/pdo_mysql/mysql_driver.c | 12 +++++++-- ext/pdo_mysql/mysql_statement.c | 45 ++++++++++++++++++++++++++++++++- 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/ext/pdo_mysql/config.m4 b/ext/pdo_mysql/config.m4 index 4ea134621c..c38e970f2d 100755 --- a/ext/pdo_mysql/config.m4 +++ b/ext/pdo_mysql/config.m4 @@ -58,7 +58,7 @@ Note that the MySQL client library is not bundled anymore!]) _SAVE_LDFLAGS=$LDFLAGS LDFLAGS="$LDFLAGS $PDO_MYSQL_LIBS" - AC_CHECK_FUNCS([mysql_commit mysql_stmt_prepare]) + AC_CHECK_FUNCS([mysql_commit mysql_stmt_prepare mysql_next_result]) LDFLAGS=$_SAVE_LDFLAGS PHP_CHECK_PDO_INCLUDES diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index 8d15cf35a0..a0f7ac07c1 100755 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2004 The PHP Group | + | Copyright (c) 1997-2005 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.0 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -305,6 +305,14 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ { "port", "3306", 0 }, { "unix_socket", PDO_MYSQL_UNIX_ADDR, 0 }, }; + int connect_opts = 0 +#ifdef CLIENT_MULTI_RESULTS + |CLIENT_MULTI_RESULTS +#endif +#ifdef CLIENT_MULTI_STATEMENTS + |CLIENT_MULTI_STATEMENTS +#endif + ; php_pdo_parse_data_source(dbh->data_source, dbh->data_source_len, vars, 4); @@ -337,7 +345,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ port = atoi(vars[3].optval); } dbname = vars[1].optval; - if (mysql_real_connect(H->server, host, dbh->username, dbh->password, dbname, port, unix_socket, 0) == NULL) { + if (mysql_real_connect(H->server, host, dbh->username, dbh->password, dbname, port, unix_socket, connect_opts) == NULL) { pdo_mysql_error(dbh); goto cleanup; } diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c index 564418c695..a88eb15b8d 100755 --- a/ext/pdo_mysql/mysql_statement.c +++ b/ext/pdo_mysql/mysql_statement.c @@ -93,6 +93,46 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC) return 1; } +#if HAVE_MYSQL_NEXT_RESULT +static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) +{ + pdo_mysql_stmt *S = (pdo_mysql_stmt*)stmt->driver_data; + pdo_mysql_db_handle *H = S->H; + my_ulonglong row_count; + int debug=0; + int ret; + + /* ensure that we free any previous unfetched results */ + if (S->result) { + mysql_free_result(S->result); + S->result = NULL; + } + + ret = mysql_next_result(H->server); + + if (ret > 0) { + pdo_mysql_error_stmt(stmt); + return 0; + } else if (ret < 0) { + /* No more results */ + return 0; + } else { + row_count = mysql_affected_rows(H->server); + S->result = mysql_use_result(H->server); + + if (NULL == S->result) { + return 0; + } + + stmt->row_count = row_count; + stmt->column_count = (int) mysql_num_fields(S->result); + S->fields = mysql_fetch_fields(S->result); + return 1; + } +} +#endif + + static int pdo_mysql_stmt_param_hook(pdo_stmt_t *stmt, struct pdo_bound_param_data *param, enum pdo_param_event event_type TSRMLS_DC) { @@ -256,7 +296,10 @@ struct pdo_stmt_methods mysql_stmt_methods = { pdo_mysql_stmt_param_hook, NULL, /* set_attr */ NULL, /* get_attr */ - pdo_mysql_stmt_col_meta + pdo_mysql_stmt_col_meta, +#if HAVE_MYSQL_NEXT_RESULT + pdo_mysql_stmt_next_rowset +#endif }; /* -- 2.40.0