MediaWiki
REL1_22
|
Helper for testing the methods from the DatabaseBase class. More...
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() |
Helper for testing the methods from the DatabaseBase class.
Definition at line 7 of file DatabaseTestHelper.php.
DatabaseTestHelper::__construct | ( | $ | testName | ) |
Definition at line 28 of file DatabaseTestHelper.php.
References $testName.
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.
$s | 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.
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().
DatabaseTestHelper::closeConnection | ( | ) | [protected] |
Closes underlying database connection.
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.
$res | Mixed: A SQL result |
$row | Mixed: 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()
$sql | String: SQL query. |
Reimplemented from DatabaseBase.
Definition at line 163 of file DatabaseTestHelper.php.
References array().
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.
$res | ResultWrapper|object as returned from DatabaseBase::query(), etc. |
DBUnexpectedError | Thrown if the database returns an error |
Implements DatabaseType.
Definition at line 99 of file DatabaseTestHelper.php.
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.
$res | ResultWrapper result object as returned from DatabaseBase::query(), etc. |
DBUnexpectedError | Thrown 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
string | $table | table name |
string | $field | field name |
Implements DatabaseType.
Definition at line 135 of file DatabaseTestHelper.php.
DatabaseTestHelper::fieldName | ( | $ | res, |
$ | n | ||
) |
Get a field name in a result object.
$res | Mixed: A SQL result |
$n | Integer |
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.
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.
Reimplemented from DatabaseBase.
Definition at line 155 of file DatabaseTestHelper.php.
A string describing the current software version, like from mysql_get_server_info().
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.
Implements DatabaseType.
Definition at line 147 of file DatabaseTestHelper.php.
Get the type of the DBMS, as it appears in $wgDBtype.
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.
string | $table | Table name |
string | $index | Index name |
string | $fname | Calling function name |
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();
Implements DatabaseType.
Definition at line 119 of file DatabaseTestHelper.php.
Get the last error number.
Implements DatabaseType.
Definition at line 127 of file DatabaseTestHelper.php.
Get a description of the last error.
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.
string | $table | Table name |
array | $rows | Rows to insert |
string | $fname | Caller function name |
Reimplemented from DatabaseBase.
Definition at line 87 of file DatabaseTestHelper.php.
References $fname.
DatabaseTestHelper::numFields | ( | $ | res | ) |
Get the number of fields in a result object.
$res | Mixed: A SQL result |
Implements DatabaseType.
Definition at line 111 of file DatabaseTestHelper.php.
DatabaseTestHelper::numRows | ( | $ | res | ) |
Get the number of rows in a result object.
$res | Mixed: A SQL result |
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
string | $server | database server host |
string | $user | database user name |
string | $password | database user password |
string | $dbName | database name |
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.
$sql | String: SQL query |
$fname | String: Name of the calling function, for profiling/SHOW PROCESSLIST comment (you can use __METHOD__ or add some extra info) |
$tempIgnore | Boolean: Whether to avoid throwing an exception on errors... maybe best to catch the exception instead? |
MWException |
Reimplemented from DatabaseBase.
Definition at line 73 of file DatabaseTestHelper.php.
References $fname, addSql(), and checkFunctionName().
DatabaseTestHelper::setExistingTables | ( | $ | tablesExists | ) |
Definition at line 43 of file DatabaseTestHelper.php.
References $tablesExists, and array().
Wrapper for addslashes()
string | $s | to be slashed. |
Implements DatabaseType.
Definition at line 63 of file DatabaseTestHelper.php.
References $s.
DatabaseTestHelper::tableExists | ( | $ | table, |
$ | fname = __METHOD__ |
||
) |
Query whether a given table exists.
$table | string |
$fname | string |
Reimplemented from DatabaseBase.
Definition at line 80 of file DatabaseTestHelper.php.
References $fname, array(), and checkFunctionName().
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().