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;
|
||||
|
||||
/*
|
||||
* if we're on a In-Memory db
|
||||
*/
|
||||
protected $lives_in_memory = false;
|
||||
|
||||
public static $default_pragma = array();
|
||||
|
||||
public static $vacuum = true;
|
||||
@ -65,23 +60,16 @@ class SQLite3Database extends SS_Database {
|
||||
/*
|
||||
* 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();
|
||||
$parameters = $this->parameters;
|
||||
$dbName = !isset($this->database) ? $parameters['database'] : $this->database;
|
||||
$file = $parameters['path'];
|
||||
|
||||
$parameters=$this->parameters;
|
||||
|
||||
$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,8 +79,7 @@ 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->active = true;
|
||||
$this->database = $dbName;
|
||||
|
||||
if(!$this->dbConn) {
|
||||
|
@ -10,21 +10,16 @@ class SQLitePDODatabase extends SQLite3Database {
|
||||
/*
|
||||
* 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();
|
||||
|
||||
$parameters=$this->parameters;
|
||||
|
||||
$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,8 +28,7 @@ class SQLitePDODatabase extends SQLite3Database {
|
||||
|
||||
$this->dbConn = new PDO("sqlite:$file");
|
||||
|
||||
//By virtue of getting here, the connection is active:
|
||||
$this->active=true;
|
||||
$this->active = true;
|
||||
$this->database = $dbName;
|
||||
|
||||
if(!$this->dbConn) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user