xref: /PHP-8.2/ext/dba/tests/dba_lmdb_flags.phpt (revision 3c372901)
1--TEST--
2DBA LMDB handler flags test
3--EXTENSIONS--
4dba
5--SKIPIF--
6<?php
7    $handler = 'lmdb';
8    require_once __DIR__ .'/skipif.inc';
9?>
10--FILE--
11<?php
12$handler = 'lmdb';
13
14// Pass bogus flag
15try {
16    $db_file = dba_open('irrelevant', 'c', $handler, flags: 45);
17} catch (\ValueError $e) {
18    echo $e->getMessage(), \PHP_EOL;
19}
20
21// Use current test folder
22$db_filename = __DIR__;
23$db_file = dba_open($db_filename, 'c', $handler, flags: DBA_LMDB_USE_SUB_DIR);
24assert($db_file !== false);
25
26// Check insertion of data
27dba_insert("key1", "Content String 1", $db_file);
28dba_insert("key2", "Content String 2", $db_file);
29dba_insert("key3", "Third Content String", $db_file);
30dba_insert("key4", "Another Content String", $db_file);
31dba_insert("key5", "The last content string", $db_file);
32
33// Remove some data
34dba_delete("key3", $db_file);
35dba_delete("key1", $db_file);
36
37// Fetch data
38$key = dba_firstkey($db_file);
39$total_keys = 0;
40while ($key) {
41    echo $key, ': ', dba_fetch($key, $db_file), \PHP_EOL;
42    $key = dba_nextkey($db_file);
43    $total_keys++;
44}
45echo 'Total keys: ', $total_keys, \PHP_EOL;
46for ($i = 1; $i < 6; $i++) {
47    echo "Key $i exists? ", dba_exists("key$i", $db_file) ? "Y" : "N", \PHP_EOL;
48}
49
50// Replace second key data
51dba_replace("key2", "Content 2 replaced", $db_file);
52echo dba_fetch("key2", $db_file), \PHP_EOL;
53
54// Close handler
55dba_close($db_file);
56
57?>
58--CLEAN--
59<?php
60$db_filename = __DIR__ . '/data.mdb';
61$db_loc_filename = __DIR__ . '/lock.mdb';
62@unlink($db_filename);
63@unlink($db_loc_filename);
64?>
65--EXPECT--
66dba_open(): Argument #6 ($flags) must be either DBA_LMDB_USE_SUB_DIR or DBA_LMDB_NO_SUB_DIR for LMDB driver
67key2: Content String 2
68key4: Another Content String
69key5: The last content string
70Total keys: 3
71Key 1 exists? N
72Key 2 exists? Y
73Key 3 exists? N
74Key 4 exists? Y
75Key 5 exists? Y
76Content 2 replaced
77