diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-12-16 15:17:13 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-12-16 15:17:13 +0100 |
commit | 205d209de931d5c5e1535277531a7e4dc8a6000a (patch) | |
tree | c10d6519c5f833ce0d408e52211247484627721c | |
parent | 1a66d64717d08e9b7f7c9328be673018cfe28c11 (diff) | |
download | php-git-205d209de931d5c5e1535277531a7e4dc8a6000a.tar.gz |
PDO MySQL: Use mysqlnd column names
mysqlnd already creates interned zend_strings for us, so let's
make use of them.
This also required updating the PDO case changing code to work
with potentially shared strings. For the lowercasing, use the
optimized zend_string_tolower() implementation.
-rw-r--r-- | Zend/zend_string.h | 13 | ||||
-rw-r--r-- | ext/pdo/pdo_stmt.c | 21 | ||||
-rw-r--r-- | ext/pdo_mysql/mysql_statement.c | 4 |
3 files changed, 27 insertions, 11 deletions
diff --git a/Zend/zend_string.h b/Zend/zend_string.h index 557042b3e3..96f1a6f4a0 100644 --- a/Zend/zend_string.h +++ b/Zend/zend_string.h @@ -195,6 +195,19 @@ static zend_always_inline zend_string *zend_string_dup(zend_string *s, bool pers } } +static zend_always_inline zend_string *zend_string_separate(zend_string *s, bool persistent) +{ + if (ZSTR_IS_INTERNED(s) || GC_REFCOUNT(s) > 1) { + if (!ZSTR_IS_INTERNED(s)) { + GC_DELREF(s); + } + return zend_string_init(ZSTR_VAL(s), ZSTR_LEN(s), persistent); + } + + zend_string_forget_hash_val(s); + return s; +} + static zend_always_inline zend_string *zend_string_realloc(zend_string *s, size_t len, bool persistent) { zend_string *ret; diff --git a/ext/pdo/pdo_stmt.c b/ext/pdo/pdo_stmt.c index a172ae27c5..80b50605b9 100644 --- a/ext/pdo/pdo_stmt.c +++ b/ext/pdo/pdo_stmt.c @@ -138,23 +138,22 @@ int pdo_stmt_describe_columns(pdo_stmt_t *stmt) /* {{{ */ /* if we are applying case conversions on column names, do so now */ if (stmt->dbh->native_case != stmt->dbh->desired_case && stmt->dbh->desired_case != PDO_CASE_NATURAL) { - char *s = ZSTR_VAL(stmt->columns[col].name); - + zend_string *orig_name = stmt->columns[col].name; switch (stmt->dbh->desired_case) { - case PDO_CASE_UPPER: - while (*s != '\0') { - *s = toupper(*s); - s++; - } - break; case PDO_CASE_LOWER: + stmt->columns[col].name = zend_string_tolower(orig_name); + zend_string_release(orig_name); + break; + case PDO_CASE_UPPER: { + stmt->columns[col].name = zend_string_separate(orig_name, 0); + char *s = ZSTR_VAL(stmt->columns[col].name); while (*s != '\0') { - *s = tolower(*s); + *s = toupper(*s); s++; } break; - default: - ; + } + EMPTY_SWITCH_DEFAULT_CASE() } } diff --git a/ext/pdo_mysql/mysql_statement.c b/ext/pdo_mysql/mysql_statement.c index 871b7f9c7c..180a4616ef 100644 --- a/ext/pdo_mysql/mysql_statement.c +++ b/ext/pdo_mysql/mysql_statement.c @@ -619,7 +619,11 @@ static int pdo_mysql_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */ if (S->H->fetch_table_names) { cols[i].name = strpprintf(0, "%s.%s", S->fields[i].table, S->fields[i].name); } else { +#ifdef PDO_USE_MYSQLND + cols[i].name = zend_string_copy(S->fields[i].sname); +#else cols[i].name = zend_string_init(S->fields[i].name, S->fields[i].name_length, 0); +#endif } cols[i].precision = S->fields[i].decimals; |