Database Class Reference
[Database]

Database abstraction object. More...

Inherited by DatabaseIbm_db2, DatabaseMssql, DatabaseMysql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

List of all members.

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.
 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)
 clearFlag ($flag)
 getFlag ($flag)
 getProperty ($name)
 General read-only accessor.
 getWikiID ()
 __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.
 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, based on EXPLAIN output 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.
 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.
 tableNamesWithUseIndexOrJOIN ($tables, $use_index=array(), $join_conds=array())
 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.
 nextSequenceValue ($seqName)
 Returns an appropriately quoted sequence value for inserting a new row.
 useIndexClause ($index)
 USE INDEX clause PostgreSQL doesn't have them and returns "".
 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 ()
 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 This is used for query pages.
 limitResultForUpdate ($sql, $num)
 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.
 wasErrorReissuable ()
 Determines if the last query error was something that should be dealt with by pinging the connection and reissuing the query.
 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.
 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 ()
 getServerVersion ()
 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)
 lock ($lockName, $method)
 Acquire a lock.
 unlock ($lockName, $method)
 Release a lock.
 getSearchEngine ()
 Get search engine class.

Static Public Member Functions

static newFromParams ($server, $user, $password, $dbName, $failFunction=false, $flags=0)
 Same as new Database( .
static generalizeSQL ($sql)
 Removes most variables from an SQL query and replaces them with X or N for numbers.

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

Private Member Functions

 doQuery ($sql)
 The DBMS-dependent part of query().
 makeSelectOptions ($options)
 Returns an optional USE INDEX clause to go after the table, and a string to go at the end of the query.


Detailed Description

Database abstraction object.

Definition at line 22 of file Database.php.


Constructor & Destructor Documentation

Database::__construct ( server = false,
user = false,
password = false,
dbName = false,
failFunction = false,
flags = 0,
tablePrefix = 'get from global' 
)

Constructor.

Parameters:
$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.

Definition at line 269 of file Database.php.

References $flags, $password, $user, $wgCommandLineMode, $wgDBprefix, $wgOut, and open().


Member Function Documentation

Database::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 1632 of file Database.php.

References $s, and strencode().

Referenced by fillPreparedArg(), lock(), makeList(), masterPosWait(), and unlock().

Database::affectedRows (  ) 

Get the number of rows affected by the last write query See mysql_affected_rows() for more details.

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 915 of file Database.php.

Database::aggregateValue ( valuedata,
valuename = 'value' 
)

Return aggregated value alias.

Reimplemented in DatabaseOracle, and DatabasePostgres.

Definition at line 2087 of file Database.php.

Database::begin ( fname = 'Database::begin'  ) 

Begin a transaction, committing any previously open transaction.

Reimplemented in DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 2012 of file Database.php.

References $fname, and query().

Referenced by deadlockLoop(), DatabaseMssql::immediateBegin(), immediateBegin(), and query().

Database::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 75 of file Database.php.

References wfSetBit().

Referenced by doQuery().

Database::buildConcat ( stringList  ) 

Reimplemented in DatabaseIbm_db2, and DatabasePostgres.

Definition at line 2332 of file Database.php.

Database::cascadingDeletes (  ) 

Returns true if this database supports (and uses) cascading deletes.

Reimplemented in DatabaseIbm_db2, DatabaseOracle, and DatabasePostgres.

Definition at line 153 of file Database.php.

Database::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 160 of file Database.php.

Database::clearFlag ( flag  ) 

Definition at line 232 of file Database.php.

Database::close (  ) 

Closes a database connection.

if it is open : commits any open transactions

Returns:
Bool operation success. true if already closed.

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 469 of file Database.php.

References immediateCommit(), and trxLevel().

Referenced by open().

Database::commit ( fname = 'Database::commit'  ) 

End a transaction.

Reimplemented in DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 2020 of file Database.php.

References $fname, and query().

Referenced by DatabaseMssql::immediateCommit(), and immediateCommit().

Database::conditional ( cond,
trueVal,
falseVal 
)

Returns an SQL expression for a simple conditional.

Uses IF on MySQL.

Parameters:
$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
Returns:
String: SQL fragment

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 1840 of file Database.php.

Database::connectionErrorHandler ( errno,
errstr 
) [protected]

Definition at line 459 of file Database.php.

Database::dataSeek ( res,
row 
)

Change the position of the cursor in a result object See mysql_data_seek().

Parameters:
$res Mixed: A SQL result
$row Mixed: Either MySQL row or ResultWrapper

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 871 of file Database.php.

References $res, and $row.

Database::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 1887 of file Database.php.

References $args, $error, $fname, $sql, begin(), ignoreErrors(), lastErrno(), lastError(), lastQuery(), query(), reportQueryError(), and wasDeadlock().

Database::debug ( debug = NULL  ) 

Boolean, controls output of large amounts of debug information.

Definition at line 67 of file Database.php.

References wfSetBit().

Referenced by query().

Database::decodeBlob ( b  ) 

Reimplemented in DatabaseIbm_db2, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 2188 of file Database.php.

Database::delete ( table,
conds,
fname = 'Database::delete' 
)

DELETE query wrapper.

Use $conds == "*" to delete all rows

Reimplemented in DatabaseIbm_db2.

Definition at line 1767 of file Database.php.

References $conds, $fname, $sql, makeList(), query(), and tableName().

Database::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

Parameters:
$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 1721 of file Database.php.

References $conds, $fname, $sql, makeList(), query(), and tableName().

Database::doneWrites (  ) 

Returns true if the connection may have been used for write queries.

Should return true if unsure.

Definition at line 220 of file Database.php.

Database::doQuery ( sql  )  [private]

The DBMS-dependent part of query().

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

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 632 of file Database.php.

References $sql, and bufferResults().

Referenced by masterPosWait(), and query().

Database::encodeBlob ( b  ) 

Reimplemented in DatabaseIbm_db2, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 2184 of file Database.php.

Database::errorCount ( count = NULL  ) 

Number of errors logged, only useful when errors are ignored.

Definition at line 105 of file Database.php.

References $count, and wfSetVar().

Database::escapeLike ( s  ) 

Escape string for safe LIKE usage.

Definition at line 1647 of file Database.php.

References $s, and strencode().

Database::estimateRowCount ( table,
vars = '*',
conds = '',
fname = 'Database::estimateRowCount',
options = array() 
)

Estimate rows in dataset Returns estimated count, based on EXPLAIN output Takes same arguments as Database::select().

Reimplemented in DatabaseIbm_db2, DatabaseMssql, and DatabasePostgres.

Definition at line 1125 of file Database.php.

References $conds, $fname, $options, $res, $rows, fetchObject(), freeResult(), numRows(), and select().

Database::execute ( prepared,
args = null 
)

Execute a prepared query with the various arguments.

Parameters:
$prepared String: the prepared sql
$args Mixed: Either an array here, or put scalars as varargs

Definition at line 691 of file Database.php.

References $args, $sql, fillPrepared(), and query().

Referenced by safeQuery().

Database::failFunction ( function = NULL  ) 

Fail function, takes a Database as a parameter Set to false for default, 1 for ignore errors.

Definition at line 52 of file Database.php.

References wfSetVar().

Database::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.

Parameters:
$res SQL result object as returned from Database::query(), etc.
Returns:
MySQL row object
Exceptions:
DBUnexpectedError Thrown if the database returns an error

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 782 of file Database.php.

References $res, $row, lastErrno(), and lastError().

Referenced by estimateRowCount(), fieldExists(), getLag(), getMasterPos(), getSlavePos(), getStatus(), indexInfo(), lock(), selectRow(), and textFieldSize().

Database::fetchRow ( res  ) 

Fetch the next row from the given result object, in associative array form.

Fields are retrieved with $row['fieldname'].

Parameters:
$res SQL result object as returned from Database::query(), etc.
Returns:
MySQL row object
Exceptions:
DBUnexpectedError Thrown if the database returns an error

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 801 of file Database.php.

References $res, $row, lastErrno(), and lastError().

Referenced by masterPosWait(), and selectField().

Database::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, DatabasePostgres, and DatabaseSqlite.

Definition at line 1177 of file Database.php.

References $fname, $res, $row, fetchObject(), query(), and tableName().

Database::fieldInfo ( table,
field 
)

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

Parameters:
$table 
$field 

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 1260 of file Database.php.

References $i, $n, $res, query(), and tableName().

Database::fieldName ( res,
n 
)

Get a field name in a result object See documentation for mysql_field_name(): http://www.php.net/mysql_field_name.

Parameters:
$res Mixed: A SQL result
$n Integer

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 846 of file Database.php.

References $n, and $res.

Database::fieldType ( res,
index 
)

mysql_field_type() wrapper

Reimplemented in DatabaseIbm_db2, DatabaseMssql, and DatabasePostgres.

Definition at line 1276 of file Database.php.

References $res.

Database::fillPrepared ( preparedQuery,
args 
)

For faking prepared SQL statements on DBs that don't support it directly.

Parameters:
$preparedQuery String: a 'preparable' SQL statement
$args Array of arguments to fill it with
Returns:
string executable SQL

Definition at line 726 of file Database.php.

References $args.

Referenced by execute().

Database::fillPreparedArg ( matches  ) 

preg_callback func for fillPrepared() The arguments should be in $this->preparedArgs and must not be touched while we're doing this.

Parameters:
$matches Array
Returns:
String
Access:
private

Definition at line 742 of file Database.php.

References addQuotes().

Database::freePrepared ( prepared  ) 

Definition at line 682 of file Database.php.

Referenced by safeQuery().

Database::freeResult ( res  ) 

Free a result object.

Parameters:
$res Mixed: A SQL result

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 764 of file Database.php.

References $res.

Referenced by estimateRowCount(), indexInfo(), lock(), masterPosWait(), selectField(), selectRow(), tableExists(), textFieldSize(), and unlock().

Database::functionalIndexes (  ) 

Returns true if this database can use functional indexes.

Reimplemented in DatabaseIbm_db2, and DatabasePostgres.

Definition at line 205 of file Database.php.

static Database::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.

Parameters:
$sql String: A SQL Query

Definition at line 1152 of file Database.php.

References $sql.

Referenced by query().

Database::getDBname (  ) 

Get the current DB name.

Reimplemented in DatabaseOracle, and DatabasePostgres.

Definition at line 1453 of file Database.php.

Database::getFlag ( flag  ) 

Definition at line 236 of file Database.php.

Database::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 2133 of file Database.php.

References $res, $row, fetchObject(), query(), and wfDebug().

Database::getLBInfo ( name = NULL  ) 

Properties passed down from the server info array of the load balancer.

Definition at line 116 of file Database.php.

References $name.

Referenced by query().

Database::getMasterPos (  ) 

Get the position of the master from SHOW MASTER STATUS.

Definition at line 1996 of file Database.php.

References $res, $row, fetchObject(), and query().

Database::getProperty ( name  ) 

General read-only accessor.

Definition at line 243 of file Database.php.

References $name.

Database::getSearchEngine (  ) 

Get search engine class.

All subclasses of this need to implement this if they wish to use searching.

Returns:
String

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 2380 of file Database.php.

Database::getServer (  ) 

Get the server hostname or IP address.

Reimplemented in DatabaseOracle, and DatabasePostgres.

Definition at line 1460 of file Database.php.

Database::getServerVersion (  ) 

Returns:
String: Version information from the database

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 2101 of file Database.php.

Referenced by open().

Database::getSlavePos (  ) 

Get the position of the master from SHOW SLAVE STATUS.

Definition at line 1977 of file Database.php.

References $res, $row, fetchObject(), query(), and wfDebug().

Database::getSoftwareLink (  ) 

Returns:
String: wikitext of a link to the server software's web site

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 2094 of file Database.php.

Database::getStatus ( which = "%"  ) 

Get status information from SHOW STATUS in an associative array.

Reimplemented in DatabaseIbm_db2.

Definition at line 2168 of file Database.php.

References $res, $row, $status, fetchObject(), and query().

Database::getWikiID (  ) 

Reimplemented in DatabaseIbm_db2.

Definition at line 247 of file Database.php.

Database::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 90 of file Database.php.

References wfSetBit().

Referenced by deadlockLoop(), DatabasePostgres::reportQueryError(), DatabaseOracle::reportQueryError(), reportQueryError(), and tableExists().

Database::immediateBegin ( fname = 'Database::immediateBegin'  ) 

Begin a transaction, committing any previously open transaction.

Deprecated:
use begin()

Reimplemented in DatabaseMssql.

Definition at line 2038 of file Database.php.

References begin().

Database::immediateCommit ( fname = 'Database::immediateCommit'  ) 

Commit transaction, if one is open.

Deprecated:
use commit()

Reimplemented in DatabaseMssql, DatabaseOracle, and DatabasePostgres.

Definition at line 2046 of file Database.php.

References commit().

Referenced by DatabaseSqlite::close(), close(), and masterPosWait().

Database::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 182 of file Database.php.

Database::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, DatabasePostgres, and DatabaseSqlite.

Definition at line 190 of file Database.php.

Database::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 1200 of file Database.php.

References $fname, and indexInfo().

Database::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 1214 of file Database.php.

References $fname, $res, $result, $row, $sql, fetchObject(), freeResult(), indexName(), query(), and tableName().

Referenced by indexExists(), and indexUnique().

Database::indexName ( index  ) 

Get the name of an index in a given table.

Reimplemented in DatabaseSqlite.

Definition at line 1605 of file Database.php.

Referenced by indexInfo(), indexNameCallback(), DatabasePostgres::indexUnique(), and useIndexClause().

Database::indexNameCallback ( matches  )  [protected]

Index name callback.

Definition at line 2325 of file Database.php.

References indexName().

Database::indexUnique ( table,
index 
)

Determines if a given index is unique.

Definition at line 1286 of file Database.php.

References indexInfo().

Database::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 1303 of file Database.php.

References $fname, $keys, $options, $row, $sql, makeList(), query(), and tableName().

Database::insertId (  ) 

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, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 863 of file Database.php.

Database::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.

Definition at line 1786 of file Database.php.

References $conds, $fname, $sql, makeList(), makeSelectOptions(), query(), and tableName().

Database::installErrorHandler (  )  [protected]

Definition at line 439 of file Database.php.

Referenced by DatabasePostgres::open(), and open().

Database::isOpen (  ) 

Is a connection to the database open?

Returns:
Boolean

Reimplemented in DatabaseIbm_db2.

Definition at line 226 of file Database.php.

Database::isWriteQuery ( sql  ) 

Determine whether a query writes to the DB.

Should return true if unsure.

Definition at line 507 of file Database.php.

References $sql.

Referenced by query().

Database::lastErrno (  ) 

Get the last error number See mysql_errno().

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 882 of file Database.php.

Referenced by deadlockLoop(), fetchObject(), fetchRow(), numRows(), query(), wasDeadlock(), and wasErrorReissuable().

Database::lastError (  ) 

Get a description of the last error See mysql_error() for more details.

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 894 of file Database.php.

References $error, wfRestoreWarnings(), and wfSuppressWarnings().

Referenced by deadlockLoop(), fetchObject(), fetchRow(), numRows(), open(), query(), reportConnectionError(), and sourceStream().

Database::lastQuery (  ) 

Return the last query that went through Database::query().

Returns:
String

Definition at line 213 of file Database.php.

Referenced by deadlockLoop().

Database::limitResult ( sql,
limit,
offset = false 
)

Construct a LIMIT query with optional offset This is used for query pages.

Parameters:
$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 1819 of file Database.php.

References $offset.

Referenced by DatabaseSqlite::limitResultForUpdate(), limitResultForUpdate(), and selectSQLText().

Database::limitResultForUpdate ( sql,
num 
)

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 1827 of file Database.php.

References $sql, and limitResult().

Database::lock ( lockName,
method 
)

Acquire a lock.

Abstracted from Filestore::lock() so child classes can implement for their own needs.

Parameters:
$lockName String: Name of lock to aquire
$method String: Name of method calling us
Returns:
bool

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 2346 of file Database.php.

References $method, $result, $row, addQuotes(), fetchObject(), freeResult(), query(), and wfDebug().

Database::lowPriorityOption (  ) 

Returns:
string Returns the text of the low priority option if it is supported, or a blank string otherwise

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 1758 of file Database.php.

Referenced by makeUpdateOptions().

Database::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 1390 of file Database.php.

References $mode, and addQuotes().

Referenced by delete(), DatabasePostgres::deleteJoin(), DatabaseOracle::deleteJoin(), DatabaseMssql::deleteJoin(), deleteJoin(), DatabasePostgres::insert(), insert(), DatabaseMssql::insertSelect(), insertSelect(), DatabaseMssql::makeListWithoutNulls(), DatabasePostgres::replace(), DatabaseOracle::replace(), DatabaseMssql::replace(), replace(), DatabaseMssql::select(), selectSQLText(), tableNamesWithUseIndexOrJOIN(), DatabaseMssql::update(), and update().

Database::makeSelectOptions ( options  )  [private]

Returns an optional USE INDEX clause to go after the table, and a string to go at the end of the query.

Parameters:
$options Array: associative array of options to be turned into an SQL query, valid keys are listed in the function.
Returns:
Array

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 966 of file Database.php.

References $key, $options, and useIndexClause().

Referenced by insertSelect(), and selectSQLText().

Database::makeUpdateOptions ( options  ) 

Make UPDATE options for the Database::update function.

Access:
private
Parameters:
$options Array: The options passed to Database::update
Returns:
string

Reimplemented in DatabaseMssql.

Definition at line 1347 of file Database.php.

References $options, and lowPriorityOption().

Referenced by DatabaseIbm_db2::update(), and update().

Database::masterPosWait ( MySQLMasterPos pos,
timeout 
)

Do a SELECT MASTER_POS_WAIT().

Parameters:
$pos MySQLMasterPos object
$timeout Integer: the maximum number of seconds to wait for synchronisation

Definition at line 1932 of file Database.php.

References $fname, $res, $row, $sql, addQuotes(), doQuery(), fetchRow(), freeResult(), immediateCommit(), wfDebug(), wfProfileIn(), and wfProfileOut().

Database::maxListLen (  ) 

Return the maximum number of items allowed in a list, or 0 for unlimited.

Definition at line 2180 of file Database.php.

static Database::newFromParams ( server,
user,
password,
dbName,
failFunction = false,
flags = 0 
) [static]

Same as new Database( .

.. ), kept for backward compatibility

Parameters:
$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 317 of file Database.php.

References $flags, $password, and $user.

Referenced by convertLinks(), and createTempTable().

Database::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 1659 of file Database.php.

Database::numFields ( res  ) 

Get the number of fields in a result object See documentation for mysql_num_fields().

Parameters:
$res Mixed: A SQL result

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 832 of file Database.php.

References $res.

Database::numRows ( res  ) 

Get the number of rows in a result object.

Parameters:
$res Mixed: A SQL result

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 816 of file Database.php.

References $n, $res, lastErrno(), and lastError().

Referenced by estimateRowCount(), selectField(), and selectRow().

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

Usually aborts on failure If the failFunction is set to a non-zero integer, returns success.

Parameters:
$server String: database server host
$user String: database user name
$password String: database user password
$dbName String: database name

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 330 of file Database.php.

References $error, $i, $password, $success, $user, $version, $wgAllDBsAreLocalhost, $wgDBmysql5, close(), getServerVersion(), installErrorHandler(), lastError(), query(), reportConnectionError(), restoreErrorHandler(), wfDebug(), wfHostname(), wfLogDBError(), wfProfileIn(), and wfProfileOut().

Referenced by __construct(), and ping().

Database::ping (  ) 

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

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 2108 of file Database.php.

References open(), and wfDebug().

Referenced by query().

Database::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...)

