Req #74883 [Opn]: SQLite3::__construct() produces "out of memory" exception with invalid flags
Edit report at https://bugs.php.net/bug.php?id=74883&edit=1
ID: 74883
Updated by: ab@php.net
Reported by: jeroen at treurniet dot us
Summary: SQLite3::__construct() produces "out of memory"
exception with invalid flags
Status: Open
Type: Feature/Change Request
Package: SQLite related
Operating System: Windows
PHP Version: 7.1.7
Block user comment: N
Private report: N
New Comment:
Thanks for the report. As for me, the suggested solution doesn't sound optimal. It is
application dependent, so why should be one flag removed in favor of another one? Another script
might need it in exactly opposite way. IMO it is merely about improving the error check, not more.
SQLite should be able to detect such cases.
Thanks.
Previous Comments:
------------------------------------------------------------------------
[2017-07-08 21:00:33] jeroen at treurniet dot us
Description:
------------
When opening a SQLite3 database with both the SQLITE3_OPEN_READONLY and SQLITE3_OPEN_CREATE flags,
an exception thrown which reads "Unable to open database: out of memory".
While it is understandable that it doesn't make sense to combine the two flags (since creating
a new database would require writing, and opening an empty database that cannot be written to is
probably not very helpful), the "out of memory" error is confusing, and does not seem like
an accurate description of the problem. Especially since the documentation for neither
SQLite3::__construct() and SQLite3::open() hints to this, I was personally stuck for some time
figuring out why it was telling me it was out of memory.
This behavior occurs regardless of whether or not the specified database file actually exists/is
readable.
I propose that when either of these functions is called with SQLITE3_OPEN_READONLY, they should
either silently ignore the SQLITE3_OPEN_CREATE flag if it is specified, or produce an E_NOTICE with
a more helpful message, rather than throwing a fatal error with an unhelpful description ("out
of memory").
Test script:
---------------
$db = new SQLite3( "my_database.db", SQLITE3_OPEN_READONLY | SQLITE3_OPEN_CREATE );
Expected result:
----------------
Either silently ignore the SQLITE3_OPEN_CREATE flag, or throw an E_NOTICE rather than an exception.
Actual result:
--------------
Fatal error: Uncaught Exception: Unable to open database: out of memory in ...
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74883&edit=1
Thread (6 messages)