Fix function level comments that start with /* not /**
[lhc/web/wiklou.git] / includes / db / DatabaseSqlite.php
index e7bc31e..be8e781 100644 (file)
@@ -89,6 +89,8 @@ class DatabaseSqlite extends DatabaseBase {
 
        /**
         * Close an SQLite database
+        *
+        * @return bool
         */
        function close() {
                $this->mOpened = false;
@@ -111,7 +113,7 @@ class DatabaseSqlite extends DatabaseBase {
 
        /**
         * Check if the searchindext table is FTS enabled.
-        * @returns false if not enabled.
+        * @return false if not enabled.
         */
        function checkForEnabledSearch() {
                if ( self::$fulltextEnabled === null ) {
@@ -165,6 +167,8 @@ class DatabaseSqlite extends DatabaseBase {
 
        /**
         * @see DatabaseBase::isWriteQuery()
+        *
+        * @return bool
         */
        function isWriteQuery( $sql ) {
                return parent::isWriteQuery( $sql ) && !preg_match( '/^ATTACH\b/i', $sql );
@@ -254,10 +258,10 @@ class DatabaseSqlite extends DatabaseBase {
        /**
         * Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks
         */
-       function tableName( $name ) {
+       function tableName( $name, $quoted = true ) {
                // table names starting with sqlite_ are reserved
                if ( strpos( $name, 'sqlite_' ) === 0 ) return $name;
-               return str_replace( '`', '', parent::tableName( $name ) );
+               return str_replace( '"', '', parent::tableName( $name, $quoted ) );
        }
 
        /**
@@ -363,22 +367,44 @@ class DatabaseSqlite extends DatabaseBase {
        }
 
        /**
-        * Based on generic method (parent) with some prior SQLite-sepcific adjustments
+        * @param $options array
+        * @return string
         */
-       function insert( $table, $a, $fname = 'DatabaseSqlite::insert', $options = array() ) {
-               if ( !count( $a ) ) {
-                       return true;
-               }
-               if ( !is_array( $options ) ) {
-                       $options = array( $options );
-               }
+       function makeUpdateOptions( $options ) {
+               $options = self::fixIgnore( $options );
+               return parent::makeUpdateOptions( $options );
+       }
 
+       /**
+        * @param $options array
+        * @return array
+        */
+       static function fixIgnore( $options ) {
                # SQLite uses OR IGNORE not just IGNORE
                foreach ( $options as $k => $v ) {
                        if ( $v == 'IGNORE' ) {
                                $options[$k] = 'OR IGNORE';
                        }
                }
+               return $options;
+       }
+
+       /**
+        * @param $options array
+        * @return string
+        */
+       function makeInsertOptions( $options ) {
+               $options = self::fixIgnore( $options );
+               return parent::makeInsertOptions( $options );
+       }
+
+       /**
+        * Based on generic method (parent) with some prior SQLite-sepcific adjustments
+        */
+       function insert( $table, $a, $fname = 'DatabaseSqlite::insert', $options = array() ) {
+               if ( !count( $a ) ) {
+                       return true;
+               }
 
                # SQLite can't handle multi-row inserts, so divide up into multiple single-row inserts
                if ( isset( $a[0] ) && is_array( $a[0] ) ) {
@@ -467,6 +493,8 @@ class DatabaseSqlite extends DatabaseBase {
        /**
         * Get information about a given field
         * Returns false if the field does not exist.
+        *
+        * @return SQLiteField|false
         */
        function fieldInfo( $table, $field ) {
                $tableName = $this->tableName( $table );
@@ -546,6 +574,10 @@ class DatabaseSqlite extends DatabaseBase {
                return call_user_func_array( $function, $args );
        }
 
+       /**
+        * @param $s string
+        * @return string
+        */
        protected function replaceVars( $s ) {
                $s = parent::replaceVars( $s );
                if ( preg_match( '/^\s*(CREATE|ALTER) TABLE/i', $s ) ) {
@@ -588,22 +620,23 @@ class DatabaseSqlite extends DatabaseBase {
                return $s;
        }
 
-       /*
+       /**
         * Build a concatenation list to feed into a SQL query
+        *
+        * @return string
         */
        function buildConcat( $stringList ) {
                return '(' . implode( ') || (', $stringList ) . ')';
        }
 
        function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseSqlite::duplicateTableStructure' ) {
-       
-               $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name='$oldName' AND type='table'", $fname );
+               $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name=" . $this->addQuotes( $oldName ) . " AND type='table'", $fname );
                $obj = $this->fetchObject( $res );
                if ( !$obj ) {
                        throw new MWException( "Couldn't retrieve structure for table $oldName" );
                }
                $sql = $obj->sql;
-               $sql = preg_replace( '/\b' . preg_quote( $oldName ) . '\b/', $newName, $sql, 1 );
+               $sql = preg_replace( '/(?<=\W)"?' . preg_quote( trim( $this->addIdentifierQuotes( $oldName ), '"' ) ) . '"?(?=\W)/', $this->addIdentifierQuotes( $newName ), $sql, 1 );
                if ( $temporary ) {
                        if ( preg_match( '/^\\s*CREATE\\s+VIRTUAL\\s+TABLE\b/i', $sql ) ) {
                                wfDebug( "Table $oldName is virtual, can't create a temporary duplicate.\n" );
@@ -620,6 +653,8 @@ class DatabaseSqlite extends DatabaseBase {
         *
         * @param $prefix Only show tables with this prefix, e.g. mw_
         * @param $fname String: calling function name
+        *
+        * @return array
         */
        function listTables( $prefix = null, $fname = 'DatabaseSqlite::listTables' ) {
                $result = $this->select(