-Destroy the DB automatically when initting the DB
[lhc/web/wiklou.git] / includes / db / DatabaseSqlite.php
index 3a9a171..92b8124 100644 (file)
@@ -431,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
        }
@@ -526,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] ) ) {
@@ -538,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";
        }
@@ -638,6 +608,37 @@ class DatabaseSqlite extends DatabaseBase {
                $sql = preg_replace( '/\b' . preg_quote( $oldName ) . '\b/', $newName, $sql, 1 );
                return $this->query( $sql, $fname );
        }
+       
+       
+       /**
+        * List all tables on the database
+        *
+        * @param $prefix Only show tables with this prefix, e.g. mw_
+        * @param $fname String: calling function name
+        */
+       function listTables( $prefix = null, $fname = 'DatabaseSqlite::listTables' ) {
+               $result = $this->select(
+                       'sqlite_master',
+                       'name',
+                       "type='table'"
+               );
+               
+               $endArray = array();
+               
+               foreach( $result as $table ) {  
+                       $vars = get_object_vars($table);
+                       $table = array_pop( $vars );
+                       
+                       if( !$prefix || strpos( $table, $prefix ) === 0 ) {
+                               if ( strpos( $table, 'sqlite_' ) !== 0 ) {
+                                       $endArray[] = $table;
+                               }
+                               
+                       }
+               }
+               
+               return $endArray;
+       }
 
 } // end DatabaseSqlite class
 
@@ -656,7 +657,7 @@ class DatabaseSqliteStandalone extends DatabaseSqlite {
 /**
  * @ingroup Database
  */
-class SQLiteField {
+class SQLiteField implements Field {
        private $info, $tableName;
        function __construct( $info, $tableName ) {
                $this->info = $info;
@@ -681,18 +682,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;
        }