MediaWiki  REL1_22
DatabaseTestHelper Class Reference

Helper for testing the methods from the DatabaseBase class. More...

Inheritance diagram for DatabaseTestHelper:
Collaboration diagram for DatabaseTestHelper:

List of all members.

Public Member Functions

 __construct ($testName)
 addIdentifierQuotes ($s)
 Quotes an identifier using `backticks` or "double quotes" depending on the database type.
 affectedRows ()
 Get the number of rows affected by the last write query.
 dataSeek ($res, $row)
 Change the position of the cursor in a result object.
 fetchObject ($res)
 Fetch the next row from the given result object, in object form.
 fetchRow ($res)
 Fetch the next row from the given result object, in associative array form.
 fieldInfo ($table, $field)
 mysql_fetch_field() wrapper Returns false if the field doesn't exist
 fieldName ($res, $n)
 Get a field name in a result object.
 getLastSqls ()
 Returns SQL queries grouped by '; ' Clear the list of queries that have been done so far.
 getServerInfo ()
 A string describing the current software version, and possibly other details in a user-friendly way.
 getServerVersion ()
 A string describing the current software version, like from mysql_get_server_info().
 getSoftwareLink ()
 Returns a wikitext link to the DB's website, e.g., return "[http://www.mysql.com/ MySQL]"; Should at least contain plain text, if for some reason your database has no website.
 getType ()
 Get the type of the DBMS, as it appears in $wgDBtype.
 indexInfo ($table, $index, $fname= 'Database::indexInfo')
 Get information about an index into an object.
 insertId ()
 Get the inserted value of an auto-increment row.
 lastErrno ()
 Get the last error number.
 lastError ()
 Get a description of the last error.
 nativeReplace ($table, $rows, $fname)
 REPLACE query wrapper for MySQL and SQLite, which have a native REPLACE statement.
 numFields ($res)
 Get the number of fields in a result object.
 numRows ($res)
 Get the number of rows in a result object.
 open ($server, $user, $password, $dbName)
 Open a connection to the database.
 query ($sql, $fname= '', $tempIgnore=false)
 Run an SQL query and return the result.
 setExistingTables ($tablesExists)
 strencode ($s)
 Wrapper for addslashes()
 tableExists ($table, $fname=__METHOD__)
 Query whether a given table exists.

Protected Member Functions

 addSql ($sql)
 checkFunctionName ($fname)
 closeConnection ()
 Closes underlying database connection.
 doQuery ($sql)
 The DBMS-dependent part of query()

Protected Attributes

 $lastSqls = array()
 Array of lastSqls passed to query(), This is an array since some methods in DatabaseBase can do more than one query.
 $tablesExists
 Array of tables to be considered as existing by tableExist() Use setExistingTables() to alter.
 $testName = array()
 __CLASS__ of the test suite, used to determine, if the function name is passed every time to query()

Detailed Description

Helper for testing the methods from the DatabaseBase class.

Since:
1.22

Definition at line 7 of file DatabaseTestHelper.php.


Constructor & Destructor Documentation

Definition at line 28 of file DatabaseTestHelper.php.

References $testName.


Member Function Documentation

Quotes an identifier using `backticks` or "double quotes" depending on the database type.

MySQL uses `backticks` while basically everything else uses double quotes. Since MySQL is the odd one out here the double quotes are our generic and we implement backticks in DatabaseMysql.

Parameters:
$sstring
Returns:
string

Reimplemented from DatabaseBase.

Definition at line 68 of file DatabaseTestHelper.php.

References $s.

DatabaseTestHelper::addSql ( sql) [protected]

Definition at line 47 of file DatabaseTestHelper.php.

Referenced by query().

Get the number of rows affected by the last write query.

See also:
http://www.php.net/mysql_affected_rows
Returns:
int

Implements DatabaseType.

Definition at line 143 of file DatabaseTestHelper.php.

DatabaseTestHelper::checkFunctionName ( fname) [protected]

Definition at line 55 of file DatabaseTestHelper.php.

References $fname.

Referenced by query(), and tableExists().

Closes underlying database connection.

Since:
1.20
Returns:
bool: Whether connection was closed successfully

Reimplemented from DatabaseBase.

Definition at line 159 of file DatabaseTestHelper.php.

DatabaseTestHelper::dataSeek ( res,
row 
)

Change the position of the cursor in a result object.

See also:
http://www.php.net/mysql_data_seek
Parameters:
$resMixed: A SQL result
$rowMixed: Either MySQL row or ResultWrapper

Implements DatabaseType.

Definition at line 123 of file DatabaseTestHelper.php.

DatabaseTestHelper::doQuery ( sql) [protected]

The DBMS-dependent part of query()

Parameters:
$sqlString: SQL query.
Returns:
ResultWrapper Result object to feed to fetchObject, fetchRow, ...; or false on failure

Reimplemented from DatabaseBase.

Definition at line 163 of file DatabaseTestHelper.php.

References array().

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:
$resResultWrapper|object as returned from DatabaseBase::query(), etc.
Returns:
object|bool
Exceptions:
DBUnexpectedErrorThrown if the database returns an error

Implements DatabaseType.

