* 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->mFlags = $flags;
$this->mName = $dbName;
*/
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
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;
return implode( $glue, $sqls );
}
+ public function unixTimestamp( $field ) {
+ return $field;
+ }
+
function wasDeadlock() {
return $this->lastErrno() == 5; // SQLITE_BUSY
}
}
}
- function quote_ident( $s ) {
- return $s;
- }
-
function buildLike() {
$params = func_get_args();
if ( count( $params ) > 0 && is_array( $params[0] ) ) {
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";
}
$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
/**
* @ingroup Database
*/
-class SQLiteField {
+class SQLiteField implements Field {
private $info, $tableName;
function __construct( $info, $tableName ) {
$this->info = $info;
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;
}