]> granicus.if.org Git - php/commitdiff
check whether a written databse can be appended and if read during write
authorMarcus Boerger <helly@php.net>
Wed, 6 Nov 2002 11:18:00 +0000 (11:18 +0000)
committerMarcus Boerger <helly@php.net>
Wed, 6 Nov 2002 11:18:00 +0000 (11:18 +0000)
is permitted
#i use ksort for the result here since some dbm libraries sort their result
#but that is nothing to test here.

ext/dba/tests/dba_cdb.phpt
ext/dba/tests/dba_db2.phpt
ext/dba/tests/dba_db3.phpt
ext/dba/tests/dba_dbm.phpt
ext/dba/tests/dba_flatfile.phpt
ext/dba/tests/dba_gdbm.phpt
ext/dba/tests/dba_handler.inc
ext/dba/tests/dba_ndbm.phpt
ext/dba/tests/test.inc

index 716773c2f63cbbcd0bdc761e75d621c71fe78437..a9afe916d8c3d0fa7463fa4c27ac5166053b0a36 100644 (file)
@@ -17,3 +17,14 @@ database handler: cdb
 3NYNYY
 Content String 2
 Content 2 replaced
+Read during write permitted
+Content 2 replaced 2nd time
+The 6th value
+array(3) {
+  ["key number 6"]=>
+  string(13) "The 6th value"
+  ["key2"]=>
+  string(27) "Content 2 replaced 2nd time"
+  ["key5"]=>
+  string(23) "The last content string"
+}
\ No newline at end of file
index cfbdb7e4d7a890d8035a3eb4af9aa0e76be89640..d23700fbd6edcc207c1643ee4c11113fe13993d7 100644 (file)
@@ -16,3 +16,14 @@ database handler: db2
 3NYNYY
 Content String 2
 Content 2 replaced
+Read during write permitted
+Content 2 replaced 2nd time
+The 6th value
+array(3) {
+  ["key number 6"]=>
+  string(13) "The 6th value"
+  ["key2"]=>
+  string(27) "Content 2 replaced 2nd time"
+  ["key5"]=>
+  string(23) "The last content string"
+}
\ No newline at end of file
index 82a08c8fd309c88abd5512095a7096f7173e3319..eea48d1b2a6ed7ee863b37d5d1ab4d962ce1ec7a 100644 (file)
@@ -16,3 +16,14 @@ database handler: db3
 3NYNYY
 Content String 2
 Content 2 replaced
+Read during write permitted
+Content 2 replaced 2nd time
+The 6th value
+array(3) {
+  ["key number 6"]=>
+  string(13) "The 6th value"
+  ["key2"]=>
+  string(27) "Content 2 replaced 2nd time"
+  ["key5"]=>
+  string(23) "The last content string"
+}
\ No newline at end of file
index 59c1e4ffe08752e854b510cc22680d7efe030f3a..3f4d0fcf422015085b297ba70c73149a89429c6b 100644 (file)
@@ -16,3 +16,14 @@ database handler: dbm
 3NYNYY
 Content String 2
 Content 2 replaced
+Read during write permitted
+Content 2 replaced 2nd time
+The 6th value
+array(3) {
+  ["key number 6"]=>
+  string(13) "The 6th value"
+  ["key2"]=>
+  string(27) "Content 2 replaced 2nd time"
+  ["key5"]=>
+  string(23) "The last content string"
+}
index 33304e72fbe265c5fb3170b035eb22deb7949cba..33d01809cf4f8bb02b81e6b34b9fba006aa184c7 100644 (file)
@@ -16,3 +16,14 @@ database handler: flatfile
 3NYNYY
 Content String 2
 Content 2 replaced
+Read during write permitted
+Content 2 replaced 2nd time
+The 6th value
+array(3) {
+  ["key number 6"]=>
+  string(13) "The 6th value"
+  ["key2"]=>
+  string(27) "Content 2 replaced 2nd time"
+  ["key5"]=>
+  string(23) "The last content string"
+}
\ No newline at end of file
index a45c1075c1935f8c5dae7aba8b6be02227b9da78..79b41dadea9505772d74970a2aa50d6ac517f51a 100644 (file)
@@ -16,3 +16,14 @@ database handler: gdbm
 3NYNYY
 Content String 2
 Content 2 replaced
+Read during write permitted
+Content 2 replaced 2nd time
+The 6th value
+array(3) {
+  ["key number 6"]=>
+  string(13) "The 6th value"
+  ["key2"]=>
+  string(27) "Content 2 replaced 2nd time"
+  ["key5"]=>
+  string(23) "The last content string"
+}
\ No newline at end of file
index 393ffef89b59fd77aa13bba89e2dd9bcb9415131..e8bb97c1a0ed7591f2b700e760a3b17d0d6fde7f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
        echo "database handler: $handler\n";
-       if (($db_file=dba_open($db_file, "n", $handler))!==FALSE) {
+       if (($db_file=dba_open($db_filename, "n", $handler))!==FALSE) {
                dba_insert("key1", "Content String 1", $db_file);
                dba_insert("key2", "Content String 2", $db_file);
                dba_insert("key3", "Third Content String", $db_file);
        } else {
                echo "Error creating database\n";
        }
+       $db_writer=dba_open($db_filename, "w", $handler);
+       if (($dba_reader=dba_open($db_filename, "r", $handler))===false) {
+               echo "Cannot read during write operation\n";
+       } else {
+               echo "Read during write permitted\n";
+       }
+       if ($db_writer!==FALSE) {
+               dba_insert("key number 6", "The 6th value", $db_writer);
+               dba_replace("key2", "Content 2 replaced 2nd time", $db_writer);
+               dba_delete("key4", $db_writer);
+               echo dba_fetch("key2", $db_writer)."\n";
+               echo dba_fetch("key number 6", $db_writer)."\n";
+               dba_close($db_writer); // when the writer is open at least db3 would fail because of buffered io.
+       } else {
+               die("Error reopening database\n");
+       }
+       if (($db_file=dba_open($db_filename, "r", $handler))!==FALSE) {
+               $key = dba_firstkey($db_file);
+               $res = array();
+               while($key) {
+                       $res[$key] = dba_fetch($key, $db_file);
+                       $key = dba_nextkey($db_file);
+               }
+               ksort($res);
+               var_dump($res);
+               dba_close($db_file);
+       } else {
+               echo "Error reading database\n";
+       }
+       if ($dba_reader) {
+               dba_close($dba_reader);
+       }
 ?>
\ No newline at end of file
index 8fb94048f39ddefd195ce24141d2a7c5d66fef2b..04ddfa51d04018d8489b8d03c7514964c32c6a0f 100644 (file)
@@ -16,3 +16,14 @@ database handler: ndbm
 3NYNYY
 Content String 2
 Content 2 replaced
+Read during write permitted
+Content 2 replaced 2nd time
+The 6th value
+array(3) {
+  ["key number 6"]=>
+  string(13) "The 6th value"
+  ["key2"]=>
+  string(27) "Content 2 replaced 2nd time"
+  ["key5"]=>
+  string(23) "The last content string"
+}
\ No newline at end of file
index 768fc8dac53ecdd069867cd6283ed26f17d582e0..0f920838cea938566c07f0f210183698b54703fc 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-       $db_file = dirname(__FILE__).'/test0.dbm'; 
+       $db_filename = $db_file = dirname(__FILE__).'/test0.dbm';
        $handler = dba_handlers(); 
        // CDB currently supports only reading 
        if ($handler[0]=='cdb') {