mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 15:05:37 +00:00
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:
parent
7a11b353d7
commit
69fee85469
@ -37,11 +37,6 @@ class SQLite3Database extends SS_Database {
|
|||||||
*/
|
*/
|
||||||
protected $parameters;
|
protected $parameters;
|
||||||
|
|
||||||
/*
|
|
||||||
* if we're on a In-Memory db
|
|
||||||
*/
|
|
||||||
protected $lives_in_memory = false;
|
|
||||||
|
|
||||||
public static $default_pragma = array();
|
public static $default_pragma = array();
|
||||||
|
|
||||||
public static $vacuum = true;
|
public static $vacuum = true;
|
||||||
@ -67,21 +62,14 @@ class SQLite3Database extends SS_Database {
|
|||||||
*/
|
*/
|
||||||
function connectDatabase() {
|
function connectDatabase() {
|
||||||
$this->enum_map = array();
|
$this->enum_map = array();
|
||||||
|
|
||||||
$parameters = $this->parameters;
|
$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
|
||||||
|
// this is only necessary if we're using a filesystem path, and not an in-memory database
|
||||||
//assumes that the path to dbname will always be provided:
|
if($file != ':memory:') {
|
||||||
|
|
||||||
|
|
||||||
// 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 {
|
|
||||||
$file = $parameters['path'] . '/' . $dbName;
|
$file = $parameters['path'] . '/' . $dbName;
|
||||||
$this->lives_in_memory = false;
|
|
||||||
if(!file_exists($parameters['path'])) {
|
if(!file_exists($parameters['path'])) {
|
||||||
SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']);
|
SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']);
|
||||||
SQLiteDatabaseConfigurationHelper::secure_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']);
|
$this->dbConn = new SQLite3($file, SQLITE3_OPEN_READWRITE | SQLITE3_OPEN_CREATE, $parameters['key']);
|
||||||
if(method_exists('SQLite3', 'busyTimeout')) $this->dbConn->busyTimeout(60000);
|
if(method_exists('SQLite3', 'busyTimeout')) $this->dbConn->busyTimeout(60000);
|
||||||
|
|
||||||
//By virtue of getting here, the connection is active:
|
|
||||||
$this->active = true;
|
$this->active = true;
|
||||||
$this->database = $dbName;
|
$this->database = $dbName;
|
||||||
|
|
||||||
|
@ -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
|
* Uses whatever connection details are in the $parameters array to connect to a database of a given name
|
||||||
*/
|
*/
|
||||||
function connectDatabase() {
|
function connectDatabase() {
|
||||||
|
|
||||||
$this->enum_map = array();
|
$this->enum_map = array();
|
||||||
|
|
||||||
$parameters = $this->parameters;
|
$parameters = $this->parameters;
|
||||||
|
|
||||||
$dbName = !isset($this->database) ? $parameters['database'] : $dbName=$this->database;
|
$dbName = !isset($this->database) ? $parameters['database'] : $dbName=$this->database;
|
||||||
|
$file = $parameters['path'];
|
||||||
|
|
||||||
// use the very lightspeed SQLite In-Memory feature for testing
|
// assumes that the path to dbname will always be provided
|
||||||
if((isset($parameters['memory']) && $parameters['memory']) || !isset($parameters['path'])) {
|
// this is only necessary if we're using a filesystem path, and not an in-memory database
|
||||||
$file = ':memory:';
|
if($file != ':memory:') {
|
||||||
$this->lives_in_memory = true;
|
|
||||||
} else {
|
|
||||||
$file = $parameters['path'] . '/' . $dbName;
|
$file = $parameters['path'] . '/' . $dbName;
|
||||||
$this->lives_in_memory = false;
|
|
||||||
if(!file_exists($parameters['path'])) {
|
if(!file_exists($parameters['path'])) {
|
||||||
SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']);
|
SQLiteDatabaseConfigurationHelper::create_db_dir($parameters['path']);
|
||||||
SQLiteDatabaseConfigurationHelper::secure_db_dir($parameters['path']);
|
SQLiteDatabaseConfigurationHelper::secure_db_dir($parameters['path']);
|
||||||
@ -33,7 +28,6 @@ class SQLitePDODatabase extends SQLite3Database {
|
|||||||
|
|
||||||
$this->dbConn = new PDO("sqlite:$file");
|
$this->dbConn = new PDO("sqlite:$file");
|
||||||
|
|
||||||
//By virtue of getting here, the connection is active:
|
|
||||||
$this->active = true;
|
$this->active = true;
|
||||||
$this->database = $dbName;
|
$this->database = $dbName;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user