-Destroy the DB automatically when initting the DB
[lhc/web/wiklou.git] / includes / db / DatabaseSqlite.php
index af00b04..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] ) ) {
@@ -608,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
 
@@ -626,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;
@@ -651,18 +682,10 @@ class SQLiteField {
                return $this->info->dflt_value;
        }
 
-       function maxLength() {
-               return -1;
+       function isNullable() {
+               return !$this->info->notnull;
        }
 
-       function nullable() {
-               // SQLite dynamic types are always nullable
-               return true;
-       }
-
-       # isKey(),  isMultipleKey() not implemented, MySQL-specific concept.
-       # Suggest removal from base class [TS]
-
        function type() {
                return $this->info->type;
        }