BlueSpice MediaWiki master
 All Classes Namespaces Files Functions Variables Groups Pages
DatabaseTestHelper Class Reference
Inheritance diagram for DatabaseTestHelper:
Collaboration diagram for DatabaseTestHelper:

Public Member Functions

 __construct ($testName, array $opts=[])
 
 getLastSqls ()
 
 setExistingTables ($tablesExists)
 
 forceNextResult ($res)
 
 forceNextQueryError ($errno, $error, $options=[])
 
 strencode ($s)
 
 addIdentifierQuotes ($s)
 
 query ($sql, $fname= '', $tempIgnore=false)
 
 tableExists ($table, $fname=__METHOD__)
 
 nativeReplace ($table, $rows, $fname)
 
 getType ()
 
 open ($server, $user, $password, $dbName)
 
 fetchObject ($res)
 
 fetchRow ($res)
 
 numRows ($res)
 
 numFields ($res)
 
 fieldName ($res, $n)
 
 insertId ()
 
 dataSeek ($res, $row)
 
 lastErrno ()
 
 lastError ()
 
 fieldInfo ($table, $field)
 
 indexInfo ($table, $index, $fname= 'Database::indexInfo')
 
 fetchAffectedRowCount ()
 
 getSoftwareLink ()
 
 getServerVersion ()
 
 getServerInfo ()
 
 isOpen ()
 
 ping (&$rtt=null)
 
 unionSupportsOrderAndLimit ()
 
 setUnionSupportsOrderAndLimit ($v)
 
- Public Member Functions inherited from Wikimedia\Rdbms\Database
 initConnection ()
 
 setLogger (LoggerInterface $logger)
 
 getServerInfo ()
 
 bufferResults ($buffer=null)
 
 trxLevel ()
 
 trxTimestamp ()
 
 trxStatus ()
 
 tablePrefix ($prefix=null)
 
 dbSchema ($schema=null)
 
 getLBInfo ($name=null)
 
 setLBInfo ($name, $value=null)
 
 setLazyMasterHandle (IDatabase $conn)
 
 implicitGroupby ()
 
 implicitOrderby ()
 
 lastQuery ()
 
 doneWrites ()
 
 lastDoneWrites ()
 
 writesPending ()
 
 writesOrCallbacksPending ()
 
 pendingWriteQueryDuration ($type=self::ESTIMATE_TOTAL)
 
 pendingWriteCallers ()
 
 pendingWriteRowsAffected ()
 
 pendingWriteAndCallbackCallers ()
 
 isOpen ()
 
 setFlag ($flag, $remember=self::REMEMBER_NOTHING)
 
 clearFlag ($flag, $remember=self::REMEMBER_NOTHING)
 
 restoreFlags ($state=self::RESTORE_PRIOR)
 
 getFlag ($flag)
 
 getProperty ($name)
 
 getDomainID ()
 
 getWikiID ()
 
 indexInfo ($table, $index, $fname=__METHOD__)
 
 strencode ($s)
 
 connectionErrorLogger ($errno, $errstr)
 
 close ()
 
 reportConnectionError ($error= 'Unknown error')
 
 query ($sql, $fname=__METHOD__, $tempIgnore=false)
 
 reportQueryError ($error, $errno, $sql, $fname, $tempIgnore=false)
 
 freeResult ($res)
 
 selectField ($table, $var, $cond= '', $fname=__METHOD__, $options=[], $join_conds=[])
 
 selectFieldValues ($table, $var, $cond= '', $fname=__METHOD__, $options=[], $join_conds=[])
 
 select ($table, $vars, $conds= '', $fname=__METHOD__, $options=[], $join_conds=[])
 
 selectSQLText ($table, $vars, $conds= '', $fname=__METHOD__, $options=[], $join_conds=[])
 
 selectRow ($table, $vars, $conds, $fname=__METHOD__, $options=[], $join_conds=[])
 
 estimateRowCount ($table, $var= '*', $conds= '', $fname=__METHOD__, $options=[], $join_conds=[])
 
 selectRowCount ($tables, $var= '*', $conds= '', $fname=__METHOD__, $options=[], $join_conds=[])
 
 fieldExists ($table, $field, $fname=__METHOD__)
 
 indexExists ($table, $index, $fname=__METHOD__)
 
 tableExists ($table, $fname=__METHOD__)
 
 indexUnique ($table, $index)
 
 insert ($table, $a, $fname=__METHOD__, $options=[])
 
 update ($table, $values, $conds, $fname=__METHOD__, $options=[])
 
 makeList ($a, $mode=self::LIST_COMMA)
 
 makeWhereFrom2d ($data, $baseKey, $subKey)
 
 aggregateValue ($valuedata, $valuename= 'value')
 
 bitNot ($field)
 
 bitAnd ($fieldLeft, $fieldRight)
 
 bitOr ($fieldLeft, $fieldRight)
 
 buildConcat ($stringList)
 
 buildGroupConcatField ($delim, $table, $field, $conds= '', $join_conds=[])
 
 buildSubstring ($input, $startPosition, $length=null)
 
 buildStringCast ($field)
 
 buildIntegerCast ($field)
 
 buildSelectSubquery ($table, $vars, $conds= '', $fname=__METHOD__, $options=[], $join_conds=[])
 
 databasesAreIndependent ()
 
 selectDB ($db)
 
 getDBname ()
 
 getServer ()
 
 tableName ($name, $format= 'quoted')
 
 tableNames ()
 
 tableNamesN ()
 
 addQuotes ($s)
 
 addIdentifierQuotes ($s)
 
 isQuotedIdentifier ($name)
 
 buildLike ()
 
 anyChar ()
 
 anyString ()
 
 nextSequenceValue ($seqName)
 
 useIndexClause ($index)
 
 ignoreIndexClause ($index)
 
 replace ($table, $uniqueIndexes, $rows, $fname=__METHOD__)
 
 upsert ($table, array $rows, array $uniqueIndexes, array $set, $fname=__METHOD__)
 
 deleteJoin ($delTable, $joinTable, $delVar, $joinVar, $conds, $fname=__METHOD__)
 
 textFieldSize ($table, $field)
 
 delete ($table, $conds, $fname=__METHOD__)
 
 insertSelect ($destTable, $srcTable, $varMap, $conds, $fname=__METHOD__, $insertOptions=[], $selectOptions=[], $selectJoinConds=[])
 
 limitResult ($sql, $limit, $offset=false)
 
 unionSupportsOrderAndLimit ()
 
 unionQueries ($sqls, $all)
 
 unionConditionPermutations ($table, $vars, array $permute_conds, $extra_conds= '', $fname=__METHOD__, $options=[], $join_conds=[])
 
 conditional ($cond, $trueVal, $falseVal)
 
 strreplace ($orig, $old, $new)
 
 getServerUptime ()
 
 wasDeadlock ()
 
 wasLockTimeout ()
 
 wasConnectionLoss ()
 
 wasReadOnlyError ()
 
 wasErrorReissuable ()
 
 wasConnectionError ($errno)
 
 masterPosWait (DBMasterPos $pos, $timeout)
 
 getReplicaPos ()
 
 getMasterPos ()
 
 serverIsReadOnly ()
 
 onTransactionResolution (callable $callback, $fname=__METHOD__)
 
 onTransactionIdle (callable $callback, $fname=__METHOD__)
 
 onTransactionPreCommitOrIdle (callable $callback, $fname=__METHOD__)
 
 setTransactionListener ($name, callable $callback=null)
 
 setTrxEndCallbackSuppression ($suppress)
 
 runOnTransactionPreCommitCallbacks ()
 
 startAtomic ($fname=__METHOD__, $cancelable=self::ATOMIC_NOT_CANCELABLE)
 
 endAtomic ($fname=__METHOD__)
 
 cancelAtomic ($fname=__METHOD__, AtomicSectionIdentifier $sectionId=null)
 
 doAtomicSection ($fname, callable $callback, $cancelable=self::ATOMIC_NOT_CANCELABLE)
 
 begin ($fname=__METHOD__, $mode=self::TRANSACTION_EXPLICIT)
 
 commit ($fname=__METHOD__, $flush=self::FLUSHING_ONE)
 
 rollback ($fname=__METHOD__, $flush= '')
 
 flushSnapshot ($fname=__METHOD__)
 
 explicitTrxActive ()
 
 duplicateTableStructure ($oldName, $newName, $temporary=false, $fname=__METHOD__)
 
 listTables ($prefix=null, $fname=__METHOD__)
 
 listViews ($prefix=null, $fname=__METHOD__)
 
 timestamp ($ts=0)
 
 timestampOrNull ($ts=null)
 
 affectedRows ()
 
 ping (&$rtt=null)
 
 getSessionLagStatus ()
 
 getLag ()
 
 maxListLen ()
 
 encodeBlob ($b)
 
 decodeBlob ($b)
 
 setSessionOptions (array $options)
 
 sourceFile ($filename, callable $lineCallback=null, callable $resultCallback=null, $fname=false, callable $inputCallback=null)
 
 setSchemaVars ($vars)
 
 sourceStream ($fp, callable $lineCallback=null, callable $resultCallback=null, $fname=__METHOD__, callable $inputCallback=null)
 
 streamStatementEnd (&$sql, &$newLine)
 
 lockIsFree ($lockName, $method)
 
 lock ($lockName, $method, $timeout=5)
 
 unlock ($lockName, $method)
 
 getScopedLockAndFlush ($lockKey, $fname, $timeout)
 
 namedLocksEnqueue ()
 
 tableLocksHaveTransactionScope ()
 
 lockTables (array $read, array $write, $method)
 
 unlockTables ($method)
 
 dropTable ($tableName, $fName=__METHOD__)
 
 getInfinity ()
 
 encodeExpiry ($expiry)
 
 decodeExpiry ($expiry, $format=TS_MW)
 
 setBigSelects ($value=true)
 
 isReadOnly ()
 
 setTableAliases (array $aliases)
 
 setIndexAliases (array $aliases)
 
 __toString ()
 
 __clone ()
 
 __sleep ()
 
 __destruct ()
 
