]> granicus.if.org Git - php/commitdiff
Implemented dba_list() that returns an array rsrcid=>filename and a test.
authorMarcus Boerger <helly@php.net>
Fri, 25 Oct 2002 10:06:35 +0000 (10:06 +0000)
committerMarcus Boerger <helly@php.net>
Fri, 25 Oct 2002 10:06:35 +0000 (10:06 +0000)
ext/dba/dba.c
ext/dba/php_dba.h
ext/dba/tests/007.phpt [new file with mode: 0644]

index eed953b5c9f166f6143888f38e17c812961a69c8..71f21ad4e7bb8abd6e01a53cfbe1fa6ee7043dda 100644 (file)
@@ -52,6 +52,7 @@ function_entry dba_functions[] = {
        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 @@ PHP_FUNCTION(dba_sync)
 }
 /* }}} */
 
-/* {{{ proto array dba_list()
+/* {{{ proto array dba_handlers()
    List configured databases */
 PHP_FUNCTION(dba_handlers)
 {
@@ -534,6 +535,36 @@ PHP_FUNCTION(dba_handlers)
 }
 /* }}} */
 
+/* {{{ 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);
+               }
+       }
+}
+/* }}} */
+
 #endif
 
 /*
index c1bc6f1dd06d74f5c3fab4b96095c3dae0cbee51..832e66638c3357bb022654b273c1f1e610dd5c0c 100644 (file)
@@ -95,6 +95,7 @@ PHP_FUNCTION(dba_fetch);
 PHP_FUNCTION(dba_optimize);
 PHP_FUNCTION(dba_sync);
 PHP_FUNCTION(dba_handlers);
+PHP_FUNCTION(dba_list);
 
 #else
 #define dba_module_ptr NULL
diff --git a/ext/dba/tests/007.phpt b/ext/dba/tests/007.phpt
new file mode 100644 (file)
index 0000000..82316cf
--- /dev/null
@@ -0,0 +1,40 @@
+--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"
+}
\ No newline at end of file