From 14601368b8b572f718b79f40cabdfa92218a85b8 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 5 Jul 2012 13:43:46 +0200 Subject: [PATCH] API Don't run in-memory by default. While the SQLite3 module is predominantly used for testing, its best to leave this decision to the code using it. We should default to a conservative setting (slower, but persistent). Also remove coupling to SapphireTest when setting this value. Don't bother creating the directory if running in-memory. --- _config.php | 1 - code/SQLite3Database.php | 11 +++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/_config.php b/_config.php index 896fb23..f018bac 100644 --- a/_config.php +++ b/_config.php @@ -10,7 +10,6 @@ if(defined('SS_DATABASE_CLASS') && in_array(SS_DATABASE_CLASS, $classes)) { if(in_array($databaseConfig['type'], $classes)) { if(empty($databaseConfig['path'])) $databaseConfig['path'] = defined('SS_SQLITE_DATABASE_PATH') && SS_SQLITE_DATABASE_PATH ? SS_SQLITE_DATABASE_PATH : ASSETS_PATH . '/.sqlitedb/'; // where to put the database file $databaseConfig['database'] = (defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : '') . $databaseConfig['database'] . (defined('SS_DATABASE_SUFFIX') ? SS_DATABASE_SUFFIX : ''); - if(!isset($databaseConfig['memory'])) $databaseConfig['memory'] = true; // run tests in memory if(empty($databaseConfig['key'])) $databaseConfig['key'] = defined('SS_SQLITE_DATABASE_KEY') && SS_SQLITE_DATABASE_KEY ? SS_SQLITE_DATABASE_KEY : 'SQLite3DatabaseKey'; /** diff --git a/code/SQLite3Database.php b/code/SQLite3Database.php index 60d151e..bc72a4d 100644 --- a/code/SQLite3Database.php +++ b/code/SQLite3Database.php @@ -76,18 +76,17 @@ class SQLite3Database extends SS_Database { $file = $parameters['path'] . '/' . $dbName; // use the very lightspeed SQLite In-Memory feature for testing - if(SapphireTest::using_temp_db() && $parameters['memory']) { + if(isset($parameters['memory']) && $parameters['memory']) { $file = ':memory:'; $this->lives_in_memory = true; } else { $this->lives_in_memory = false; + if(!file_exists($parameters['path'])) { + SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']); + SQLiteDatabaseConfigurationHelper::secure_db_dir($parameters['path']); + } } - if(!file_exists($parameters['path'])) { - SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']); - SQLiteDatabaseConfigurationHelper::secure_db_dir($parameters['path']); - } - $this->dbConn = new SQLite3($file, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $parameters['key']); if(method_exists('SQLite3', 'busyTimeout')) $this->dbConn->busyTimeout(60000);