- Public Member Functions inherited from Wikimedia\Rdbms\IDatabase
 buildSubString ($input, $startPosition, $length=null)
 
- Public Member Functions inherited from Wikimedia\Rdbms\IMaintainableDatabase
 deadlockLoop ()
 

Protected Member Functions

 addSql ($sql)
 
 checkFunctionName ($fname)
 
 wasKnownStatementRollbackError ()
 
 closeConnection ()
 
 doQuery ($sql)
 
- Protected Member Functions inherited from Wikimedia\Rdbms\Database
 __construct (array $params)
 
 doInitConnection ()
 
 getLazyMasterHandle ()
 
 getTransactionRoundId ()
 
 installErrorHandler ()
 
 restoreErrorHandler ()
 
 getLastPHPError ()
 
 getLogContext (array $extras=[])
 
 assertOpen ()
 
 closeConnection ()
 
 doQuery ($sql)
 
 isWriteQuery ($sql)
 
 getQueryVerb ($sql)
 
 isTransactableQuery ($sql)
 
 registerTempTableOperation ($sql)
 
 wasQueryTimeout ($error, $errno)
 
 makeSelectOptions ($options)
 
 makeGroupByWithHaving ($options)
 
 makeOrderBy ($options)
 
 normalizeConditions ($conds, $fname)
 
 extractSingleFieldFromList ($var)
 
 makeInsertOptions ($options)
 
 makeUpdateOptionsArray ($options)
 
 makeUpdateOptions ($options)
 
 assertBuildSubstringParams ($startPosition, $length)
 
 qualifiedTableComponents ($name)
 
 tableNameWithAlias ($table, $alias=false)
 
 tableNamesWithAlias ($tables)
 
 fieldNameWithAlias ($name, $alias=false)
 
 fieldNamesWithAlias ($fields)
 
 tableNamesWithIndexClauseOrJOIN ($tables, $use_index=[], $ignore_index=[], $join_conds=[])
 
 indexName ($index)
 
 escapeLikeInternal ($s, $escapeChar= '`')
 
 nativeReplace ($table, $rows, $fname)
 
 isInsertSelectSafe (array $insertOptions, array $selectOptions)
 
 nonNativeInsertSelect ($destTable, $srcTable, $varMap, $conds, $fname=__METHOD__, $insertOptions=[], $selectOptions=[], $selectJoinConds=[])
 
 nativeInsertSelect ($destTable, $srcTable, $varMap, $conds, $fname=__METHOD__, $insertOptions=[], $selectOptions=[], $selectJoinConds=[])
 
 wasKnownStatementRollbackError ()
 
 doSavepoint ($identifier, $fname)
 
 doReleaseSavepoint ($identifier, $fname)
 
 doRollbackToSavepoint ($identifier, $fname)
 
 doBegin ($fname)
 
 doCommit ($fname)
 
 doRollback ($fname)
 
 fetchAffectedRowCount ()
 
 resultObject ($result)
 
 replaceLostConnection ($fname)
 
 getRecordedTransactionLagStatus ()
 
 getApproximateLagStatus ()
 
 replaceVars ($ins)
 
 getSchemaVars ()
 
 getDefaultSchemaVars ()
 
 doLockTables (array $read, array $write, $method)
 
 doUnlockTables ($method)
 
 getReadOnlyReason ()
 
 getBindingHandle ()
 

