/**
* Constructor
+ *
+ * @param $params array
*/
public function __construct( $params ) {
parent::__construct( $params );
$this->makeLicenses();
}
- /**#@+
+ /**
* @private
*/
protected function makeLicenses() {
$lines = explode( "\n", $this->msg );
foreach ( $lines as $line ) {
- if ( strpos( $line, '*' ) !== 0 )
+ if ( strpos( $line, '*' ) !== 0 ) {
continue;
- else {
+ } else {
list( $level, $line ) = $this->trimStars( $line );
if ( strpos( $line, '|' ) !== false ) {
}
}
+ /**
+ * @param $str
+ * @return array
+ */
protected function trimStars( $str ) {
$numStars = strspn( $str, '*' );
return array( $numStars, ltrim( substr( $str, $numStars ), ' ' ) );
}
+ /**
+ * @param $list
+ * @param $path
+ * @param $item
+ */
protected function stackItem( &$list, $path, $item ) {
$position =& $list;
- if ( $path )
- foreach( $path as $key )
+ if ( $path ) {
+ foreach( $path as $key ) {
$position =& $position[$key];
+ }
+ }
$position[] = $item;
}
+ /**
+ * @param $tagset
+ * @param $depth int
+ */
protected function makeHtml( $tagset, $depth = 0 ) {
foreach ( $tagset as $key => $val )
if ( is_array( $val ) ) {
}
}
+ /**
+ * @param $text
+ * @param $value
+ * @param $attribs null
+ * @param $depth int
+ * @return string
+ */
protected function outputOption( $text, $value, $attribs = null, $depth = 0 ) {
$attribs['value'] = $value;
if ( $value === $this->selected )
*
* @return array
*/
- public function getLicenses() { return $this->licenses; }
+ public function getLicenses() {
+ return $this->licenses;
+ }
/**
* Accessor for $this->html
*
+ * @param $value bool
+ *
* @return string
*/
public function getInputHTML( $value ) {
'name' => $this->mName,
'id' => $this->mID
);
- if ( !empty( $this->mParams['disabled'] ) )
+ if ( !empty( $this->mParams['disabled'] ) ) {
$attibs['disabled'] = 'disabled';
+ }
return Html::rawElement( 'select', $attribs, $this->html );
}
var $mDatabaseFile;
var $mName;
+ /**
+ * @var PDO
+ */
+ protected $mConn;
+
/**
* Constructor.
* Parameters $server, $user and $password are not used.
}
}
+ /**
+ * @return string
+ */
function getType() {
return 'sqlite';
}
/**
* @todo: check if it should be true like parent class
+ *
+ * @return bool
*/
- function implicitGroupby() { return false; }
+ function implicitGroupby() {
+ return false;
+ }
/** Open an SQLite database and return a resource handle to it
* NOTE: only $dbName is used, the other parameters are irrelevant for SQLite databases
/**
* Opens a database file
- * @return SQL connection or false if failed
+ *
+ * @param $fileName string
+ *
+ * @return PDO|false SQL connection or false if failed
*/
function openFile( $fileName ) {
$this->mDatabaseFile = $fileName;
/**
* Attaches external database to our connection, see http://sqlite.org/lang_attach.html
* for details.
+ *
* @param $name String: database name to be used in queries like SELECT foo FROM dbname.table
* @param $file String: database file name. If omitted, will be generated using $name and $wgSQLiteDataDir
* @param $fname String: calling function name
+ *
+ * @return ResultWrapper
*/
function attachDatabase( $name, $file = false, $fname = 'DatabaseSqlite::attachDatabase' ) {
global $wgSQLiteDataDir;
/**
* @see DatabaseBase::isWriteQuery()
*
+ * @param $sql string
+ *
* @return bool
*/
function isWriteQuery( $sql ) {
/**
* SQLite doesn't allow buffered results or data seeking etc, so we'll use fetchAll as the result
+ *
+ * @param $sql string
+ *
+ * @return ResultWrapper
*/
function doQuery( $sql ) {
$res = $this->mConn->query( $sql );
return $res;
}
+ /**
+ * @param $res ResultWrapper
+ */
function freeResult( $res ) {
if ( $res instanceof ResultWrapper ) {
$res->result = null;
}
}
+ /**
+ * @param $res ResultWrapper
+ * @return
+ */
function fetchObject( $res ) {
if ( $res instanceof ResultWrapper ) {
$r =& $res->result;
return false;
}
+ /**
+ * @param $res ResultWrapper
+ * @return bool|mixed
+ */
function fetchRow( $res ) {
if ( $res instanceof ResultWrapper ) {
$r =& $res->result;
/**
* The PDO::Statement class implements the array interface so count() will work
+ *
+ * @param $res ResultWrapper
+ *
+ * @return int
*/
function numRows( $res ) {
$r = $res instanceof ResultWrapper ? $res->result : $res;
return count( $r );
}
+ /**
+ * @param $res ResultWrapper
+ * @return int
+ */
function numFields( $res ) {
$r = $res instanceof ResultWrapper ? $res->result : $res;
return is_array( $r ) ? count( $r[0] ) : 0;
}
+ /**
+ * @param $res ResultWrapper
+ * @param $n
+ * @return bool
+ */
function fieldName( $res, $n ) {
$r = $res instanceof ResultWrapper ? $res->result : $res;
if ( is_array( $r ) ) {
$keys = array_keys( $r[0] );
return $keys[$n];
}
- return false;
+ return false;
}
/**
* Use MySQL's naming (accounts for prefix etc) but remove surrounding backticks
+ *
+ * @param $name
+ * @param bool $quoted
+ * @return string
*/
function tableName( $name, $quoted = true ) {
// table names starting with sqlite_ are reserved
- if ( strpos( $name, 'sqlite_' ) === 0 ) return $name;
+ if ( strpos( $name, 'sqlite_' ) === 0 ) {
+ return $name;
+ }
return str_replace( '"', '', parent::tableName( $name, $quoted ) );
}
/**
* Index names have DB scope
+ *
+ * @param $index string
+ *
+ * @return string
*/
function indexName( $index ) {
return $index;
/**
* This must be called after nextSequenceVal
+ *
+ * @return int
*/
function insertId() {
return $this->mConn->lastInsertId();
}
+ /**
+ * @param $res ResultWrapper
+ * @param $row
+ */
function dataSeek( $res, $row ) {
if ( $res instanceof ResultWrapper ) {
$r =& $res->result;
}
}
+ /**
+ * @return string
+ */
function lastError() {
if ( !is_object( $this->mConn ) ) {
return "Cannot return last error, no db connection";
return isset( $e[2] ) ? $e[2] : '';
}
+ /**
+ * @return string
+ */
function lastErrno() {
if ( !is_object( $this->mConn ) ) {
return "Cannot return last error, no db connection";
}
}
+ /**
+ * @return int
+ */
function affectedRows() {
return $this->mAffectedRows;
}
* Returns information about an index
* Returns false if the index does not exist
* - if errors are explicitly ignored, returns NULL on failure
+ *
+ * @return array
*/
function indexInfo( $table, $index, $fname = 'DatabaseSqlite::indexExists' ) {
$sql = 'PRAGMA index_info(' . $this->addQuotes( $this->indexName( $index ) ) . ')';
return $info;
}
+ /**
+ * @param $table
+ * @param $index
+ * @param $fname string
+ * @return bool|null
+ */
function indexUnique( $table, $index, $fname = 'DatabaseSqlite::indexUnique' ) {
$row = $this->selectRow( 'sqlite_master', '*',
array(
/**
* Filter the options used in SELECT statements
+ *
+ * @param $options array
+ *
+ * @return array
*/
function makeSelectOptions( $options ) {
foreach ( $options as $k => $v ) {
return $ret;
}
+ /**
+ * @param $table
+ * @param $uniqueIndexes
+ * @param $rows
+ * @param $fname string
+ * @return bool|ResultWrapper
+ */
function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseSqlite::replace' ) {
if ( !count( $rows ) ) return true;
/**
* Returns the size of a text field, or -1 for "unlimited"
* In SQLite this is SQLITE_MAX_LENGTH, by default 1GB. No way to query it though.
+ *
+ * @return int
*/
function textFieldSize( $table, $field ) {
return -1;
}
+ /**
+ * @return bool
+ */
function unionSupportsOrderAndLimit() {
return false;
}
+ /**
+ * @param $sqls
+ * @param $all
+ * @return string
+ */
function unionQueries( $sqls, $all ) {
$glue = $all ? ' UNION ALL ' : ' UNION ';
return implode( $glue, $sqls );
}
+ /**
+ * @return bool
+ */
function wasDeadlock() {
return $this->lastErrno() == 5; // SQLITE_BUSY
}
+ /**
+ * @return bool
+ */
function wasErrorReissuable() {
return $this->lastErrno() == 17; // SQLITE_SCHEMA;
}
+ /**
+ * @return bool
+ */
function wasReadOnlyError() {
return $this->lastErrno() == 8; // SQLITE_READONLY;
}
}
function begin( $fname = '' ) {
- if ( $this->mTrxLevel == 1 ) $this->commit();
+ if ( $this->mTrxLevel == 1 ) {
+ $this->commit();
+ }
$this->mConn->beginTransaction();
$this->mTrxLevel = 1;
}
function commit( $fname = '' ) {
- if ( $this->mTrxLevel == 0 ) return;
+ if ( $this->mTrxLevel == 0 ) {
+ return;
+ }
$this->mConn->commit();
$this->mTrxLevel = 0;
}
function rollback( $fname = '' ) {
- if ( $this->mTrxLevel == 0 ) return;
+ if ( $this->mTrxLevel == 0 ) {
+ return;
+ }
$this->mConn->rollBack();
$this->mTrxLevel = 0;
}
+ /**
+ * @param $sql
+ * @param $num
+ * @return string
+ */
function limitResultForUpdate( $sql, $num ) {
return $this->limitResult( $sql, $num );
}
+ /**
+ * @param $s string
+ * @return string
+ */
function strencode( $s ) {
return substr( $this->addQuotes( $s ), 1, - 1 );
}
+ /**
+ * @param $b
+ * @return Blob
+ */
function encodeBlob( $b ) {
return new Blob( $b );
}
+ /**
+ * @param $b Blob|string
+ * @return string
+ */
function decodeBlob( $b ) {
if ( $b instanceof Blob ) {
$b = $b->fetch();
return $b;
}
+ /**
+ * @param $s Blob|string
+ * @return string
+ */
function addQuotes( $s ) {
if ( $s instanceof Blob ) {
return "x'" . bin2hex( $s->fetch() ) . "'";
}
}
+ /**
+ * @return string
+ */
function buildLike() {
$params = func_get_args();
if ( count( $params ) > 0 && is_array( $params[0] ) ) {
return parent::buildLike( $params ) . "ESCAPE '\' ";
}
+ /**
+ * @return string
+ */
public function getSearchEngine() {
return "SearchSqlite";
}
/**
* Build a concatenation list to feed into a SQL query
*
+ * @param $stringList array
+ *
* @return string
*/
function buildConcat( $stringList ) {
return '(' . implode( ') || (', $stringList ) . ')';
}
+ /**
+ * @throws MWException
+ * @param $oldName
+ * @param $newName
+ * @param $temporary bool
+ * @param $fname string
+ * @return bool|ResultWrapper
+ */
function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseSqlite::duplicateTableStructure' ) {
$res = $this->query( "SELECT sql FROM sqlite_master WHERE tbl_name=" . $this->addQuotes( $oldName ) . " AND type='table'", $fname );
$obj = $this->fetchObject( $res );
return $this->info->dflt_value;
}
+ /**
+ * @return bool
+ */
function isNullable() {
return !$this->info->notnull;
}