global $wgOut,$wgSQLiteDataDir, $wgSQLiteDataDirMode;
if ("$wgSQLiteDataDir" == '') $wgSQLiteDataDir = dirname($_SERVER['DOCUMENT_ROOT']).'/data';
if (!is_dir($wgSQLiteDataDir)) wfMkdirParents( $wgSQLiteDataDir, $wgSQLiteDataDirMode );
- if (!isset($wgOut)) $wgOut = NULL; # Can't get a reference if it hasn't been set yet
- $this->mOut =& $wgOut;
$this->mFailFunction = $failFunction;
$this->mFlags = $flags;
$this->mDatabaseFile = "$wgSQLiteDataDir/$dbName.sqlite";
$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;
}
}
function encodeBlob($b) {
- return $this->strencode($b);
+ return new Blob( $b );
}
function decodeBlob($b) {
+ if ($b instanceof Blob) {
+ $b = $b->fetch();
+ }
return $b;
}
function addQuotes($s) {
- return $this->mConn->quote($s);
+ if ( $s instanceof Blob ) {
+ return "x'" . bin2hex( $s->fetch() ) . "'";
+ } else {
+ return $this->mConn->quote($s);
+ }
}
function quote_ident($s) { return $s; }