Protected Attributes

 $testName = []
 
 $lastSqls = []
 
 $nextResult = []
 
 $nextError = null
 
 $lastError = null
 
 $tablesExists
 
 $unionSupportsOrderAndLimit = true
 
- Protected Attributes inherited from Wikimedia\Rdbms\Database
 $lastQuery = ''
 
 $lastWriteTime = false
 
 $phpError = false
 
 $server
 
 $user
 
 $password
 
 $dbName
 
 $tableAliases = []
 
 $indexAliases = []
 
 $cliMode
 
 $agent
 
 $connectionParams = []
 
 $srvCache
 
 $connLogger
 
 $queryLogger
 
 $errorLogger
 
 $deprecationLogger
 
 $conn = null
 
 $opened = false
 
 $trxIdleCallbacks = []
 
 $trxPreCommitCallbacks = []
 
 $trxEndCallbacks = []
 
 $trxRecurringCallbacks = []
 
 $trxEndCallbacksSuppressed = false
 
 $tablePrefix = ''
 
 $schema = ''
 
 $flags
 
 $lbInfo = []
 
 $schemaVars = false
 
 $sessionVars = []
 
 $preparedArgs
 
 $htmlErrors
 
 $delimiter = ';'
 
 $currentDomain
 
 $affectedRowCount
 
 $trxStatus = self::STATUS_TRX_NONE
 
 $trxStatusCause
 
 $trxStatusIgnoredCause
 
 $trxLevel = 0
 
 $trxShortId = ''
 
 $sessionTempTables = []
 
 $lastPing = 0.0
 
 $profiler
 
 $trxProfiler
 
 $nonNativeInsertSelectBatchSize = 10000
 

Additional Inherited Members

- Static Public Member Functions inherited from Wikimedia\Rdbms\Database
static attributesFromType ($dbType, $driver=null)
 
- Public Attributes inherited from Wikimedia\Rdbms\Database
const DEADLOCK_TRIES = 4
 
const DEADLOCK_DELAY_MIN = 500000
 
const DEADLOCK_DELAY_MAX = 1500000
 
const PING_TTL = 1.0
 
const PING_QUERY = 'SELECT 1 AS ping'
 
const TINY_WRITE_SEC = 0.010
 
const SLOW_WRITE_SEC = 0.500
 
const SMALL_WRITE_ROWS = 100
 
const ATTR_DB_LEVEL_LOCKING = 'db-level-locking'
 
const NEW_UNCONNECTED = 0
 
