Skip to content

Commit 205d209

Browse files
committed
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.
1 parent 1a66d64 commit 205d209

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

Zend/zend_string.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,19 @@ static zend_always_inline zend_string *zend_string_dup(zend_string *s, bool pers
195195
}
196196
}
197197

198+
static zend_always_inline zend_string *zend_string_separate(zend_string *s, bool persistent)
199+
{
200+
if (ZSTR_IS_INTERNED(s) || GC_REFCOUNT(s) > 1) {
201+
if (!ZSTR_IS_INTERNED(s)) {
202+
GC_DELREF(s);
203+
}
204+
return zend_string_init(ZSTR_VAL(s), ZSTR_LEN(s), persistent);
205+
}
206+
207+
zend_string_forget_hash_val(s);
208+
return s;
209+
}
210+
198211
static zend_always_inline zend_string *zend_string_realloc(zend_string *s, size_t len, bool persistent)
199212
{
200213
zend_string *ret;

ext/pdo/pdo_stmt.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,23 +138,22 @@ int pdo_stmt_describe_columns(pdo_stmt_t *stmt) /* {{{ */
138138

139139
/* if we are applying case conversions on column names, do so now */
140140
if (stmt->dbh->native_case != stmt->dbh->desired_case && stmt->dbh->desired_case != PDO_CASE_NATURAL) {
141-
char *s = ZSTR_VAL(stmt->columns[col].name);
142-
141+
zend_string *orig_name = stmt->columns[col].name;
143142
switch (stmt->dbh->desired_case) {
144-
case PDO_CASE_UPPER:
145-
while (*s != '\0') {
146-
*s = toupper(*s);
147-
s++;
148-
}
149-
break;
150143
case PDO_CASE_LOWER:
144+
stmt->columns[col].name = zend_string_tolower(orig_name);
145+
zend_string_release(orig_name);
146+
break;
147+
case PDO_CASE_UPPER: {
148+
stmt->columns[col].name = zend_string_separate(orig_name, 0);
149+
char *s = ZSTR_VAL(stmt->columns[col].name);
151150
while (*s != '\0') {
152-
*s = tolower(*s);
151+
*s = toupper(*s);
153152
s++;
154153
}
155154
break;
156-
default:
157-
;
155+
}
156+
EMPTY_SWITCH_DEFAULT_CASE()
158157
}
159158
}
160159

ext/pdo_mysql/mysql_statement.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,11 @@ static int pdo_mysql_stmt_describe(pdo_stmt_t *stmt, int colno) /* {{{ */
619619
if (S->H->fetch_table_names) {
620620
cols[i].name = strpprintf(0, "%s.%s", S->fields[i].table, S->fields[i].name);
621621
} else {
622+
#ifdef PDO_USE_MYSQLND
623+
cols[i].name = zend_string_copy(S->fields[i].sname);
624+
#else
622625
cols[i].name = zend_string_init(S->fields[i].name, S->fields[i].name_length, 0);
626+
#endif
623627
}
624628

625629
cols[i].precision = S->fields[i].decimals;

0 commit comments

Comments
 (0)