MediaWiki  REL1_19
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.
 begin ($fname= 'DatabaseMssql::begin')
 Begin a transaction, committing any previously open transaction.
 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.
 close ()
 Closes a database connection, if it is open Returns success, true if already closed.
 commit ($fname= 'DatabaseMssql::commit')
 End a transaction.
 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)
 limitResultForUpdate ($sql, $num)
 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.
 rollback ($fname= 'DatabaseMssql::rollback')
 Rollback a transaction.
 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

 doQuery ($sql)
 The DBMS-dependent part of query()

Private Member Functions

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

Detailed Description

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

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

Parameters:
$sstring
Returns:
string

Reimplemented from DatabaseBase.

Definition at line 837 of file DatabaseMssql.php.

Referenced by initial_setup(), and insert().

Here is the caller graph for this function:

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 258 of file DatabaseMssql.php.

Begin a transaction, committing any previously open transaction.

Reimplemented from DatabaseBase.

Definition at line 684 of file DatabaseMssql.php.

DatabaseMssql::buildConcat ( stringList)

Build a concatenation list to feed into a SQL query.

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

Reimplemented from DatabaseBase.

Definition at line 901 of file DatabaseMssql.php.

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

Returns:
bool

Reimplemented from DatabaseBase.

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

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

Reimplemented from DatabaseBase.

Definition at line 111 of file DatabaseMssql.php.

Referenced by open().

Here is the caller graph for this function:

End a transaction.

Reimplemented from DatabaseBase.

Definition at line 692 of file DatabaseMssql.php.

Return the current value of a sequence.

Assumes it has ben nextval'ed in this session.

Definition at line 531 of file DatabaseMssql.php.

References nextSequenceValue().

Here is the call graph for this function:

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 234 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 791 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 120 of file DatabaseMssql.php.

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

Referenced by initial_setup(), and insert().

Here is the call graph for this function:

Here is the caller graph for this function:

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 786 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

Definition at line 711 of file DatabaseMssql.php.

Referenced by initial_setup().

Here is the caller graph for this function:

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()

Reimplemented from DatabaseBase.

Definition at line 314 of file DatabaseMssql.php.

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

Here is the call graph for this function:

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:
$resResultWrapper|object as returned from DatabaseBase::query(), etc.
Returns:
Row object
Exceptions:
DBUnexpectedErrorThrown if the database returns an error

Implements DatabaseType.

Definition at line 175 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'].

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

Implements DatabaseType.

Definition at line 198 of file DatabaseMssql.php.

References $res.

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

Here is the caller graph for this function:

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

Query whether a given column exists in the mediawiki schema.

Reimplemented from DatabaseBase.

Definition at line 651 of file DatabaseMssql.php.

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

Here is the call graph for this function:

DatabaseMssql::fieldInfo ( table,
field 
)

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

Parameters:
$tablestring: table name
$fieldstring: field name
Returns:
Field

Implements DatabaseType.

Definition at line 666 of file DatabaseMssql.php.

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

Here is the call graph for this function:

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 220 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 168 of file DatabaseMssql.php.

References $res.

Returns true if this database can use functional indexes.

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 40 of file DatabaseMssql.php.

Definition at line 183 of file DatabaseMssql.php.

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

Here is the caller graph for this function:

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

Todo:
Remove magic date

Reimplemented from DatabaseBase.

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

Returns:
string Version information from the database

Implements DatabaseType.

Definition at line 625 of file DatabaseMssql.php.

References $version.

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

Implements DatabaseType.

Definition at line 618 of file DatabaseMssql.php.

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

Implements DatabaseType.

Definition at line 897 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 34 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 37 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.

Implements DatabaseType.

Definition at line 330 of file DatabaseMssql.php.

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

Here is the call graph for this function:

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 730 of file DatabaseMssql.php.

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

Here is the call graph for this function:

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

Reimplemented from DatabaseBase.

Definition at line 369 of file DatabaseMssql.php.

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

Here is the call graph for this function:

This must be called after nextSequenceVal.

Implements DatabaseType.

Definition at line 230 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.

Reimplemented from DatabaseBase.

Definition at line 498 of file DatabaseMssql.php.

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

Here is the call graph for this function:

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 850 of file DatabaseMssql.php.

Get the last error number.

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

Implements DatabaseType.

Definition at line 249 of file DatabaseMssql.php.

Referenced by insert(), and insertSelect().

Here is the caller graph for this function:

Get a description of the last error.

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

Implements DatabaseType.

Definition at line 241 of file DatabaseMssql.php.

References getErrors().

Referenced by open().

Here is the call graph for this function:

Here is the caller graph for this function:

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)

Reimplemented from DatabaseBase.

Definition at line 563 of file DatabaseMssql.php.

References $limit.

Referenced by LimitToTopN().

Here is the caller graph for this function:

DatabaseMssql::limitResultForUpdate ( sql,
num 
)
Parameters:
$sql
$num
Returns:
string

Reimplemented from DatabaseBase.

Definition at line 607 of file DatabaseMssql.php.

Definition at line 585 of file DatabaseMssql.php.

References $matches, and limitResult().

Referenced by doQuery().

Here is the call graph for this function:

Here is the caller graph for this function:

Access:
private
Parameters:
$optionsArray: an 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 865 of file DatabaseMssql.php.

References $options.

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

Reimplemented from DatabaseBase.

Definition at line 515 of file DatabaseMssql.php.

References tableExists().

Referenced by currentSequenceValue().

Here is the call graph for this function:

Here is the caller graph for this function:

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 213 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 206 of file DatabaseMssql.php.

References $res.

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

Usually aborts on failure.

Implements DatabaseType.

Definition at line 50 of file DatabaseMssql.php.

References $user, $wgDBport, close(), lastError(), wfDebug(), wfRestoreWarnings(), and wfSuppressWarnings().

Here is the call graph for this function:

Returns true if this database uses timestamps rather than integers.

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 31 of file DatabaseMssql.php.

Rollback a transaction.

No-op on non-transactional databases.

Reimplemented from DatabaseBase.

Definition at line 701 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
$optionsArray: associative 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 275 of file DatabaseMssql.php.

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

Referenced by estimateRowCount().

Here is the call graph for this function:

Here is the caller graph for this function:

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 854 of file DatabaseMssql.php.

References DatabaseBase\query().

Here is the call graph for this function:

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
$optionsArray: Associative 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 300 of file DatabaseMssql.php.

References $fname, and $options.

Referenced by select().

Here is the caller graph for this function:

Wrapper for addslashes()

Parameters:
$sstring: to be slashed.
Returns:
string: slashed string.

Implements DatabaseType.

Definition at line 833 of file DatabaseMssql.php.

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 28 of file DatabaseMssql.php.

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

Definition at line 634 of file DatabaseMssql.php.

References $res, getErrors(), and print.

Referenced by nextSequenceValue().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from DatabaseBase.

Definition at line 799 of file DatabaseMssql.php.

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

Here is the call graph for this function:

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 543 of file DatabaseMssql.php.

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

Here is the call graph for this function:

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 611 of file DatabaseMssql.php.

References wfTimestamp().

Here is the call graph for this function:

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 43 of file DatabaseMssql.php.


Member Data Documentation

DatabaseMssql::$mAffectedRows = NULL

Definition at line 18 of file DatabaseMssql.php.

DatabaseMssql::$mInsertId = NULL

Definition at line 16 of file DatabaseMssql.php.

DatabaseMssql::$mLastResult = NULL

Definition at line 17 of file DatabaseMssql.php.

DatabaseMssql::$mPort

Definition at line 20 of file DatabaseMssql.php.


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