DatabaseMssql Class Reference
[Database]

Inherits DatabaseBase.

List of all members.

Public Member Functions

 __construct ($server=false, $user=false, $password=false, $dbName=false, $failFunction=false, $flags=0, $tablePrefix= 'get from global')
 Constructor.
 getType ()
 Get the type of the DBMS, as it appears in $wgDBtype.
 implicitGroupby ()
 todo: check if these should be true like parent class
 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.
 open ($server, $user, $password, $dbName)
 Open an MSSQL database and return a resource handle to it NOTE: only $dbName is used, the other parameters are irrelevant for MSSQL databases.
 close ()
 Close an MSSQL database.
 doQuery ($sql)
 
  • MSSQL doesn't seem to do buffered results
    • the trasnaction syntax is modified here to avoid having to replicate Database::query which uses BEGIN, COMMIT, ROLLBACK

 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.
 lastError ()
 Get a description of the last error.
 affectedRows ()
 Get the number of rows affected by the last write query.
 set ($table, $var, $value, $cond, $fname= 'Database::set')
 Simple UPDATE wrapper Usually aborts on failure If errors are explicitly ignored, returns success.
 selectField ($table, $var, $cond='', $fname= 'Database::selectField', $options=array())
 Simple SELECT wrapper, returns a single field, input must be encoded Usually aborts on failure If errors are explicitly ignored, returns FALSE on failure.
 makeSelectOptions ($options)
 Returns an optional USE INDEX clause to go after the table, and a string to go at the end of the query.
 select ($table, $vars, $conds='', $fname= 'Database::select', $options=array())
 SELECT wrapper.
 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.
 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
 insert ($table, $a, $fname= 'Database::insert', $options=array())
 INSERT wrapper, inserts an array into a table.
 makeListWithoutNulls ($a, $mode=LIST_COMMA)
 MSSQL doesn't allow implicit casting of NULL's into non-null values for NOT NULL columns for now I've just converted the NULL's in the lists for updates and inserts into empty strings which get implicitly casted to 0 for numeric columns NOTE: the set() method above converts NULL to empty string as well but not via this method.
 update ($table, $values, $conds, $fname= 'Database::update', $options=array())
 UPDATE wrapper, takes a condition array and a SET array.
 makeUpdateOptions ($options)
 Make UPDATE options for the Database::update function.
 selectDB ($db)
 Change the current database.
 tableName ($name)
 MSSQL has a problem with the backtick quoting, so all this does is ensure the prefix is added exactly once.
 strencode ($s)
 MSSQL doubles quotes instead of escaping them.
 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 ()
 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 $sql string SQL query we will append the limit to $limit integer the SQL limit $offset integer the SQL offset (default false).
 wasDeadlock ()
 Should determine if the last failure was due to a deadlock.
 timestamp ($ts=0)
 Return MW-style timestamp used for MySQL schema.
 timestampOrNull ($ts=null)
 Local database timestamp format or null.
 getSoftwareLink ()
 getServerVersion ()
 limitResultForUpdate ($sql, $num)
 getLag ()
 How lagged is this slave?
 setup_database ()
 Called by the installer script
  • this is the same way as DatabasePostgresql.php, MySQL reads in tables.sql and interwiki.sql using dbsource (which calls db->sourceFile).

 getSearchEngine ()
 Get search engine class.

Static Public Member Functions

