From 205d209de931d5c5e1535277531a7e4dc8a6000a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 16 Dec 2020 15:17:13 +0100 Subject: 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. --- ext/pdo/pdo_stmt.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'ext/pdo') 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() } } -- cgit v1.2.1