Definition at line 675 of file Database.php.

References $sql.

Referenced by safeQuery().

Database::query ( sql,
fname = '',
tempIgnore = false 
)

Usually aborts on failure.

If errors are explicitly ignored, returns success.

Parameters:
$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?
Returns:
true for a successful write query, ResultWrapper object for a successful read query, or false on failure if $tempIgnore set
Exceptions:
DBQueryError Thrown when the database returns an error of any kind

Definition at line 523 of file Database.php.

References $fname, $sql, $userName, $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(), DatabaseOracle::deleteJoin(), DatabaseMssql::deleteJoin(), DatabaseIbm_db2::deleteJoin(), deleteJoin(), execute(), DatabasePostgres::fieldExists(), DatabaseMssql::fieldExists(), DatabaseIbm_db2::fieldExists(), fieldExists(), DatabaseSqlite::fieldInfo(), DatabaseMssql::fieldInfo(), fieldInfo(), getLag(), getMasterPos(), getSlavePos(), getStatus(), DatabaseSqlite::indexInfo(), DatabasePostgres::indexInfo(), DatabaseMssql::indexInfo(), DatabaseIbm_db2::indexInfo(), indexInfo(), DatabasePostgres::indexUnique(), DatabaseIbm_db2::indexUnique(), DatabasePostgres::insert(), DatabaseMssql::insert(), DatabaseIbm_db2::insert(), insert(), DatabaseMssql::insertSelect(), insertSelect(), lock(), DatabasePostgres::nextSequenceValue(), DatabaseOracle::nextSequenceValue(), DatabaseIbm_db2::nextSequenceValue(), open(), DatabasePostgres::queryIgnore(), DatabaseOracle::queryIgnore(), DatabasePostgres::relationExists(), DatabasePostgres::replace(), DatabaseOracle::replace(), DatabaseMssql::replace(), DatabaseIbm_db2::replace(), replace(), rollback(), DatabasePostgres::schemaExists(), DatabaseMssql::select(), select(), DatabaseMssql::set(), set(), setTimeout(), DatabaseSqlite::setup_database(), DatabasePostgres::setup_database(), DatabaseMssql::setup_database(), sourceStream(), DatabaseOracle::tableExists(), DatabaseMssql::tableExists(), DatabaseIbm_db2::tableExists(), tableExists(), DatabasePostgres::textFieldSize(), DatabaseOracle::textFieldSize(), DatabaseMssql::textFieldSize(), DatabaseIbm_db2::textFieldSize(), textFieldSize(), DatabasePostgres::triggerExists(), unlock(), DatabaseMssql::update(), DatabaseIbm_db2::update(), and update().

