summaryrefslogtreecommitdiff
path: root/ext/dba/tests/dba_cdb_read.phpt
blob: 39fc85e454caca437f300d2ed0eb508f681206ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
--TEST--
DBA CDB handler test (read only)
--SKIPIF--
<?php
	$handler = 'cdb_make';
	require_once __DIR__ .'/skipif.inc';
?>
--FILE--
<?php
    echo "database handler: cdb\n";
    $handler = 'cdb';
    $db_file = __DIR__.'/test.cdb';
    if (($db_file=dba_open($db_file, "r", $handler))!==FALSE) {
        // read key sequence
        $a = dba_firstkey($db_file);
        $count= 0;
        $keys = $a;
        while($a) {
            $a = dba_nextkey($db_file);
            $keys .= $a;
            $count++;
        }
        // display number of entries and key existence
        echo $count;
        for ($i=1; $i<8; $i++) {
            echo dba_exists($i, $db_file) ? "Y" : "N";
        }
        echo "\n=";
        echo dba_fetch(1, $db_file);
        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(2, $db_file);
        echo dba_fetch(2, $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";
    }
?>
--EXPECT--
database handler: cdb
7YYYYNNN
=1234
#1122
?1212314
#1212314
=1231324