Author: ahristov
Date: 2008-04-10 18:38:30 +0200 (Thu, 10 Apr 2008)
New Revision: 1418
Modified:
trunk/php5/ext/pdo_mysqlnd/mysql_driver.c
Log:
Prettify and use functions instead of direct statements -
mysql_commit, mysql_rollback, mysql_autocommit
Modified: trunk/php5/ext/pdo_mysqlnd/mysql_driver.c
===================================================================
--- trunk/php5/ext/pdo_mysqlnd/mysql_driver.c 2008-04-10 15:44:51 UTC (rev 1417)
+++ trunk/php5/ext/pdo_mysqlnd/mysql_driver.c 2008-04-10 16:38:30 UTC (rev 1418)
@@ -50,6 +50,7 @@
}
/* }}} */
+/* {{{ _pdo_mysql_error */
int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line
TSRMLS_DC) /* {{{ */
{
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
@@ -122,6 +123,7 @@
}
/* }}} */
+/* {{{ pdo_mysql_fetch_error_func */
static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info
TSRMLS_DC)
{
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
@@ -141,7 +143,9 @@
return 1;
}
+/* }}} */
+/* {{{ mysql_handle_closer */
static int mysql_handle_closer(pdo_dbh_t *dbh TSRMLS_DC) /* {{{ */
{
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
@@ -163,6 +167,7 @@
}
/* }}} */
+/* {{{ mysql_handle_preparer */
static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
pdo_stmt_t *stmt, zval *driver_options TSRMLS_DC)
{
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
@@ -257,7 +262,9 @@
return 1;
}
+/* }}} */
+/* {{{ mysql_handle_doer */
static long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRMLS_DC)
{
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
@@ -275,7 +282,9 @@
}
}
}
+/* }}} */
+/* {{{ pdo_mysql_last_insert_id */
static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned int *len
TSRMLS_DC)
{
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
@@ -284,6 +293,7 @@
return id;
}
+/* {{{ mysql_handle_quoter */
static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, int unquotedlen,
char **quoted, int *quotedlen, enum pdo_param_type paramtype TSRMLS_DC)
{
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
@@ -293,57 +303,63 @@
(*quoted)[++*quotedlen] = '\0';
return 1;
}
+/* }}} */
+/* {{{ mysql_handle_begin */
static int mysql_handle_begin(pdo_dbh_t *dbh TSRMLS_DC)
{
return 0 <= mysql_handle_doer(dbh, ZEND_STRL("START TRANSACTION") TSRMLS_CC);
}
+/* }}} */
+/* {{{ mysql_handle_commit */
static int mysql_handle_commit(pdo_dbh_t *dbh TSRMLS_DC)
{
- return 0 <= mysql_handle_doer(dbh, ZEND_STRL("COMMIT") TSRMLS_CC);
+ return 0 <= mysql_commit(((pdo_mysql_db_handle *)dbh->driver_data)->server);
}
+/* {{{ mysql_handle_rollback */
static int mysql_handle_rollback(pdo_dbh_t *dbh TSRMLS_DC)
{
- return 0 <= mysql_handle_doer(dbh, ZEND_STRL("ROLLBACK") TSRMLS_CC);
+ return 0 <= mysql_rollback(((pdo_mysql_db_handle *)dbh->driver_data)->server);
}
+/* }}} */
-static int mysql_handle_autocommit(pdo_dbh_t *dbh TSRMLS_DC)
+/* {{{ mysql_handle_autocommit */
+static inline int mysql_handle_autocommit(pdo_dbh_t *dbh TSRMLS_DC)
{
- if (dbh->auto_commit) {
- return 0 <= mysql_handle_doer(dbh, ZEND_STRL("SET AUTOCOMMIT=1") TSRMLS_CC);
- } else {
- return 0 <= mysql_handle_doer(dbh, ZEND_STRL("SET AUTOCOMMIT=0") TSRMLS_CC);
- }
+ return 0 <= mysql_autocommit(((pdo_mysql_db_handle *)dbh->driver_data)->server,
dbh->auto_commit);
}
+/* }}} */
+/* {{{ pdo_mysql_set_attribute */
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);
+ 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 TSRMLS_CC);
- }
- return 1;
+ /* 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 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;
- case PDO_MYSQL_ATTR_DIRECT_QUERY:
- case PDO_ATTR_EMULATE_PREPARES:
- ((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = Z_BVAL_P(val);
- return 1;
- default:
- return 0;
+ case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY:
+ ((pdo_mysql_db_handle *)dbh->driver_data)->buffered = Z_BVAL_P(val);
+ return 1;
+ case PDO_MYSQL_ATTR_DIRECT_QUERY:
+ case PDO_ATTR_EMULATE_PREPARES:
+ ((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = Z_BVAL_P(val);
+ return 1;
+ default:
+ return 0;
}
}
+/* }}} */
+/* {{{ pdo_mysql_get_attribute */
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;
@@ -401,7 +417,9 @@
return 1;
}
+/* }}} */
+/* {{{ pdo_mysql_check_liveness */
static int pdo_mysql_check_liveness(pdo_dbh_t *dbh TSRMLS_DC) /* {{{ */
{
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
@@ -415,11 +433,11 @@
return FAILURE;
}
#else /* no mysql_ping() */
- handler=signal(SIGPIPE, SIG_IGN);
+ handler = signal(SIGPIPE, SIG_IGN);
mysql_stat(H->server);
switch (mysql_errno(H->server)) {
case CR_SERVER_GONE_ERROR:
- /* case CR_SERVER_LOST: I'm not sure this means the same as "gone" for us */
+ case CR_SERVER_LOST:
signal(SIGPIPE, handler);
return FAILURE;
default:
@@ -431,6 +449,7 @@
}
/* }}} */
+/* {{{ mysql_methods */
static struct pdo_dbh_methods mysql_methods = {
mysql_handle_closer,
mysql_handle_preparer,
@@ -445,6 +464,7 @@
pdo_mysql_get_attribute,
pdo_mysql_check_liveness
};
+/* }}} */
#ifndef PDO_MYSQL_UNIX_ADDR
# ifdef PHP_WIN32
@@ -454,6 +474,7 @@
# endif
#endif
+/* {{{ pdo_mysql_handle_factory */
static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_DC) /*
{{{ */
{
pdo_mysql_db_handle *H;
@@ -597,16 +618,14 @@
password_len = strlen(dbh->password);
}
- if (mysqlnd_connect(H->server, host, dbh->username, dbh->password,
password_len, dbname, dbname_len, port, unix_socket, connect_opts, NULL TSRMLS_CC) ==
NULL) {
- pdo_mysql_error(dbh);
- goto cleanup;
- }
+ if (mysqlnd_connect(H->server, host, dbh->username, dbh->password,
password_len, dbname, dbname_len,
+ port, unix_socket, connect_opts, NULL TSRMLS_CC) == NULL) {
#else
if (mysql_real_connect(H->server, host, dbh->username, dbh->password, dbname,
port, unix_socket, connect_opts) == NULL) {
+#endif
pdo_mysql_error(dbh);
goto cleanup;
}
-#endif
if (!dbh->auto_commit) {
mysql_handle_autocommit(dbh TSRMLS_CC);
| Thread |
|---|
| • PHP mysqlnd svn commit: r1418 - trunk/php5/ext/pdo_mysqlnd | ahristov | 10 Apr |