mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
ENHANCEMENT Added SQLiteDatabaseConfigurationHelper::requireDatabaseVersion() for checking SQLite library version is at least 3.3
This commit is contained in:
parent
483da30a0f
commit
5b0318bdf3
@ -108,9 +108,36 @@ class SQLiteDatabaseConfigurationHelper implements DatabaseConfigurationHelper {
|
||||
}
|
||||
|
||||
public function requireDatabaseVersion($databaseConfig) {
|
||||
$success = false;
|
||||
$error = '';
|
||||
$version = 0;
|
||||
|
||||
if(class_exists('SQLite3')) {
|
||||
$info = SQLite3::version();
|
||||
if($info && isset($info['versionString'])) {
|
||||
$version = trim($info['versionString']);
|
||||
}
|
||||
} else {
|
||||
// Fallback to using sqlite_version() query
|
||||
$file = $databaseConfig['path'] . '/' . $databaseConfig['database'];
|
||||
$file = preg_replace('/\/$/', '', $file);
|
||||
$conn = @(new PDO("sqlite:$file"));
|
||||
if($conn) {
|
||||
$result = @$conn->query('SELECT sqlite_version()');
|
||||
$version = $result->fetchColumn();
|
||||
}
|
||||
}
|
||||
|
||||
if($version) {
|
||||
$success = version_compare($version, '3.3', '>=');
|
||||
if(!$success) {
|
||||
$error = "Your SQLite3 library version is $version. It's recommended you use at least 3.3.";
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => true,
|
||||
'error' => ''
|
||||
'success' => $success,
|
||||
'error' => $error
|
||||
);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user