From: Ilia Alshanetsky Date: Fri, 24 Jun 2005 19:45:59 +0000 (+0000) Subject: Added PDO_MYSQL_ATTR_USE_BUFFERED_QUERY parameter for pdo_mysql, to toggle X-Git-Tag: php-5.1.0b3~322 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=348c0cddae153a7875973a3f673eb01710202e45;p=php Added PDO_MYSQL_ATTR_USE_BUFFERED_QUERY parameter for pdo_mysql, to toggle usage of buffered queries. --- diff --git a/NEWS b/NEWS index ded041dd89..c82fd0bc2b 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,8 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2005, PHP 5.1 Beta 3 +- Added PDO_MYSQL_ATTR_USE_BUFFERED_QUERY parameter for pdo_mysql, to toggle + usage of buffered queries. - Fixed bug #32660 (Assignment by reference causes crash when field access is overloaded (__get)). (Dmitry) - Fixed bug #30828 (debug_backtrace() reports incorrect class in overridden diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index b7647269b9..293a822aff 100755 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -37,6 +37,7 @@ const char *pdo_mysql_get_sqlstate(unsigned int my_errno) { switch (my_errno) { /* import auto-generated case: code */ #include "php_pdo_mysql_sqlstate.h" + case 2014: return "PDDRV"; /* out of sync */ default: return "HY000"; } } @@ -66,7 +67,11 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin } if (einfo->errcode) { - einfo->errmsg = pestrdup(mysql_error(H->server), dbh->is_persistent); + if (2014 != einfo->errcode) { + einfo->errmsg = pestrdup(mysql_error(H->server), dbh->is_persistent); + } else { + einfo->errmsg = pestrdup("Cannot execute queries, while other unbuffered queries are active. To enable query buffering set PDO_MYSQL_ATTR_USE_BUFFERED_QUERY attribute.", dbh->is_persistent); + } } else { /* no error */ strcpy(*pdo_err, PDO_ERR_NONE); return 0; @@ -208,6 +213,10 @@ static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_D mysql_handle_autocommit(dbh TSRMLS_CC); } return 1; + + case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY: + ((pdo_mysql_db_handle *)dbh->driver_data)->buffered = Z_BVAL_P(val); + return 1; default: return 0; @@ -247,6 +256,10 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value ZVAL_LONG(return_value, dbh->auto_commit); return 1; + case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY: + ZVAL_LONG(return_value, H->buffered); + return 1; + default: return 0; } @@ -309,6 +322,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_ /* handle MySQL options */ if (driver_options) { long connect_timeout = pdo_attr_lval(driver_options, PDO_ATTR_TIMEOUT, 30 TSRMLS_CC); + H->buffered = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 0 TSRMLS_CC); if (mysql_options(H->server, MYSQL_OPT_CONNECT_TIMEOUT, (const char *)&connect_timeout)) { pdo_mysql_error(dbh); diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c index 0615534f35..564418c695 100755 --- a/ext/pdo_mysql/mysql_statement.c +++ b/ext/pdo_mysql/mysql_statement.c @@ -69,7 +69,11 @@ static int pdo_mysql_stmt_execute(pdo_stmt_t *stmt TSRMLS_DC) if (row_count == (my_ulonglong)-1) { /* we either have a query that returned a result set or an error occured lets see if we have access to a result set */ - S->result = mysql_use_result(H->server); + if (!H->buffered) { + S->result = mysql_use_result(H->server); + } else { + S->result = mysql_store_result(H->server); + } if (NULL == S->result) { pdo_mysql_error_stmt(stmt); return 0; diff --git a/ext/pdo_mysql/pdo_mysql.c b/ext/pdo_mysql/pdo_mysql.c index ccf22d0438..d42c13f72d 100755 --- a/ext/pdo_mysql/pdo_mysql.c +++ b/ext/pdo_mysql/pdo_mysql.c @@ -75,6 +75,8 @@ ZEND_GET_MODULE(pdo_mysql) */ PHP_MINIT_FUNCTION(pdo_mysql) { + REGISTER_LONG_CONSTANT("PDO_MYSQL_ATTR_USE_BUFFERED_QUERY", (long)PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, CONST_CS|CONST_PERSISTENT); + return php_pdo_register_driver(&pdo_mysql_driver); } /* }}} */ diff --git a/ext/pdo_mysql/php_pdo_mysql_int.h b/ext/pdo_mysql/php_pdo_mysql_int.h index 4dc5739793..9a2c473a13 100755 --- a/ext/pdo_mysql/php_pdo_mysql_int.h +++ b/ext/pdo_mysql/php_pdo_mysql_int.h @@ -35,6 +35,7 @@ typedef struct { MYSQL *server; unsigned attached:1; + unsigned buffered:1; unsigned _reserved:31; pdo_mysql_error_info einfo; @@ -67,4 +68,8 @@ extern int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, #define pdo_mysql_error_stmt(s) _pdo_mysql_error(stmt->dbh, stmt, __FILE__, __LINE__ TSRMLS_CC) extern struct pdo_stmt_methods mysql_stmt_methods; + +enum { + PDO_MYSQL_ATTR_USE_BUFFERED_QUERY = PDO_ATTR_DRIVER_SPECIFIC, +}; #endif diff --git a/ext/pdo_mysql/tests/pdo_016.phpt b/ext/pdo_mysql/tests/pdo_016.phpt index 1be753f306..adb73d1f75 100755 --- a/ext/pdo_mysql/tests/pdo_016.phpt +++ b/ext/pdo_mysql/tests/pdo_016.phpt @@ -10,6 +10,7 @@ require_once('skipif.inc'); require_once('connection.inc'); require_once('prepare.inc'); +$DB->setAttribute(PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 1); require_once($PDO_TESTS . 'pdo_016.inc'); ?>