File: dba_cdb_read.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (69 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download
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
66
67
68
69
--TEST--
DBA CDB handler test (read only)
--EXTENSIONS--
dba
--SKIPIF--
<?php
require_once __DIR__ . '/setup/setup_dba_tests.inc';
check_skip('cdb_make');
?>
--CONFLICTS--
test.cdb
--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, $db_file, $skip[$key]);
            $skip[$key]++;
        }
        dba_close($db_file);
    } else {
        echo "Error creating database\n";
    }
?>
--EXPECT--
database handler: cdb
7YYYYNNN
=1234
#1122
?1212314
#1212314
=1231324