Bug #55154 [Com]: SQLite does not support stream wrappers to access to database file

From: Date: Thu, 31 Jul 2014 18:31:06 +0000
Subject: Bug #55154 [Com]: SQLite does not support stream wrappers to access to database file
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186917@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55154&edit=1 ID: 55154 Comment by: sun at unleashedmind dot com Reported by: ivan dot enderlin at hoa-project dot net Summary: SQLite does not support stream wrappers to access to database file Status: Closed Type: Bug Package: SQLite related PHP Version: 5.4SVN-2011-07-07 (SVN) Block user comment: N Private report: N New Comment: > A stream just wouldn't cut it here. Could you clarify what this was meant to say? A) "Sorry, it's not impossible to forward a PHP stream (wrapper) to SQLite; incompatible." or B) "Meh, too much of an edge-case; a stream wrapper would have to support plenty of advanced operations, so unlikely to see in the wild; hence, not willing to spend time on this." I'm asking, because in case of B), a very frequent question and use-case is to use PHPUnit with e.g. https://github.com/mikey179/vfsStream (which hides away the complexity of a virtual filesystem), using database URI of e.g. vfs://root/db.sqlite That is useful in case you need to test multiple database connections for a shared in-memory SQLite database -- in which case ':memory:' doesn't work, since every connection is a new db, and 'file:memdb1?mode=memory&cache=shared' triggers open_basedir restrictions. In short - if it's technically possible - this would resolve a range of unit testing challenges (without creating artifacts on disk that might not be cleaned up in case of e.g. a fatal error). Previous Comments: ------------------------------------------------------------------------ [2011-07-07 11:43:10] ivan dot enderlin at hoa-project dot net I understand. So there is no possible workaround to fix this little issue? In this case, I change the bug status to “closed”. Thanks. ------------------------------------------------------------------------ [2011-07-07 11:40:53] scottmac@php.net The underlying library creates journal files and locking in the same directory as the file it's working on. A stream just wouldn't cut it here. ------------------------------------------------------------------------ [2011-07-07 04:24:47] ivan dot enderlin at hoa-project dot net Description: ------------ It seems like SQLite does not considere stream wrappers to access to database file (with \SQLite3 class or PDO driver). Test script: --------------- <?php /** * $ echo "CREATE TABLE t ( x INTEGER PRIMARY KEY ASC, y, z );" |\ * sqlite3 -init 0 Foo.sqlite */ class W { public function stream_open ( $path, $mode, $options, &$openedPath ) { return fopen('Foo.sqlite', $mode); } public function url_stat ( $path, $flags ) { return stat('Foo.sqlite'); } } stream_wrapper_register('sw', 'W'); var_dump(fopen('sw://foo', 'r')); var_dump(file_exists('sw://foo')); var_dump(new \SQLite3('Foo.sqlite')); var_dump(new \SQLite3('sw://foo')); Expected result: ---------------- resource(7) of type (stream) bool(true) object(SQLite3)#1 (0) { } object(SQLite3)#2 (0) { } Actual result: -------------- resource(7) of type (stream) bool(true) object(SQLite3)#1 (0) { } Fatal error: Uncaught exception 'Exception' with message 'Unable to open database: unable to open database file' in ….php:27 Stack trace: #0 ….php(27): SQLite3->__construct('sw://foo') #1 {main} thrown in ….php on line 27 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55154&edit=1

« previous php.bugs (#186917) next »