cvs: pecl /pdo_mysql mysql_driver.c

From: Date: Sun, 13 Feb 2005 00:51:18 +0000
Subject: cvs: pecl /pdo_mysql mysql_driver.c
Groups: php.pecl.cvs 
Request: Send a blank email to pecl-cvs+get-2522@lists.php.net to get a copy of this message
hholzgra Sat Feb 12 19:51:18 2005 EDT Modified files: /pecl/pdo_mysql mysql_driver.c Log: added MySQL transaction support http://cvs.php.net/diff.php/pecl/pdo_mysql/mysql_driver.c?r1=1.30&r2=1.31&ty=u Index: pecl/pdo_mysql/mysql_driver.c diff -u pecl/pdo_mysql/mysql_driver.c:1.30 pecl/pdo_mysql/mysql_driver.c:1.31 --- pecl/pdo_mysql/mysql_driver.c:1.30 Sat Feb 12 19:48:00 2005 +++ pecl/pdo_mysql/mysql_driver.c Sat Feb 12 19:51:17 2005 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: mysql_driver.c,v 1.30 2005/02/13 00:48:00 hholzgra Exp $ */ +/* $Id: mysql_driver.c,v 1.31 2005/02/13 00:51:17 hholzgra Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -179,6 +179,45 @@ return 1; } +static int mysql_handle_begin(pdo_dbh_t *dbh TSRMLS_DC) +{ + return 0 <= mysql_handle_doer(dbh, ZEND_STRL("START TRANSACTION") TSRMLS_CC); +} + +static int mysql_handle_commit(pdo_dbh_t *dbh TSRMLS_DC) +{ + return 0 <= mysql_handle_doer(dbh, ZEND_STRL("COMMIT") TSRMLS_CC); +} + +static int mysql_handle_rollback(pdo_dbh_t *dbh TSRMLS_DC) +{ + return 0 <= mysql_handle_doer(dbh, ZEND_STRL("ROLLBACK") TSRMLS_CC); +} + +static int mysql_handle_autocommit(pdo_dbh_t *dbh TSRMLS_DC) +{ + return 0 <= mysql_handle_doer(dbh, ZEND_STRL("SET SESSION AUTOCOMMIT=0") TSRMLS_CC); +} + +static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, long attr, zval *val TSRMLS_DC) +{ + switch (attr) { + case PDO_ATTR_AUTOCOMMIT: + + convert_to_boolean(val); + + /* ignore if the new value equals the old one */ + if (dbh->auto_commit ^ Z_BVAL_P(val)) { + dbh->auto_commit = Z_BVAL_P(val); + mysql_handle_autocommit(dbh); + } + return 1; + + default: + return 0; + } +} + static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value TSRMLS_DC) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; @@ -208,6 +247,10 @@ } break; + case PDO_ATTR_AUTOCOMMIT: + ZVAL_LONG(return_value, dbh->auto_commit); + return 1; + default: return 0; } @@ -215,15 +258,16 @@ return 1; } + static struct pdo_dbh_methods mysql_methods = { mysql_handle_closer, mysql_handle_preparer, mysql_handle_doer, mysql_handle_quoter, - NULL, - NULL, - NULL, - NULL, + mysql_handle_begin, + mysql_handle_commit, + mysql_handle_rollback, + pdo_mysql_set_attribute, pdo_mysql_last_insert_id, pdo_mysql_fetch_error_func, pdo_mysql_get_attribute, @@ -270,6 +314,8 @@ pdo_mysql_error(dbh); goto cleanup; } + + mysql_handle_autocommit(dbh); } #ifndef PHP_WIN32

« previous php.pecl.cvs (#2522) next »