Change database path to allow use of ":memory:"

Instead of using a custom "memory" key in the $databaseConfig
which never really got used this now allows someone to simply enable
in-memory databases by setting the path to ":memory:" or to use the
following environment variable:

define('SS_SQLITE_DATABASE_PATH', ':memory:');
This commit is contained in:
Sean Harvey 2014-02-18 16:44:00 +13:00
parent 7a11b353d7
commit 69fee85469
2 changed files with 16 additions and 35 deletions

View File

@ -37,11 +37,6 @@ class SQLite3Database extends SS_Database {
*/
protected $parameters;
/*
* if we're on a In-Memory db
*/
protected $lives_in_memory = false;
public static $default_pragma = array();
public static $vacuum = true;
@ -67,21 +62,14 @@ class SQLite3Database extends SS_Database {
*/
function connectDatabase() {
$this->enum_map = array();
$parameters = $this->parameters;
$dbName = !isset($this->database) ? $parameters['database'] : $this->database;
$file = $parameters['path'];
$dbName = !isset($this->database) ? $parameters['database'] : $dbName=$this->database;
//assumes that the path to dbname will always be provided:
// use the very lightspeed SQLite In-Memory feature for testing
if((isset($parameters['memory']) && $parameters['memory']) || !isset($parameters['path'])) {
$file = ':memory:';
$this->lives_in_memory = true;
} else {
// assumes that the path to dbname will always be provided
// this is only necessary if we're using a filesystem path, and not an in-memory database
if($file != ':memory:') {
$file = $parameters['path'] . '/' . $dbName;
$this->lives_in_memory = false;
if(!file_exists($parameters['path'])) {
SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']);
SQLiteDatabaseConfigurationHelper::secure_db_dir($parameters['path']);
@ -91,7 +79,6 @@ class SQLite3Database extends SS_Database {
$this->dbConn = new SQLite3($file, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $parameters['key']);
if(method_exists('SQLite3', 'busyTimeout')) $this->dbConn->busyTimeout(60000);
//By virtue of getting here, the connection is active:
$this->active = true;
$this->database = $dbName;

View File

@ -11,20 +11,15 @@ class SQLitePDODatabase extends SQLite3Database {
* Uses whatever connection details are in the $parameters array to connect to a database of a given name
*/
function connectDatabase() {
$this->enum_map = array();
$parameters = $this->parameters;
$dbName = !isset($this->database) ? $parameters['database'] : $dbName=$this->database;
$file = $parameters['path'];
// use the very lightspeed SQLite In-Memory feature for testing
if((isset($parameters['memory']) && $parameters['memory']) || !isset($parameters['path'])) {
$file = ':memory:';
$this->lives_in_memory = true;
} else {
// assumes that the path to dbname will always be provided
// this is only necessary if we're using a filesystem path, and not an in-memory database
if($file != ':memory:') {
$file = $parameters['path'] . '/' . $dbName;
$this->lives_in_memory = false;
if(!file_exists($parameters['path'])) {
SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']);
SQLiteDatabaseConfigurationHelper::secure_db_dir($parameters['path']);
@ -33,7 +28,6 @@ class SQLitePDODatabase extends SQLite3Database {
$this->dbConn = new PDO("sqlite:$file");
//By virtue of getting here, the connection is active:
$this->active = true;
$this->database = $dbName;