diff options
Diffstat (limited to 'includes/db/DatabaseSqlite.php')
-rw-r--r-- | includes/db/DatabaseSqlite.php | 43 |
1 files changed, 35 insertions, 8 deletions
diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 112c417b..dfc506cc 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -20,11 +20,9 @@ class DatabaseSqlite extends Database { * Constructor */ function __construct($server = false, $user = false, $password = false, $dbName = false, $failFunction = false, $flags = 0) { - global $wgOut,$wgSQLiteDataDir; + global $wgOut,$wgSQLiteDataDir, $wgSQLiteDataDirMode; if ("$wgSQLiteDataDir" == '') $wgSQLiteDataDir = dirname($_SERVER['DOCUMENT_ROOT']).'/data'; - if (!is_dir($wgSQLiteDataDir)) mkdir($wgSQLiteDataDir,0700); - if (!isset($wgOut)) $wgOut = NULL; # Can't get a reference if it hasn't been set yet - $this->mOut =& $wgOut; + if (!is_dir($wgSQLiteDataDir)) wfMkdirParents( $wgSQLiteDataDir, $wgSQLiteDataDirMode ); $this->mFailFunction = $failFunction; $this->mFlags = $flags; $this->mDatabaseFile = "$wgSQLiteDataDir/$dbName.sqlite"; @@ -48,11 +46,28 @@ class DatabaseSqlite extends Database { $this->mConn = false; if ($dbName) { $file = $this->mDatabaseFile; - if ($this->mFlags & DBO_PERSISTENT) $this->mConn = new PDO("sqlite:$file",$user,$pass,array(PDO::ATTR_PERSISTENT => true)); - else $this->mConn = new PDO("sqlite:$file",$user,$pass); - if ($this->mConn === false) wfDebug("DB connection error: $err\n");; + try { + if ( $this->mFlags & DBO_PERSISTENT ) { + $this->mConn = new PDO( "sqlite:$file", $user, $pass, + array( PDO::ATTR_PERSISTENT => true ) ); + } else { + $this->mConn = new PDO( "sqlite:$file", $user, $pass ); + } + } catch ( PDOException $e ) { + $err = $e->getMessage(); + } + if ( $this->mConn === false ) { + wfDebug( "DB connection error: $err\n" ); + if ( !$this->mFailFunction ) { + throw new DBConnectionError( $this, $err ); + } else { + return false; + } + + } $this->mOpened = $this->mConn; - $this->mConn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_SILENT); # set error codes only, dont raise exceptions + # set error codes only, don't raise exceptions + $this->mConn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT ); } return $this->mConn; } @@ -390,7 +405,19 @@ class DatabaseSqlite extends Database { public function unlock( $lockName, $method ) { return true; } + + public function getSearchEngine() { + return "SearchEngineDummy"; + } + /** + * No-op version of deadlockLoop + */ + public function deadlockLoop( /*...*/ ) { + $args = func_get_args(); + $function = array_shift( $args ); + return call_user_func_array( $function, $args ); + } } /** |