Req #74883 [Opn->Csd]: SQLite3::__construct() produces "out of memory" exception with invalid flags
| From: | ab@php.net | Date: | Sat, 08 Jul 2017 23:38:44 +0000 |
| Subject: | Req #74883 [Opn->Csd]: SQLite3::__construct() produces "out of memory" exception with invalid flags | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209928@lists.php.net to get a copy of this message | ||
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
+Status: Closed
Type: Feature/Change Request
Package: SQLite related
Operating System: Windows
PHP Version: 7.1.7
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=b5338c0b7d145d9b5b5abcb9d695691ca5d6e418
Log: Fixed bug #74883 SQLite3::__construct() produces "out of memory" exception
with invalid flags
Previous Comments:
------------------------------------------------------------------------
[2017-07-08 21:57:36] ab@php.net
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.
------------------------------------------------------------------------
[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