Database::realTimestamps (  ) 

Returns true if this database uses timestamps rather than integers.

Reimplemented in DatabaseIbm_db2, DatabaseOracle, and DatabasePostgres.

Definition at line 175 of file Database.php.

Database::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

Todo:
migrate comment to phodocumentor format

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, and DatabasePostgres.

Definition at line 1684 of file Database.php.

References $fname, $row, $rows, $sql, makeList(), query(), and tableName().

Database::replaceVars ( ins  )  [protected]

Replace variables in sourced SQL.

Reimplemented in DatabasePostgres, and DatabaseSqlite.

Definition at line 2287 of file Database.php.

References $GLOBALS.

Referenced by sourceStream().

Database::reportConnectionError ( error = 'Unknown error'  ) 

Parameters:
$error String: fallback error message, used if none is given by MySQL

Definition at line 485 of file Database.php.

References $error, and lastError().

Referenced by DatabaseMssql::open(), DatabaseIbm_db2::open(), and open().

Database::reportQueryError ( error,
errno,
sql,
fname,
tempIgnore = false 
)

Parameters:
$error String
$errno Integer
$sql String
$fname String
$tempIgnore Boolean

Reimplemented in DatabaseOracle, and DatabasePostgres.

Definition at line 648 of file Database.php.

References $error, $fname, $ignore, $sql, $wgCommandLineMode, ignoreErrors(), wfDebug(), and wfLogDBError().

