diff options
author | Ard Biesheuvel <abies@php.net> | 2004-05-21 14:24:34 +0000 |
---|---|---|
committer | Ard Biesheuvel <abies@php.net> | 2004-05-21 14:24:34 +0000 |
commit | c6773a06cd5d135f6131781623ea069a52633dc2 (patch) | |
tree | 9f5bb73586ee58749634cdb0b41f9a1d459e786c | |
parent | 64f0ec7bde2252ed09f95b6dee4cafb62149c7df (diff) | |
download | php-git-c6773a06cd5d135f6131781623ea069a52633dc2.tar.gz |
Removed strcpy() call from most common case
Added test for hash index generation
-rw-r--r-- | ext/interbase/ibase_query.c | 11 | ||||
-rw-r--r-- | ext/interbase/tests/003.phpt | 51 |
2 files changed, 57 insertions, 5 deletions
diff --git a/ext/interbase/ibase_query.c b/ext/interbase/ibase_query.c index 2e370601ff..0caf2b43a6 100644 --- a/ext/interbase/ibase_query.c +++ b/ext/interbase/ibase_query.c @@ -1504,8 +1504,8 @@ 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]; + char buf[METADATALENGTH+4], *alias = var->aliasname; if (! (fetch_type & FETCH_ROW)) { int i = 0; @@ -1515,17 +1515,18 @@ static void _php_ibase_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int fetch_type) * Ensure no two columns have identical names: * keep generating new names until we find one that is unique. */ - switch (*var->aliasname) { + switch (*alias) { void *p; default: i = 1; - strcpy(alias, base = var->aliasname); + base = alias; - while (SUCCESS == zend_symtable_find(Z_ARRVAL_P(return_value),alias,strlen(alias)+1,&p)) { + while (SUCCESS == zend_symtable_find( + Z_ARRVAL_P(return_value),alias,strlen(alias)+1,&p)) { case '\0': - sprintf(alias, "%s_%02d", base, i++); + sprintf(alias = buf, "%s_%02d", base, i++); } } } diff --git a/ext/interbase/tests/003.phpt b/ext/interbase/tests/003.phpt index a700c3cc46..fe0074e518 100644 --- a/ext/interbase/tests/003.phpt +++ b/ext/interbase/tests/003.phpt @@ -125,8 +125,59 @@ InterBase: misc sql types (may take a while) ibase_free_result($sel); } /* for($iter) */ + /* check for correct handling of duplicate field names */ + $q = ibase_query('SELECT 1 AS id, 2 AS id, 3 AS id, 4 AS id, 5 AS id, 6 AS id, 7 AS id, 8 AS id, 9 AS id, + 10 AS id, 11 AS id, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 FROM rdb$database'); + var_dump(ibase_fetch_assoc($q)); + ibase_close(); echo "end of test\n"; ?> --EXPECT-- +array(22) { + ["ID"]=> + int(1) + ["ID_01"]=> + int(2) + ["ID_02"]=> + int(3) + ["ID_03"]=> + int(4) + ["ID_04"]=> + int(5) + ["ID_05"]=> + int(6) + ["ID_06"]=> + int(7) + ["ID_07"]=> + int(8) + ["ID_08"]=> + int(9) + ["ID_09"]=> + int(10) + ["ID_10"]=> + int(11) + ["FIELD_00"]=> + int(12) + ["FIELD_01"]=> + int(13) + ["FIELD_02"]=> + int(14) + ["FIELD_03"]=> + int(15) + ["FIELD_04"]=> + int(16) + ["FIELD_05"]=> + int(17) + ["FIELD_06"]=> + int(18) + ["FIELD_07"]=> + int(19) + ["FIELD_08"]=> + int(20) + ["FIELD_09"]=> + int(21) + ["FIELD_10"]=> + int(22) +} end of test |