const NEW_CONNECTED = 1
 
const STATUS_TRX_ERROR = 1
 
const STATUS_TRX_OK = 2
 
const STATUS_TRX_NONE = 3
 
- Public Attributes inherited from Wikimedia\Rdbms\IDatabase
const TRIGGER_IDLE = 1
 
const TRIGGER_COMMIT = 2
 
const TRIGGER_ROLLBACK = 3
 
const TRANSACTION_EXPLICIT = ''
 
const TRANSACTION_INTERNAL = 'implicit'
 
const ATOMIC_NOT_CANCELABLE = ''
 
const ATOMIC_CANCELABLE = 'cancelable'
 
const FLUSHING_ONE = ''
 
const FLUSHING_ALL_PEERS = 'flush'
 
const FLUSHING_INTERNAL = 'flush-internal'
 
const REMEMBER_NOTHING = ''
 
const REMEMBER_PRIOR = 'remember'
 
const RESTORE_PRIOR = 'prior'
 
const RESTORE_INITIAL = 'initial'
 
const ESTIMATE_TOTAL = 'total'
 
const ESTIMATE_DB_APPLY = 'apply'
 
const LIST_COMMA = 0
 
const LIST_AND = 1
 
const LIST_SET = 2
 
const LIST_NAMES = 3
 
const LIST_OR = 4
 
const DBO_DEBUG = 1
 
const DBO_NOBUFFER = 2
 
const DBO_IGNORE = 4
 
const DBO_TRX = 8
 
const DBO_DEFAULT = 16
 
const DBO_PERSISTENT = 32
 
const DBO_SYSDBA = 64
 
const DBO_DDLMODE = 128
 
const DBO_SSL = 256
 
const DBO_COMPRESS = 512
 
- Static Protected Member Functions inherited from Wikimedia\Rdbms\Database
static getAttributes ()
 
static generalizeSQL ($sql)
 

Detailed Description

Helper for testing the methods from the Database class

Since
1.22

Member Function Documentation

DatabaseTestHelper::dataSeek (   $res,
  $row 
)

Change the position of the cursor in a result object

See Also
https://secure.php.net/mysql_data_seek
Parameters
mixed$resA SQL result
int$row

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::fetchObject (   $res)

Fetch the next row from the given result object, in object form. Fields can be retrieved with $row->fieldname, with fields acting like member variables. If no more rows are available, false is returned.

Parameters
IResultWrapper | stdClass$resObject as returned from IDatabase::query(), etc.
Returns
stdClass|bool
Exceptions
DBUnexpectedErrorThrown if the database returns an error

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::fetchRow (   $res)

Fetch the next row from the given result object, in associative array form. Fields are retrieved with $row['fieldname']. If no more rows are available, false is returned.

Parameters
IResultWrapper$resResult object as returned from IDatabase::query(), etc.
Returns
array|bool
Exceptions
DBUnexpectedErrorThrown if the database returns an error

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::fieldInfo (   $table,
  $field 
)

mysql_fetch_field() wrapper Returns false if the field doesn't exist

Parameters
string$tableTable name
string$fieldField name
Returns
Field

Implements Wikimedia\Rdbms\IMaintainableDatabase.

DatabaseTestHelper::fieldName (   $res,
  $n 
)

Get a field name in a result object

See Also
https://secure.php.net/mysql_field_name
Parameters
mixed$resA SQL result
int$n
Returns
string

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::forceNextQueryError (   $errno,
  $error,
  $options = [] 
)
Parameters
int$errnoError number
string$errorError text
array$options
  • wasKnownStatementRollbackError: Return value for wasKnownStatementRollbackError()
DatabaseTestHelper::forceNextResult (   $res)
Parameters
mixed$resUse an array of row arrays to set row result
DatabaseTestHelper::getLastSqls ( )

Returns SQL queries grouped by '; ' Clear the list of queries that have been done so far.

Returns
string
DatabaseTestHelper::getServerInfo ( )

