diff options
author | Ard Biesheuvel <abies@php.net> | 2004-05-21 13:46:04 +0000 |
---|---|---|
committer | Ard Biesheuvel <abies@php.net> | 2004-05-21 13:46:04 +0000 |
commit | 27c3c301bd184029b199a2c53fb1c765b66e990c (patch) | |
tree | 8940d049781dd4c588925034b12991128bdee6c0 /ext/interbase | |
parent | bf48daa8d595026dd8b4d0ff4030c4073ede9306 (diff) | |
download | php-git-27c3c301bd184029b199a2c53fb1c765b66e990c.tar.gz |
Added test for duplicate field names when returning rows as hashes or objects
# This change should be in 5.0.0, as it might break BC
Diffstat (limited to 'ext/interbase')
-rw-r--r-- | ext/interbase/ibase_query.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/ext/interbase/ibase_query.c b/ext/interbase/ibase_query.c index 463bcd66c5..2e370601ff 100644 --- a/ext/interbase/ibase_query.c +++ b/ext/interbase/ibase_query.c @@ -1504,7 +1504,31 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type) array_init(return_value); for (i = 0; i < ib_result->out_sqlda->sqld; ++i) { + char alias[METADATALENGTH+4]; XSQLVAR *var = &ib_result->out_sqlda->sqlvar[i]; + + if (! (fetch_type & FETCH_ROW)) { + int i = 0; + char const *base = "FIELD"; /* use 'FIELD' if name is empty */ + + /** + * Ensure no two columns have identical names: + * keep generating new names until we find one that is unique. + */ + switch (*var->aliasname) { + void *p; + + default: + i = 1; + strcpy(alias, base = var->aliasname); + + while (SUCCESS == zend_symtable_find(Z_ARRVAL_P(return_value),alias,strlen(alias)+1,&p)) { + + case '\0': + sprintf(alias, "%s_%02d", base, i++); + } + } + } if (((var->sqltype & 1) == 0) || *var->sqlind != -1) { zval *result; @@ -1614,13 +1638,13 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type) if (fetch_type & FETCH_ROW) { add_index_zval(return_value, i, result); } else { - add_assoc_zval(return_value, var->aliasname, result); + add_assoc_zval(return_value, alias, result); } } else { if (fetch_type & FETCH_ROW) { add_index_null(return_value, i); } else { - add_assoc_null(return_value, var->aliasname); + add_assoc_null(return_value, alias); } } } /* for field */ |