/**
* @ingroup Database
*/
-class DatabaseMssql extends Database {
+class DatabaseMssql extends DatabaseBase {
var $mAffectedRows;
var $mLastResult;
$failFunction = false, $flags = 0, $tablePrefix = 'get from global') {
global $wgOut, $wgDBprefix, $wgCommandLineMode;
- if (!isset($wgOut)) $wgOut = NULL; # Can't get a reference if it hasn't been set yet
+ if (!isset($wgOut)) $wgOut = null; # Can't get a reference if it hasn't been set yet
$this->mOut =& $wgOut;
$this->mFailFunction = $failFunction;
$this->mFlags = $flags;
}
+ function getType() {
+ return 'mssql';
+ }
+
/**
* todo: check if these should be true like parent class
*/
$success = @/**/mssql_select_db($dbName, $this->mConn);
if (!$success) {
$error = "Error selecting database $dbName on server {$this->mServer} " .
- "from client host {$wguname['nodename']}\n";
+ "from client host " . wfHostname() . "\n";
wfLogDBError(" Error selecting database $dbName on server {$this->mServer} \n");
wfDebug( $error );
}
function close() {
$this->mOpened = false;
if ($this->mConn) {
- if ($this->trxLevel()) $this->immediateCommit();
+ if ($this->trxLevel()) $this->commit();
return mssql_close($this->mConn);
} else return true;
}
return $ret;
}
- /**#@+
- * @param mixed $res A SQL result
- */
/**
* Free a result object
*/
/**
* Get the number of fields in a result object
* See documentation for mysql_num_fields()
+ * @param $res SQL result object as returned from Database::query(), etc.
*/
function numFields( $res ) {
if ( $res instanceof ResultWrapper ) {
* Get a field name in a result object
* See documentation for mysql_field_name():
* http://www.php.net/mysql_field_name
+ * @param $res SQL result object as returned from Database::query(), etc.
+ * @param $n Int
*/
function fieldName( $res, $n ) {
if ( $res instanceof ResultWrapper ) {
/**
* Change the position of the cursor in a result object
* See mysql_data_seek()
+ * @param $res SQL result object as returned from Database::query(), etc.
+ * @param $row Database row
*/
function dataSeek( $res, $row ) {
if ( $res instanceof ResultWrapper ) {
*
* @private
*
- * @param array $options an associative array of options to be turned into
+ * @param $options Array: an associative array of options to be turned into
* an SQL query, valid keys are listed in the function.
* @return array
*/
/**
* SELECT wrapper
*
- * @param mixed $table Array or string, table name(s) (prefix auto-added)
- * @param mixed $vars Array or string, field name(s) to be retrieved
- * @param mixed $conds Array or string, condition(s) for WHERE
- * @param string $fname Calling function name (use __METHOD__) for logs/profiling
- * @param array $options Associative array of options (e.g. array('GROUP BY' => 'page_title')),
+ * @param $table Mixed: Array or string, table name(s) (prefix auto-added)
+ * @param $vars Mixed: Array or string, field name(s) to be retrieved
+ * @param $conds Mixed: Array or string, condition(s) for WHERE
+ * @param $fname String: Calling function name (use __METHOD__) for logs/profiling
+ * @param $options Array: Associative array of options (e.g. array('GROUP BY' => 'page_title')),
* see Database::makeSelectOptions code for list of supported stuff
* @return mixed Database result resource (feed to Database::fetchObject or whatever), or false on failure
*/
return $this->query( $sql, $fname );
}
- /**
- * Estimate rows in dataset
- * Returns estimated count, based on EXPLAIN output
- * Takes same arguments as Database::select()
- */
- function estimateRowCount( $table, $vars='*', $conds='', $fname = 'Database::estimateRowCount', $options = array() ) {
- $rows = 0;
- $res = $this->select ($table, 'COUNT(*)', $conds, $fname, $options );
- if ($res) {
- $row = $this->fetchObject($res);
- $rows = $row[0];
- }
- $this->freeResult($res);
- return $rows;
- }
-
/**
* Determines whether a field exists in a table
* Usually aborts on failure
function indexInfo( $table, $index, $fname = 'Database::indexInfo' ) {
throw new DBUnexpectedError( $this, 'Database::indexInfo called which is not supported yet' );
- return NULL;
+ return null;
$table = $this->tableName( $table );
$sql = 'SHOW INDEX FROM '.$table;
$res = $this->query( $sql, $fname );
if ( !$res ) {
- return NULL;
+ return null;
}
$result = array();
/**
* UPDATE wrapper, takes a condition array and a SET array
*
- * @param string $table The table to UPDATE
- * @param array $values An array of values to SET
- * @param array $conds An array of conditions (WHERE). Use '*' to update all rows.
- * @param string $fname The Class::Function calling this function
- * (for the log)
- * @param array $options An array of UPDATE options, can be one or
+ * @param $table String: The table to UPDATE
+ * @param $values Array: An array of values to SET
+ * @param $conds Array: An array of conditions (WHERE). Use '*' to update all rows.
+ * @param $fname String: The Class::Function calling this function
+ * (for the log)
+ * @param $options Array: An array of UPDATE options, can be one or
* more of IGNORE, LOW_PRIORITY
* @return bool
*/
* Make UPDATE options for the Database::update function
*
* @private
- * @param array $options The options passed to Database::update
+ * @param $options Array: The options passed to Database::update
* @return string
*/
function makeUpdateOptions( $options ) {
/**
* MSSQL doubles quotes instead of escaping them
- * @param string $s String to be slashed.
+ * @param $s String to be slashed.
* @return string slashed string.
*/
function strencode($s) {
return str_replace("'","''",$s);
}
- /**
- * USE INDEX clause
- */
- function useIndexClause( $index ) {
- return "";
- }
-
/**
* REPLACE query wrapper
* PostgreSQL simulates this with a DELETE followed by INSERT
*
* DO NOT put the join condition in $conds
*
- * @param string $delTable The table to delete from.
- * @param string $joinTable The other table.
- * @param string $delVar The variable to join on, in the first table.
- * @param string $joinVar The variable to join on, in the second table.
- * @param array $conds Condition array of field names mapped to variables, ANDed together in the WHERE clause
+ * @param $delTable String: The table to delete from.
+ * @param $joinTable String: The other table.
+ * @param $delVar String: The variable to join on, in the first table.
+ * @param $joinVar String: The variable to join on, in the second table.
+ * @param $conds Array: Condition array of field names mapped to variables, ANDed together in the WHERE clause
+ * @param $fname String: Calling function name
*/
function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'Database::deleteJoin' ) {
if ( !$conds ) {
if ($offset) {
throw new DBUnexpectedError( $this, 'Database::limitResult called with non-zero offset which is not supported yet' );
} else {
- $sql = ereg_replace("^SELECT", "SELECT TOP $limit", $sql);
+ $sql = preg_replace("/^SELECT/i", "SELECT TOP $limit", $sql);
}
return $sql;
}
- /**
- * Returns an SQL expression for a simple conditional.
- *
- * @param string $cond SQL expression which will result in a boolean value
- * @param string $trueVal SQL expression to return if true
- * @param string $falseVal SQL expression to return if false
- * @return string SQL fragment
- */
- function conditional( $cond, $trueVal, $falseVal ) {
- return " (CASE WHEN $cond THEN $trueVal ELSE $falseVal END) ";
- }
-
/**
* Should determine if the last failure was due to a deadlock
* @return bool
return $this->lastErrno() == 1205;
}
- /**
- * Begin a transaction, committing any previously open transaction
- * @deprecated use begin()
- */
- function immediateBegin( $fname = 'Database::immediateBegin' ) {
- $this->begin();
- }
-
- /**
- * Commit transaction, if one is open
- * @deprecated use commit()
- */
- function immediateCommit( $fname = 'Database::immediateCommit' ) {
- $this->commit();
- }
-
/**
* Return MW-style timestamp used for MySQL schema
*/
*/
function getServerVersion() {
$row = mssql_fetch_row(mssql_query('select @@VERSION'));
- return ereg("^(.+[0-9]+\\.[0-9]+\\.[0-9]+) ",$row[0],$m) ? $m[1] : $row[0];
+ return preg_match("/^(.+[0-9]+\\.[0-9]+\\.[0-9]+) /",$row[0],$m) ? $m[1] : $row[0];
}
function limitResultForUpdate($sql, $num) {
return $sql;
}
- /**
- * not done
- */
- public function setTimeout($timeout) { return; }
-
- function ping() {
- wfDebug("Function ping() not written for MSSQL yet");
- return true;
- }
-
/**
* How lagged is this slave?
*/
}
}
- /**
- * No-op lock functions
- */
- public function lock( $lockName, $method ) {
- return true;
- }
- public function unlock( $lockName, $method ) {
- return true;
- }
-
public function getSearchEngine() {
return "SearchEngineDummy";
}
-
}
/**