Referenced by deadlockLoop(), query(), DatabaseSqlite::setup_database(), and DatabaseMssql::setup_database().

Database::restoreErrorHandler (  )  [protected]

Definition at line 445 of file Database.php.

References $error.

Referenced by DatabasePostgres::open(), and open().

Database::resultObject ( result  ) 

Todo:
document

Definition at line 2071 of file Database.php.

References $result.

Referenced by query().

Database::rollback ( fname = 'Database::rollback'  ) 

Rollback a transaction.

No-op on non-transactional databases.

Reimplemented in DatabaseSqlite.

Definition at line 2029 of file Database.php.

References $fname, and query().

Database::safeQuery ( query,
args = null 
)

Prepare & execute an SQL statement, quoting and inserting arguments in the appropriate places.

Parameters:
$query String
$args ...

Definition at line 707 of file Database.php.

References $args, execute(), freePrepared(), and prepare().

Database::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 198 of file Database.php.

Database::select ( table,
vars,
conds = '',
fname = 'Database::select',
options = array(),
join_conds = array() 
)

SELECT wrapper.

Parameters:
$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') )
Returns:
mixed Database result resource (feed to Database::fetchObject or whatever), or false on failure

Reimplemented in DatabaseIbm_db2.

Definition at line 1023 of file Database.php.

