summaryrefslogtreecommitdiff
path: root/ext/pdo_mysql/mysql_driver.c
diff options
context:
space:
mode:
authorOndřej Surý <ondrej@sury.org>2012-02-01 21:25:15 +0100
committerOndřej Surý <ondrej@sury.org>2012-02-02 16:22:43 +0100
commitb6284c07d03a04d737467c0bba1dc268be85c9e1 (patch)
tree7bb7d6362aec024912ce83d0717d656ffad3db66 /ext/pdo_mysql/mysql_driver.c
parent047c0f130629403041f97af7705453f5ff33df9f (diff)
downloadphp-b6284c07d03a04d737467c0bba1dc268be85c9e1.tar.gz
Imported Upstream version 5.4.0~rc6
Diffstat (limited to 'ext/pdo_mysql/mysql_driver.c')
-rwxr-xr-xext/pdo_mysql/mysql_driver.c46
1 files changed, 7 insertions, 39 deletions
diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c
index 88b2ba6ed..771c6ee29 100755
--- a/ext/pdo_mysql/mysql_driver.c
+++ b/ext/pdo_mysql/mysql_driver.c
@@ -36,23 +36,12 @@
#endif
#include "zend_exceptions.h"
-#if PDO_USE_MYSQLND
+#if defined(PDO_USE_MYSQLND)
# define pdo_mysql_init(persistent) mysqlnd_init(persistent)
#else
# define pdo_mysql_init(persistent) mysql_init(NULL)
#endif
-#if !defined(HAVE_MYSQL_SQLSTATE) && !defined(PDO_USE_MYSQLND)
-static const char *pdo_mysql_get_sqlstate(unsigned int my_errno) { /* {{{ */
- switch (my_errno) {
- /* import auto-generated case: code */
-#include "php_pdo_mysql_sqlstate.h"
- default: return "HY000";
- }
-}
-/* }}} */
-#endif
-
/* {{{ _pdo_mysql_error */
int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int line TSRMLS_DC)
{
@@ -72,13 +61,9 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin
einfo = &H->einfo;
}
-#if defined(HAVE_MYSQL_STMT_PREPARE) || defined(PDO_USE_MYSQLND)
if (S && S->stmt) {
einfo->errcode = mysql_stmt_errno(S->stmt);
- }
- else
-#endif
- {
+ } else {
einfo->errcode = mysql_errno(H->server);
}
@@ -112,18 +97,11 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin
PDO_DBG_RETURN(0);
}
-#if defined(HAVE_MYSQL_SQLSTATE) || defined(PDO_USE_MYSQLND)
-# if defined(HAVE_MYSQL_STMT_PREPARE) || defined(PDO_USE_MYSQLND)
if (S && S->stmt) {
strcpy(*pdo_err, mysql_stmt_sqlstate(S->stmt));
- } else
-# endif
- {
+ } else {
strcpy(*pdo_err, mysql_sqlstate(H->server));
}
-#else
- strcpy(*pdo_err, pdo_mysql_get_sqlstate(einfo->errcode));
-#endif
if (!dbh->methods) {
PDO_DBG_INF("Throwing exception");
@@ -187,12 +165,10 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
{
pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data;
pdo_mysql_stmt *S = ecalloc(1, sizeof(pdo_mysql_stmt));
-#if defined(HAVE_MYSQL_STMT_PREPARE) || defined(PDO_USE_MYSQLND)
char *nsql = NULL;
int nsql_len = 0;
int ret;
int server_version;
-#endif
PDO_DBG_ENTER("mysql_handle_preparer");
PDO_DBG_INF_FMT("dbh=%p", dbh);
@@ -206,7 +182,6 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
goto end;
}
-#if defined(HAVE_MYSQL_STMT_PREPARE) || defined(PDO_USE_MYSQLND)
server_version = mysql_get_server_version(H->server);
if (server_version < 40100) {
goto fallback;
@@ -255,7 +230,7 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
if (S->num_params) {
S->params_given = 0;
-#ifdef PDO_USE_MYSQLND
+#if defined(PDO_USE_MYSQLND)
S->params = NULL;
#else
S->params = ecalloc(S->num_params, sizeof(MYSQL_BIND));
@@ -270,7 +245,6 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, long sql_len,
PDO_DBG_RETURN(1);
fallback:
-#endif
end:
stmt->supports_placeholders = PDO_PLACEHOLDER_NONE;
@@ -296,7 +270,6 @@ static long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM
PDO_DBG_RETURN(H->einfo.errcode ? -1 : 0);
} else {
-#if defined(HAVE_MYSQL_NEXT_RESULT) || defined(PDO_USE_MYSQLND)
/* MULTI_QUERY support - eat up all unfetched result sets */
MYSQL_RES* result;
while (mysql_more_results(H->server)) {
@@ -308,7 +281,6 @@ static long mysql_handle_doer(pdo_dbh_t *dbh, const char *sql, long sql_len TSRM
mysql_free_result(result);
}
}
-#endif
PDO_DBG_RETURN((int)c);
}
}
@@ -324,7 +296,7 @@ static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, unsigned
*len = strlen(id);
PDO_DBG_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)
@@ -463,7 +435,7 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, long attr, zval *return_value
break;
case PDO_ATTR_SERVER_INFO: {
char *tmp;
-#ifdef PDO_USE_MYSQLND
+#if defined(PDO_USE_MYSQLND)
unsigned int tmp_len;
if (mysqlnd_stat(H->server, &tmp, &tmp_len) == PASS) {
@@ -584,7 +556,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
#endif
;
-#ifdef PDO_USE_MYSQLND
+#if defined(PDO_USE_MYSQLND)
int dbname_len = 0;
int password_len = 0;
#endif
@@ -626,9 +598,7 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
char *default_file = NULL, *default_group = NULL;
long compress = 0;
#endif
-#if defined(HAVE_MYSQL_STMT_PREPARE) || defined(PDO_USE_MYSQLND)
char *ssl_key = NULL, *ssl_cert = NULL, *ssl_ca = NULL, *ssl_capath = NULL, *ssl_cipher = NULL;
-#endif
H->buffered = pdo_attr_lval(driver_options, PDO_MYSQL_ATTR_USE_BUFFERED_QUERY, 1 TSRMLS_CC);
H->emulate_prepare = pdo_attr_lval(driver_options,
@@ -715,7 +685,6 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
}
}
#endif
-#if defined(HAVE_MYSQL_STMT_PREPARE) || defined(PDO_USE_MYSQLND)
ssl_key = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_KEY, NULL TSRMLS_CC);
ssl_cert = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CERT, NULL TSRMLS_CC);
ssl_ca = pdo_attr_strval(driver_options, PDO_MYSQL_ATTR_SSL_CA, NULL TSRMLS_CC);
@@ -740,7 +709,6 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options TSRMLS_
efree(ssl_cipher);
}
}
-#endif
}
#ifdef PDO_MYSQL_HAS_CHARSET