static newFromParams ($server, $user, $password, $dbName, $failFunction=false, $flags=0)
 Same as new DatabaseMysql( .

Public Attributes

 $mAffectedRows
 $mLastResult
 $mLastError
 $mLastErrorNo
 $mDatabaseFile


Detailed Description

Definition at line 13 of file DatabaseMssql.php.


Constructor & Destructor Documentation

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

Constructor.

Reimplemented from DatabaseBase.

Definition at line 24 of file DatabaseMssql.php.

References $wgCommandLineMode, $wgDBprefix, $wgOut, and open().


Member Function Documentation

DatabaseMssql::affectedRows (  ) 

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

Reimplemented from DatabaseBase.

Definition at line 297 of file DatabaseMssql.php.

DatabaseMssql::close (  ) 

Close an MSSQL database.

Reimplemented from DatabaseBase.

Definition at line 135 of file DatabaseMssql.php.

References DatabaseBase::commit(), and DatabaseBase::trxLevel().

Referenced by open().

DatabaseMssql::dataSeek ( res,
row 
)

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

Parameters:
$res SQL result object as returned from Database::query(), etc.
$row Database row

Reimplemented from DatabaseBase.

Definition at line 273 of file DatabaseMssql.php.

References $res.

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

Reimplemented from DatabaseBase.

Definition at line 748 of file DatabaseMssql.php.

References $fname, DatabaseBase::makeList(), DatabaseBase::query(), and tableName().

DatabaseMssql::doQuery ( sql  ) 

  • MSSQL doesn't seem to do buffered results
    • the trasnaction syntax is modified here to avoid having to replicate Database::query which uses BEGIN, COMMIT, ROLLBACK

Reimplemented from DatabaseBase.

Definition at line 148 of file DatabaseMssql.php.

DatabaseMssql::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 from DatabaseBase.

Definition at line 182 of file DatabaseMssql.php.

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

Referenced by indexInfo(), and textFieldSize().

DatabaseMssql::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 from DatabaseBase.

Definition at line 201 of file DatabaseMssql.php.

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

Referenced by selectField().

DatabaseMssql::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 from DatabaseBase.

Definition at line 457 of file DatabaseMssql.php.

References $res, freeResult(), DatabaseBase::query(), and tableName().

DatabaseMssql::fieldInfo ( table,
field 
)

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

Parameters:
$table 
$field 

Reimplemented from DatabaseBase.

Definition at line 519 of file DatabaseMssql.php.

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

DatabaseMssql::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 SQL result object as returned from Database::query(), etc.
$n Int

Reimplemented from DatabaseBase.

Definition at line 245 of file DatabaseMssql.php.

References $n, and $res.

DatabaseMssql::fieldType ( res,
index 
)

mysql_field_type() wrapper

Reimplemented from DatabaseBase.

Definition at line 535 of file DatabaseMssql.php.

References $res.

DatabaseMssql::freeResult ( res  ) 

Free a result object.

Reimplemented from DatabaseBase.

Definition at line 164 of file DatabaseMssql.php.

References $res.

Referenced by fieldExists(), indexInfo(), selectField(), tableExists(), and textFieldSize().

DatabaseMssql::getLag (  ) 

How lagged is this slave?

Reimplemented from DatabaseBase.

Definition at line 889 of file DatabaseMssql.php.

DatabaseMssql::getSearchEngine (  ) 

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

DatabaseMssql::getServerVersion (  ) 

Returns:
string Version information from the database

Reimplemented from DatabaseBase.

Definition at line 877 of file DatabaseMssql.php.

DatabaseMssql::getSoftwareLink (  ) 

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

Reimplemented from DatabaseBase.

Definition at line 870 of file DatabaseMssql.php.

DatabaseMssql::getType (  ) 

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

Reimplemented from DatabaseBase.

Definition at line 48 of file DatabaseMssql.php.

DatabaseMssql::implicitGroupby (  ) 

todo: check if these should be true like parent class

Reimplemented from DatabaseBase.

Definition at line 55 of file DatabaseMssql.php.

DatabaseMssql::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 from DatabaseBase.

Definition at line 56 of file DatabaseMssql.php.

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

Get information about an index into an object Returns false if the index does not exist.

Reimplemented from DatabaseBase.

Definition at line 478 of file DatabaseMssql.php.

References $fname, $res, $result, fetchObject(), freeResult(), DatabaseBase::query(), and tableName().

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

Same as parent class implementation except that it removes primary key from column lists because MSSQL doesn't support writing nulls to IDENTITY (AUTO_INCREMENT) columns

Reimplemented from DatabaseBase.

Definition at line 554 of file DatabaseMssql.php.

References $fname, $i, $ignore, $keys, $options, makeListWithoutNulls(), DatabaseBase::query(), and tableName().

DatabaseMssql::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 from DatabaseBase.

Definition at line 262 of file DatabaseMssql.php.

DatabaseMssql::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 from DatabaseBase.

Definition at line 796 of file DatabaseMssql.php.

References $fname, DatabaseBase::makeList(), makeSelectOptions(), DatabaseBase::query(), and tableName().

DatabaseMssql::lastErrno (  ) 

Get the last error number.

Reimplemented from DatabaseBase.

Definition at line 283 of file DatabaseMssql.php.

Referenced by fetchObject(), fetchRow(), numRows(), and wasDeadlock().

DatabaseMssql::lastError (  ) 

Get a description of the last error.

Reimplemented from DatabaseBase.

Definition at line 290 of file DatabaseMssql.php.

Referenced by fetchObject(), fetchRow(), and numRows().

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 to $limit integer the SQL limit $offset integer the SQL offset (default false).

Reimplemented from DatabaseBase.

Definition at line 829 of file DatabaseMssql.php.

Referenced by select().

DatabaseMssql::limitResultForUpdate ( sql,
num 
)

Reimplemented from DatabaseBase.

Definition at line 882 of file DatabaseMssql.php.

DatabaseMssql::lowPriorityOption (  ) 

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

Reimplemented from DatabaseBase.

Definition at line 785 of file DatabaseMssql.php.

Referenced by makeUpdateOptions().

DatabaseMssql::makeListWithoutNulls ( a,
mode = LIST_COMMA 
)

MSSQL doesn't allow implicit casting of NULL's into non-null values for NOT NULL columns for now I've just converted the NULL's in the lists for updates and inserts into empty strings which get implicitly casted to 0 for numeric columns NOTE: the set() method above converts NULL to empty string as well but not via this method.

Definition at line 629 of file DatabaseMssql.php.

References $mode, and DatabaseBase::makeList().

Referenced by insert(), set(), and update().

DatabaseMssql::makeSelectOptions ( options  ) 

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

Access:
private
Parameters:
$options Array: 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 352 of file DatabaseMssql.php.

References $options, and DatabaseBase::useIndexClause().

Referenced by insertSelect(), and select().

DatabaseMssql::makeUpdateOptions ( options  ) 

Make UPDATE options for the Database::update function.

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

Reimplemented from DatabaseBase.

Definition at line 662 of file DatabaseMssql.php.

References $options, and lowPriorityOption().

Referenced by update().

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

Same as new DatabaseMysql( .

.. ), 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 from DatabaseBase.

Definition at line 58 of file DatabaseMssql.php.

DatabaseMssql::numFields ( res  ) 

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

Parameters:
$res SQL result object as returned from Database::query(), etc.

Reimplemented from DatabaseBase.

Definition at line 231 of file DatabaseMssql.php.

References $res.

DatabaseMssql::numRows ( res  ) 

Get the number of rows in a result object.

Reimplemented from DatabaseBase.

Definition at line 215 of file DatabaseMssql.php.

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

Referenced by selectField().

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

Open an MSSQL database and return a resource handle to it NOTE: only $dbName is used, the other parameters are irrelevant for MSSQL databases.

Reimplemented from DatabaseBase.

Definition at line 65 of file DatabaseMssql.php.

References $i, $success, close(), DatabaseBase::reportConnectionError(), wfDebug(), wfHostname(), wfLogDBError(), wfProfileIn(), and wfProfileOut().

Referenced by __construct().

DatabaseMssql::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 from DatabaseBase.

Definition at line 711 of file DatabaseMssql.php.

References $fname, $rows, DatabaseBase::makeList(), DatabaseBase::query(), and tableName().

DatabaseMssql::select ( table,
vars,
conds = '',
fname = 'Database::select',
options = 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
Returns:
mixed Database result resource (feed to Database::fetchObject or whatever), or false on failure

Definition at line 407 of file DatabaseMssql.php.

References $fname, $options, limitResult(), DatabaseBase::makeList(), makeSelectOptions(), DatabaseBase::query(), and tableName().

Referenced by selectField().

DatabaseMssql::selectDB ( db  ) 

Change the current database.

Reimplemented from DatabaseBase.

Definition at line 677 of file DatabaseMssql.php.

DatabaseMssql::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 from DatabaseBase.

Definition at line 323 of file DatabaseMssql.php.

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

DatabaseMssql::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 from DatabaseBase.

Definition at line 309 of file DatabaseMssql.php.

References $fname, makeListWithoutNulls(), DatabaseBase::query(), strencode(), and tableName().

DatabaseMssql::setup_database (  ) 

Called by the installer script

  • this is the same way as DatabasePostgresql.php, MySQL reads in tables.sql and interwiki.sql using dbsource (which calls db->sourceFile).

Definition at line 897 of file DatabaseMssql.php.

References $IP, $wgDBTableOptions, DatabaseBase::conditional(), DatabaseBase::query(), DatabaseBase::reportQueryError(), and DatabaseBase::sourceFile().

DatabaseMssql::strencode ( s  ) 

MSSQL doubles quotes instead of escaping them.

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

Reimplemented from DatabaseBase.

Definition at line 694 of file DatabaseMssql.php.

References $s.

Referenced by set().

DatabaseMssql::tableExists ( table  ) 

Query whether a given table exists.

Reimplemented from DatabaseBase.

Definition at line 504 of file DatabaseMssql.php.

References $res, freeResult(), DatabaseBase::query(), and tableName().

DatabaseMssql::tableName ( name  ) 

MSSQL has a problem with the backtick quoting, so all this does is ensure the prefix is added exactly once.

Reimplemented from DatabaseBase.

Definition at line 685 of file DatabaseMssql.php.

References $name.

Referenced by deleteJoin(), fieldExists(), fieldInfo(), indexInfo(), insert(), insertSelect(), replace(), select(), set(), tableExists(), textFieldSize(), and update().

DatabaseMssql::textFieldSize ( table,
field 
)

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

Reimplemented from DatabaseBase.

Definition at line 766 of file DatabaseMssql.php.

References $res, $size, fetchObject(), freeResult(), DatabaseBase::query(), and tableName().

DatabaseMssql::timestamp ( ts = 0  ) 

Return MW-style timestamp used for MySQL schema.

Reimplemented from DatabaseBase.

Definition at line 852 of file DatabaseMssql.php.

References wfTimestamp().

Referenced by timestampOrNull().

DatabaseMssql::timestampOrNull ( ts = null  ) 

Local database timestamp format or null.

Reimplemented from DatabaseBase.

Definition at line 859 of file DatabaseMssql.php.

References timestamp().

DatabaseMssql::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:
bool

Reimplemented from DatabaseBase.

Definition at line 645 of file DatabaseMssql.php.

References $fname, $options, DatabaseBase::makeList(), makeListWithoutNulls(), makeUpdateOptions(), DatabaseBase::query(), and tableName().

DatabaseMssql::wasDeadlock (  ) 

Should determine if the last failure was due to a deadlock.

Returns:
bool

Reimplemented from DatabaseBase.

Definition at line 845 of file DatabaseMssql.php.

References lastErrno().


Member Data Documentation

DatabaseMssql::$mAffectedRows

Definition at line 15 of file DatabaseMssql.php.

DatabaseMssql::$mDatabaseFile

Definition at line 19 of file DatabaseMssql.php.

DatabaseMssql::$mLastError

Definition at line 17 of file DatabaseMssql.php.

DatabaseMssql::$mLastErrorNo

Definition at line 18 of file DatabaseMssql.php.

DatabaseMssql::$mLastResult

Definition at line 16 of file DatabaseMssql.php.


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

Generated on Sat Apr 30 22:57:35 2011 for MediaWiki by  doxygen 1.5.9