Fixed bugs in pdo_mysql

This commit is contained in:
Xinchen Hui 2014-05-08 15:19:43 +08:00
parent dfc940c5d9
commit 5f46c8fa31
4 changed files with 20 additions and 13 deletions

View File

@ -434,6 +434,10 @@ struct placeholder {
struct placeholder *next;
};
static void free_param_name(zval *el) {
efree(Z_PTR_P(el));
}
PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len,
char **outquery, int *outquery_len TSRMLS_DC)
{
@ -670,7 +674,7 @@ rewrite:
if (stmt->bound_param_map == NULL) {
ALLOC_HASHTABLE(stmt->bound_param_map);
zend_hash_init(stmt->bound_param_map, 13, NULL, NULL, 0);
zend_hash_init(stmt->bound_param_map, 13, NULL, free_param_name, 0);
}
for (plc = placeholders; plc; plc = plc->next) {
@ -711,12 +715,11 @@ rewrite:
if (stmt->bound_param_map == NULL) {
ALLOC_HASHTABLE(stmt->bound_param_map);
zend_hash_init(stmt->bound_param_map, 13, NULL, NULL, 0);
zend_hash_init(stmt->bound_param_map, 13, NULL, free_param_name, 0);
}
for (plc = placeholders; plc; plc = plc->next) {
char *name;
name = estrndup(plc->pos, plc->len);
zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, name, plc->len + 1);
efree(name);

View File

@ -76,6 +76,10 @@ struct placeholder {
struct placeholder *next;
};
static void free_param_name(zval *el) {
efree(Z_PTR_P(el));
}
PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len,
char **outquery, int *outquery_len TSRMLS_DC)
{
@ -312,7 +316,7 @@ rewrite:
if (stmt->bound_param_map == NULL) {
ALLOC_HASHTABLE(stmt->bound_param_map);
zend_hash_init(stmt->bound_param_map, 13, NULL, NULL, 0);
zend_hash_init(stmt->bound_param_map, 13, NULL, free_param_name, 0);
}
for (plc = placeholders; plc; plc = plc->next) {
@ -353,12 +357,11 @@ rewrite:
if (stmt->bound_param_map == NULL) {
ALLOC_HASHTABLE(stmt->bound_param_map);
zend_hash_init(stmt->bound_param_map, 13, NULL, NULL, 0);
zend_hash_init(stmt->bound_param_map, 13, NULL, free_param_name, 0);
}
for (plc = placeholders; plc; plc = plc->next) {
char *name;
name = estrndup(plc->pos, plc->len);
zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, name, plc->len + 1);
efree(name);

View File

@ -128,7 +128,7 @@ static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_pa
* we will raise an error, as we can't be sure that it is safe
* to bind multiple parameters onto the same zval in the underlying
* driver */
zval *name;
char *name;
int position = 0;
if (stmt->named_rewrite_template) {
@ -137,16 +137,16 @@ static inline int rewrite_name_to_position(pdo_stmt_t *stmt, struct pdo_bound_pa
}
if (!param->name) {
/* do the reverse; map the parameter number to the name */
if ((name = zend_hash_index_find(stmt->bound_param_map, param->paramno)) != NULL) {
param->name = STR_COPY(Z_STR_P(name));
if ((name = zend_hash_index_find_ptr(stmt->bound_param_map, param->paramno)) != NULL) {
param->name = STR_INIT(name, strlen(name), 0);
return 1;
}
pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined" TSRMLS_CC);
return 0;
}
ZEND_HASH_FOREACH_VAL(stmt->bound_param_map, name) {
if (strncmp(Z_STRVAL_P(name), param->name->val, param->name->len + 1)) {
ZEND_HASH_FOREACH_PTR(stmt->bound_param_map, name) {
if (strncmp(name, param->name->val, param->name->len + 1)) {
position++;
continue;
}
@ -460,7 +460,7 @@ static PHP_METHOD(PDOStatement, execute)
if (key) {
/* yes this is correct. we don't want to count the null byte. ask wez */
param.name = STR_COPY(key);
param.name = key;
param.paramno = -1;
} else {
/* we're okay to be zero based here */

View File

@ -404,7 +404,8 @@ static int pdo_mysql_stmt_next_rowset(pdo_stmt_t *stmt TSRMLS_DC) /* {{{ */
/* ensure that we free any previous unfetched results */
#ifndef PDO_USE_MYSQLND
if (S->stmt) {
stmt->column_count = (int)mysql_num_fields(S->result);
//???? This line is very suspicious
//stmt->column_count = (int)mysql_num_fields(S->result);
mysql_stmt_free_result(S->stmt);
}
#endif