diff options
Diffstat (limited to 'ext/pdo_mysql/mysql_driver.c')
-rw-r--r-- | ext/pdo_mysql/mysql_driver.c | 118 |
1 files changed, 65 insertions, 53 deletions
diff --git a/ext/pdo_mysql/mysql_driver.c b/ext/pdo_mysql/mysql_driver.c index 980a285c0d..ad27937feb 100644 --- a/ext/pdo_mysql/mysql_driver.c +++ b/ext/pdo_mysql/mysql_driver.c @@ -117,7 +117,7 @@ int _pdo_mysql_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt, const char *file, int lin /* }}} */ /* {{{ pdo_mysql_fetch_error_func */ -static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) +static void pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *info) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; pdo_mysql_error_info *einfo = &H->einfo; @@ -136,12 +136,12 @@ static int pdo_mysql_fetch_error_func(pdo_dbh_t *dbh, pdo_stmt_t *stmt, zval *in add_next_index_string(info, einfo->errmsg); } - PDO_DBG_RETURN(1); + PDO_DBG_VOID_RETURN; } /* }}} */ /* {{{ mysql_handle_closer */ -static int mysql_handle_closer(pdo_dbh_t *dbh) +static void mysql_handle_closer(pdo_dbh_t *dbh) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; @@ -157,23 +157,21 @@ static int mysql_handle_closer(pdo_dbh_t *dbh) pefree(H, dbh->is_persistent); dbh->driver_data = NULL; } - PDO_DBG_RETURN(0); } /* }}} */ /* {{{ mysql_handle_preparer */ -static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len, pdo_stmt_t *stmt, zval *driver_options) +static bool mysql_handle_preparer(pdo_dbh_t *dbh, zend_string *sql, pdo_stmt_t *stmt, zval *driver_options) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; pdo_mysql_stmt *S = ecalloc(1, sizeof(pdo_mysql_stmt)); - char *nsql = NULL; - size_t nsql_len = 0; + zend_string *nsql = NULL; int ret; int server_version; PDO_DBG_ENTER("mysql_handle_preparer"); PDO_DBG_INF_FMT("dbh=%p", dbh); - PDO_DBG_INF_FMT("sql=%.*s", (int)sql_len, sql); + PDO_DBG_INF_FMT("sql=%.*s", ZSTR_LEN(sql), ZSTR_VAL(sql)); S->H = H; stmt->driver_data = S; @@ -188,29 +186,28 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len goto fallback; } stmt->supports_placeholders = PDO_PLACEHOLDER_POSITIONAL; - ret = pdo_parse_params(stmt, (char*)sql, sql_len, &nsql, &nsql_len); + ret = pdo_parse_params(stmt, sql, &nsql); if (ret == 1) { /* query was rewritten */ sql = nsql; - sql_len = nsql_len; } else if (ret == -1) { /* failed to parse */ strcpy(dbh->error_code, stmt->error_code); - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } if (!(S->stmt = mysql_stmt_init(H->server))) { pdo_mysql_error(dbh); if (nsql) { - efree(nsql); + zend_string_release(nsql); } - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } - if (mysql_stmt_prepare(S->stmt, sql, sql_len)) { + if (mysql_stmt_prepare(S->stmt, ZSTR_VAL(sql), ZSTR_LEN(sql))) { if (nsql) { - efree(nsql); + zend_string_release(nsql); } /* TODO: might need to pull statement specific info here? */ /* if the query isn't supported by the protocol, fallback to emulation */ @@ -220,10 +217,10 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len goto fallback; } pdo_mysql_error(dbh); - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } if (nsql) { - efree(nsql); + zend_string_release(nsql); } S->num_params = mysql_stmt_param_count(S->stmt); @@ -241,13 +238,13 @@ static int mysql_handle_preparer(pdo_dbh_t *dbh, const char *sql, size_t sql_len S->max_length = pdo_attr_lval(driver_options, PDO_ATTR_MAX_COLUMN_LEN, 0); - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); fallback: end: stmt->supports_placeholders = PDO_PLACEHOLDER_NONE; - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); } /* }}} */ @@ -304,10 +301,13 @@ static char *pdo_mysql_last_insert_id(pdo_dbh_t *dbh, const char *name, size_t * #endif /* {{{ mysql_handle_quoter */ -static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unquotedlen, char **quoted, size_t *quotedlen, enum pdo_param_type paramtype ) +static zend_string* mysql_handle_quoter(pdo_dbh_t *dbh, const zend_string *unquoted, enum pdo_param_type paramtype ) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; - zend_bool use_national_character_set = 0; + bool use_national_character_set = 0; + char *quoted; + size_t quotedlen; + zend_string *quoted_str; if (H->assume_national_character_set_strings) { use_national_character_set = 1; @@ -321,29 +321,32 @@ static int mysql_handle_quoter(pdo_dbh_t *dbh, const char *unquoted, size_t unqu PDO_DBG_ENTER("mysql_handle_quoter"); PDO_DBG_INF_FMT("dbh=%p", dbh); - PDO_DBG_INF_FMT("unquoted=%.*s", (int)unquotedlen, unquoted); - *quoted = safe_emalloc(2, unquotedlen, 3 + (use_national_character_set ? 1 : 0)); + PDO_DBG_INF_FMT("unquoted=%.*s", (int)ZSTR_LEN(unquoted), ZSTR_VAL(unquoted)); + quoted = safe_emalloc(2, ZSTR_LEN(unquoted), 3 + (use_national_character_set ? 1 : 0)); if (use_national_character_set) { - *quotedlen = mysql_real_escape_string_quote(H->server, *quoted + 2, unquoted, unquotedlen, '\''); - (*quoted)[0] = 'N'; - (*quoted)[1] = '\''; + quotedlen = mysql_real_escape_string_quote(H->server, quoted + 2, ZSTR_VAL(unquoted), ZSTR_LEN(unquoted), '\''); + quoted[0] = 'N'; + quoted[1] = '\''; - ++*quotedlen; /* N prefix */ + ++quotedlen; /* N prefix */ } else { - *quotedlen = mysql_real_escape_string_quote(H->server, *quoted + 1, unquoted, unquotedlen, '\''); - (*quoted)[0] = '\''; + quotedlen = mysql_real_escape_string_quote(H->server, quoted + 1, ZSTR_VAL(unquoted), ZSTR_LEN(unquoted), '\''); + quoted[0] = '\''; } - (*quoted)[++*quotedlen] = '\''; - (*quoted)[++*quotedlen] = '\0'; - PDO_DBG_INF_FMT("quoted=%.*s", (int)*quotedlen, *quoted); - PDO_DBG_RETURN(1); + quoted[++quotedlen] = '\''; + quoted[++quotedlen] = '\0'; + PDO_DBG_INF_FMT("quoted=%.*s", (int)quotedlen, quoted); + + quoted_str = zend_string_init(quoted, quotedlen, 0); + efree(quoted); + PDO_DBG_RETURN(quoted_str); } /* }}} */ /* {{{ mysql_handle_begin */ -static int mysql_handle_begin(pdo_dbh_t *dbh) +static bool mysql_handle_begin(pdo_dbh_t *dbh) { PDO_DBG_ENTER("mysql_handle_quoter"); PDO_DBG_INF_FMT("dbh=%p", dbh); @@ -352,28 +355,28 @@ static int mysql_handle_begin(pdo_dbh_t *dbh) /* }}} */ /* {{{ mysql_handle_commit */ -static int mysql_handle_commit(pdo_dbh_t *dbh) +static bool mysql_handle_commit(pdo_dbh_t *dbh) { PDO_DBG_ENTER("mysql_handle_commit"); PDO_DBG_INF_FMT("dbh=%p", dbh); if (mysql_commit(((pdo_mysql_db_handle *)dbh->driver_data)->server)) { pdo_mysql_error(dbh); - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); } /* }}} */ /* {{{ mysql_handle_rollback */ -static int mysql_handle_rollback(pdo_dbh_t *dbh) +static bool mysql_handle_rollback(pdo_dbh_t *dbh) { PDO_DBG_ENTER("mysql_handle_rollback"); PDO_DBG_INF_FMT("dbh=%p", dbh); if (mysql_rollback(((pdo_mysql_db_handle *)dbh->driver_data)->server)) { pdo_mysql_error(dbh); - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); } /* }}} */ @@ -392,10 +395,10 @@ static inline int mysql_handle_autocommit(pdo_dbh_t *dbh) /* }}} */ /* {{{ pdo_mysql_set_attribute */ -static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) +static bool pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) { zend_long lval = zval_get_long(val); - zend_bool bval = lval ? 1 : 0; + bool bval = lval ? 1 : 0; PDO_DBG_ENTER("pdo_mysql_set_attribute"); PDO_DBG_INF_FMT("dbh=%p", dbh); PDO_DBG_INF_FMT("attr=%l", attr); @@ -405,29 +408,29 @@ static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) if (dbh->auto_commit ^ bval) { dbh->auto_commit = bval; if (!mysql_handle_autocommit(dbh)) { - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } } - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); case PDO_ATTR_DEFAULT_STR_PARAM: ((pdo_mysql_db_handle *)dbh->driver_data)->assume_national_character_set_strings = lval == PDO_PARAM_STR_NATL; - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); case PDO_MYSQL_ATTR_USE_BUFFERED_QUERY: /* ignore if the new value equals the old one */ ((pdo_mysql_db_handle *)dbh->driver_data)->buffered = bval; - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); case PDO_MYSQL_ATTR_DIRECT_QUERY: case PDO_ATTR_EMULATE_PREPARES: /* ignore if the new value equals the old one */ ((pdo_mysql_db_handle *)dbh->driver_data)->emulate_prepare = bval; - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); case PDO_ATTR_FETCH_TABLE_NAMES: ((pdo_mysql_db_handle *)dbh->driver_data)->fetch_table_names = bval; - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); #ifndef PDO_USE_MYSQLND case PDO_MYSQL_ATTR_MAX_BUFFER_SIZE: @@ -438,12 +441,12 @@ static int pdo_mysql_set_attribute(pdo_dbh_t *dbh, zend_long attr, zval *val) } else { ((pdo_mysql_db_handle *)dbh->driver_data)->max_buffer_size = lval; } - PDO_DBG_RETURN(1); + PDO_DBG_RETURN(true); break; #endif default: - PDO_DBG_RETURN(0); + PDO_DBG_RETURN(false); } } /* }}} */ @@ -522,7 +525,7 @@ static int pdo_mysql_get_attribute(pdo_dbh_t *dbh, zend_long attr, zval *return_ /* }}} */ /* {{{ pdo_mysql_check_liveness */ -static int pdo_mysql_check_liveness(pdo_dbh_t *dbh) +static zend_result pdo_mysql_check_liveness(pdo_dbh_t *dbh) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; @@ -558,7 +561,7 @@ static void pdo_mysql_request_shutdown(pdo_dbh_t *dbh) #endif /* {{{ pdo_mysql_in_transaction */ -static int pdo_mysql_in_transaction(pdo_dbh_t *dbh) +static bool pdo_mysql_in_transaction(pdo_dbh_t *dbh) { pdo_mysql_db_handle *H = (pdo_mysql_db_handle *)dbh->driver_data; PDO_DBG_ENTER("pdo_mysql_in_transaction"); @@ -582,7 +585,8 @@ static const struct pdo_dbh_methods mysql_methods = { pdo_mysql_check_liveness, NULL, pdo_mysql_request_shutdown, - pdo_mysql_in_transaction + pdo_mysql_in_transaction, + NULL /* get_gc */ }; /* }}} */ @@ -827,6 +831,14 @@ static int pdo_mysql_handle_factory(pdo_dbh_t *dbh, zval *driver_options) goto cleanup; } +#ifdef PDO_USE_MYSQLND + unsigned int int_and_float_native = 1; + if (mysql_options(H->server, MYSQLND_OPT_INT_AND_FLOAT_NATIVE, (const char *) &int_and_float_native)) { + pdo_mysql_error(dbh); + goto cleanup; + } +#endif + if (vars[0].optval && mysql_options(H->server, MYSQL_SET_CHARSET_NAME, vars[0].optval)) { pdo_mysql_error(dbh); goto cleanup; |