MediaWiki  REL1_22
DatabaseMssql Class Reference
Inheritance diagram for DatabaseMssql:
Collaboration diagram for DatabaseMssql:

List of all members.

Public Member Functions

 addIdentifierQuotes ($s)
 Quotes an identifier using `backticks` or "double quotes" depending on the database type.
 addQuotes ($s)
 Adds quotes and backslashes.
 affectedRows ()
 Get the number of rows affected by the last write query.
 buildConcat ($stringList)
 Build a concatenation list to feed into a SQL query.
 cascadingDeletes ()
 Returns true if this database supports (and uses) cascading deletes.
 cleanupTriggers ()
 Returns true if this database supports (and uses) triggers (e.g.
 currentSequenceValue ($seqName)
 Return the current value of a sequence.
 dataSeek ($res, $row)
 Change the position of the cursor in a result object.
 decodeBlob ($b)
 Some DBMSs return a special placeholder object representing blob fields in result objects.
 encodeBlob ($b)
 Some DBMSs have a special format for inserting into blob fields, they don't allow simple quoted strings to be inserted.
 estimateRowCount ($table, $vars= '*', $conds= '', $fname=__METHOD__, $options=array())
 Estimate rows in dataset Returns estimated count, based on SHOWPLAN_ALL output This is not necessarily an accurate estimate, so use sparingly Returns -1 if count cannot be found Takes same arguments as Database::select()
 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.
 fieldExists ($table, $field, $fname=__METHOD__)
 Query whether a given column exists in the mediawiki schema.
 fieldInfo ($table, $field)
 mysql_fetch_field() wrapper Returns false if the field doesn't exist
 fieldName ($res, $n)
 Get a field name in a result object.
 freeResult ($res)
 Free a result object returned by query() or select().
 functionalIndexes ()
 Returns true if this database can use functional indexes.
 getErrors ()
 getInfinity ()
 Since MSSQL doesn't recognize the infinity keyword, set date manually.
 getSearchEngine ()
 Get search engine class.
 getServerVersion ()
 getSoftwareLink ()
 getType ()
 Get the type of the DBMS, as it appears in $wgDBtype.
 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.
 indexInfo ($table, $index, $fname=__METHOD__)
 Returns information about an index If errors are explicitly ignored, returns NULL on failure.
 initial_setup ($dbName, $newUser, $loginPassword)
 Initial setup.
 insert ($table, $arrToInsert, $fname=__METHOD__, $options=array())
 INSERT wrapper, inserts an array into a table.
 insertId ()
 This must be called after nextSequenceVal.
 insertSelect ($destTable, $srcTable, $varMap, $conds, $fname=__METHOD__, $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.
 isQuotedIdentifier ($name)
 Returns if the given identifier looks quoted or not according to the database convention for quoting identifiers .
 lastErrno ()
 Get the last error number.
 lastError ()
 Get a description of the last error.
 limitResult ($sql, $limit, $offset=false)
 Construct a LIMIT query with optional offset This is used for query pages $sql string SQL query we will append the limit too $limit integer the SQL limit $offset integer the SQL offset (default false)
 LimitToTopN ($sql)
 makeSelectOptions ($options)
 nextSequenceValue ($seqName)
 Return the next in a sequence, save the value for retrieval via insertId()
 numFields ($res)
 Get the number of fields in a result object.
 numRows ($res)
 Get the number of rows in a result object.
 open ($server, $user, $password, $dbName)
 Usually aborts on failure.
 realTimestamps ()
 Returns true if this database uses timestamps rather than integers.
 select ($table, $vars, $conds= '', $fname=__METHOD__, $options=array(), $join_conds=array())
 SELECT wrapper.
 selectDB ($db)
 Change the current database.
 selectSQLText ($table, $vars, $conds= '', $fname=__METHOD__, $options=array(), $join_conds=array())
 SELECT wrapper.
 strencode ($s)
 Wrapper for addslashes()
 strictIPs ()
 Returns true if this database is strict about what can be put into an IP field.
 tableExists ($table, $fname=__METHOD__, $schema=false)
 tableNamesWithUseIndexOrJOIN ($tables, $use_index=array(), $join_conds=array())
 textFieldSize ($table, $field)
 Returns the size of a text field, or -1 for "unlimited".
 timestamp ($ts=0)
 Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting into timestamp fields in this DBMS.
 unionSupportsOrderAndLimit ()
 Returns true if current database backend supports ORDER BY or LIMIT for separate subqueries within the UNION construct.

Public Attributes

 $mAffectedRows = null
 $mInsertId = null
 $mLastResult = null
 $mPort

Protected Member Functions

 closeConnection ()
 Closes a database connection, if it is open Returns success, true if already closed.
 doBegin ($fname=__METHOD__)
 Begin a transaction, committing any previously open transaction.
 doCommit ($fname=__METHOD__)
 End a transaction.
 doQuery ($sql)
 The DBMS-dependent part of query()
 doRollback ($fname=__METHOD__)
 Rollback a transaction.

Private Member Functions

 escapeIdentifier ($identifier)
 Escapes a identifier for use inm SQL.

Detailed Description

Definition at line 30 of file DatabaseMssql.php.


Member Function Documentation

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

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

Parameters:
$sstring
Returns:
string

Reimplemented from DatabaseBase.

Definition at line 887 of file DatabaseMssql.php.

References $s.

Adds quotes and backslashes.

Parameters:
$sstring
Returns:
string

Reimplemented from DatabaseBase.

Definition at line 879 of file DatabaseMssql.php.

References $s.

Referenced by initial_setup(), and insert().

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

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

Implements DatabaseType.

Definition at line 283 of file DatabaseMssql.php.

DatabaseMssql::buildConcat ( stringList)

Build a concatenation list to feed into a SQL query.

Parameters:
array$stringListlist of raw SQL expressions; caller is responsible for any quoting
Returns:
String

Reimplemented from DatabaseBase.

Definition at line 938 of file DatabaseMssql.php.

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

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 37 of file DatabaseMssql.php.

Returns true if this database supports (and uses) triggers (e.g.

on the page table)

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 41 of file DatabaseMssql.php.

Closes a database connection, if it is open Returns success, true if already closed.

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 140 of file DatabaseMssql.php.

Return the current value of a sequence.

Assumes it has ben nextval'ed in this session.

Returns:

Definition at line 577 of file DatabaseMssql.php.

References $ret, and nextSequenceValue().

DatabaseMssql::dataSeek ( res,
row 
)

Change the position of the cursor in a result object.

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

Implements DatabaseType.

Definition at line 259 of file DatabaseMssql.php.

References $res.

Some DBMSs return a special placeholder object representing blob fields in result objects.

Pass the object through this function to return the original string.

Parameters:
$bstring
Returns:
string

Reimplemented from DatabaseBase.

Definition at line 832 of file DatabaseMssql.php.

DatabaseMssql::doBegin ( fname = __METHOD__) [protected]

Begin a transaction, committing any previously open transaction.

Reimplemented from DatabaseBase.

Definition at line 724 of file DatabaseMssql.php.

DatabaseMssql::doCommit ( fname = __METHOD__) [protected]

End a transaction.

Reimplemented from DatabaseBase.

Definition at line 732 of file DatabaseMssql.php.

DatabaseMssql::doQuery ( sql) [protected]

The DBMS-dependent part of query()

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

Reimplemented from DatabaseBase.

Definition at line 144 of file DatabaseMssql.php.

References $error, $matches, $res, as, LimitToTopN(), and wfDebug().

Referenced by initial_setup(), and insert().

DatabaseMssql::doRollback ( fname = __METHOD__) [protected]

Rollback a transaction.

No-op on non-transactional databases.

Reimplemented from DatabaseBase.

Definition at line 741 of file DatabaseMssql.php.

Some DBMSs have a special format for inserting into blob fields, they don't allow simple quoted strings to be inserted.

To insert into such a field, pass the data through this function before passing it to DatabaseBase::insert().

Parameters:
$bstring
Returns:
string

Reimplemented from DatabaseBase.

Definition at line 827 of file DatabaseMssql.php.

DatabaseMssql::escapeIdentifier ( identifier) [private]

Escapes a identifier for use inm SQL.

Throws an exception if it is invalid. Reference: http://msdn.microsoft.com/en-us/library/aa224033%28v=SQL.80%29.aspx

Parameters:
$identifier
Exceptions:
MWException
Returns:
string

Definition at line 754 of file DatabaseMssql.php.

Referenced by initial_setup().

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

Estimate rows in dataset Returns estimated count, based on SHOWPLAN_ALL output This is not necessarily an accurate estimate, so use sparingly Returns -1 if count cannot be found Takes same arguments as Database::select()

Returns:
int

Reimplemented from DatabaseBase.

Definition at line 340 of file DatabaseMssql.php.

References $fname, $options, $res, $vars, fetchRow(), and select().

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

Fields can be retrieved with $row->fieldname, with fields acting like member variables. If no more rows are available, false is returned.

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

Implements DatabaseType.

Definition at line 199 of file DatabaseMssql.php.

References $res.

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

Fields are retrieved with $row['fieldname']. If no more rows are available, false is returned.

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

Implements DatabaseType.

Definition at line 222 of file DatabaseMssql.php.

References $res.

Referenced by estimateRowCount(), fieldInfo(), and textFieldSize().

DatabaseMssql::fieldExists ( table,
field,
fname = __METHOD__ 
)

Query whether a given column exists in the mediawiki schema.

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 691 of file DatabaseMssql.php.

References $res, getErrors(), print, and DatabaseBase\tableName().

DatabaseMssql::fieldInfo ( table,
field 
)

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

Parameters:
string$tabletable name
string$fieldfield name
Returns:
Field

Implements DatabaseType.

Definition at line 706 of file DatabaseMssql.php.

References $res, fetchRow(), getErrors(), print, and DatabaseBase\tableName().

DatabaseMssql::fieldName ( res,
n 
)

Get a field name in a result object.

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

Implements DatabaseType.

Definition at line 244 of file DatabaseMssql.php.

References $n, and $res.

Free a result object returned by query() or select().

It's usually not necessary to call this, just use unset() or let the variable holding the result object go out of scope.

Parameters:
$resMixed: A SQL result

Reimplemented from DatabaseBase.

Definition at line 192 of file DatabaseMssql.php.

References $res.

Returns true if this database can use functional indexes.

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 61 of file DatabaseMssql.php.

Definition at line 207 of file DatabaseMssql.php.

References as.

Referenced by fieldExists(), fieldInfo(), insert(), insertSelect(), lastError(), and tableExists().

Since MSSQL doesn't recognize the infinity keyword, set date manually.

Todo:
Remove magic date
Returns:
string

Reimplemented from DatabaseBase.

Definition at line 951 of file DatabaseMssql.php.

Get search engine class.

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

Returns:
String

Reimplemented from DatabaseBase.

Definition at line 942 of file DatabaseMssql.php.

Returns:
string Version information from the database

Implements DatabaseType.

Definition at line 664 of file DatabaseMssql.php.

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

Implements DatabaseType.

Definition at line 657 of file DatabaseMssql.php.

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

Returns:
string

Implements DatabaseType.

Definition at line 934 of file DatabaseMssql.php.

Returns true if this database does an implicit sort when doing GROUP BY.

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 53 of file DatabaseMssql.php.

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.

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 57 of file DatabaseMssql.php.

DatabaseMssql::indexInfo ( table,
index,
fname = __METHOD__ 
)

Returns information about an index If errors are explicitly ignored, returns NULL on failure.

Returns:
array|bool|null

Implements DatabaseType.

Definition at line 359 of file DatabaseMssql.php.

References $fname, $res, $result, array(), as, empty, and DatabaseBase\query().

DatabaseMssql::initial_setup ( dbName,
newUser,
loginPassword 
)

Initial setup.

Precondition: This object is connected as the superuser. Creates the database, schema, user and login.

Definition at line 773 of file DatabaseMssql.php.

References addQuotes(), doQuery(), and escapeIdentifier().

DatabaseMssql::insert ( table,
arrToInsert,
fname = __METHOD__,
options = array() 
)

INSERT wrapper, inserts an array into a table.

$arrToInsert 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

Parameters:
string$table
array$arrToInsert
string$fname
array$options
Exceptions:
DBQueryError
Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 404 of file DatabaseMssql.php.

References $fname, $keys, $options, $res, $ret, $value, addQuotes(), array(), as, doQuery(), getErrors(), lastErrno(), and DatabaseBase\tableName().

This must be called after nextSequenceVal.

Returns:
null

Implements DatabaseType.

Definition at line 255 of file DatabaseMssql.php.

DatabaseMssql::insertSelect ( destTable,
srcTable,
varMap,
conds,
fname = __METHOD__,
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.

Parameters:
string$destTable
array | string$srcTable
array$varMap
array$conds
string$fname
array$insertOptions
array$selectOptions
Exceptions:
DBQueryError
Returns:
null|ResultWrapper

Reimplemented from DatabaseBase.

Definition at line 542 of file DatabaseMssql.php.

References $fname, $ret, getErrors(), and lastErrno().

Returns if the given identifier looks quoted or not according to the database convention for quoting identifiers .

Parameters:
$namestring
Returns:
boolean

Reimplemented from DatabaseBase.

Definition at line 892 of file DatabaseMssql.php.

References $name.

Get the last error number.

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

Implements DatabaseType.

Definition at line 274 of file DatabaseMssql.php.

Referenced by insert(), and insertSelect().

Get a description of the last error.

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

Implements DatabaseType.

Definition at line 266 of file DatabaseMssql.php.

References getErrors().

Referenced by open().

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

Construct a LIMIT query with optional offset This is used for query pages $sql string SQL query we will append the limit too $limit integer the SQL limit $offset integer the SQL offset (default false)

Returns:
mixed|string

Reimplemented from DatabaseBase.

Definition at line 610 of file DatabaseMssql.php.

References $limit.

Referenced by LimitToTopN().

Definition at line 632 of file DatabaseMssql.php.

References $matches, and limitResult().

Referenced by doQuery().

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

Reimplemented from DatabaseBase.

Definition at line 907 of file DatabaseMssql.php.

References $key, $options, array(), as, DatabaseBase\makeGroupByWithHaving(), and DatabaseBase\makeOrderBy().

Return the next in a sequence, save the value for retrieval via insertId()

Returns:

Reimplemented from DatabaseBase.

Definition at line 560 of file DatabaseMssql.php.

References $ret, and tableExists().

Referenced by currentSequenceValue().

Get the number of fields in a result object.

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

Implements DatabaseType.

Definition at line 237 of file DatabaseMssql.php.

References $res.

Get the number of rows in a result object.

Parameters:
$resMixed: A SQL result
Returns:
int

Implements DatabaseType.

Definition at line 230 of file DatabaseMssql.php.

References $res.

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

Usually aborts on failure.

Parameters:
string$server
string$user
string$password
string$dbName
Exceptions:
DBConnectionError
Returns:
bool|DatabaseBase|null

Implements DatabaseType.

Definition at line 78 of file DatabaseMssql.php.

References $password, $user, array(), DatabaseBase\close(), e, global, is, lastError(), wfDebug(), wfRestoreWarnings(), and wfSuppressWarnings().

Returns true if this database uses timestamps rather than integers.

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 49 of file DatabaseMssql.php.

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

SELECT wrapper.

Parameters:
$tableMixed: array or string, table name(s) (prefix auto-added)
$varsMixed: array or string, field name(s) to be retrieved
$condsMixed: array or string, condition(s) for WHERE
$fnameString: calling function name (use __METHOD__) for logs/profiling
array$optionsassociative array of options (e.g. array('GROUP BY' => 'page_title')), see Database::makeSelectOptions code for list of supported stuff
$join_condsArray: 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 from DatabaseBase.

Definition at line 300 of file DatabaseMssql.php.

References $fname, $options, $ret, $vars, DatabaseBase\query(), and selectSQLText().

Referenced by estimateRowCount().

Change the current database.

Todo:
Explain what exactly will fail if this is not overridden.
Parameters:
$db
Returns:
bool Success or failure

Reimplemented from DatabaseBase.

Definition at line 896 of file DatabaseMssql.php.

References DatabaseBase\query().

DatabaseMssql::selectSQLText ( table,
vars,
conds = '',
fname = __METHOD__,
options = array(),
join_conds = array() 
)

SELECT wrapper.

Parameters:
$tableMixed: Array or string, table name(s) (prefix auto-added)
$varsMixed: Array or string, field name(s) to be retrieved
$condsMixed: Array or string, condition(s) for WHERE
$fnameString: Calling function name (use __METHOD__) for logs/profiling
array$optionsAssociative array of options (e.g. array('GROUP BY' => 'page_title')), see Database::makeSelectOptions code for list of supported stuff
$join_condsArray: Associative array of table join conditions (optional) (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') )
Returns:
string, the SQL text

Reimplemented from DatabaseBase.

Definition at line 325 of file DatabaseMssql.php.

References $fname, $options, and $vars.

Referenced by select().

Wrapper for addslashes()

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

Implements DatabaseType.

Definition at line 875 of file DatabaseMssql.php.

References $s.

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.

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 45 of file DatabaseMssql.php.

DatabaseMssql::tableExists ( table,
fname = __METHOD__,
schema = false 
)

Definition at line 673 of file DatabaseMssql.php.

References $res, getErrors(), and print.

Referenced by nextSequenceValue().

DatabaseMssql::tableNamesWithUseIndexOrJOIN ( tables,
use_index = array(),
join_conds = array() 
)
Access:
private
Returns:
string

Reimplemented from DatabaseBase.

Definition at line 841 of file DatabaseMssql.php.

References $ret, array(), as, empty, DatabaseBase\makeList(), DatabaseBase\tableName(), and DatabaseBase\useIndexClause().

DatabaseMssql::textFieldSize ( table,
field 
)

Returns the size of a text field, or -1 for "unlimited".

Parameters:
$tablestring
$fieldstring
Returns:
int

Reimplemented from DatabaseBase.

Definition at line 589 of file DatabaseMssql.php.

References $res, $size, fetchRow(), DatabaseBase\query(), and DatabaseBase\tableName().

DatabaseMssql::timestamp ( ts = 0)

Convert a timestamp in one of the formats accepted by wfTimestamp() to the format used for inserting into timestamp fields in this DBMS.

The result is unquoted, and needs to be passed through addQuotes() before it can be included in raw SQL.

Parameters:
$tsstring|int
Returns:
string

Reimplemented from DatabaseBase.

Definition at line 650 of file DatabaseMssql.php.

References wfTimestamp().

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

Returns:
Boolean

Reimplemented from DatabaseBase.

Definition at line 65 of file DatabaseMssql.php.


Member Data Documentation

DatabaseMssql::$mAffectedRows = null

Definition at line 33 of file DatabaseMssql.php.

DatabaseMssql::$mInsertId = null

Definition at line 31 of file DatabaseMssql.php.

DatabaseMssql::$mLastResult = null

Definition at line 32 of file DatabaseMssql.php.

DatabaseMssql::$mPort

Definition at line 35 of file DatabaseMssql.php.


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