wfDebug( "DB connection error\n" );
wfDebug( "Server: $server, Database: $dbName, User: $user, Password: " . substr( $password, 0, 3 ) . "...\n" );
wfDebug( $this->lastError() . "\n" );
+
return false;
}
$this->mOpened = true;
+
return $this->mConn;
}
// if it is a SELECT statement, or an insert with a request to output something we want to return a row.
if ( ( preg_match( '#\bSELECT\s#i', $sql ) ) ||
- ( preg_match( '#\bINSERT\s#i', $sql ) && preg_match( '#\bOUTPUT\s+INSERTED\b#i', $sql ) ) ) {
+ ( preg_match( '#\bINSERT\s#i', $sql ) && preg_match( '#\bOUTPUT\s+INSERTED\b#i', $sql ) )
+ ) {
// this is essentially a rowset, but Mediawiki calls these 'result'
// the rowset owns freeing the statement
$res = new MssqlResult( $stmt );
// otherwise we simply return it was successful, failure throws an exception
$res = true;
}
+
return $res;
}
$res = $res->result;
}
$row = $res->fetch( 'OBJECT' );
+
return $row;
}
} else {
$strRet = "No errors found";
}
+
return $strRet;
}
$res = $res->result;
}
$row = $res->fetch( SQLSRV_FETCH_BOTH );
+
return $row;
}
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
}
+
return ( $res ) ? $res->numrows() : 0;
}
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
}
+
return ( $res ) ? $res->numfields() : 0;
}
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
}
+
return ( $res ) ? $res->fieldname( $n ) : 0;
}
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
}
+
return ( $res ) ? $res->seek( $row ) : false;
}
* @param array $options associative array of options (e.g. array('GROUP BY' => 'page_title')),
* see Database::makeSelectOptions code for list of supported stuff
* @param $join_conds Array: Associative array of table join conditions (optional)
- * (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') )
+ * (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') )
* @return Mixed: database result resource (feed to Database::fetchObject or whatever), or false on failure
*/
- function select( $table, $vars, $conds = '', $fname = __METHOD__, $options = array(), $join_conds = array() )
- {
+ function select( $table, $vars, $conds = '', $fname = __METHOD__, $options = array(), $join_conds = array() ) {
$sql = $this->selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds );
if ( isset( $options['EXPLAIN'] ) ) {
sqlsrv_query( $this->mConn, "SET SHOWPLAN_ALL ON;" );
$ret = $this->query( $sql, $fname );
sqlsrv_query( $this->mConn, "SET SHOWPLAN_ALL OFF;" );
+
return $ret;
}
+
return $this->query( $sql, $fname );
}
* @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 array $options Associative array of options (e.g. array('GROUP BY' => 'page_title')),
+ * @param array $options Associative array of options (e.g. array('GROUP BY' => 'page_title')),
* see Database::makeSelectOptions code for list of supported stuff
* @param $join_conds Array: Associative array of table join conditions (optional)
* (e.g. array( 'page' => array('LEFT JOIN','page_latest=rev_id') )
if ( isset( $options['EXPLAIN'] ) ) {
unset( $options['EXPLAIN'] );
}
+
return parent::selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds );
}
* @return int
*/
function estimateRowCount( $table, $vars = '*', $conds = '', $fname = __METHOD__, $options = array() ) {
- $options['EXPLAIN'] = true;// http://msdn2.microsoft.com/en-us/library/aa259203.aspx
+ // http://msdn2.microsoft.com/en-us/library/aa259203.aspx
+ $options['EXPLAIN'] = true;
$res = $this->select( $table, $vars, $conds, $fname, $options );
$rows = -1;
$rows = $row['EstimateRows'];
}
}
+
return $rows;
}
}
}
}
+
return empty( $result ) ? false : $result;
}
$table = $this->tableName( $table );
- if ( !( isset( $arrToInsert[0] ) && is_array( $arrToInsert[0] ) ) ) {// Not multi row
- $arrToInsert = array( 0 => $arrToInsert );// make everything multi row compatible
+ if ( !( isset( $arrToInsert[0] ) && is_array( $arrToInsert[0] ) ) ) { // Not multi row
+ $arrToInsert = array( 0 => $arrToInsert ); // make everything multi row compatible
}
$allOk = true;
// there is a value being passed to us, we need to turn on and off inserted identity
$sqlPre = "SET IDENTITY_INSERT $table ON;";
$sqlPost = ";SET IDENTITY_INSERT $table OFF;";
-
} else {
// we can't insert NULL into an identity column, so remove the column from the insert.
unset( $a[$k] );
}
$allOk = false;
}
+
return $allOk;
}
} elseif ( $ret != null ) {
// remember number of rows affected
$this->mAffectedRows = sqlsrv_rows_affected( $ret );
+
return $ret;
}
+
return null;
}
}
sqlsrv_query( $this->mConn, "INSERT INTO [sequence_$seqName] (junk) VALUES ('')" );
$ret = sqlsrv_query( $this->mConn, "SELECT TOP 1 id FROM [sequence_$seqName] ORDER BY id DESC" );
- $row = sqlsrv_fetch_array( $ret, SQLSRV_FETCH_ASSOC );// KEEP ASSOC THERE, weird weird bug dealing with the return value if you don't
+ $row = sqlsrv_fetch_array( $ret, SQLSRV_FETCH_ASSOC ); // KEEP ASSOC THERE, weird weird bug dealing with the return value if you don't
sqlsrv_free_stmt( $ret );
$this->mInsertId = $row['id'];
+
return $row['id'];
}
if ( $ret !== false ) {
$row = sqlsrv_fetch_array( $ret );
sqlsrv_free_stmt( $ret );
+
return $row['id'];
} else {
return $this->nextSequenceValue( $seqName );
if ( strtolower( $row['DATA_TYPE'] ) != 'text' ) {
$size = $row['CHARACTER_MAXIMUM_LENGTH'];
}
+
return $size;
}
) as sub2
) AS sub3
WHERE line3 BETWEEN ' . ( $offset + 1 ) . ' AND ' . ( $offset + $limit );
+
return $sql;
}
}
$row_count = $matches[4];
// offset = $matches[3] OR $matches[6]
$offset = $matches[3] or
- $offset = $matches[6] or
- $offset = false;
+ $offset = $matches[6] or
+ $offset = false;
// strip the matching LIMIT clause out
$sql = str_replace( $matches[0], '', $sql );
+
return $this->limitResult( $sql, $row_count, $offset );
}
+
return $sql;
}
if ( isset( $server_info['SQLServerVersion'] ) ) {
$version = $server_info['SQLServerVersion'];
}
+
return $version;
}
WHERE table_type='BASE TABLE' AND table_name = '$table'" );
if ( $res === false ) {
print "Error in tableExists query: " . $this->getErrors();
+
return false;
}
if ( sqlsrv_fetch( $res ) ) {
WHERE TABLE_NAME = '$table' AND COLUMN_NAME = '$field'" );
if ( $res === false ) {
print "Error in fieldExists query: " . $this->getErrors();
+
return false;
}
if ( sqlsrv_fetch( $res ) ) {
WHERE TABLE_NAME = '$table' AND COLUMN_NAME = '$field'" );
if ( $res === false ) {
print "Error in fieldInfo query: " . $this->getErrors();
+
return false;
}
$meta = $this->fetchRow( $res );
if ( $meta ) {
return new MssqlField( $meta );
}
+
return false;
}
// It may be allowed if you quoted with double quotation marks, but that would break if QUOTED_IDENTIFIER is OFF
throw new MWException( "You can't use square brackers in the identifier '$identifier'" );
}
+
return "[$identifier]";
}
}
function encodeBlob( $b ) {
- // we can't have zero's and such, this is a simple encoding to make sure we don't barf
+ // we can't have zero's and such, this is a simple encoding to make sure we don't barf
return base64_encode( $b );
}
function decodeBlob( $b ) {
- // we can't have zero's and such, this is a simple encoding to make sure we don't barf
- return base64_decode( $b );
+ // we can't have zero's and such, this is a simple encoding to make sure we don't barf
+ return base64_decode( $b );
}
/**
// We can't separate explicit JOIN clauses with ',', use ' ' for those
$straightJoins = !empty( $ret ) ? implode( ',', $ret ) : "";
$otherJoins = !empty( $retJOIN ) ? implode( ' ', $retJOIN ) : "";
+
// Compile our final table clause
return implode( ' ', array( $straightJoins, $otherJoins ) );
}
public function getInfinity() {
return '3000-01-31 00:00:00.000';
}
-
} // end DatabaseMssql class
/**
*/
class MssqlField implements Field {
private $name, $tablename, $default, $max_length, $nullable, $type;
+
function __construct( $info ) {
$this->name = $info['COLUMN_NAME'];
$this->tablename = $info['TABLE_NAME'];
foreach ( $rows as $row ) {
if ( $row !== null ) {
foreach ( $row as $k => $v ) {
- if ( is_object( $v ) && method_exists( $v, 'format' ) ) {// DateTime Object
+ if ( is_object( $v ) && method_exists( $v, 'format' ) ) { // DateTime Object
$row[$k] = $v->format( "Y-m-d\TH:i:s\Z" );
}
}
- $this->mRows[] = $row;// read results into memory, cursors are not supported
+ $this->mRows[] = $row; // read results into memory, cursors are not supported
}
}
$this->mRowCount = count( $this->mRows );
}
}
}
+
return $obj;
}
}
$this->mCursor++;
+
return $ret;
}
public function fieldname( $nr ) {
$arrKeys = array_keys( $this->mRows[0] );
+
return $arrKeys[$nr];
}
default:
$strType = $intType;
}
+
return $strType;
}