php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55154 SQLite does not support stream wrappers to access to database file
Submitted: 2011-07-07 04:24 UTC Modified: 2011-07-07 11:43 UTC
From: ivan dot enderlin at hoa-project dot net Assigned:
Status: Closed Package: SQLite related
PHP Version: 5.4SVN-2011-07-07 (SVN) OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ivan dot enderlin at hoa-project dot net
New email:
PHP Version: OS:

 

 [2011-07-07 04:24 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-07-07 11:40 UTC] scottmac@php.net
-Status: Open +Status: Wont fix
 [2011-07-07 11:40 UTC] 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 11:43 UTC] ivan dot enderlin at hoa-project dot net
-Status: Wont fix +Status: Closed
 [2011-07-07 11:43 UTC] 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.
 [2014-07-31 18:31 UTC] sun at unleashedmind dot com
> 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).
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 18:01:29 2024 UTC