A string describing the current software version, and possibly other details in a user-friendly way. Will be listed on Special:Version, etc. Use getServerVersion() to get machine-friendly information.

Returns
string Version information from the database server

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::getServerVersion ( )

A string describing the current software version, like from mysql_get_server_info().

Returns
string Version information from the database server.

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::getSoftwareLink ( )

Returns a wikitext link to the DB's website, e.g., return "[https://www.mysql.com/ MySQL]"; Should at least contain plain text, if for some reason your database has no website.

Returns
string Wikitext of a link to the server software's web site

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::getType ( )

Get the type of the DBMS, as it appears in $wgDBtype.

Returns
string

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::insertId ( )

Get the inserted value of an auto-increment row

This should only be called after an insert that used an auto-incremented value. If no such insert was previously done in the current database session, the return value is undefined.

Returns
int

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::isOpen ( )

Is a connection to the database open?

Returns
bool

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::lastErrno ( )

Get the last error number

See Also
https://secure.php.net/mysql_errno
Returns
int

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::lastError ( )

Get a description of the last error

See Also
https://secure.php.net/mysql_error
Returns
string

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::numFields (   $res)

Get the number of fields in a result object

See Also
https://secure.php.net/mysql_num_fields
Parameters
mixed$resA SQL result
Returns
int

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::numRows (   $res)

Get the number of rows in a result object

Parameters
mixed$resA SQL result
Returns
int

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::open (   $server,
  $user,
  $password,
  $dbName 
)

Open a new connection to the database (closing any existing one)

Parameters
string$serverDatabase server host
string$userDatabase user name
string$passwordDatabase user password
string$dbNameDatabase name
Returns
bool
Exceptions
DBConnectionError

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::ping ( $rtt = null)

Ping the server and try to reconnect if it there is no connection

Parameters
float | null&$rttValue to store the estimated RTT [optional]
Returns
bool Success or failure

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::query (   $sql,
  $fname = '',
  $tempIgnore = false 
)

Run an SQL query and return the result. Normally throws a DBQueryError on failure. If errors are ignored, returns false instead.

If a connection loss is detected, then an attempt to reconnect will be made. For queries that involve no larger transactions or locks, they will be re-issued for convenience, provided the connection was re-established.

In new code, the query wrappers select(), insert(), update(), delete(), etc. should be used where possible, since they give much better DBMS independence and automatically quote or validate user input in a variety of contexts. This function is generally only useful for queries which are explicitly DBMS-dependent and are unsupported by the query wrappers, such as CREATE TABLE.

However, the query wrappers themselves should call this function.

Parameters
string$sqlSQL query
string$fnameName of the calling function, for profiling/SHOW PROCESSLIST comment (you can use METHOD or add some extra info)
bool$tempIgnoreWhether to avoid throwing an exception on errors... maybe best to catch the exception instead?
Returns
bool|IResultWrapper True for a successful write query, IResultWrapper object for a successful read query, or false on failure if $tempIgnore set
Exceptions
DBError

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::tableExists (   $table,
  $fname = __METHOD__ 
)

Query whether a given table exists

Parameters
string$table
string$fname
Returns
bool
Exceptions
DBError

Implements Wikimedia\Rdbms\IDatabase.

DatabaseTestHelper::unionSupportsOrderAndLimit ( )

Returns true if current database backend supports ORDER BY or LIMIT for separate subqueries within the UNION construct.

Returns
bool

Implements Wikimedia\Rdbms\IDatabase.

Member Data Documentation

DatabaseTestHelper::$lastSqls = []
protected

Array of lastSqls passed to query(), This is an array since some methods in Database can do more than one query. Cleared when calling getLastSqls().

DatabaseTestHelper::$tablesExists
protected

Array of tables to be considered as existing by tableExist() Use setExistingTables() to alter.

DatabaseTestHelper::$testName = []
protected

CLASS of the test suite, used to determine, if the function name is passed every time to query()

DatabaseTestHelper::$unionSupportsOrderAndLimit = true
protected

Value to return from unionSupportsOrderAndLimit()


The documentation for this class was generated from the following file: