/**
* Close an SQLite database
+ *
+ * @return bool
*/
function close() {
$this->mOpened = false;
/**
* Check if the searchindext table is FTS enabled.
- * @returns false if not enabled.
+ * @return false if not enabled.
*/
function checkForEnabledSearch() {
if ( self::$fulltextEnabled === null ) {
/**
* @see DatabaseBase::isWriteQuery()
+ *
+ * @return bool
*/
function isWriteQuery( $sql ) {
return parent::isWriteQuery( $sql ) && !preg_match( '/^ATTACH\b/i', $sql );
/**
* 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 ) );
}
/**
}
/**
- * 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] ) ) {
/**
* 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 );
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 ) ) {
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" );
*
* @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(