Follow-up r75476: Windows set command treats everything until the && as part of the...
[lhc/web/wiklou.git] / includes / db / DatabaseSqlite.php
index 387d405..52637a2 100644 (file)
@@ -23,9 +23,8 @@ class DatabaseSqlite extends DatabaseBase {
         * Constructor.
         * Parameters $server, $user and $password are not used.
         */
-       function __construct( $server = false, $user = false, $password = false, $dbName = false, $failFunction = false, $flags = 0 ) {
+       function __construct( $server = false, $user = false, $password = false, $dbName = false, $flags = 0 ) {
                global $wgSharedDB;
-               $this->mFailFunction = $failFunction;
                $this->mFlags = $flags;
                $this->mName = $dbName;
 
@@ -34,16 +33,6 @@ class DatabaseSqlite extends DatabaseBase {
                }
        }
 
-       /**
-        * Serialization handler, see http://php.net/manual/en/language.oop5.magic.php#language.oop5.magic.sleep
-        * for details. Instances of this class sometimes get serialized, e.g. with Title and its BacklinkCache
-        * Because attempts to serialize mConn end in "can't serialize PDO objects" exceptions, we simply disallow
-        * to serialize anything in this class.
-        */
-       function __sleep() {
-               return array();
-       }
-
        function getType() {
                return 'sqlite';
        }
@@ -53,8 +42,8 @@ class DatabaseSqlite extends DatabaseBase {
         */
        function implicitGroupby()   { return false; }
 
-       static function newFromParams( $server, $user, $password, $dbName, $failFunction = false, $flags = 0 ) {
-               return new DatabaseSqlite( $server, $user, $password, $dbName, $failFunction, $flags );
+       static function newFromParams( $server, $user, $password, $dbName, $flags = 0 ) {
+               return new DatabaseSqlite( $server, $user, $password, $dbName, $flags );
        }
 
        /** Open an SQLite database and return a resource handle to it
@@ -88,14 +77,9 @@ class DatabaseSqlite extends DatabaseBase {
                } catch ( PDOException $e ) {
                        $err = $e->getMessage();
                }
-               if ( $this->mConn === false ) {
+               if ( !$this->mConn ) {
                        wfDebug( "DB connection error: $err\n" );
-                       if ( !$this->mFailFunction ) {
-                               throw new DBConnectionError( $this, $err );
-                       } else {
-                               return false;
-                       }
-
+                       throw new DBConnectionError( $this, $err );
                }
                $this->mOpened = !!$this->mConn;
                # set error codes only, don't raise exceptions
@@ -134,7 +118,8 @@ class DatabaseSqlite extends DatabaseBase {
        function checkForEnabledSearch() {
                if ( self::$fulltextEnabled === null ) {
                        self::$fulltextEnabled = false;
-                       $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name = 'searchindex'", __METHOD__ );
+                       $table = $this->tableName( 'searchindex' );
+                       $res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name = '$table'", __METHOD__ );
                        if ( $res ) {
                                $row = $res->fetchRow();
                                self::$fulltextEnabled = stristr($row['sql'], 'fts' ) !== false;
@@ -446,6 +431,10 @@ class DatabaseSqlite extends DatabaseBase {
                return implode( $glue, $sqls );
        }
 
+       public function unixTimestamp( $field ) {
+               return $field;
+       }
+
        function wasDeadlock() {
                return $this->lastErrno() == 5; // SQLITE_BUSY
        }
@@ -541,10 +530,6 @@ class DatabaseSqlite extends DatabaseBase {
                }
        }
 
-       function quote_ident( $s ) {
-               return $s;
-       }
-
        function buildLike() {
                $params = func_get_args();
                if ( count( $params ) > 0 && is_array( $params[0] ) ) {
@@ -553,36 +538,6 @@ class DatabaseSqlite extends DatabaseBase {
                return parent::buildLike( $params ) . "ESCAPE '\' ";
        }
 
-       /**
-        * Called by the installer script
-        * - this is the same way PostgreSQL works, MySQL reads in tables.sql and interwiki.sql using DatabaseBase::sourceFile()
-        */
-       public function setup_database() {
-               global $IP;
-
-               # Process common MySQL/SQLite table definitions
-               $err = $this->sourceFile( "$IP/maintenance/tables.sql" );
-               if ( $err !== true ) {
-                       echo " <b>FAILED</b></li>";
-                       dieout( htmlspecialchars( $err ) );
-               }
-               echo " done.</li>";
-
-               # Use DatabasePostgres's code to populate interwiki from MySQL template
-               $f = fopen( "$IP/maintenance/interwiki.sql", 'r' );
-               if ( !$f ) {
-                       dieout( "Could not find the interwiki.sql file." );
-               }
-
-               $sql = "INSERT INTO interwiki(iw_prefix,iw_url,iw_local,iw_api,iw_wikiid) VALUES ";
-               while ( !feof( $f ) ) {
-                       $line = fgets( $f, 1024 );
-                       $matches = array();
-                       if ( !preg_match( '/^\s*(\(.+?),(\d)\)/', $line, $matches ) ) continue;
-                       $this->query( "$sql $matches[1],$matches[2],'','')" );
-               }
-       }
-
        public function getSearchEngine() {
                return "SearchSqlite";
        }
@@ -671,7 +626,7 @@ class DatabaseSqliteStandalone extends DatabaseSqlite {
 /**
  * @ingroup Database
  */
-class SQLiteField {
+class SQLiteField implements Field {
        private $info, $tableName;
        function __construct( $info, $tableName ) {
                $this->info = $info;
@@ -696,18 +651,10 @@ class SQLiteField {
                return $this->info->dflt_value;
        }
 
-       function maxLength() {
-               return -1;
-       }
-
-       function nullable() {
-               // SQLite dynamic types are always nullable
-               return true;
+       function isNullable() {
+               return !$this->info->notnull;
        }
 
-       # isKey(),  isMultipleKey() not implemented, MySQL-specific concept.
-       # Suggest removal from base class [TS]
-
        function type() {
                return $this->info->type;
        }