References $conds, $fname, $options, $sql, query(), and selectSQLText().

Referenced by DatabasePostgres::estimateRowCount(), estimateRowCount(), selectField(), and selectRow().

Database::selectDB ( db  ) 

Change the current database.

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 1445 of file Database.php.

References $db.

Database::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 937 of file Database.php.

References $fname, $options, $res, $row, fetchRow(), freeResult(), numRows(), and select().

Referenced by DatabasePostgres::ruleExists().

Database::selectRow ( table,
vars,
conds,
fname = 'Database::selectRow',
options = array(),
join_conds = array() 
)

Single row SELECT wrapper Aborts or returns FALSE on error.

Parameters:
$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 functio name
$options Array
$join_conds Array
Todo:
migrate documentation to phpdocumentor format

Definition at line 1104 of file Database.php.

References $conds, $fname, $obj, $options, $res, fetchObject(), freeResult(), numRows(), and select().

Referenced by DatabaseSqlite::indexUnique().

Database::selectSQLText ( table,
vars,
conds = '',
fname = 'Database::select',
options = array(),
join_conds = array() 
)

SELECT wrapper.

Parameters:
$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') )
Returns:
string, the SQL text

Definition at line 1042 of file Database.php.

References $conds, $options, $sql, limitResult(), makeList(), makeSelectOptions(), tableName(), and tableNamesWithUseIndexOrJOIN().

