summaryrefslogtreecommitdiff
path: root/ext/pgsql/pgsql.c
diff options
context:
space:
mode:
authorYasuo Ohgaki <yohgaki@php.net>2014-02-16 07:52:00 +0900
committerYasuo Ohgaki <yohgaki@php.net>2014-02-16 07:52:00 +0900
commita12c896dbaf5615e8feb1e97eaa505bf30fbb2fa (patch)
tree2d9e0fd284837da3e110da8bd5d8edbe815264eb /ext/pgsql/pgsql.c
parent53f34bca76d155a7368522427f7bf3b6f9c9e7ef (diff)
parentf9537c2a0bf324a892182ff2dd3ec3218dba812a (diff)
downloadphp-git-a12c896dbaf5615e8feb1e97eaa505bf30fbb2fa.tar.gz
Merge branch 'PHP-5.5' into PHP-5.6
* PHP-5.5: Refactor build_tablename()
Diffstat (limited to 'ext/pgsql/pgsql.c')
-rw-r--r--ext/pgsql/pgsql.c35
1 files changed, 8 insertions, 27 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index ea2d64b2f1..e0e7f964c8 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -1054,26 +1054,6 @@ static int _php_pgsql_detect_identifier_escape(const char *identifier, size_t le
}
-/* {{{ _php_pgsql_strndup, no strndup should be used */
-static char *_php_pgsql_strndup(const char *s, size_t len)
-{
- char *new;
-
- if (NULL == s) {
- return (char *)NULL;
- }
-
- new = (char *) malloc(len + 1);
-
- if (NULL == new) {
- return (char *)NULL;
- }
-
- new[len] = '\0';
-
- return memmove(new, s, len);
-}
-/* }}} */
/* {{{ PHP_INI
*/
@@ -6214,23 +6194,24 @@ static inline void build_tablename(smart_str *querystr, PGconn *pg_link, const c
token = php_strtok_r(table_copy, ".", &tmp);
len = strlen(token);
if (_php_pgsql_detect_identifier_escape(token, len) == SUCCESS) {
- escaped = _php_pgsql_strndup(token, len);
+ smart_str_appendl(querystr, token, len);
} else {
escaped = PGSQLescapeIdentifier(pg_link, token, len);
+ smart_str_appends(querystr, escaped);
+ PGSQLfree(escaped);
}
- smart_str_appends(querystr, escaped);
- PGSQLfree(escaped);
if (tmp && *tmp) {
len = strlen(tmp);
/* "schema"."table" format */
if (_php_pgsql_detect_identifier_escape(tmp, len) == SUCCESS) {
- escaped = _php_pgsql_strndup(tmp, len);
+ smart_str_appendc(querystr, '.');
+ smart_str_appendl(querystr, tmp, len);
} else {
escaped = PGSQLescapeIdentifier(pg_link, tmp, len);
+ smart_str_appendc(querystr, '.');
+ smart_str_appends(querystr, escaped);
+ PGSQLfree(escaped);
}
- smart_str_appendc(querystr, '.');
- smart_str_appends(querystr, escaped);
- PGSQLfree(escaped);
}
efree(table_copy);
}