Inherited by DatabaseIbm_db2, DatabaseMock, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Public Member Functions | |
failFunction ($function=null) | |
Fail function, takes a Database as a parameter Set to false for default, 1 for ignore errors. | |
setOutputPage ($out) | |
Output page, used for reporting errors FALSE means discard output. | |
debug ($debug=null) | |
Boolean, controls output of large amounts of debug information. | |
bufferResults ($buffer=null) | |
Turns buffering of SQL result sets on (true) or off (false). | |
ignoreErrors ($ignoreErrors=null) | |
Turns on (false) or off (true) the automatic generation and sending of a "we're sorry, but there has been a database error" page on database errors. | |
trxLevel ($level=null) | |
The current depth of nested transactions. | |
errorCount ($count=null) | |
Number of errors logged, only useful when errors are ignored. | |
tablePrefix ($prefix=null) | |
getLBInfo ($name=null) | |
Properties passed down from the server info array of the load balancer. | |
setLBInfo ($name, $value=null) | |
setFakeSlaveLag ($lag) | |
Set lag time in seconds for a fake slave. | |
setFakeMaster ($enabled=true) | |
Make this connection a fake master. | |
cascadingDeletes () | |
Returns true if this database supports (and uses) cascading deletes. | |
cleanupTriggers () | |
Returns true if this database supports (and uses) triggers (e.g. | |
strictIPs () | |
Returns true if this database is strict about what can be put into an IP field. | |
realTimestamps () | |
Returns true if this database uses timestamps rather than integers. | |
implicitGroupby () | |
Returns true if this database does an implicit sort when doing GROUP BY. | |
implicitOrderby () | |
Returns true if this database does an implicit order by when the column has an index For example: SELECT page_title FROM page LIMIT 1. | |
standardSelectDistinct () | |
Returns true if this database requires that SELECT DISTINCT queries require that all ORDER BY expressions occur in the SELECT list per the SQL92 standard. | |
searchableIPs () | |
Returns true if this database can do a native search on IP columns e.g. | |
functionalIndexes () | |
Returns true if this database can use functional indexes. | |
lastQuery () | |
Return the last query that went through Database::query(). | |
doneWrites () | |
Returns true if the connection may have been used for write queries. | |
isOpen () | |
Is a connection to the database open? | |
setFlag ($flag) | |
Set a flag for this connection. | |
clearFlag ($flag) | |
Clear a flag for this connection. | |
getFlag ($flag) | |
Returns a boolean whether the flag $flag is set for this connection. | |
getProperty ($name) | |
General read-only accessor. | |
getWikiID () | |
getType () | |
Get the type of the DBMS, as it appears in $wgDBtype. | |
__construct ($server=false, $user=false, $password=false, $dbName=false, $failFunction=false, $flags=0, $tablePrefix= 'get from global') | |
Constructor. | |
open ($server, $user, $password, $dbName) | |
Usually aborts on failure If the failFunction is set to a non-zero integer, returns success. | |
close () | |
Closes a database connection. | |
reportConnectionError ($error= 'Unknown error') | |
isWriteQuery ($sql) | |
Determine whether a query writes to the DB. | |
query ($sql, $fname= '', $tempIgnore=false) | |
Usually aborts on failure. | |
reportQueryError ($error, $errno, $sql, $fname, $tempIgnore=false) | |
prepare ($sql, $func= 'Database::prepare') | |
Intended to be compatible with the PEAR::DB wrapper functions. | |
freePrepared ($prepared) | |
execute ($prepared, $args=null) | |
Execute a prepared query with the various arguments. | |
safeQuery ($query, $args=null) | |
Prepare & execute an SQL statement, quoting and inserting arguments in the appropriate places. | |
fillPrepared ($preparedQuery, $args) | |
For faking prepared SQL statements on DBs that don't support it directly. | |
fillPreparedArg ($matches) | |
preg_callback func for fillPrepared() The arguments should be in $this->preparedArgs and must not be touched while we're doing this. | |
freeResult ($res) | |
Free 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. | |
numRows ($res) | |
Get the number of rows in a result object. | |
numFields ($res) | |
Get the number of fields in a result object See documentation for mysql_num_fields(). | |
fieldName ($res, $n) | |
Get a field name in a result object See documentation for mysql_field_name(): http://www.php.net/mysql_field_name. | |
insertId () | |
Get the inserted value of an auto-increment row. | |
dataSeek ($res, $row) | |
Change the position of the cursor in a result object See mysql_data_seek(). | |
lastErrno () | |
Get the last error number See mysql_errno(). | |
lastError () | |
Get a description of the last error See mysql_error() for more details. | |
affectedRows () | |
Get the number of rows affected by the last write query See mysql_affected_rows() for more details. | |
set ($table, $var, $value, $cond, $fname= 'Database::set') | |
Simple UPDATE wrapper Usually aborts on failure If errors are explicitly ignored, returns success. | |
selectField ($table, $var, $cond='', $fname= 'Database::selectField', $options=array()) | |
Simple SELECT wrapper, returns a single field, input must be encoded Usually aborts on failure If errors are explicitly ignored, returns FALSE on failure. | |
makeSelectOptions ($options) | |
Returns an optional USE INDEX clause to go after the table, and a string to go at the end of the query. | |
select ($table, $vars, $conds='', $fname= 'Database::select', $options=array(), $join_conds=array()) | |
SELECT wrapper. | |
selectSQLText ($table, $vars, $conds='', $fname= 'Database::select', $options=array(), $join_conds=array()) | |
SELECT wrapper. | |
selectRow ($table, $vars, $conds, $fname= 'Database::selectRow', $options=array(), $join_conds=array()) | |
Single row SELECT wrapper Aborts or returns FALSE on error. | |
estimateRowCount ($table, $vars='*', $conds='', $fname= 'Database::estimateRowCount', $options=array()) | |
Estimate rows in dataset Returns estimated count - not necessarily an accurate estimate across different databases, so use sparingly Takes same arguments as Database::select(). | |
fieldExists ($table, $field, $fname= 'Database::fieldExists') | |
Determines whether a field exists in a table Usually aborts on failure If errors are explicitly ignored, returns NULL on failure. | |
indexExists ($table, $index, $fname= 'Database::indexExists') | |
Determines whether an index exists Usually aborts on failure If errors are explicitly ignored, returns NULL on failure. | |
indexInfo ($table, $index, $fname= 'Database::indexInfo') | |
Get information about an index into an object Returns false if the index does not exist. | |
tableExists ($table) | |
Query whether a given table exists. | |
fieldInfo ($table, $field) | |
mysql_fetch_field() wrapper Returns false if the field doesn't exist | |
fieldType ($res, $index) | |
mysql_field_type() wrapper | |
indexUnique ($table, $index) | |
Determines if a given index is unique. | |
insert ($table, $a, $fname= 'Database::insert', $options=array()) | |
INSERT wrapper, inserts an array into a table. | |
makeUpdateOptions ($options) | |
Make UPDATE options for the Database::update function. | |
update ($table, $values, $conds, $fname= 'Database::update', $options=array()) | |
UPDATE wrapper, takes a condition array and a SET array. | |
makeList ($a, $mode=LIST_COMMA) | |
Makes an encoded list of strings from an array $mode: LIST_COMMA - comma separated, no field names LIST_AND - ANDed WHERE clause (without the WHERE) LIST_OR - ORed WHERE clause (without the WHERE) LIST_SET - comma separated with field names, like a SET clause LIST_NAMES - comma separated field names. | |
bitNot ($field) | |
Bitwise operations. | |
bitAnd ($fieldLeft, $fieldRight) | |
bitOr ($fieldLeft, $fieldRight) | |
selectDB ($db) | |
Change the current database. | |
getDBname () | |
Get the current DB name. | |
getServer () | |
Get the server hostname or IP address. | |
tableName ($name) | |
Format a table name ready for use in constructing an SQL query. | |
tableNames () | |
Fetch a number of table names into an array This is handy when you need to construct SQL for joins. | |
tableNamesN () | |
Fetch a number of table names into an zero-indexed numerical array This is handy when you need to construct SQL for joins. | |
indexName ($index) | |
Get the name of an index in a given table. | |
strencode ($s) | |
Wrapper for addslashes(). | |
addQuotes ($s) | |
If it's a string, adds quotes and backslashes Otherwise returns as-is. | |
escapeLike ($s) | |
Escape string for safe LIKE usage. | |
buildLike () | |
LIKE statement wrapper, receives a variable-length argument list with parts of pattern to match containing either string literals that will be escaped or tokens returned by anyChar() or anyString(). | |
anyChar () | |
Returns a token for buildLike() that denotes a '_' to be used in a LIKE query. | |
anyString () | |
Returns a token for buildLike() that denotes a '' to be used in a LIKE query. | |
nextSequenceValue ($seqName) | |
Returns an appropriately quoted sequence value for inserting a new row. | |
useIndexClause ($index) | |
USE INDEX clause. | |
replace ($table, $uniqueIndexes, $rows, $fname= 'Database::replace') | |
REPLACE query wrapper PostgreSQL simulates this with a DELETE followed by INSERT $row is the row to insert, an associative array $uniqueIndexes is an array of indexes. | |
deleteJoin ($delTable, $joinTable, $delVar, $joinVar, $conds, $fname= 'Database::deleteJoin') | |
DELETE where the condition is a join MySQL does this with a multi-table DELETE syntax, PostgreSQL does it with sub-selects. | |
textFieldSize ($table, $field) | |
Returns the size of a text field, or -1 for "unlimited". | |
lowPriorityOption () | |
A string to insert into queries to show that they're low-priority, like MySQL's LOW_PRIORITY. | |
delete ($table, $conds, $fname= 'Database::delete') | |
DELETE query wrapper. | |
insertSelect ($destTable, $srcTable, $varMap, $conds, $fname= 'Database::insertSelect', $insertOptions=array(), $selectOptions=array()) | |
INSERT SELECT wrapper $varMap must be an associative array of the form array( 'dest1' => 'source1', . | |
limitResult ($sql, $limit, $offset=false) | |
Construct a LIMIT query with optional offset. | |
limitResultForUpdate ($sql, $num) | |
unionSupportsOrderAndLimit () | |
Returns true if current database backend supports ORDER BY or LIMIT for separate subqueries within the UNION construct. | |
unionQueries ($sqls, $all) | |
Construct a UNION query This is used for providing overload point for other DB abstractions not compatible with the MySQL syntax. | |
conditional ($cond, $trueVal, $falseVal) | |
Returns an SQL expression for a simple conditional. | |
strreplace ($orig, $old, $new) | |
Returns a comand for str_replace function in SQL query. | |
wasDeadlock () | |
Determines if the last failure was due to a deadlock STUB. | |
wasErrorReissuable () | |
Determines if the last query error was something that should be dealt with by pinging the connection and reissuing the query. | |
wasReadOnlyError () | |
Determines if the last failure was due to the database being read-only. | |
deadlockLoop () | |
Perform a deadlock-prone transaction. | |
masterPosWait (MySQLMasterPos $pos, $timeout) | |
Do a SELECT MASTER_POS_WAIT(). | |
getSlavePos () | |
Get the position of the master from SHOW SLAVE STATUS. | |
getMasterPos () | |
Get the position of the master from SHOW MASTER STATUS. | |
begin ($fname= 'Database::begin') | |
Begin a transaction, committing any previously open transaction. | |
commit ($fname= 'Database::commit') | |
End a transaction. | |
rollback ($fname= 'Database::rollback') | |
Rollback a transaction. | |
immediateBegin ($fname= 'Database::immediateBegin') | |
Begin a transaction, committing any previously open transaction. | |
immediateCommit ($fname= 'Database::immediateCommit') | |
Commit transaction, if one is open. | |
duplicateTableStructure ($oldName, $newName, $temporary=false, $fname= 'Database::duplicateTableStructure') | |
Creates a new table with structure copied from existing table Note that unlike most database abstraction functions, this function does not automatically append database prefix, because it works at a lower abstraction level. | |
timestamp ($ts=0) | |
Return MW-style timestamp used for MySQL schema. | |
timestampOrNull ($ts=null) | |
Local database timestamp format or null. | |
resultObject ($result) | |
aggregateValue ($valuedata, $valuename='value') | |
Return aggregated value alias. | |
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. | |
getServerVersion () | |
A string describing the current software version, like from mysql_get_server_info(). | |
ping () | |
Ping the server and try to reconnect if it there is no connection. | |
getLag () | |
Get slave lag. | |
getStatus ($which="%") | |
Get status information from SHOW STATUS in an associative array. | |
maxListLen () | |
Return the maximum number of items allowed in a list, or 0 for unlimited. | |
encodeBlob ($b) | |
decodeBlob ($b) | |
setTimeout ($timeout) | |
Override database's default connection timeout. | |
sourceFile ($filename, $lineCallback=false, $resultCallback=false) | |
Read and execute SQL commands from a file. | |
sourceStream ($fp, $lineCallback=false, $resultCallback=false) | |
Read and execute commands from an open file handle Returns true on success, error string or exception on failure (depending on object's error ignore settings). | |
buildConcat ($stringList) | |
Build a concatenation list to feed into a SQL query. | |
lock ($lockName, $method, $timeout=5) | |
Acquire a named lock. | |
unlock ($lockName, $method) | |
Release a lock. | |
lockTables ($read, $write, $method, $lowPriority=true) | |
Lock specific tables. | |
unlockTables ($method) | |
Unlock specific tables. | |
getSearchEngine () | |
Get search engine class. | |
setBigSelects ($value=true) | |
Allow or deny "big selects" for this session only. | |
Static Public Member Functions | |
static | newFromParams ($server, $user, $password, $dbName, $failFunction=false, $flags=0) |
Same as new DatabaseMysql( . | |
static | generalizeSQL ($sql) |
Removes most variables from an SQL query and replaces them with X or N for numbers. | |
static | patchPath ($patch) |
Get the full path of a patch file. | |
Protected Member Functions | |
installErrorHandler () | |
restoreErrorHandler () | |
connectionErrorHandler ($errno, $errstr) | |
replaceVars ($ins) | |
Replace variables in sourced SQL. | |
tableNameCallback ($matches) | |
Table name callback. | |
indexNameCallback ($matches) | |
Index name callback. | |
Protected Attributes | |
$mLastQuery = '' | |
$mDoneWrites = false | |
$mPHPError = false | |
$mServer | |
$mUser | |
$mPassword | |
$mConn = null | |
$mDBname | |
$mOpened = false | |
$mFailFunction | |
$mTablePrefix | |
$mFlags | |
$mTrxLevel = 0 | |
$mErrorCount = 0 | |
$mLBInfo = array() | |
$mFakeSlaveLag = null | |
$mFakeMaster = false | |
$mDefaultBigSelects = null | |
Private Member Functions | |
doQuery ($sql) | |
The DBMS-dependent part of query(). | |
tableNamesWithUseIndexOrJOIN ($tables, $use_index=array(), $join_conds=array()) |
Definition at line 22 of file Database.php.
DatabaseBase::__construct | ( | $ | server = false , |
|
$ | user = false , |
|||
$ | password = false , |
|||
$ | dbName = false , |
|||
$ | failFunction = false , |
|||
$ | flags = 0 , |
|||
$ | tablePrefix = 'get from global' | |||
) |
Constructor.
$server | String: database server host | |
$user | String: database user name | |
$password | String: database user password | |
$dbName | String: database name | |
$failFunction | ||
$flags | ||
$tablePrefix | String: database table prefixes. By default use the prefix gave in LocalSettings.php |
Reimplemented in DatabaseMssql, DatabaseOracle, and DatabaseMock.
Definition at line 306 of file Database.php.
References $wgCommandLineMode, $wgDBprefix, $wgOut, and open().
DatabaseBase::addQuotes | ( | $ | s | ) |
If it's a string, adds quotes and backslashes Otherwise returns as-is.
Reimplemented in DatabaseIbm_db2, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 1485 of file Database.php.
References $s, and strencode().
Referenced by fillPreparedArg(), DatabaseMysql::lock(), makeList(), masterPosWait(), and DatabaseMysql::unlock().
DatabaseBase::affectedRows | ( | ) | [abstract] |
Get the number of rows affected by the last write query See mysql_affected_rows() for more details.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
DatabaseBase::aggregateValue | ( | $ | valuedata, | |
$ | valuename = 'value' | |||
) |
Return aggregated value alias.
Reimplemented in DatabaseOracle, and DatabasePostgres.
Definition at line 2050 of file Database.php.
DatabaseBase::anyChar | ( | ) |
Returns a token for buildLike() that denotes a '_' to be used in a LIKE query.
Definition at line 1540 of file Database.php.
DatabaseBase::anyString | ( | ) |
Returns a token for buildLike() that denotes a '' to be used in a LIKE query.
Definition at line 1547 of file Database.php.
DatabaseBase::begin | ( | $ | fname = 'Database::begin' |
) |
Begin a transaction, committing any previously open transaction.
Reimplemented in DatabaseIbm_db2, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 1960 of file Database.php.
References $fname, and query().
Referenced by deadlockLoop(), immediateBegin(), and query().
DatabaseBase::bitAnd | ( | $ | fieldLeft, | |
$ | fieldRight | |||
) |
DatabaseBase::bitNot | ( | $ | field | ) |
Bitwise operations.
Reimplemented in DatabaseIbm_db2, and DatabaseOracle.
Definition at line 1280 of file Database.php.
DatabaseBase::bitOr | ( | $ | fieldLeft, | |
$ | fieldRight | |||
) |
DatabaseBase::bufferResults | ( | $ | buffer = null |
) |
Turns buffering of SQL result sets on (true) or off (false).
Default is "on" and it should not be changed without good reasons.
Definition at line 76 of file Database.php.
References wfSetBit().
Referenced by DatabaseMysql::doQuery().
DatabaseBase::buildConcat | ( | $ | stringList | ) |
Build a concatenation list to feed into a SQL query.
$stringList | Array: list of raw SQL expressions; caller is responsible for any quoting |
Reimplemented in DatabaseIbm_db2, DatabasePostgres, and DatabaseSqlite.
Definition at line 2319 of file Database.php.
DatabaseBase::buildLike | ( | ) |
LIKE statement wrapper, receives a variable-length argument list with parts of pattern to match containing either string literals that will be escaped or tokens returned by anyChar() or anyString().
Alternatively, the function could be provided with an array of aforementioned parameters.
Example: $dbr->buildLike( 'My_page_title/', $dbr->anyString() ) returns a LIKE clause that searches for subpages of 'My page title'. Alternatively: $pattern = array( 'My_page_title/', $dbr->anyString() ); $query .= $dbr->buildLike( $pattern );
@ return String: fully built LIKE statement
Reimplemented in DatabaseSqlite.
Definition at line 1520 of file Database.php.
References $s, and escapeLike().
DatabaseBase::cascadingDeletes | ( | ) |
Returns true if this database supports (and uses) cascading deletes.
Reimplemented in DatabaseIbm_db2, DatabaseOracle, and DatabasePostgres.
Definition at line 154 of file Database.php.
DatabaseBase::cleanupTriggers | ( | ) |
Returns true if this database supports (and uses) triggers (e.g.
on the page table)
Reimplemented in DatabaseIbm_db2, DatabaseOracle, and DatabasePostgres.
Definition at line 161 of file Database.php.
DatabaseBase::clearFlag | ( | $ | flag | ) |
Clear a flag for this connection.
$flag,: | same as setFlag()'s $flag param |
Definition at line 258 of file Database.php.
DatabaseBase::close | ( | ) |
Closes a database connection.
if it is open : commits any open transactions
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 399 of file Database.php.
DatabaseBase::commit | ( | $ | fname = 'Database::commit' |
) |
End a transaction.
Reimplemented in DatabaseIbm_db2, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 1968 of file Database.php.
References $fname, and query().
Referenced by DatabaseMysql::close(), DatabaseMssql::close(), immediateCommit(), and masterPosWait().
DatabaseBase::conditional | ( | $ | cond, | |
$ | trueVal, | |||
$ | falseVal | |||
) |
Returns an SQL expression for a simple conditional.
This doesn't need to be overridden unless CASE isn't supported in your DBMS.
$cond | String: SQL expression which will result in a boolean value | |
$trueVal | String: SQL expression to return if true | |
$falseVal | String: SQL expression to return if false |
Definition at line 1778 of file Database.php.
Referenced by DatabaseMssql::setup_database().
DatabaseBase::connectionErrorHandler | ( | $ | errno, | |
$ | errstr | |||
) | [protected] |
Definition at line 389 of file Database.php.
DatabaseBase::dataSeek | ( | $ | res, | |
$ | row | |||
) | [abstract] |
Change the position of the cursor in a result object See mysql_data_seek().
$res | Mixed: A SQL result | |
$row | Mixed: Either MySQL row or ResultWrapper |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
DatabaseBase::deadlockLoop | ( | ) |
Perform a deadlock-prone transaction.
This function invokes a callback function to perform a set of write queries. If a deadlock occurs during the processing, the transaction will be rolled back and the callback function will be called again.
Usage: $dbw->deadlockLoop( callback, ... );
Extra arguments are passed through to the specified callback function.
Returns whatever the callback function returned on its successful, iteration, or false on error, for example if the retry limit was reached.
Reimplemented in DatabaseSqlite.
Definition at line 1835 of file Database.php.
References $fname, begin(), ignoreErrors(), lastErrno(), lastError(), lastQuery(), query(), reportQueryError(), and wasDeadlock().
DatabaseBase::debug | ( | $ | debug = null |
) |
Boolean, controls output of large amounts of debug information.
Definition at line 68 of file Database.php.
References wfSetBit().
Referenced by query().
DatabaseBase::decodeBlob | ( | $ | b | ) |
Reimplemented in DatabaseIbm_db2, DatabasePostgres, and DatabaseSqlite.
Definition at line 2144 of file Database.php.
DatabaseBase::delete | ( | $ | table, | |
$ | conds, | |||
$ | fname = 'Database::delete' | |||
) |
DELETE query wrapper.
Use $conds == "*" to delete all rows
Reimplemented in DatabaseIbm_db2, and DatabaseOracle.
Definition at line 1672 of file Database.php.
References $fname, makeList(), query(), and tableName().
DatabaseBase::deleteJoin | ( | $ | delTable, | |
$ | joinTable, | |||
$ | delVar, | |||
$ | joinVar, | |||
$ | conds, | |||
$ | fname = 'Database::deleteJoin' | |||
) |
DELETE where the condition is a join MySQL does this with a multi-table DELETE syntax, PostgreSQL does it with sub-selects.
For safety, an empty $conds will not delete everything. If you want to delete all rows where the join condition matches, set $conds='*'
DO NOT put the join condition in $conds
$delTable | String: The table to delete from. | |
$joinTable | String: The other table. | |
$delVar | String: The variable to join on, in the first table. | |
$joinVar | String: The variable to join on, in the second table. | |
$conds | Array: Condition array of field names mapped to variables, ANDed together in the WHERE clause | |
$fname | String: Calling function name (use __METHOD__) for logs/profiling |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, and DatabasePostgres.
Definition at line 1622 of file Database.php.
References $fname, makeList(), query(), and tableName().
DatabaseBase::doneWrites | ( | ) |
Returns true if the connection may have been used for write queries.
Should return true if unsure.
Definition at line 229 of file Database.php.
DatabaseBase::doQuery | ( | $ | sql | ) | [abstract, private] |
The DBMS-dependent part of query().
$sql | String: SQL query. |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
Referenced by masterPosWait(), and query().
DatabaseBase::duplicateTableStructure | ( | $ | oldName, | |
$ | newName, | |||
$ | temporary = false , |
|||
$ | fname = 'Database::duplicateTableStructure' | |||
) |
Creates a new table with structure copied from existing table Note that unlike most database abstraction functions, this function does not automatically append database prefix, because it works at a lower abstraction level.
$oldName | String: name of table whose structure should be copied | |
$newName | String: name of table to be created | |
$temporary | Boolean: whether the new table should be temporary |
Reimplemented in DatabaseMysql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 2009 of file Database.php.
DatabaseBase::encodeBlob | ( | $ | b | ) |
Reimplemented in DatabaseIbm_db2, DatabasePostgres, and DatabaseSqlite.
Definition at line 2140 of file Database.php.
DatabaseBase::errorCount | ( | $ | count = null |
) |
Number of errors logged, only useful when errors are ignored.
Definition at line 106 of file Database.php.
References wfSetVar().
DatabaseBase::escapeLike | ( | $ | s | ) |
Escape string for safe LIKE usage.
WARNING: you should almost never use this function directly, instead use buildLike() that escapes everything automatically
Definition at line 1502 of file Database.php.
References $s, and strencode().
Referenced by buildLike().
DatabaseBase::estimateRowCount | ( | $ | table, | |
$ | vars = '*' , |
|||
$ | conds = '' , |
|||
$ | fname = 'Database::estimateRowCount' , |
|||
$ | options = array() | |||
) |
Estimate rows in dataset Returns estimated count - not necessarily an accurate estimate across different databases, so use sparingly Takes same arguments as Database::select().
string | $table table name | |
array | $vars unused | |
array | $conds filters on the table | |
string | $fname function name for profiling | |
array | $options options for select |
Reimplemented in DatabaseMysql, and DatabasePostgres.
Definition at line 980 of file Database.php.
References $fname, $options, $res, $rows, fetchRow(), freeResult(), and select().
DatabaseBase::execute | ( | $ | prepared, | |
$ | args = null | |||
) |
Execute a prepared query with the various arguments.
$prepared | String: the prepared sql | |
$args | Mixed: Either an array here, or put scalars as varargs |
Reimplemented in DatabaseIbm_db2.
Definition at line 606 of file Database.php.
References fillPrepared(), and query().
Referenced by safeQuery().
DatabaseBase::failFunction | ( | $ | function = null |
) |
Fail function, takes a Database as a parameter Set to false for default, 1 for ignore errors.
Definition at line 53 of file Database.php.
References wfSetVar().
DatabaseBase::fetchObject | ( | $ | res | ) | [abstract] |
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.
$res | SQL result object as returned from Database::query(), etc. |
DBUnexpectedError | Thrown if the database returns an error |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
Referenced by fieldExists(), getLag(), getMasterPos(), getSlavePos(), getStatus(), indexInfo(), selectRow(), and textFieldSize().
DatabaseBase::fetchRow | ( | $ | res | ) | [abstract] |
Fetch the next row from the given result object, in associative array form.
Fields are retrieved with $row['fieldname'].
$res | SQL result object as returned from Database::query(), etc. |
DBUnexpectedError | Thrown if the database returns an error |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
Referenced by estimateRowCount(), masterPosWait(), and selectField().
DatabaseBase::fieldExists | ( | $ | table, | |
$ | field, | |||
$ | fname = 'Database::fieldExists' | |||
) |
Determines whether a field exists in a table Usually aborts on failure If errors are explicitly ignored, returns NULL on failure.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 1022 of file Database.php.
References $fname, $res, fetchObject(), query(), and tableName().
DatabaseBase::fieldInfo | ( | $ | table, | |
$ | field | |||
) | [abstract] |
mysql_fetch_field() wrapper Returns false if the field doesn't exist
$table | ||
$field |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
DatabaseBase::fieldName | ( | $ | res, | |
$ | n | |||
) | [abstract] |
Get a field name in a result object See documentation for mysql_field_name(): http://www.php.net/mysql_field_name.
$res | Mixed: A SQL result | |
$n | Integer |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
DatabaseBase::fieldType | ( | $ | res, | |
$ | index | |||
) |
mysql_field_type() wrapper
Reimplemented in DatabaseIbm_db2, DatabaseMssql, and DatabasePostgres.
Definition at line 1110 of file Database.php.
References $res.
DatabaseBase::fillPrepared | ( | $ | preparedQuery, | |
$ | args | |||
) |
For faking prepared SQL statements on DBs that don't support it directly.
$preparedQuery | String: a 'preparable' SQL statement | |
$args | Array of arguments to fill it with |
Reimplemented in DatabaseIbm_db2.
Definition at line 641 of file Database.php.
Referenced by execute().
DatabaseBase::fillPreparedArg | ( | $ | matches | ) |
preg_callback func for fillPrepared() The arguments should be in $this->preparedArgs and must not be touched while we're doing this.
$matches | Array |
Reimplemented in DatabaseIbm_db2.
Definition at line 657 of file Database.php.
References addQuotes().
DatabaseBase::freePrepared | ( | $ | prepared | ) |
Reimplemented in DatabaseIbm_db2.
Definition at line 597 of file Database.php.
Referenced by safeQuery().
DatabaseBase::freeResult | ( | $ | res | ) |
Free a result object.
$res | Mixed: A SQL result |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 679 of file Database.php.
Referenced by estimateRowCount(), indexInfo(), masterPosWait(), selectField(), selectRow(), tableExists(), and textFieldSize().
DatabaseBase::functionalIndexes | ( | ) |
Returns true if this database can use functional indexes.
Reimplemented in DatabaseIbm_db2, and DatabasePostgres.
Definition at line 214 of file Database.php.
static DatabaseBase::generalizeSQL | ( | $ | sql | ) | [static] |
Removes most variables from an SQL query and replaces them with X or N for numbers.
It's only slightly flawed. Don't use for anything important.
$sql | String: A SQL Query |
Definition at line 997 of file Database.php.
Referenced by query().
DatabaseBase::getDBname | ( | ) |
Get the current DB name.
Reimplemented in DatabaseOracle, and DatabasePostgres.
Definition at line 1308 of file Database.php.
DatabaseBase::getFlag | ( | $ | flag | ) |
Returns a boolean whether the flag $flag is set for this connection.
$flag,: | same as setFlag()'s $flag param |
Definition at line 268 of file Database.php.
DatabaseBase::getLag | ( | ) |
Get slave lag.
At the moment, this will only work if the DB user has the PROCESS privilege
Reimplemented in DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 2086 of file Database.php.
References $res, fetchObject(), query(), and wfDebug().
DatabaseBase::getLBInfo | ( | $ | name = null |
) |
Properties passed down from the server info array of the load balancer.
Definition at line 117 of file Database.php.
References $name.
Referenced by query().
DatabaseBase::getMasterPos | ( | ) |
Get the position of the master from SHOW MASTER STATUS.
Definition at line 1944 of file Database.php.
References $res, fetchObject(), and query().
DatabaseBase::getProperty | ( | $ | name | ) |
DatabaseBase::getSearchEngine | ( | ) |
Get search engine class.
All subclasses of this need to implement this if they wish to use searching.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 2379 of file Database.php.
DatabaseBase::getServer | ( | ) |
Get the server hostname or IP address.
Reimplemented in DatabaseOracle, and DatabasePostgres.
Definition at line 1315 of file Database.php.
DatabaseBase::getServerVersion | ( | ) | [abstract] |
A string describing the current software version, like from mysql_get_server_info().
Will be listed on Special:Version, etc.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
DatabaseBase::getSlavePos | ( | ) |
Get the position of the master from SHOW SLAVE STATUS.
Definition at line 1925 of file Database.php.
References $res, fetchObject(), query(), and wfDebug().
DatabaseBase::getSoftwareLink | ( | ) | [abstract] |
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.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
DatabaseBase::getStatus | ( | $ | which = "%" |
) |
Get status information from SHOW STATUS in an associative array.
Reimplemented in DatabaseIbm_db2.
Definition at line 2124 of file Database.php.
References $res, fetchObject(), and query().
DatabaseBase::getType | ( | ) | [abstract] |
Get the type of the DBMS, as it appears in $wgDBtype.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
DatabaseBase::getWikiID | ( | ) |
DatabaseBase::ignoreErrors | ( | $ | ignoreErrors = null |
) |
Turns on (false) or off (true) the automatic generation and sending of a "we're sorry, but there has been a database error" page on database errors.
Default is on (false). When turned off, the code should use lastErrno() and lastError() to handle the situation as appropriate.
Definition at line 91 of file Database.php.
References wfSetBit().
Referenced by deadlockLoop(), DatabasePostgres::reportQueryError(), reportQueryError(), and tableExists().
DatabaseBase::immediateBegin | ( | $ | fname = 'Database::immediateBegin' |
) |
Begin a transaction, committing any previously open transaction.
Definition at line 1986 of file Database.php.
References begin().
DatabaseBase::immediateCommit | ( | $ | fname = 'Database::immediateCommit' |
) |
Commit transaction, if one is open.
Reimplemented in DatabaseOracle, and DatabasePostgres.
Definition at line 1994 of file Database.php.
References commit().
DatabaseBase::implicitGroupby | ( | ) |
Returns true if this database does an implicit sort when doing GROUP BY.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 183 of file Database.php.
DatabaseBase::implicitOrderby | ( | ) |
Returns true if this database does an implicit order by when the column has an index For example: SELECT page_title FROM page LIMIT 1.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, and DatabasePostgres.
Definition at line 191 of file Database.php.
DatabaseBase::indexExists | ( | $ | table, | |
$ | index, | |||
$ | fname = 'Database::indexExists' | |||
) |
Determines whether an index exists Usually aborts on failure If errors are explicitly ignored, returns NULL on failure.
Definition at line 1045 of file Database.php.
References $fname, and indexInfo().
DatabaseBase::indexInfo | ( | $ | table, | |
$ | index, | |||
$ | fname = 'Database::indexInfo' | |||
) |
Get information about an index into an object Returns false if the index does not exist.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 1059 of file Database.php.
References $fname, $res, $result, fetchObject(), freeResult(), indexName(), query(), and tableName().
Referenced by indexExists(), and indexUnique().
DatabaseBase::indexName | ( | $ | index | ) |
Get the name of an index in a given table.
Reimplemented in DatabaseSqlite.
Definition at line 1460 of file Database.php.
Referenced by indexInfo(), indexNameCallback(), DatabasePostgres::indexUnique(), and DatabaseMysql::useIndexClause().
DatabaseBase::indexNameCallback | ( | $ | matches | ) | [protected] |
DatabaseBase::indexUnique | ( | $ | table, | |
$ | index | |||
) |
Determines if a given index is unique.
Definition at line 1120 of file Database.php.
References indexInfo().
DatabaseBase::insert | ( | $ | table, | |
$ | a, | |||
$ | fname = 'Database::insert' , |
|||
$ | options = array() | |||
) |
INSERT wrapper, inserts an array into a table.
$a may be a single associative array, or an array of these with numeric keys, for multi-row insert.
Usually aborts on failure If errors are explicitly ignored, returns success
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 1137 of file Database.php.
References $fname, $keys, $options, makeList(), query(), and tableName().
DatabaseBase::insertId | ( | ) | [abstract] |
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();
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
DatabaseBase::insertSelect | ( | $ | destTable, | |
$ | srcTable, | |||
$ | varMap, | |||
$ | conds, | |||
$ | fname = 'Database::insertSelect' , |
|||
$ | insertOptions = array() , |
|||
$ | selectOptions = array() | |||
) |
INSERT SELECT wrapper $varMap must be an associative array of the form array( 'dest1' => 'source1', .
..) Source items may be literals rather than field names, but strings should be quoted with Database::addQuotes() $conds may be "*" to copy the whole table srcTable may be an array of tables.
Reimplemented in DatabaseMssql, DatabaseOracle, and DatabasePostgres.
Definition at line 1691 of file Database.php.
References $fname, makeList(), makeSelectOptions(), query(), and tableName().
DatabaseBase::installErrorHandler | ( | ) | [protected] |
Definition at line 369 of file Database.php.
Referenced by DatabasePostgres::open(), and DatabaseMysql::open().
DatabaseBase::isOpen | ( | ) |
Is a connection to the database open?
Reimplemented in DatabaseIbm_db2.
Definition at line 235 of file Database.php.
DatabaseBase::isWriteQuery | ( | $ | sql | ) |
Determine whether a query writes to the DB.
Should return true if unsure.
Definition at line 429 of file Database.php.
Referenced by query().
DatabaseBase::lastErrno | ( | ) | [abstract] |
Get the last error number See mysql_errno().
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
Referenced by deadlockLoop(), and query().
DatabaseBase::lastError | ( | ) | [abstract] |
Get a description of the last error See mysql_error() for more details.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
Referenced by deadlockLoop(), query(), reportConnectionError(), and sourceStream().
DatabaseBase::lastQuery | ( | ) |
Return the last query that went through Database::query().
Definition at line 222 of file Database.php.
Referenced by deadlockLoop(), and MockDatabaseSqlite::query().
DatabaseBase::limitResult | ( | $ | sql, | |
$ | limit, | |||
$ | offset = false | |||
) |
Construct a LIMIT query with optional offset.
This is used for query pages. The SQL should be adjusted so that only the first $limit rows are returned. If $offset is provided as well, then the first $offset rows should be discarded, and the next $limit rows should be returned. If the result of the query is not ordered, then the rows to be returned are theoretically arbitrary.
$sql is expected to be a SELECT, if that makes a difference. For UPDATE, limitResultForUpdate should be used.
The version provided by default works in MySQL and SQLite. It will very likely need to be overridden for most other DBMSes.
$sql | String: SQL query we will append the limit too | |
$limit | Integer: the SQL limit | |
$offset | Integer the SQL offset (default false) |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, and DatabasePostgres.
Definition at line 1735 of file Database.php.
Referenced by DatabaseSqlite::limitResultForUpdate(), limitResultForUpdate(), and selectSQLText().
DatabaseBase::limitResultForUpdate | ( | $ | sql, | |
$ | num | |||
) |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 1743 of file Database.php.
References limitResult().
DatabaseBase::lock | ( | $ | lockName, | |
$ | method, | |||
$ | timeout = 5 | |||
) |
Acquire a named lock.
Abstracted from Filestore::lock() so child classes can implement for their own needs.
$lockName | String: Name of lock to aquire | |
$method | String: Name of method calling us |
Reimplemented in DatabaseMysql.
Definition at line 2333 of file Database.php.
DatabaseBase::lockTables | ( | $ | read, | |
$ | write, | |||
$ | method, | |||
$ | lowPriority = true | |||
) |
Lock specific tables.
$read | Array of tables to lock for read access | |
$write | Array of tables to lock for write access | |
$method | String name of caller | |
$lowPriority | bool Whether to indicate writes to be LOW PRIORITY |
Reimplemented in DatabaseMysql.
Definition at line 2360 of file Database.php.
DatabaseBase::lowPriorityOption | ( | ) |
A string to insert into queries to show that they're low-priority, like MySQL's LOW_PRIORITY.
If no such feature exists, return an empty string and nothing bad should happen.
Reimplemented in DatabaseMssql, and DatabaseMysql.
Definition at line 1663 of file Database.php.
Referenced by makeUpdateOptions().
DatabaseBase::makeList | ( | $ | a, | |
$ | mode = LIST_COMMA | |||
) |
Makes an encoded list of strings from an array $mode: LIST_COMMA - comma separated, no field names LIST_AND - ANDed WHERE clause (without the WHERE) LIST_OR - ORed WHERE clause (without the WHERE) LIST_SET - comma separated with field names, like a SET clause LIST_NAMES - comma separated field names.
Reimplemented in DatabaseIbm_db2.
Definition at line 1224 of file Database.php.
References $mode, and addQuotes().
Referenced by delete(), DatabasePostgres::deleteJoin(), DatabaseMssql::deleteJoin(), deleteJoin(), DatabasePostgres::insert(), insert(), DatabasePostgres::insertSelect(), DatabaseMssql::insertSelect(), insertSelect(), DatabaseMssql::makeListWithoutNulls(), DatabasePostgres::replace(), DatabaseMssql::replace(), replace(), DatabaseMssql::select(), selectSQLText(), tableNamesWithUseIndexOrJOIN(), DatabaseMssql::update(), and update().
DatabaseBase::makeSelectOptions | ( | $ | options | ) |
Returns an optional USE INDEX clause to go after the table, and a string to go at the end of the query.
$options | Array: associative array of options to be turned into an SQL query, valid keys are listed in the function. |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 814 of file Database.php.
References $options, and useIndexClause().
Referenced by insertSelect(), and selectSQLText().
DatabaseBase::makeUpdateOptions | ( | $ | options | ) |
Make UPDATE options for the Database::update function.
$options | Array: The options passed to Database::update |
Reimplemented in DatabaseMssql.
Definition at line 1181 of file Database.php.
References $options, and lowPriorityOption().
Referenced by DatabaseIbm_db2::update(), and update().
DatabaseBase::masterPosWait | ( | MySQLMasterPos $ | pos, | |
$ | timeout | |||
) |
Do a SELECT MASTER_POS_WAIT().
$pos | MySQLMasterPos object | |
$timeout | Integer: the maximum number of seconds to wait for synchronisation |
Definition at line 1880 of file Database.php.
References $fname, $res, addQuotes(), commit(), doQuery(), fetchRow(), freeResult(), wfDebug(), wfProfileIn(), and wfProfileOut().
DatabaseBase::maxListLen | ( | ) |
Return the maximum number of items allowed in a list, or 0 for unlimited.
Definition at line 2136 of file Database.php.
static DatabaseBase::newFromParams | ( | $ | server, | |
$ | user, | |||
$ | password, | |||
$ | dbName, | |||
$ | failFunction = false , |
|||
$ | flags = 0 | |||
) | [static] |
Same as new DatabaseMysql( .
.. ), kept for backward compatibility
$server | String: database server host | |
$user | String: database user name | |
$password | String: database user password | |
$dbName | String: database name | |
failFunction | ||
$flags |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 354 of file Database.php.
Referenced by convertLinks(), ConvertLinks::createTempTable(), createTempTable(), and ConvertLinks::execute().
DatabaseBase::nextSequenceValue | ( | $ | seqName | ) |
Returns an appropriately quoted sequence value for inserting a new row.
MySQL has autoincrement fields, so this is just NULL. But the PostgreSQL subclass will return an integer, and save the value for insertId()
Reimplemented in DatabaseIbm_db2, DatabaseOracle, and DatabasePostgres.
Definition at line 1556 of file Database.php.
DatabaseBase::numFields | ( | $ | res | ) | [abstract] |
Get the number of fields in a result object See documentation for mysql_num_fields().
$res | Mixed: A SQL result |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
DatabaseBase::numRows | ( | $ | res | ) | [abstract] |
Get the number of rows in a result object.
$res | Mixed: A SQL result |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
Referenced by selectField(), and selectRow().
DatabaseBase::open | ( | $ | server, | |
$ | user, | |||
$ | password, | |||
$ | dbName | |||
) | [abstract] |
Usually aborts on failure If the failFunction is set to a non-zero integer, returns success.
$server | String: database server host | |
$user | String: database user name | |
$password | String: database user password | |
$dbName | String: database name |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
Referenced by __construct().
static DatabaseBase::patchPath | ( | $ | patch | ) | [static] |
Get the full path of a patch file.
Originally based on archive() from updaters.inc. Keep in mind this always returns a patch, as it fails back to MySQL if no DB-specific patch can be found
$patch | String The name of the patch, like patch-something.sql |
Definition at line 2197 of file Database.php.
References $IP, and $wgDBtype.
Referenced by PatchSql::execute().
DatabaseBase::ping | ( | ) |
Ping the server and try to reconnect if it there is no connection.
Reimplemented in DatabaseIbm_db2, and DatabaseMysql.
Definition at line 2077 of file Database.php.
Referenced by query().
DatabaseBase::prepare | ( | $ | sql, | |
$ | func = 'Database::prepare' | |||
) |
Intended to be compatible with the PEAR::DB wrapper functions.
http://pear.php.net/manual/en/package.database.db.intro-execute.php
? = scalar value, quoted as necessary ! = raw SQL bit (a function for instance) & = filename; reads the file and inserts as a blob (we don't use this though...)
Reimplemented in DatabaseIbm_db2.
Definition at line 590 of file Database.php.
Referenced by safeQuery().
DatabaseBase::query | ( | $ | sql, | |
$ | fname = '' , |
|||
$ | tempIgnore = false | |||
) |
Usually aborts on failure.
If errors are explicitly ignored, returns success.
$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? |
DBQueryError | Thrown when the database returns an error of any kind |
Reimplemented in MockDatabaseSqlite.
Definition at line 445 of file Database.php.
References $fname, $wgRequestTime, $wgUser, begin(), debug(), doQuery(), generalizeSQL(), getLBInfo(), isWriteQuery(), lastErrno(), lastError(), ping(), reportQueryError(), resultObject(), trxLevel(), wasErrorReissuable(), wfDebug(), wfLogDBError(), wfProfileIn(), and wfProfileOut().
Referenced by DatabasePostgres::begin(), begin(), DatabasePostgres::commit(), commit(), DatabasePostgres::constraintExists(), DatabasePostgres::currentSequenceValue(), deadlockLoop(), DatabaseIbm_db2::delete(), delete(), DatabasePostgres::deleteJoin(), DatabaseMssql::deleteJoin(), DatabaseIbm_db2::deleteJoin(), deleteJoin(), DatabaseSqlite::duplicateTableStructure(), DatabasePostgres::duplicateTableStructure(), DatabaseMysql::duplicateTableStructure(), execute(), DatabasePostgres::fieldExists(), DatabaseMssql::fieldExists(), DatabaseIbm_db2::fieldExists(), fieldExists(), DatabaseSqlite::fieldInfo(), DatabaseMysql::fieldInfo(), DatabaseMssql::fieldInfo(), DatabaseSqlite::getFulltextSearchModule(), getLag(), getMasterPos(), getSlavePos(), getStatus(), DatabaseSqlite::indexInfo(), DatabasePostgres::indexInfo(), DatabaseMssql::indexInfo(), DatabaseIbm_db2::indexInfo(), indexInfo(), DatabasePostgres::indexUnique(), DatabaseIbm_db2::indexUnique(), DatabasePostgres::insert(), DatabaseMssql::insert(), insert(), DatabasePostgres::insertSelect(), DatabaseMssql::insertSelect(), insertSelect(), DatabaseMysql::lock(), DatabaseMysql::lockTables(), DatabasePostgres::nextSequenceValue(), DatabaseMysql::open(), DatabasePostgres::queryIgnore(), DatabasePostgres::relationExists(), DatabasePostgres::replace(), DatabaseMssql::replace(), DatabaseIbm_db2::replace(), replace(), rollback(), DatabasePostgres::schemaExists(), DatabaseMssql::select(), select(), DatabaseMssql::set(), set(), DatabaseMysql::setBigSelects(), DatabaseMysql::setTimeout(), DatabaseSqlite::setup_database(), DatabasePostgres::setup_database(), DatabaseMssql::setup_database(), sourceStream(), DatabaseMssql::tableExists(), DatabaseIbm_db2::tableExists(), tableExists(), DatabasePostgres::textFieldSize(), DatabaseMssql::textFieldSize(), DatabaseIbm_db2::textFieldSize(), textFieldSize(), DatabasePostgres::triggerExists(), DatabaseMysql::unlock(), DatabaseMysql::unlockTables(), DatabaseMssql::update(), DatabaseIbm_db2::update(), and update().
DatabaseBase::realTimestamps | ( | ) |
Returns true if this database uses timestamps rather than integers.
Reimplemented in DatabaseIbm_db2, DatabaseOracle, and DatabasePostgres.
Definition at line 176 of file Database.php.
DatabaseBase::replace | ( | $ | table, | |
$ | uniqueIndexes, | |||
$ | rows, | |||
$ | fname = 'Database::replace' | |||
) |
REPLACE query wrapper PostgreSQL simulates this with a DELETE followed by INSERT $row is the row to insert, an associative array $uniqueIndexes is an array of indexes.
Each element may be either a field name or an array of field names
It may be more efficient to leave off unique indexes which are unlikely to collide. However if you do this, you run the risk of encountering errors which wouldn't have occurred in MySQL
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 1585 of file Database.php.
References $fname, $rows, makeList(), query(), and tableName().
DatabaseBase::replaceVars | ( | $ | ins | ) | [protected] |
Replace variables in sourced SQL.
Reimplemented in DatabaseOracle, DatabasePostgres, DatabaseSqlite, and MockDatabaseSqlite.
Definition at line 2272 of file Database.php.
Referenced by sourceStream().
DatabaseBase::reportConnectionError | ( | $ | error = 'Unknown error' |
) |
$error | String: fallback error message, used if none is given by MySQL |
Definition at line 407 of file Database.php.
References lastError().
Referenced by DatabaseMysql::open(), DatabaseMssql::open(), and DatabaseIbm_db2::open().
DatabaseBase::reportQueryError | ( | $ | error, | |
$ | errno, | |||
$ | sql, | |||
$ | fname, | |||
$ | tempIgnore = false | |||
) |
$error | String | |
$errno | Integer | |
$sql | String | |
$fname | String | |
$tempIgnore | Boolean |
Reimplemented in DatabaseOracle, and DatabasePostgres.
Definition at line 563 of file Database.php.
References $fname, $ignore, $wgCommandLineMode, ignoreErrors(), wfDebug(), and wfLogDBError().
Referenced by deadlockLoop(), query(), and DatabaseMssql::setup_database().
DatabaseBase::restoreErrorHandler | ( | ) | [protected] |
Definition at line 375 of file Database.php.
Referenced by DatabasePostgres::open(), and DatabaseMysql::open().
DatabaseBase::resultObject | ( | $ | result | ) |
Definition at line 2034 of file Database.php.
References $result.
Referenced by query().
DatabaseBase::rollback | ( | $ | fname = 'Database::rollback' |
) |
Rollback a transaction.
No-op on non-transactional databases.
Reimplemented in DatabaseIbm_db2, and DatabaseSqlite.
Definition at line 1977 of file Database.php.
DatabaseBase::safeQuery | ( | $ | query, | |
$ | args = null | |||
) |
Prepare & execute an SQL statement, quoting and inserting arguments in the appropriate places.
$query | String | |
$args | ... |
Reimplemented in DatabaseIbm_db2.
Definition at line 622 of file Database.php.
References execute(), freePrepared(), and prepare().
DatabaseBase::searchableIPs | ( | ) |
Returns true if this database can do a native search on IP columns e.g.
this works as expected: .. WHERE rc_ip = '127.42.12.102/32';
Reimplemented in DatabaseIbm_db2, DatabaseOracle, and DatabasePostgres.
Definition at line 207 of file Database.php.
DatabaseBase::select | ( | $ | table, | |
$ | vars, | |||
$ | conds = '' , |
|||
$ | fname = 'Database::select' , |
|||
$ | options = array() , |
|||
$ | join_conds = array() | |||
) |
SELECT wrapper.
$table | Mixed: Array or string, table name(s) (prefix auto-added) | |
$vars | Mixed: Array or string, field name(s) to be retrieved | |
$conds | Mixed: Array or string, condition(s) for WHERE | |
$fname | String: Calling function name (use __METHOD__) for logs/profiling | |
$options | Array: Associative array of options (e.g. array('GROUP BY' => 'page_title')), see Database::makeSelectOptions code for list of supported stuff | |
$join_conds | Array: Associative array of table join conditions (optional) (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') ) |
Reimplemented in DatabaseIbm_db2.
Definition at line 871 of file Database.php.
References $fname, $options, query(), and selectSQLText().
Referenced by DatabasePostgres::estimateRowCount(), DatabaseMysql::estimateRowCount(), estimateRowCount(), selectField(), and selectRow().
DatabaseBase::selectDB | ( | $ | db | ) |
Change the current database.
Reimplemented in DatabaseMssql, and DatabaseMysql.
Definition at line 1297 of file Database.php.
DatabaseBase::selectField | ( | $ | table, | |
$ | var, | |||
$ | cond = '' , |
|||
$ | fname = 'Database::selectField' , |
|||
$ | options = array() | |||
) |
Simple SELECT wrapper, returns a single field, input must be encoded Usually aborts on failure If errors are explicitly ignored, returns FALSE on failure.
Reimplemented in DatabaseMssql.
Definition at line 785 of file Database.php.
References $fname, $options, $res, fetchRow(), freeResult(), numRows(), and select().
Referenced by DatabasePostgres::ruleExists(), and DatabaseMysql::setBigSelects().
DatabaseBase::selectRow | ( | $ | table, | |
$ | vars, | |||
$ | conds, | |||
$ | fname = 'Database::selectRow' , |
|||
$ | options = array() , |
|||
$ | join_conds = array() | |||
) |
Single row SELECT wrapper Aborts or returns FALSE on error.
$table | String: table name | |
$vars | String: the selected variables | |
$conds | Array: a condition map, terms are ANDed together. Items with numeric keys are taken to be literal conditions Takes an array of selected variables, and a condition map, which is ANDed e.g: selectRow( "page", array( "page_id" ), array( "page_namespace" => NS_MAIN, "page_title" => "Astronomy" ) ) would return an object where $obj- >page_id is the ID of the Astronomy article | |
$fname | String: Calling function name | |
$options | Array | |
$join_conds | Array |
Reimplemented in DatabaseOracle.
Definition at line 952 of file Database.php.
References $fname, $options, $res, fetchObject(), freeResult(), numRows(), and select().
Referenced by DatabaseSqlite::indexUnique().
DatabaseBase::selectSQLText | ( | $ | table, | |
$ | vars, | |||
$ | conds = '' , |
|||
$ | fname = 'Database::select' , |
|||
$ | options = array() , |
|||
$ | join_conds = array() | |||
) |
SELECT wrapper.
$table | Mixed: Array or string, table name(s) (prefix auto-added) | |
$vars | Mixed: Array or string, field name(s) to be retrieved | |
$conds | Mixed: Array or string, condition(s) for WHERE | |
$fname | String: Calling function name (use __METHOD__) for logs/profiling | |
$options | Array: Associative array of options (e.g. array('GROUP BY' => 'page_title')), see Database::makeSelectOptions code for list of supported stuff | |
$join_conds | Array: Associative array of table join conditions (optional) (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') ) |
Definition at line 890 of file Database.php.
References $options, limitResult(), makeList(), makeSelectOptions(), tableName(), and tableNamesWithUseIndexOrJOIN().
Referenced by select().
DatabaseBase::set | ( | $ | table, | |
$ | var, | |||
$ | value, | |||
$ | cond, | |||
$ | fname = 'Database::set' | |||
) |
Simple UPDATE wrapper Usually aborts on failure If errors are explicitly ignored, returns success.
This function exists for historical reasons, Database::update() has a more standard calling convention and feature set
Reimplemented in DatabaseMssql.
Definition at line 773 of file Database.php.
References $fname, query(), strencode(), and tableName().
DatabaseBase::setBigSelects | ( | $ | value = true |
) |
Allow or deny "big selects" for this session only.
This is done by setting the sql_big_selects session variable.
This is a MySQL-specific feature.
mixed | $value true for allow, false for deny, or "default" to restore the initial value |
Reimplemented in DatabaseMysql.
Definition at line 2391 of file Database.php.
DatabaseBase::setFakeMaster | ( | $ | enabled = true |
) |
Make this connection a fake master.
Reimplemented in DatabaseIbm_db2, DatabaseOracle, and DatabasePostgres.
Definition at line 147 of file Database.php.
DatabaseBase::setFakeSlaveLag | ( | $ | lag | ) |
Set lag time in seconds for a fake slave.
Reimplemented in DatabaseIbm_db2, DatabaseOracle, and DatabasePostgres.
Definition at line 140 of file Database.php.
DatabaseBase::setFlag | ( | $ | flag | ) |
Set a flag for this connection.
$flag | Integer: DBO_* constants from Defines.php:
|
Definition at line 249 of file Database.php.
DatabaseBase::setLBInfo | ( | $ | name, | |
$ | value = null | |||
) |
DatabaseBase::setOutputPage | ( | $ | out | ) |
Output page, used for reporting errors FALSE means discard output.
Definition at line 61 of file Database.php.
References wfDeprecated().
DatabaseBase::setTimeout | ( | $ | timeout | ) |
Override database's default connection timeout.
May be useful for very long batch queries such as full-wiki dumps, where a single query reads out over hours or days. May or may not be necessary for non-MySQL databases. For most purposes, leaving it as a no-op should be fine.
$timeout | Integer in seconds |
Reimplemented in DatabaseMysql.
Definition at line 2156 of file Database.php.
DatabaseBase::sourceFile | ( | $ | filename, | |
$ | lineCallback = false , |
|||
$ | resultCallback = false | |||
) |
Read and execute SQL commands from a file.
Returns true on success, error string or exception on failure (depending on object's error ignore settings)
$filename | String: File name to open | |
$lineCallback | Callback: Optional function called before reading each line | |
$resultCallback | Callback: Optional function called for each MySQL result |
Definition at line 2165 of file Database.php.
References $filename, and sourceStream().
Referenced by DatabaseSqlite::setup_database(), DatabasePostgres::setup_database(), DatabaseMssql::setup_database(), and DatabaseIbm_db2::setup_database().
DatabaseBase::sourceStream | ( | $ | fp, | |
$ | lineCallback = false , |
|||
$ | resultCallback = false | |||
) |
Read and execute commands from an open file handle Returns true on success, error string or exception on failure (depending on object's error ignore settings).
$fp | String: File handle | |
$lineCallback | Callback: Optional function called before reading each line | |
$resultCallback | Callback: Optional function called for each MySQL result |
Reimplemented in DatabaseOracle.
Definition at line 2213 of file Database.php.
References $res, lastError(), query(), and replaceVars().
Referenced by sourceFile().
DatabaseBase::standardSelectDistinct | ( | ) |
Returns true if this database requires that SELECT DISTINCT queries require that all ORDER BY expressions occur in the SELECT list per the SQL92 standard.
Reimplemented in DatabaseMysql.
Definition at line 199 of file Database.php.
DatabaseBase::strencode | ( | $ | s | ) | [abstract] |
Wrapper for addslashes().
$s | String: to be slashed. |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, DatabaseSqlite, and DatabaseMock.
Referenced by addQuotes(), escapeLike(), and set().
DatabaseBase::strictIPs | ( | ) |
Returns true if this database is strict about what can be put into an IP field.
Specifically, it uses a NULL value instead of an empty string.
Reimplemented in DatabaseIbm_db2, DatabaseOracle, and DatabasePostgres.
Definition at line 169 of file Database.php.
DatabaseBase::strreplace | ( | $ | orig, | |
$ | old, | |||
$ | new | |||
) |
Returns a comand for str_replace function in SQL query.
Uses REPLACE() in MySQL
$orig | String: column to modify | |
$old | String: column to seek | |
$new | String: column to replace with |
Definition at line 1790 of file Database.php.
DatabaseBase::tableExists | ( | $ | table | ) |
Query whether a given table exists.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, and DatabaseOracle.
Definition at line 1085 of file Database.php.
References $res, freeResult(), ignoreErrors(), query(), and tableName().
DatabaseBase::tableName | ( | $ | name | ) |
Format a table name ready for use in constructing an SQL query.
This does two important things: it quotes the table names to clean them up, and it adds a table prefix if only given a table name with no quotes.
All functions of this object which require a table name call this function themselves. Pass the canonical name to such functions. This is only needed when calling query() directly.
$name | String: database table name |
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 1332 of file Database.php.
References $name, $wgSharedDB, $wgSharedPrefix, and $wgSharedTables.
Referenced by delete(), deleteJoin(), fieldExists(), DatabaseMysql::fieldInfo(), indexInfo(), insert(), insertSelect(), DatabaseMysql::lockTables(), replace(), selectSQLText(), set(), tableExists(), tableNameCallback(), tableNames(), tableNamesN(), tableNamesWithUseIndexOrJOIN(), textFieldSize(), and update().
DatabaseBase::tableNameCallback | ( | $ | matches | ) | [protected] |
Table name callback.
Definition at line 2303 of file Database.php.
References tableName().
DatabaseBase::tableNames | ( | ) |
Fetch a number of table names into an array This is handy when you need to construct SQL for joins.
Example: extract($dbr->tableNames('user','watchlist')); $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user WHERE wl_user=user_id AND wl_user=$nameWithQuotes";
Definition at line 1393 of file Database.php.
References $name, and tableName().
DatabaseBase::tableNamesN | ( | ) |
Fetch a number of table names into an zero-indexed numerical array This is handy when you need to construct SQL for joins.
Example: list( $user, $watchlist ) = $dbr->tableNamesN('user','watchlist'); $sql = "SELECT wl_namespace,wl_title FROM $watchlist,$user WHERE wl_user=user_id AND wl_user=$nameWithQuotes";
Definition at line 1411 of file Database.php.
References $name, and tableName().
DatabaseBase::tableNamesWithUseIndexOrJOIN | ( | $ | tables, | |
$ | use_index = array() , |
|||
$ | join_conds = array() | |||
) | [private] |
Definition at line 1423 of file Database.php.
References makeList(), tableName(), and useIndexClause().
Referenced by selectSQLText().
DatabaseBase::tablePrefix | ( | $ | prefix = null |
) |
DatabaseBase::textFieldSize | ( | $ | table, | |
$ | field | |||
) |
Returns the size of a text field, or -1 for "unlimited".
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 1640 of file Database.php.
References $res, $size, fetchObject(), freeResult(), query(), and tableName().
DatabaseBase::timestamp | ( | $ | ts = 0 |
) |
Return MW-style timestamp used for MySQL schema.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, and DatabasePostgres.
Definition at line 2016 of file Database.php.
References wfTimestamp().
Referenced by timestampOrNull().
DatabaseBase::timestampOrNull | ( | $ | ts = null |
) |
Local database timestamp format or null.
Reimplemented in DatabaseMssql.
Definition at line 2023 of file Database.php.
References timestamp().
DatabaseBase::trxLevel | ( | $ | level = null |
) |
The current depth of nested transactions.
$level | Integer: , default NULL. |
Definition at line 99 of file Database.php.
References wfSetVar().
Referenced by DatabaseSqlite::close(), DatabaseMysql::close(), DatabaseMssql::close(), DatabaseIbm_db2::close(), and query().
DatabaseBase::unionQueries | ( | $ | sqls, | |
$ | all | |||
) |
Construct a UNION query This is used for providing overload point for other DB abstractions not compatible with the MySQL syntax.
$sqls | Array: SQL statements to combine | |
$all | Boolean: use UNION ALL |
Reimplemented in DatabaseOracle, and DatabaseSqlite.
Definition at line 1764 of file Database.php.
DatabaseBase::unionSupportsOrderAndLimit | ( | ) |
Returns true if current database backend supports ORDER BY or LIMIT for separate subqueries within the UNION construct.
Reimplemented in DatabaseSqlite.
Definition at line 1752 of file Database.php.
DatabaseBase::unlock | ( | $ | lockName, | |
$ | method | |||
) |
Release a lock.
$lockName | String: Name of lock to release | |
$method | String: Name of method calling us |
Reimplemented in DatabaseMysql.
Definition at line 2348 of file Database.php.
DatabaseBase::unlockTables | ( | $ | method | ) |
Unlock specific tables.
$method | String the caller |
Reimplemented in DatabaseMysql.
Definition at line 2369 of file Database.php.
DatabaseBase::update | ( | $ | table, | |
$ | values, | |||
$ | conds, | |||
$ | fname = 'Database::update' , |
|||
$ | options = array() | |||
) |
UPDATE wrapper, takes a condition array and a SET array.
$table | String: The table to UPDATE | |
$values | Array: An array of values to SET | |
$conds | Array: An array of conditions (WHERE). Use '*' to update all rows. | |
$fname | String: The Class::Function calling this function (for the log) | |
$options | Array: An array of UPDATE options, can be one or more of IGNORE, LOW_PRIORITY |
Reimplemented in DatabaseIbm_db2, and DatabaseMssql.
Definition at line 1205 of file Database.php.
References $fname, $options, makeList(), makeUpdateOptions(), query(), and tableName().
DatabaseBase::useIndexClause | ( | $ | index | ) |
USE INDEX clause.
Unlikely to be useful for anything but MySQL. This is only needed because a) MySQL must be as efficient as possible due to its use on Wikipedia, and b) MySQL 4.0 is kind of dumb sometimes about which index to pick. Anyway, other databases might have different indexes on a given table. So don't bother overriding this unless you're MySQL.
Reimplemented in DatabaseMysql.
Definition at line 1568 of file Database.php.
Referenced by DatabaseMssql::makeSelectOptions(), makeSelectOptions(), and tableNamesWithUseIndexOrJOIN().
DatabaseBase::wasDeadlock | ( | ) |
Determines if the last failure was due to a deadlock STUB.
Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.
Definition at line 1798 of file Database.php.
Referenced by deadlockLoop().
DatabaseBase::wasErrorReissuable | ( | ) |
Determines if the last query error was something that should be dealt with by pinging the connection and reissuing the query.
STUB
Reimplemented in DatabaseMysql, and DatabaseSqlite.
Definition at line 1807 of file Database.php.
Referenced by query().
DatabaseBase::wasReadOnlyError | ( | ) |
Determines if the last failure was due to the database being read-only.
STUB
Reimplemented in DatabaseMysql, and DatabaseSqlite.
Definition at line 1815 of file Database.php.
DatabaseBase::$mConn = null [protected] |
Definition at line 32 of file Database.php.
DatabaseBase::$mDBname [protected] |
Definition at line 32 of file Database.php.
DatabaseBase::$mDefaultBigSelects = null [protected] |
Definition at line 42 of file Database.php.
DatabaseBase::$mDoneWrites = false [protected] |
Definition at line 29 of file Database.php.
DatabaseBase::$mErrorCount = 0 [protected] |
Definition at line 39 of file Database.php.
DatabaseBase::$mFailFunction [protected] |
Definition at line 35 of file Database.php.
DatabaseBase::$mFakeMaster = false [protected] |
Definition at line 41 of file Database.php.
DatabaseBase::$mFakeSlaveLag = null [protected] |
Definition at line 41 of file Database.php.
DatabaseBase::$mFlags [protected] |
Definition at line 37 of file Database.php.
DatabaseBase::$mLastQuery = '' [protected] |
Definition at line 28 of file Database.php.
DatabaseBase::$mLBInfo = array() [protected] |
Definition at line 40 of file Database.php.
DatabaseBase::$mOpened = false [protected] |
Definition at line 33 of file Database.php.
DatabaseBase::$mPassword [protected] |
Definition at line 32 of file Database.php.
DatabaseBase::$mPHPError = false [protected] |
Definition at line 30 of file Database.php.
DatabaseBase::$mServer [protected] |
Definition at line 32 of file Database.php.
DatabaseBase::$mTablePrefix [protected] |
Definition at line 36 of file Database.php.
DatabaseBase::$mTrxLevel = 0 [protected] |
Definition at line 38 of file Database.php.
DatabaseBase::$mUser [protected] |
Definition at line 32 of file Database.php.