Referenced by select().

Database::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 925 of file Database.php.

References $fname, $sql, query(), strencode(), and tableName().

Database::setFakeMaster ( enabled = true  ) 

Make this connection a fake master.

Reimplemented in DatabaseIbm_db2, DatabaseOracle, and DatabasePostgres.

Definition at line 146 of file Database.php.

Database::setFakeSlaveLag ( lag  ) 

Set lag time in seconds for a fake slave.

Reimplemented in DatabaseIbm_db2, DatabaseOracle, and DatabasePostgres.

Definition at line 139 of file Database.php.

Database::setFlag ( flag  ) 

Definition at line 228 of file Database.php.

Database::setLBInfo ( name,
value = NULL 
)

Definition at line 128 of file Database.php.

References $name.

Database::setOutputPage ( out  ) 

Output page, used for reporting errors FALSE means discard output.

Definition at line 60 of file Database.php.

References wfDeprecated().

Database::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.

Parameters:
$timeout Integer in seconds

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 2199 of file Database.php.

References query().

Database::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)

Parameters:
$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 2211 of file Database.php.

References $error, $filename, and sourceStream().

Referenced by DatabaseSqlite::setup_database(), and DatabaseMssql::setup_database().

Database::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).

Parameters:
$fp String: File handle
$lineCallback Callback: Optional function called before reading each line
$resultCallback Callback: Optional function called for each MySQL result

