diff --git a/code/SQLite3Database.php b/code/SQLite3Database.php index 040e8d2..bbba443 100644 --- a/code/SQLite3Database.php +++ b/code/SQLite3Database.php @@ -123,15 +123,13 @@ class SQLite3Database extends Database $file = ':memory:'; } else { // Ensure path is given - if (empty($parameters['path'])) { - $parameters['path'] = ASSETS_PATH . '/.sqlitedb'; - } + $path = $this->getPath(); //assumes that the path to dbname will always be provided: - $file = $parameters['path'] . '/' . $parameters['database'] . self::database_extension(); - if (!file_exists($parameters['path'])) { - SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']); - SQLiteDatabaseConfigurationHelper::secure_db_dir($parameters['path']); + $file = $path . '/' . $parameters['database'] . self::database_extension(); + if (!file_exists($path)) { + SQLiteDatabaseConfigurationHelper::create_db_dir($path); + SQLiteDatabaseConfigurationHelper::secure_db_dir($path); } } @@ -165,11 +163,31 @@ class SQLite3Database extends Database return $this->parameters; } + /** + * Determine if this Db is in memory + * + * @return bool + */ public function getLivesInMemory() { return isset($this->parameters['path']) && $this->parameters['path'] === ':memory:'; } + /** + * Get file path. If in memory this is null + * + * @return string|null + */ + public function getPath() { + if ($this->getLivesInMemory()) { + return null; + } + if (empty($this->parameters['path'])) { + return ASSETS_PATH . '/.sqlitedb'; + } + return $this->parameters['path']; + } + public function supportsCollations() { return true; diff --git a/code/SQLite3SchemaManager.php b/code/SQLite3SchemaManager.php index 26d5145..73513ae 100644 --- a/code/SQLite3SchemaManager.php +++ b/code/SQLite3SchemaManager.php @@ -49,8 +49,8 @@ class SQLite3SchemaManager extends DBSchemaManager } // If using file based database ensure any existing file is removed - $parameters = $this->database->getParameters(); - $fullpath = $parameters['path'] . '/' . $name . SQLite3Database::database_extension(); + $path = $this->database->getPath(); + $fullpath = $path . '/' . $name . SQLite3Database::database_extension(); if (is_writable($fullpath)) { unlink($fullpath); } @@ -58,15 +58,16 @@ class SQLite3SchemaManager extends DBSchemaManager public function databaseList() { - $parameters = $this->database->getParameters(); - // If in-memory use the current database name only if ($this->database->getLivesInMemory()) { - return array($parameters['database']); + return array( + $this->database->getConnector()->getSelectedDatabase() + ?: 'database' + ); } // If using file based database enumerate files in the database directory - $directory = $parameters['path']; + $directory = $this->database->getPath(); $files = scandir($directory); // Filter each file in this directory