Definition at line 99 of file DatabaseTestHelper.php.

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:
$resResultWrapper result object as returned from DatabaseBase::query(), etc.
Returns:
array|bool
Exceptions:
DBUnexpectedErrorThrown if the database returns an error

Implements DatabaseType.

Definition at line 103 of file DatabaseTestHelper.php.

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 DatabaseType.

Definition at line 135 of file DatabaseTestHelper.php.

DatabaseTestHelper::fieldName ( res,
n 
)

Get a field name in a result object.

See also:
http://www.php.net/mysql_field_name
Parameters:
$resMixed: A SQL result
$nInteger
Returns:
string

Implements DatabaseType.

Definition at line 115 of file DatabaseTestHelper.php.

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

Definition at line 36 of file DatabaseTestHelper.php.

References $lastSqls, and array().

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

Reimplemented from DatabaseBase.

Definition at line 155 of file DatabaseTestHelper.php.

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

Returns:
string: Version information from the database server.

Implements DatabaseType.

Definition at line 151 of file DatabaseTestHelper.php.

Returns a wikitext link to the DB's website, e.g., return "[http://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 DatabaseType.

Definition at line 147 of file DatabaseTestHelper.php.

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

Returns:
string

Implements DatabaseType.

Definition at line 91 of file DatabaseTestHelper.php.

DatabaseTestHelper::indexInfo ( table,
index,
fname = 'Database::indexInfo' 
)

Get information about an index into an object.

Parameters:
string$tableTable name
string$indexIndex name
string$fnameCalling function name
Returns:
Mixed: Database-specific index description class or false if the index does not exist

Implements DatabaseType.

Definition at line 139 of file DatabaseTestHelper.php.

Get the inserted value of an auto-increment row.

The value inserted should be fetched from nextSequenceValue()

Example: $id = $dbw->nextSequenceValue( 'page_page_id_seq' ); $dbw->insert( 'page', array( 'page_id' => $id ) ); $id = $dbw->insertId();

Returns:
int

Implements DatabaseType.

Definition at line 119 of file DatabaseTestHelper.php.

Get the last error number.

See also:
http://www.php.net/mysql_errno
Returns:
int

Implements DatabaseType.

Definition at line 127 of file DatabaseTestHelper.php.

Get a description of the last error.

See also:
http://www.php.net/mysql_error
Returns:
string

Implements DatabaseType.

Definition at line 131 of file DatabaseTestHelper.php.

DatabaseTestHelper::nativeReplace ( table,
rows,
fname 
)

REPLACE query wrapper for MySQL and SQLite, which have a native REPLACE statement.

Parameters:
string$tableTable name
array$rowsRows to insert
string$fnameCaller function name
Returns:
ResultWrapper

Reimplemented from DatabaseBase.

Definition at line 87 of file DatabaseTestHelper.php.

References $fname.

Get the number of fields in a result object.

See also:
http://www.php.net/mysql_num_fields
Parameters:
$resMixed: A SQL result
Returns:
int

Implements DatabaseType.

Definition at line 111 of file DatabaseTestHelper.php.

Get the number of rows in a result object.

Parameters:
$resMixed: A SQL result
Returns:
int

Implements DatabaseType.

Definition at line 107 of file DatabaseTestHelper.php.

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

Open a connection to the database.

Usually aborts on failure

Parameters:
string$serverdatabase server host
string$userdatabase user name
string$passworddatabase user password
string$dbNamedatabase name
Returns:
bool
Exceptions:
DBConnectionError

Implements DatabaseType.

Definition at line 95 of file DatabaseTestHelper.php.

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.

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:
$sqlString: SQL query
$fnameString: Name of the calling function, for profiling/SHOW PROCESSLIST comment (you can use __METHOD__ or add some extra info)
$tempIgnoreBoolean: Whether to avoid throwing an exception on errors... maybe best to catch the exception instead?
Exceptions:
MWException
Returns:
boolean|ResultWrapper. true for a successful write query, ResultWrapper object for a successful read query, or false on failure if $tempIgnore set

Reimplemented from DatabaseBase.

Definition at line 73 of file DatabaseTestHelper.php.

References $fname, addSql(), and checkFunctionName().

Definition at line 43 of file DatabaseTestHelper.php.

References $tablesExists, and array().

Wrapper for addslashes()

Parameters:
string$sto be slashed.
Returns:
string: slashed string.

Implements DatabaseType.

Definition at line 63 of file DatabaseTestHelper.php.

References $s.

DatabaseTestHelper::tableExists ( table,
fname = __METHOD__ 
)

Query whether a given table exists.

Parameters:
$tablestring
$fnamestring
Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 80 of file DatabaseTestHelper.php.

References $fname, array(), and checkFunctionName().


Member Data Documentation

DatabaseTestHelper::$lastSqls = array() [protected]

Array of lastSqls passed to query(), This is an array since some methods in DatabaseBase can do more than one query.

Cleared when calling getLastSqls().

Definition at line 20 of file DatabaseTestHelper.php.

Referenced by getLastSqls().

DatabaseTestHelper::$tablesExists [protected]

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

Definition at line 26 of file DatabaseTestHelper.php.

Referenced by setExistingTables().

DatabaseTestHelper::$testName = array() [protected]

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

Definition at line 13 of file DatabaseTestHelper.php.

Referenced by __construct().


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