MediaWiki  REL1_21
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)
 If it's a string, adds quotes and backslashes Otherwise returns as-is.
 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= 'DatabaseMssql::estimateRowCount', $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= 'DatabaseMssql::fieldExists')
 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 ()
 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= 'DatabaseMssql::indexExists')
 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= 'DatabaseMssql::insert', $options=array())
 INSERT wrapper, inserts an array into a table.
 insertId ()
 This must be called after nextSequenceVal.
 insertSelect ($destTable, $srcTable, $varMap, $conds, $fname= 'DatabaseMssql::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.
 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= 'DatabaseMssql::select', $options=array(), $join_conds=array())
 SELECT wrapper.
 selectDB ($db)
 Change the current database.
 selectSQLText ($table, $vars, $conds= '', $fname= 'DatabaseMssql::select', $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.

Static Public Member Functions

static getSoftwareLink ()

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= 'DatabaseMssql::begin')
 Begin a transaction, committing any previously open transaction.
 doCommit ($fname= 'DatabaseMssql::commit')
 End a transaction.
 doQuery ($sql)
 The DBMS-dependent part of query()
 doRollback ($fname= 'DatabaseMssql::rollback')
 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 878 of file DatabaseMssql.php.

References $s.

If it's a string, adds quotes and backslashes Otherwise returns as-is.

Parameters:
$sstring
Returns:
string

Reimplemented from DatabaseBase.

Definition at line 870 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 276 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 929 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 40 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 133 of file DatabaseMssql.php.

Return the current value of a sequence.

Assumes it has ben nextval'ed in this session.

Returns:

Definition at line 568 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 252 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 823 of file DatabaseMssql.php.

DatabaseMssql::doBegin ( fname = 'DatabaseMssql::begin') [protected]

Begin a transaction, committing any previously open transaction.

Reimplemented from DatabaseBase.

Definition at line 715 of file DatabaseMssql.php.

DatabaseMssql::doCommit ( fname = 'DatabaseMssql::commit') [protected]

End a transaction.

Reimplemented from DatabaseBase.

Definition at line 723 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 137 of file DatabaseMssql.php.

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

Referenced by initial_setup(), and insert().

DatabaseMssql::doRollback ( fname = 'DatabaseMssql::rollback') [protected]

Rollback a transaction.

No-op on non-transactional databases.

Reimplemented from DatabaseBase.

Definition at line 732 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 818 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 745 of file DatabaseMssql.php.

Referenced by initial_setup().

DatabaseMssql::estimateRowCount ( table,
vars = '*',
conds = '',
fname = 'DatabaseMssql::estimateRowCount',
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 333 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 192 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 215 of file DatabaseMssql.php.

References $res.

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

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

Query whether a given column exists in the mediawiki schema.

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 682 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 697 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 237 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 185 of file DatabaseMssql.php.

References $res.

Returns true if this database can use functional indexes.

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 55 of file DatabaseMssql.php.

Definition at line 200 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 942 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 933 of file DatabaseMssql.php.

Returns:
string Version information from the database

Implements DatabaseType.

Definition at line 655 of file DatabaseMssql.php.

static DatabaseMssql::getSoftwareLink ( ) [static]
Returns:
string wikitext of a link to the server software's web site

Implements DatabaseType.

Definition at line 648 of file DatabaseMssql.php.

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

Returns:
string

Implements DatabaseType.

Definition at line 925 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 49 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 52 of file DatabaseMssql.php.

DatabaseMssql::indexInfo ( table,
index,
fname = 'DatabaseMssql::indexExists' 
)

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

Returns:
array|bool|null

Implements DatabaseType.

Definition at line 350 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 764 of file DatabaseMssql.php.

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

DatabaseMssql::insert ( table,
arrToInsert,
fname = 'DatabaseMssql::insert',
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 395 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 248 of file DatabaseMssql.php.

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

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 533 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 883 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 267 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 259 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 601 of file DatabaseMssql.php.

References $limit.

Referenced by LimitToTopN().

Definition at line 623 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 898 of file DatabaseMssql.php.

References $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 551 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 230 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 223 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 71 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 46 of file DatabaseMssql.php.

DatabaseMssql::select ( table,
vars,
conds = '',
fname = 'DatabaseMssql::select',
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 293 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 887 of file DatabaseMssql.php.

References DatabaseBase\query().

DatabaseMssql::selectSQLText ( table,
vars,
conds = '',
fname = 'DatabaseMssql::select',
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 318 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 866 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 43 of file DatabaseMssql.php.

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

Definition at line 664 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 832 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 580 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 641 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 58 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: