com php-src: Implement #72653: SQLite should allow opening with empty filename: NEWS ext/sqlite3/sqlite3.c ext/sqlite3/tests/sqlite
3_open_empty_string.phpt
| From: | Christoph Michael Becker | Date: | Wed, 27 Jul 2016 14:41:03 +0000 |
| Subject: | com php-src: Implement #72653: SQLite should allow opening with empty filename: NEWS ext/sqlite3/sqlite3.c ext/sqlite3/tests/sqlite 3_open_empty_string.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-93418@lists.php.net to get a copy of this message | ||
Commit: cc125f277b50e0f90fc8033fe7f47d2446389a15
Author: Christoph M. Becker <cmb@php.net> Wed, 27 Jul 2016 16:37:49 +0200
Parents: cce457c68c3a15efafea3a30560c54f74f3f5ee1
Branches: PHP-5.6 PHP-7.0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=cc125f277b50e0f90fc8033fe7f47d2446389a15
Log:
Implement #72653: SQLite should allow opening with empty filename
From the [sqlite3_open](https://www.sqlite.org/c3ref/open.html) docs:
| If the filename is an empty string, then a private, temporary on-disk
| database will be created. This private database will be automatically
| deleted as soon as the database connection is closed.
We make that facility available to userland.
While we're at it, we also do some minor optimizations, remove the
unnecessary check for NUL characters in filename, which is already catered
to by ZPP(p), and add a missing
return in case db_obj isn't initialized.
Bugs:
https://bugs.php.net/72653
Changed paths:
M NEWS
M ext/sqlite3/sqlite3.c
M ext/sqlite3/tests/sqlite3_open_empty_string.phpt
Diff:
diff --git a/NEWS b/NEWS
index 1e3ef3b..bd65b76 100644
--- a/NEWS
+++ b/NEWS
@@ -65,6 +65,10 @@ PHP NEWS
.. Fixed bug #72646 (SplFileObject::getCsvControl does not return the escape
character). (cmb)
+- SQLite3:
+ . Implemented FR #72653 (SQLite should allow opening with empty filename).
+ (cmb)
+
21 Jul 2016, PHP 5.6.24
- Core:
diff --git a/ext/sqlite3/sqlite3.c b/ext/sqlite3/sqlite3.c
index c901e53..54ec73d 100644
--- a/ext/sqlite3/sqlite3.c
+++ b/ext/sqlite3/sqlite3.c
@@ -118,13 +118,11 @@ PHP_METHOD(sqlite3, open)
if (db_obj->initialised) {
zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Already initialised DB
Object", 0 TSRMLS_CC);
- }
-
- if (strlen(filename) != filename_len) {
return;
}
- if (filename_len != sizeof(":memory:")-1 ||
- memcmp(filename, ":memory:", sizeof(":memory:")-1) != 0) {
+
+ if (filename_len != 0 && (filename_len != sizeof(":memory:")-1 ||
+ memcmp(filename, ":memory:", sizeof(":memory:")-1) != 0)) {
if (!(fullpath = expand_filepath(filename, NULL TSRMLS_CC))) {
zend_throw_exception(zend_exception_get_default(TSRMLS_C), "Unable to expand
filepath", 0 TSRMLS_CC);
return;
@@ -144,7 +142,8 @@ PHP_METHOD(sqlite3, open)
return;
}
} else {
- fullpath = estrdup(filename);
+ /* filename equals "" or ":memory:" */
+ fullpath = filename;
}
#if SQLITE_VERSION_NUMBER >= 3005000
@@ -153,7 +152,7 @@ PHP_METHOD(sqlite3, open)
if (sqlite3_open(fullpath, &(db_obj->db)) != SQLITE_OK) {
#endif
zend_throw_exception_ex(zend_exception_get_default(TSRMLS_C), 0 TSRMLS_CC, "Unable to open
database: %s", sqlite3_errmsg(db_obj->db));
- if (fullpath) {
+ if (fullpath != filename) {
efree(fullpath);
}
return;
@@ -178,7 +177,7 @@ PHP_METHOD(sqlite3, open)
sqlite3_set_authorizer(db_obj->db, php_sqlite3_authorizer, NULL);
}
- if (fullpath) {
+ if (fullpath != filename) {
efree(fullpath);
}
}
diff --git a/ext/sqlite3/tests/sqlite3_open_empty_string.phpt
b/ext/sqlite3/tests/sqlite3_open_empty_string.phpt
index 86868ee..940056b 100644
--- a/ext/sqlite3/tests/sqlite3_open_empty_string.phpt
+++ b/ext/sqlite3/tests/sqlite3_open_empty_string.phpt
@@ -7,13 +7,8 @@ Thijs Feryn <thijs@feryn.eu>
<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
--FILE--
<?php
-try{
- $db = new SQLite3('');
-} catch(Exception $e) {
- echo $e->getMessage().PHP_EOL;
-}
+$db = new SQLite3('');
echo "Done\n";
?>
---EXPECTF--
-Unable to expand filepath
+--EXPECT--
Done