diff options
author | Xinchen Hui <laruence@gmail.com> | 2014-04-22 18:23:03 +0800 |
---|---|---|
committer | Xinchen Hui <laruence@gmail.com> | 2014-04-22 18:23:03 +0800 |
commit | bdfef93b424dcca4d1822c7d6393fbb00942cbaa (patch) | |
tree | 09cd047f0fff6f30952574a81bf359fa57077f3e /ext/pdo/pdo_sql_parser.c | |
parent | 89d89b95861c4366f93e705546c0ca8c4443a425 (diff) | |
download | php-git-bdfef93b424dcca4d1822c7d6393fbb00942cbaa.tar.gz |
Refactor PDO (only compilable now)
Diffstat (limited to 'ext/pdo/pdo_sql_parser.c')
-rw-r--r-- | ext/pdo/pdo_sql_parser.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/ext/pdo/pdo_sql_parser.c b/ext/pdo/pdo_sql_parser.c index 341e664bbe..be2fa35501 100644 --- a/ext/pdo/pdo_sql_parser.c +++ b/ext/pdo/pdo_sql_parser.c @@ -4,7 +4,7 @@ +----------------------------------------------------------------------+ | PHP Version 5 | +----------------------------------------------------------------------+ - | Copyright (c) 1997-2014 The PHP Group | + | Copyright (c) 1997-2013 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -523,7 +523,7 @@ PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len, if (query_type != PDO_PLACEHOLDER_POSITIONAL && bindno > zend_hash_num_elements(params)) { int ok = 1; for (plc = placeholders; plc; plc = plc->next) { - if (zend_hash_find(params, plc->pos, plc->len, (void**) ¶m) == FAILURE) { + if ((params = zend_hash_str_find_ptr(params, plc->pos, plc->len)) == NULL) { ok = 0; break; } @@ -546,38 +546,37 @@ safe: /* let's quote all the values */ for (plc = placeholders; plc; plc = plc->next) { if (query_type == PDO_PLACEHOLDER_POSITIONAL) { - ret = zend_hash_index_find(params, plc->bindno, (void**) ¶m); + param = zend_hash_index_find_ptr(params, plc->bindno); } else { - ret = zend_hash_find(params, plc->pos, plc->len, (void**) ¶m); + param = zend_hash_str_find_ptr(params, plc->pos, plc->len); } - if (ret == FAILURE) { + if (param == NULL) { /* parameter was not defined */ ret = -1; pdo_raise_impl_error(stmt->dbh, stmt, "HY093", "parameter was not defined" TSRMLS_CC); goto clean_up; } if (stmt->dbh->methods->quoter) { - if (param->param_type == PDO_PARAM_LOB && Z_TYPE_P(param->parameter) == IS_RESOURCE) { + if (param->param_type == PDO_PARAM_LOB && Z_TYPE(param->parameter) == IS_RESOURCE) { php_stream *stm; php_stream_from_zval_no_verify(stm, ¶m->parameter); if (stm) { - size_t len; - char *buf = NULL; + zend_string *buf; - len = php_stream_copy_to_mem(stm, &buf, PHP_STREAM_COPY_ALL, 0); - if (!stmt->dbh->methods->quoter(stmt->dbh, buf, len, &plc->quoted, &plc->qlen, + buf = php_stream_copy_to_mem(stm, PHP_STREAM_COPY_ALL, 0); + if (!stmt->dbh->methods->quoter(stmt->dbh, buf->val, buf->len, &plc->quoted, &plc->qlen, param->param_type TSRMLS_CC)) { /* bork */ ret = -1; strncpy(stmt->error_code, stmt->dbh->error_code, 6); if (buf) { - efree(buf); + STR_RELEASE(buf); } goto clean_up; } if (buf) { - efree(buf); + STR_RELEASE(buf); } } else { pdo_raise_impl_error(stmt->dbh, stmt, "HY105", "Expected a stream resource" TSRMLS_CC); @@ -586,8 +585,8 @@ safe: } plc->freeq = 1; } else { - zval tmp_param = *param->parameter; - zval_copy_ctor(&tmp_param); + zval tmp_param; + ZVAL_DUP(&tmp_param, ¶m->parameter); switch (Z_TYPE(tmp_param)) { case IS_NULL: plc->quoted = "NULL"; @@ -621,8 +620,8 @@ safe: zval_dtor(&tmp_param); } } else { - plc->quoted = Z_STRVAL_P(param->parameter); - plc->qlen = Z_STRLEN_P(param->parameter); + plc->quoted = Z_STRVAL(param->parameter); + plc->qlen = Z_STRLEN(param->parameter); } newbuffer_len += plc->qlen; } @@ -679,7 +678,7 @@ rewrite: name = estrndup(plc->pos, plc->len); /* check if bound parameter is already available */ - if (!strcmp(name, "?") || zend_hash_find(stmt->bound_param_map, name, plc->len + 1, (void**) &p) == FAILURE) { + if (!strcmp(name, "?") || (p = zend_hash_str_find_ptr(stmt->bound_param_map, name, plc->len)) == NULL) { spprintf(&idxbuf, 0, tmpl, bind_no++); } else { idxbuf = estrdup(p); @@ -693,11 +692,11 @@ rewrite: if (!skip_map && stmt->named_rewrite_template) { /* create a mapping */ - zend_hash_update(stmt->bound_param_map, name, plc->len + 1, idxbuf, plc->qlen + 1, NULL); + zend_hash_str_update_mem(stmt->bound_param_map, name, plc->len, idxbuf, plc->qlen + 1); } /* map number to name */ - zend_hash_index_update(stmt->bound_param_map, plc->bindno, idxbuf, plc->qlen + 1, NULL); + zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, idxbuf, plc->qlen + 1); efree(name); } @@ -718,7 +717,7 @@ rewrite: char *name; name = estrndup(plc->pos, plc->len); - zend_hash_index_update(stmt->bound_param_map, plc->bindno, name, plc->len + 1, NULL); + zend_hash_index_update_mem(stmt->bound_param_map, plc->bindno, name, plc->len + 1); efree(name); plc->quoted = "?"; plc->qlen = 1; |