helly Sun Nov 3 11:43:07 2002 EDT Modified files: /php4/ext/dba dba.c dba_cdb.c php_dba.h /php4/ext/dba/tests dba_cdb_read.phpt Log: cdb now allows multiple key-value pairs with same key Index: php4/ext/dba/dba.c diff -u php4/ext/dba/dba.c:1.47 php4/ext/dba/dba.c:1.48 --- php4/ext/dba/dba.c:1.47 Fri Nov 1 09:15:24 2002 +++ php4/ext/dba/dba.c Sun Nov 3 11:43:06 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dba.c,v 1.47 2002/11/01 14:15:24 helly Exp $ */ +/* $Id: dba.c,v 1.48 2002/11/03 16:43:06 helly Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -81,7 +81,7 @@ char *name; int (*open)(dba_info * TSRMLS_DC); void (*close)(dba_info *); - char* (*fetch)(dba_info *, char *, int, int *); + char* (*fetch)(dba_info *, char *, int, int, int *); int (*update)(dba_info *, char *, int, char *, int, int); int (*exists)(dba_info *, char *, int); int (*delete)(dba_info *, char *, int); @@ -112,11 +112,34 @@ } \ convert_to_string_ex(key) +#define DBA_GET2_3 + \ + zval **key; + \ + zval **tmp; + \ + int skip = 0; + \ + switch(ac) { + \ + case 2: + \ + if (zend_get_parameters_ex(ac, &key, &id) != SUCCESS) { \ + WRONG_PARAM_COUNT; + \ + } + \ + break; + \ + case 3: + \ + if (zend_get_parameters_ex(ac, &key, &tmp, &id) != SUCCESS) { \ + WRONG_PARAM_COUNT; + \ + } + \ + convert_to_long_ex(tmp); + \ + skip = Z_LVAL_PP(tmp); + \ + break; + \ + default: + \ + WRONG_PARAM_COUNT; + \ + } + \ + convert_to_string_ex(key) + #define DBA_ID_GET \ ZEND_FETCH_RESOURCE2(info, dba_info *, id, -1, "DBA identifier", le_db, le_pdb); -#define DBA_ID_GET1 DBA_ID_PARS; DBA_GET1; DBA_ID_GET -#define DBA_ID_GET2 DBA_ID_PARS; DBA_GET2; DBA_ID_GET +#define DBA_ID_GET1 DBA_ID_PARS; DBA_GET1; DBA_ID_GET +#define DBA_ID_GET2 DBA_ID_PARS; DBA_GET2; DBA_ID_GET +#define DBA_ID_GET2_3 DBA_ID_PARS; DBA_GET2_3; DBA_ID_GET /* a DBA handler must have specific routines */ @@ -412,15 +435,18 @@ } /* }}} */ -/* {{{ proto string dba_fetch(string key, int handle) +/* {{{ proto string dba_fetch(string key, [int skip ,] int handle) Fetches the data associated with key */ PHP_FUNCTION(dba_fetch) { char *val; int len = 0; - DBA_ID_GET2; + DBA_ID_GET2_3; - if((val = info->hnd->fetch(info, VALLEN(key), &len)) != NULL) { + if (ac==3 && strcmp(info->hnd->name, "cdb")) { + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Handler %s does not +support optional skip parameter", info->hnd->name); + } + if((val = info->hnd->fetch(info, VALLEN(key), skip, &len)) != NULL) { RETURN_STRINGL(val, len, 0); } RETURN_FALSE; Index: php4/ext/dba/dba_cdb.c diff -u php4/ext/dba/dba_cdb.c:1.15 php4/ext/dba/dba_cdb.c:1.16 --- php4/ext/dba/dba_cdb.c:1.15 Sun Nov 3 10:09:49 2002 +++ php4/ext/dba/dba_cdb.c Sun Nov 3 11:43:06 2002 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: dba_cdb.c,v 1.15 2002/11/03 15:09:49 helly Exp $ */ +/* $Id: dba_cdb.c,v 1.16 2002/11/03 16:43:06 helly Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -95,7 +95,13 @@ unsigned int len; char *new_entry = NULL; +// cdb_findstart(&cdb->c); if (cdb_find(&cdb->c, key, keylen) == 1) { + while(skip--) { + if (cdb_findnext(&cdb->c, key, keylen) != 1) { + return NULL; + } + } len = cdb_datalen(&cdb->c); new_entry = emalloc(len+1); Index: php4/ext/dba/php_dba.h diff -u php4/ext/dba/php_dba.h:1.14 php4/ext/dba/php_dba.h:1.15 --- php4/ext/dba/php_dba.h:1.14 Fri Oct 25 06:06:35 2002 +++ php4/ext/dba/php_dba.h Sun Nov 3 11:43:06 2002 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_dba.h,v 1.14 2002/10/25 10:06:35 helly Exp $ */ +/* $Id: php_dba.h,v 1.15 2002/11/03 16:43:06 helly Exp $ */ #ifndef PHP_DBA_H #define PHP_DBA_H @@ -52,7 +52,7 @@ #define DBA_CLOSE_FUNC(x) \ void dba_close_##x(dba_info *info) #define DBA_FETCH_FUNC(x) \ - char *dba_fetch_##x(dba_info *info, char *key, int keylen, int *newlen) + char *dba_fetch_##x(dba_info *info, char *key, int keylen, int skip, int +*newlen) #define DBA_UPDATE_FUNC(x) \ int dba_update_##x(dba_info *info, char *key, int keylen, char *val, int vallen, int mode) #define DBA_EXISTS_FUNC(x) \ Index: php4/ext/dba/tests/dba_cdb_read.phpt diff -u php4/ext/dba/tests/dba_cdb_read.phpt:1.2 php4/ext/dba/tests/dba_cdb_read.phpt:1.3 --- php4/ext/dba/tests/dba_cdb_read.phpt:1.2 Sun Nov 3 10:22:32 2002 +++ php4/ext/dba/tests/dba_cdb_read.phpt Sun Nov 3 11:43:07 2002 @@ -11,17 +11,18 @@ $handler = 'cdb'; $db_file = dirname(__FILE__).'/test.cdb'; if (($db_file=dba_open($db_file, "r", $handler))!==FALSE) { + // read key sequence $a = dba_firstkey($db_file); - $i=0; - echo "?$a"; - while($a) { + $count= 0; + $keys = $a; + while($a) { $a = dba_nextkey($db_file); - echo $a; - $i++; + $keys .= $a; + $count++; } - echo "\n"; - echo $i; - for ($i=1; $i<5; $i++) { + // display number of entries and key existance + echo $count; + for ($i=1; $i<8; $i++) { echo dba_exists($i, $db_file) ? "Y" : "N"; } echo "\n="; @@ -29,6 +30,26 @@ echo dba_fetch(2, $db_file); echo dba_fetch(3, $db_file); echo dba_fetch(4, $db_file); + echo "\n#"; + echo dba_fetch(1, $db_file); + echo dba_fetch(1, $db_file); + echo dba_fetch(1, $db_file); + echo dba_fetch(1, $db_file); + echo "\n?".$keys; + // with skip = 0 dba_fetch must fetch the first result + echo "\n#"; + $skip = array(); + for ($i=0; $i < strlen($keys); $i++) { + $key = substr($keys, $i, 1); + $skip[$key] = 0; + echo dba_fetch($key, $db_file); + } + echo "\n="; + for ($i=0; $i < strlen($keys); $i++) { + $key = substr($keys, $i, 1); + echo dba_fetch($key, $skip[$key], $db_file); + $skip[$key]++; + } dba_close($db_file); } else { echo "Error creating database\n"; @@ -36,6 +57,9 @@ ?> --EXPECT-- database handler: cdb +7YYYYNNN +=1234 +#1111 ?1212314 -7YYYY -=1234 \ No newline at end of file +#1212314 +=1231324 \ No newline at end of file
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php