helly Fri Oct 25 06:06:35 2002 EDT
Added files:
/php4/ext/dba/tests 007.phpt
Modified files:
/php4/ext/dba/tests .cvsignore
/php4/ext/dba dba.c php_dba.h
Log:
Implemented dba_list() that returns an array rsrcid=>filename and a test.
Index: php4/ext/dba/tests/.cvsignore
diff -u php4/ext/dba/tests/.cvsignore:1.1 php4/ext/dba/tests/.cvsignore:1.2
--- php4/ext/dba/tests/.cvsignore:1.1 Fri Oct 25 05:42:29 2002
+++ php4/ext/dba/tests/.cvsignore Fri Oct 25 06:06:35 2002
@@ -4,5 +4,5 @@
*.exp
*.out
*.php
-test.dbm
-test.dbm.lck
+*.dbm
+*.dbm.lck
Index: php4/ext/dba/dba.c
diff -u php4/ext/dba/dba.c:1.45 php4/ext/dba/dba.c:1.46
--- php4/ext/dba/dba.c:1.45 Thu Oct 24 16:43:02 2002
+++ php4/ext/dba/dba.c Fri Oct 25 06:06:35 2002
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: dba.c,v 1.45 2002/10/24 20:43:02 helly Exp $ */
+/* $Id: dba.c,v 1.46 2002/10/25 10:06:35 helly Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -52,6 +52,7 @@
PHP_FE(dba_optimize, NULL)
PHP_FE(dba_sync, NULL)
PHP_FE(dba_handlers, NULL)
+ PHP_FE(dba_list, NULL)
{NULL, NULL, NULL}
};
/* }}} */
@@ -513,7 +514,7 @@
}
/* }}} */
-/* {{{ proto array dba_list()
+/* {{{ proto array dba_handlers()
List configured databases */
PHP_FUNCTION(dba_handlers)
{
@@ -531,6 +532,36 @@
for(hptr = handler; hptr->name; hptr++) {
add_next_index_string(return_value, hptr->name, 1);
}
+}
+/* }}} */
+
+/* {{{ proto array dba_list()
+ List configured databases */
+PHP_FUNCTION(dba_list)
+{
+ ulong numitems, i;
+ zend_rsrc_list_entry *le;
+ dba_info *info;
+
+ if (ZEND_NUM_ARGS()!=0) {
+ ZEND_WRONG_PARAM_COUNT();
+ RETURN_FALSE;
+ }
+
+ if (array_init(return_value) == FAILURE) {
+ php_error_docref(NULL TSRMLS_CC, E_ERROR, "Unable to initialize
+array");
+ RETURN_FALSE;
+ }
+ numitems = zend_hash_next_free_element(&EG(regular_list));
+ for (i=1; i<numitems; i++) {
+ if (zend_hash_index_find(&EG(regular_list), i, (void **)
+&le)==FAILURE) {
+ continue;
+ }
+ if (Z_TYPE_P(le) == le_db || Z_TYPE_P(le) == le_pdb) {
+ info = (dba_info *)(le->ptr);
+ add_index_string(return_value, i, info->path, 1);
+ }
+ }
}
/* }}} */
Index: php4/ext/dba/php_dba.h
diff -u php4/ext/dba/php_dba.h:1.13 php4/ext/dba/php_dba.h:1.14
--- php4/ext/dba/php_dba.h:1.13 Thu Oct 24 16:43:03 2002
+++ php4/ext/dba/php_dba.h Fri Oct 25 06:06:35 2002
@@ -16,7 +16,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: php_dba.h,v 1.13 2002/10/24 20:43:03 helly Exp $ */
+/* $Id: php_dba.h,v 1.14 2002/10/25 10:06:35 helly Exp $ */
#ifndef PHP_DBA_H
#define PHP_DBA_H
@@ -95,6 +95,7 @@
PHP_FUNCTION(dba_optimize);
PHP_FUNCTION(dba_sync);
PHP_FUNCTION(dba_handlers);
+PHP_FUNCTION(dba_list);
#else
#define dba_module_ptr NULL
Index: php4/ext/dba/tests/007.phpt
+++ php4/ext/dba/tests/007.phpt
--TEST--
DBA Multiple File Creation Test
--SKIPIF--
<?php
require_once('skipif.inc');
if (!function_exists('dba_list')) die('skip dba_list() not available');
?>
--FILE--
<?php
require_once('test.inc');
$db_file1 = dirname(__FILE__).'/test1.dbm';
$db_file2 = dirname(__FILE__).'/test2.dbm';
if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
echo "database file created with $handler.\n";
} else {
echo "$db_file does not exist\n";
}
if (($db_file1=dba_open($db_file1, "n", $handler))!==FALSE) {
echo "database file created with $handler.\n";
} else {
echo "$db_file does not exist\n";
}
if (($db_file2=dba_open($db_file2, "n", $handler))!==FALSE) {
echo "database file created with $handler.\n";
} else {
echo "$db_file does not exist\n";
}
var_dump(dba_list());
dba_close($db_file);
?>
--EXPECTF--
database file created with %s.
array(3) {
[%d]=>
string(%d) "%sext/dba/tests/test.dbm"
[%d]=>
string(%d) "%sext/dba/tests/test1.dbm"
[%d]=>
string(%d) "%sext/dba/tests/test2.dbm"
}
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php