Definition at line 2228 of file Database.php.

References $cmd, $res, lastError(), query(), and replaceVars().

Referenced by sourceFile().

Database::strencode ( s  ) 

Wrapper for addslashes().

Parameters:
$s String: to be slashed.
Returns:
String: slashed string.

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 1624 of file Database.php.

References $s.

Referenced by addQuotes(), escapeLike(), and set().

Database::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 168 of file Database.php.

Database::strreplace ( orig,
old,
new 
)

Returns a comand for str_replace function in SQL query.

Uses REPLACE() in MySQL

Parameters:
$orig String: column to modify
$old String: column to seek
$new String: column to replace with

Definition at line 1852 of file Database.php.

Database::tableExists ( table  ) 

Query whether a given table exists.

Reimplemented in DatabaseIbm_db2, DatabaseMssql, and DatabaseOracle.

Definition at line 1240 of file Database.php.

References $res, freeResult(), ignoreErrors(), query(), and tableName().

Database::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.

Parameters:
$name String: database table name
Returns:
String: full database name

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 1477 of file Database.php.

References $database, $name, $prefix, $wgSharedDB, $wgSharedPrefix, $wgSharedTables, and table.

Referenced by delete(), deleteJoin(), fieldExists(), fieldInfo(), indexInfo(), insert(), insertSelect(), replace(), selectSQLText(), set(), tableExists(), tableNameCallback(), tableNames(), tableNamesN(), tableNamesWithUseIndexOrJOIN(), textFieldSize(), and update().

Database::tableNameCallback ( matches  )  [protected]

Table name callback.

Access:
private

Definition at line 2318 of file Database.php.

References tableName().

Database::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 1538 of file Database.php.

References $name, and tableName().

Database::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 1556 of file Database.php.

References $name, and tableName().

Database::tableNamesWithUseIndexOrJOIN ( tables,
use_index = array(),
join_conds = array() 
)

Access:
private

Definition at line 1568 of file Database.php.

References makeList(), tableName(), and useIndexClause().

Referenced by selectSQLText().

Database::tablePrefix ( prefix = null  ) 

Definition at line 109 of file Database.php.

References $prefix, and wfSetVar().

Database::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 1739 of file Database.php.

References $res, $row, $size, $sql, fetchObject(), freeResult(), query(), and tableName().

Database::timestamp ( ts = 0  ) 

Return MW-style timestamp used for MySQL schema.

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, and DatabasePostgres.

Definition at line 2053 of file Database.php.

References $ts, and wfTimestamp().

Referenced by timestampOrNull().

Database::timestampOrNull ( ts = null  ) 

Local database timestamp format or null.

Reimplemented in DatabaseMssql.

Definition at line 2060 of file Database.php.

References $ts, and timestamp().

Database::trxLevel ( level = NULL  ) 

The current depth of nested transactions.

Parameters:
$level Integer: , default NULL.

Definition at line 98 of file Database.php.

References wfSetVar().

Referenced by DatabaseSqlite::close(), DatabaseMssql::close(), DatabaseIbm_db2::close(), close(), and query().

Database::unlock ( lockName,
method 
)

Release a lock.

Todo:
fixme - Figure out a way to return a bool based on successful lock release.
Parameters:
$lockName String: Name of lock to release
$method String: Name of method calling us

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 2368 of file Database.php.

References $method, $result, addQuotes(), freeResult(), and query().

Database::update ( table,
values,
conds,
fname = 'Database::update',
options = array() 
)

UPDATE wrapper, takes a condition array and a SET array.

Parameters:
$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
Returns:
Boolean

Reimplemented in DatabaseIbm_db2, and DatabaseMssql.

Definition at line 1371 of file Database.php.

References $conds, $fname, $options, $sql, makeList(), makeUpdateOptions(), query(), and tableName().

Database::useIndexClause ( index  ) 

USE INDEX clause PostgreSQL doesn't have them and returns "".

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 1667 of file Database.php.

References indexName().

Referenced by makeSelectOptions(), and tableNamesWithUseIndexOrJOIN().

Database::wasDeadlock (  ) 

Determines if the last failure was due to a deadlock.

Reimplemented in DatabaseIbm_db2, DatabaseMssql, DatabaseOracle, DatabasePostgres, and DatabaseSqlite.

Definition at line 1859 of file Database.php.

References lastErrno().

Referenced by deadlockLoop().

Database::wasErrorReissuable (  ) 

Determines if the last query error was something that should be dealt with by pinging the connection and reissuing the query.

Reimplemented in DatabaseSqlite.

Definition at line 1867 of file Database.php.

References lastErrno().

Referenced by query().


Member Data Documentation

Database::$mConn = null [protected]

Definition at line 32 of file Database.php.

Database::$mDBname [protected]

Definition at line 32 of file Database.php.

Database::$mDoneWrites = false [protected]

Definition at line 29 of file Database.php.

Database::$mErrorCount = 0 [protected]

Definition at line 39 of file Database.php.

Database::$mFailFunction [protected]

Definition at line 35 of file Database.php.

Database::$mFakeMaster = false [protected]

Definition at line 41 of file Database.php.

Database::$mFakeSlaveLag = null [protected]

Definition at line 41 of file Database.php.

Database::$mFlags [protected]

Definition at line 37 of file Database.php.

Database::$mLastQuery = '' [protected]

Definition at line 28 of file Database.php.

Database::$mLBInfo = array() [protected]

Definition at line 40 of file Database.php.

Database::$mOpened = false [protected]

Definition at line 33 of file Database.php.

Database::$mPassword [protected]

Definition at line 32 of file Database.php.

Database::$mPHPError = false [protected]

Definition at line 30 of file Database.php.

Database::$mServer [protected]

Definition at line 32 of file Database.php.

Database::$mTablePrefix [protected]

Definition at line 36 of file Database.php.

Database::$mTrxLevel = 0 [protected]

Definition at line 38 of file Database.php.

Database::$mUser [protected]

Definition at line 32 of file Database.php.


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

Generated on Sat Sep 5 02:08:34 2009 for MediaWiki by  doxygen 1.5.9