From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001 From: Pierre Schmitz Date: Sun, 8 Dec 2013 09:55:49 +0100 Subject: Update to MediaWiki 1.22.0 --- includes/db/DatabaseSqlite.php | 49 ++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 18 deletions(-) (limited to 'includes/db/DatabaseSqlite.php') diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 0789e1b1..4a51226f 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -52,9 +52,9 @@ class DatabaseSqlite extends DatabaseBase { $this->mName = $dbName; parent::__construct( $server, $user, $password, $dbName, $flags ); // parent doesn't open when $user is false, but we can work with $dbName - if( $dbName ) { + if ( $dbName && !$this->isOpen() ) { global $wgSharedDB; - if( $this->open( $server, $user, $password, $dbName ) && $wgSharedDB ) { + if ( $this->open( $server, $user, $password, $dbName ) && $wgSharedDB ) { $this->attachDatabase( $wgSharedDB ); } } @@ -68,7 +68,7 @@ class DatabaseSqlite extends DatabaseBase { } /** - * @todo: check if it should be true like parent class + * @todo Check if it should be true like parent class * * @return bool */ @@ -90,6 +90,7 @@ class DatabaseSqlite extends DatabaseBase { function open( $server, $user, $pass, $dbName ) { global $wgSQLiteDataDir; + $this->close(); $fileName = self::generateFileName( $wgSQLiteDataDir, $dbName ); if ( !is_readable( $fileName ) ) { $this->mConn = false; @@ -200,7 +201,7 @@ class DatabaseSqlite extends DatabaseBase { * * @return ResultWrapper */ - function attachDatabase( $name, $file = false, $fname = 'DatabaseSqlite::attachDatabase' ) { + function attachDatabase( $name, $file = false, $fname = __METHOD__ ) { global $wgSQLiteDataDir; if ( !$file ) { $file = self::generateFileName( $wgSQLiteDataDir, $name ); @@ -420,7 +421,7 @@ class DatabaseSqlite extends DatabaseBase { * * @return array */ - function indexInfo( $table, $index, $fname = 'DatabaseSqlite::indexExists' ) { + function indexInfo( $table, $index, $fname = __METHOD__ ) { $sql = 'PRAGMA index_info(' . $this->addQuotes( $this->indexName( $index ) ) . ')'; $res = $this->query( $sql, $fname ); if ( !$res ) { @@ -442,7 +443,7 @@ class DatabaseSqlite extends DatabaseBase { * @param $fname string * @return bool|null */ - function indexUnique( $table, $index, $fname = 'DatabaseSqlite::indexUnique' ) { + function indexUnique( $table, $index, $fname = __METHOD__ ) { $row = $this->selectRow( 'sqlite_master', '*', array( 'type' => 'index', @@ -471,7 +472,7 @@ class DatabaseSqlite extends DatabaseBase { */ function makeSelectOptions( $options ) { foreach ( $options as $k => $v ) { - if ( is_numeric( $k ) && ($v == 'FOR UPDATE' || $v == 'LOCK IN SHARE MODE') ) { + if ( is_numeric( $k ) && ( $v == 'FOR UPDATE' || $v == 'LOCK IN SHARE MODE' ) ) { $options[$k] = ''; } } @@ -514,7 +515,7 @@ class DatabaseSqlite extends DatabaseBase { * Based on generic method (parent) with some prior SQLite-sepcific adjustments * @return bool */ - function insert( $table, $a, $fname = 'DatabaseSqlite::insert', $options = array() ) { + function insert( $table, $a, $fname = __METHOD__, $options = array() ) { if ( !count( $a ) ) { return true; } @@ -541,8 +542,10 @@ class DatabaseSqlite extends DatabaseBase { * @param $fname string * @return bool|ResultWrapper */ - function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseSqlite::replace' ) { - if ( !count( $rows ) ) return true; + function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__ ) { + if ( !count( $rows ) ) { + return true; + } # SQLite can't handle multi-row replaces, so divide up into multiple single-row queries if ( isset( $rows[0] ) && is_array( $rows[0] ) ) { @@ -610,7 +613,7 @@ class DatabaseSqlite extends DatabaseBase { /** * @return string wikitext of a link to the server software's web site */ - public static function getSoftwareLink() { + public function getSoftwareLink() { return "[http://sqlite.org/ SQLite]"; } @@ -653,7 +656,11 @@ class DatabaseSqlite extends DatabaseBase { if ( $this->mTrxLevel == 1 ) { $this->commit( __METHOD__ ); } - $this->mConn->beginTransaction(); + try { + $this->mConn->beginTransaction(); + } catch ( PDOException $e ) { + throw new DBUnexpectedError( $this, 'Error in BEGIN query: ' . $e->getMessage() ); + } $this->mTrxLevel = 1; } @@ -661,7 +668,11 @@ class DatabaseSqlite extends DatabaseBase { if ( $this->mTrxLevel == 0 ) { return; } - $this->mConn->commit(); + try { + $this->mConn->commit(); + } catch ( PDOException $e ) { + throw new DBUnexpectedError( $this, 'Error in COMMIT query: ' . $e->getMessage() ); + } $this->mTrxLevel = 0; } @@ -707,7 +718,9 @@ class DatabaseSqlite extends DatabaseBase { function addQuotes( $s ) { if ( $s instanceof Blob ) { return "x'" . bin2hex( $s->fetch() ) . "'"; - } else if ( strpos( $s, "\0" ) !== false ) { + } elseif ( is_bool( $s ) ) { + return (int)$s; + } elseif ( strpos( $s, "\0" ) !== false ) { // SQLite doesn't support \0 in strings, so use the hex representation as a workaround. // This is a known limitation of SQLite's mprintf function which PDO should work around, // but doesn't. I have reported this to php.net as bug #63419: @@ -813,7 +826,7 @@ class DatabaseSqlite extends DatabaseBase { * @param $fname string * @return bool|ResultWrapper */ - function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseSqlite::duplicateTableStructure' ) { + function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__ ) { $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name=" . $this->addQuotes( $oldName ) . " AND type='table'", $fname ); $obj = $this->fetchObject( $res ); if ( !$obj ) { @@ -839,7 +852,7 @@ class DatabaseSqlite extends DatabaseBase { * * @return array */ - function listTables( $prefix = null, $fname = 'DatabaseSqlite::listTables' ) { + function listTables( $prefix = null, $fname = __METHOD__ ) { $result = $this->select( 'sqlite_master', 'name', @@ -848,11 +861,11 @@ class DatabaseSqlite extends DatabaseBase { $endArray = array(); - foreach( $result as $table ) { + foreach ( $result as $table ) { $vars = get_object_vars( $table ); $table = array_pop( $vars ); - if( !$prefix || strpos( $table, $prefix ) === 0 ) { + if ( !$prefix || strpos( $table, $prefix ) === 0 ) { if ( strpos( $table, 'sqlite_' ) !== 0 ) { $endArray[] = $table; } -- cgit v1.2.3-54-g00ecf