-
Notifications
You must be signed in to change notification settings - Fork 7.9k
LMDB Support for driver flags #8892
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e9da8ac
Add comment in GDBM informing to what param the 0 org corresponds to
Girgias 5b25211
Remove personalisation from write on readonly db DBA error message
Girgias b8fda6e
Pass MDB_RDONLY to the LMDB environment for readonly DBs
Girgias 5b891bb
Add support to pass driver flags to DBA handlers
Girgias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
#ifdef DBA_LMDB | ||
|
||
#include "php_dba.h" | ||
#include <lmdb.h> | ||
|
||
DBA_FUNCS(lmdb); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
--TEST-- | ||
DBA new flags ValueError test | ||
--EXTENSIONS-- | ||
dba | ||
--FILE-- | ||
<?php | ||
try { | ||
dba_open('irrelevant', 'c', 'handler', flags: -1); | ||
} catch (\ValueError $e) { | ||
echo $e->getMessage(), \PHP_EOL; | ||
} | ||
?> | ||
--EXPECT-- | ||
dba_open(): Argument #6 ($flags) must be greater or equal than 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--TEST-- | ||
DBA LMDB handler flags test | ||
--EXTENSIONS-- | ||
dba | ||
--SKIPIF-- | ||
<?php | ||
$handler = 'lmdb'; | ||
require_once __DIR__ .'/skipif.inc'; | ||
?> | ||
--FILE-- | ||
<?php | ||
$handler = 'lmdb'; | ||
|
||
// Pass bogus flag | ||
try { | ||
$db_file = dba_open('irrelevant', 'c', $handler, flags: 45); | ||
} catch (\ValueError $e) { | ||
echo $e->getMessage(), \PHP_EOL; | ||
} | ||
|
||
// Use current test folder | ||
$db_filename = __DIR__; | ||
$db_file = dba_open($db_filename, 'c', $handler, flags: DBA_LMDB_USE_SUB_DIR); | ||
assert($db_file !== false); | ||
|
||
// Check insertion of data | ||
dba_insert("key1", "Content String 1", $db_file); | ||
dba_insert("key2", "Content String 2", $db_file); | ||
dba_insert("key3", "Third Content String", $db_file); | ||
dba_insert("key4", "Another Content String", $db_file); | ||
dba_insert("key5", "The last content string", $db_file); | ||
|
||
// Remove some data | ||
dba_delete("key3", $db_file); | ||
dba_delete("key1", $db_file); | ||
|
||
// Fetch data | ||
$key = dba_firstkey($db_file); | ||
$total_keys = 0; | ||
while ($key) { | ||
echo $key, ': ', dba_fetch($key, $db_file), \PHP_EOL; | ||
$key = dba_nextkey($db_file); | ||
$total_keys++; | ||
} | ||
echo 'Total keys: ', $total_keys, \PHP_EOL; | ||
for ($i = 1; $i < 6; $i++) { | ||
echo "Key $i exists? ", dba_exists("key$i", $db_file) ? "Y" : "N", \PHP_EOL; | ||
} | ||
|
||
// Replace second key data | ||
dba_replace("key2", "Content 2 replaced", $db_file); | ||
echo dba_fetch("key2", $db_file), \PHP_EOL; | ||
|
||
// Close handler | ||
dba_close($db_file); | ||
|
||
?> | ||
--CLEAN-- | ||
<?php | ||
$db_filename = __DIR__ . '/data.mdb'; | ||
$db_loc_filename = __DIR__ . '/lock.mdb'; | ||
@unlink($db_filename); | ||
@unlink($db_loc_filename); | ||
?> | ||
--EXPECT-- | ||
dba_open(): Argument #6 ($flags) must be either DBA_LMDB_USE_SUB_DIR or DBA_LMDB_NO_SUB_DIR for LMDB driver | ||
key2: Content String 2 | ||
key4: Another Content String | ||
key5: The last content string | ||
Total keys: 3 | ||
Key 1 exists? N | ||
Key 2 exists? Y | ||
Key 3 exists? N | ||
Key 4 exists? Y | ||
Key 5 exists? Y | ||
Content 2 replaced |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
--TEST-- | ||
DBA LMDB handler readonly test | ||
--EXTENSIONS-- | ||
dba | ||
--SKIPIF-- | ||
<?php | ||
$handler = 'lmdb'; | ||
require_once __DIR__ .'/skipif.inc'; | ||
?> | ||
--FILE-- | ||
<?php | ||
$handler = 'lmdb'; | ||
$db_filename = __DIR__ . "/lmdb-readonly.dbm"; | ||
|
||
// Create DB | ||
$db_file = dba_open($db_filename, "c", $handler); | ||
assert($db_file !== false); | ||
// Close handler | ||
dba_close($db_file); | ||
|
||
// Open in read only mode | ||
$db_file = dba_open($db_filename, "r", $handler); | ||
assert($db_file !== false); | ||
|
||
// Try inserting | ||
dba_insert("key1", "This is a test insert", $db_file); | ||
dba_close($db_file); | ||
?> | ||
--CLEAN-- | ||
<?php | ||
$db_filename = __DIR__ . "/lmdb-readonly.dbm"; | ||
@unlink($db_filename); | ||
@unlink($db_filename.'.lck'); | ||
@unlink($db_filename.'-lock'); | ||
?> | ||
--EXPECTF-- | ||
Warning: dba_insert(): Cannot perform a modification on a readonly database in %s on line %d |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.