PostgreSQL: Improve SQL error handling
[lhc/web/wiklou.git] / includes / db / DatabaseSqlite.php
index 48dd858..3aa21b8 100644 (file)
@@ -37,7 +37,7 @@ 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( !$user && $dbName ) {
+               if( $dbName ) {
                        global $wgSharedDB;
                        if( $this->open( $server, $user, $password, $dbName ) && $wgSharedDB ) {
                                $this->attachDatabase( $wgSharedDB );
@@ -88,7 +88,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;
@@ -115,16 +115,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;
        }
 
@@ -140,7 +135,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 ) {
@@ -213,7 +208,7 @@ class DatabaseSqlite extends DatabaseBase {
         *
         * @return ResultWrapper
         */
-       function doQuery( $sql ) {
+       protected function doQuery( $sql ) {
                $res = $this->mConn->query( $sql );
                if ( $res === false ) {
                        return false;
@@ -319,15 +314,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 ) );
        }
 
        /**
@@ -497,6 +492,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 ) ) {
@@ -532,46 +528,17 @@ 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;
        }
 
-       /**
-        * DELETE where the condition is a join
-        *
-        * @param $delTable String: The table to delete from.
-        * @param $joinTable String: The other table.
-        * @param $delVar String: The variable to join on, in the first table.
-        * @param $joinVar String: The variable to join on, in the second table.
-        * @param $conds Array: Condition array of field names mapped to variables, ANDed together in the WHERE clause
-        * @param $fname String: Calling function name (use __METHOD__) for logs/profiling
-        */
-       public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,
-               $fname = 'DatabaseSqlite::deleteJoin' )
-       {
-               if ( !$conds ) {
-                       throw new DBUnexpectedError( $this,
-                               'DatabaseSqlite::deleteJoin() called with empty $conds' );
-               }
-
-               $delTable = $this->tableName( $delTable );
-               $joinTable = $this->tableName( $joinTable );
-               $sql = "DELETE FROM $delTable WHERE $delVar IN (SELECT $joinVar FROM $joinTable";
-               if ( $conds != '*' ) {
-                       $sql .= ' WHERE ' . $this->makeList( $conds, LIST_AND );
-               }
-               $sql .= ')';
-
-               $this->query( $sql, $fname );
-       }
-
        /**
         * Returns the size of a text field, or -1 for "unlimited"
         * In SQLite this is SQLITE_MAX_LENGTH, by default 1GB. No way to query it though.
@@ -646,7 +613,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 );
@@ -662,7 +631,7 @@ class DatabaseSqlite extends DatabaseBase {
 
        function begin( $fname = '' ) {
                if ( $this->mTrxLevel == 1 ) {
-                       $this->commit();
+                       $this->commit( __METHOD__ );
                }
                $this->mConn->beginTransaction();
                $this->mTrxLevel = 1;
@@ -743,11 +712,6 @@ class DatabaseSqlite extends DatabaseBase {
                return parent::buildLike( $params ) . "ESCAPE '\' ";
        }
 
-       public function dropTable( $tableName, $fName = 'DatabaseSqlite::dropTable' ) {
-               $sql = 'DROP TABLE IF EXISTS ' . $this->tableName( $tableName );
-               return $this->query( $sql, $fName );
-       }
-
        /**
         * @return string
         */
@@ -757,6 +721,7 @@ class DatabaseSqlite extends DatabaseBase {
 
        /**
         * No-op version of deadlockLoop
+        * @return mixed
         */
        public function deadlockLoop( /*...*/ ) {
                $args = func_get_args();
@@ -851,7 +816,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