mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
14601368b8
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.
28 lines
1.3 KiB
PHP
28 lines
1.3 KiB
PHP
<?php
|
|
|
|
$classes = array('SQLiteDatabase', 'SQLite3Database', 'SQLitePDODatabase');
|
|
|
|
global $databaseConfig;
|
|
if(defined('SS_DATABASE_CLASS') && in_array(SS_DATABASE_CLASS, $classes)) {
|
|
$databaseConfig['type'] = SS_DATABASE_CLASS;
|
|
}
|
|
|
|
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(empty($databaseConfig['key'])) $databaseConfig['key'] = defined('SS_SQLITE_DATABASE_KEY') && SS_SQLITE_DATABASE_KEY ? SS_SQLITE_DATABASE_KEY : 'SQLite3DatabaseKey';
|
|
|
|
/**
|
|
* set pragma values on the connection.
|
|
* @see http://www.sqlite.org/pragma.html
|
|
*/
|
|
SQLite3Database::$default_pragma['encoding'] = '"UTF-8"';
|
|
SQLite3Database::$default_pragma['locking_mode'] = 'NORMAL';
|
|
|
|
// The SQLite3 class is available in PHP 5.3 and newer
|
|
if(class_exists('SQLite3') && $databaseConfig['type'] != 'SQLitePDODatabase') {
|
|
$databaseConfig['type'] = 'SQLite3Database';
|
|
} else {
|
|
$databaseConfig['type'] = 'SQLitePDODatabase';
|
|
}
|
|
} |