X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fdb%2FDatabaseSqlite.php;h=15d1ad024b2e1c1bc2daeb0e3a0d7df074d01ce7;hb=9cd080744ff168bf8d0630931849bb63a3d9bcdc;hp=123eaa3659895b6b50f9524b08921f88970240e7;hpb=93b8ff3a101bb730a98a7d2f33cf26c7225d397e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/db/DatabaseSqlite.php b/includes/db/DatabaseSqlite.php index 123eaa3659..15d1ad024b 100644 --- a/includes/db/DatabaseSqlite.php +++ b/includes/db/DatabaseSqlite.php @@ -3,6 +3,21 @@ * This is the SQLite database abstraction layer. * See maintenance/sqlite/README for development notes and other specific information * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * * @file * @ingroup Database */ @@ -27,12 +42,17 @@ class DatabaseSqlite extends DatabaseBase { /** * Constructor. * Parameters $server, $user and $password are not used. + * @param $server string + * @param $user string + * @param $password string + * @param $dbName string + * @param $flags int */ function __construct( $server = false, $user = false, $password = false, $dbName = false, $flags = 0 ) { $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( !$user && $dbName ) { + if( $dbName ) { global $wgSharedDB; if( $this->open( $server, $user, $password, $dbName ) && $wgSharedDB ) { $this->attachDatabase( $wgSharedDB ); @@ -58,6 +78,13 @@ class DatabaseSqlite extends DatabaseBase { /** Open an SQLite database and return a resource handle to it * NOTE: only $dbName is used, the other parameters are irrelevant for SQLite databases + * + * @param $server + * @param $user + * @param $pass + * @param $dbName + * + * @return PDO */ function open( $server, $user, $pass, $dbName ) { global $wgSQLiteDataDir; @@ -76,7 +103,7 @@ class DatabaseSqlite extends DatabaseBase { * * @param $fileName string * - * @return PDO|false SQL connection or false if failed + * @return PDO|bool SQL connection or false if failed */ function openFile( $fileName ) { $this->mDatabaseFile = $fileName; @@ -103,16 +130,11 @@ class DatabaseSqlite extends DatabaseBase { } /** - * Close an SQLite database - * + * Does not actually close the connection, just destroys the reference for GC to do its work * @return bool */ - function close() { - $this->mOpened = false; - if ( is_object( $this->mConn ) ) { - if ( $this->trxLevel() ) $this->commit(); - $this->mConn = null; - } + protected function closeConnection() { + $this->mConn = null; return true; } @@ -128,7 +150,7 @@ class DatabaseSqlite extends DatabaseBase { /** * Check if the searchindext table is FTS enabled. - * @return false if not enabled. + * @return bool False if not enabled. */ function checkForEnabledSearch() { if ( self::$fulltextEnabled === null ) { @@ -201,7 +223,7 @@ class DatabaseSqlite extends DatabaseBase { * * @return ResultWrapper */ - function doQuery( $sql ) { + protected function doQuery( $sql ) { $res = $this->mConn->query( $sql ); if ( $res === false ) { return false; @@ -307,15 +329,15 @@ class DatabaseSqlite extends DatabaseBase { * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks * * @param $name - * @param bool $quoted + * @param $format String * @return string */ - function tableName( $name, $quoted = true ) { + function tableName( $name, $format = 'quoted' ) { // table names starting with sqlite_ are reserved if ( strpos( $name, 'sqlite_' ) === 0 ) { return $name; } - return str_replace( '"', '', parent::tableName( $name, $quoted ) ); + return str_replace( '"', '', parent::tableName( $name, $format ) ); } /** @@ -335,7 +357,8 @@ class DatabaseSqlite extends DatabaseBase { * @return int */ function insertId() { - return $this->mConn->lastInsertId(); + // PDO::lastInsertId yields a string :( + return intval( $this->mConn->lastInsertId() ); } /** @@ -485,6 +508,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() ) { if ( !count( $a ) ) { @@ -520,12 +544,12 @@ class DatabaseSqlite extends DatabaseBase { if ( isset( $rows[0] ) && is_array( $rows[0] ) ) { $ret = true; foreach ( $rows as $v ) { - if ( !parent::replace( $table, $uniqueIndexes, $v, "$fname/multi-row" ) ) { + if ( !$this->nativeReplace( $table, $v, "$fname/multi-row" ) ) { $ret = false; } } } else { - $ret = parent::replace( $table, $uniqueIndexes, $rows, "$fname/single-row" ); + $ret = $this->nativeReplace( $table, $rows, "$fname/single-row" ); } return $ret; @@ -605,7 +629,9 @@ class DatabaseSqlite extends DatabaseBase { * Get information about a given field * Returns false if the field does not exist. * - * @return SQLiteField|false + * @param $table string + * @param $field string + * @return SQLiteField|bool False on failure */ function fieldInfo( $table, $field ) { $tableName = $this->tableName( $table ); @@ -621,7 +647,7 @@ class DatabaseSqlite extends DatabaseBase { function begin( $fname = '' ) { if ( $this->mTrxLevel == 1 ) { - $this->commit(); + $this->commit( __METHOD__ ); } $this->mConn->beginTransaction(); $this->mTrxLevel = 1; @@ -711,6 +737,7 @@ class DatabaseSqlite extends DatabaseBase { /** * No-op version of deadlockLoop + * @return mixed */ public function deadlockLoop( /*...*/ ) { $args = func_get_args(); @@ -805,7 +832,7 @@ class DatabaseSqlite extends DatabaseBase { /** * List all tables on the database * - * @param $prefix Only show tables with this prefix, e.g. mw_ + * @param $prefix string Only show tables with this prefix, e.g. mw_ * @param $fname String: calling function name * * @return array