* @ingroup Database
*/
class DatabaseMssql extends Database {
- protected $mPort;
- protected $mUseWindowsAuth = false;
-
- protected $mInsertId = null;
- protected $mLastResult = null;
- protected $mAffectedRows = null;
- protected $mSubqueryId = 0;
- protected $mScrollableCursor = true;
- protected $mPrepareStatements = true;
- protected $mBinaryColumnCache = null;
- protected $mBitColumnCache = null;
- protected $mIgnoreDupKeyErrors = false;
- protected $mIgnoreErrors = [];
+ /** @var int */
+ protected $serverPort;
+ /** @var bool */
+ protected $useWindowsAuth = false;
+ /** @var int|null */
+ protected $lastInsertId = null;
+ /** @var int|null */
+ protected $lastAffectedRowCount = null;
+ /** @var int */
+ protected $subqueryId = 0;
+ /** @var bool */
+ protected $scrollableCursor = true;
+ /** @var bool */
+ protected $prepareStatements = true;
+ /** @var stdClass[][]|null */
+ protected $binaryColumnCache = null;
+ /** @var stdClass[][]|null */
+ protected $bitColumnCache = null;
+ /** @var bool */
+ protected $ignoreDupKeyErrors = false;
+ /** @var string[] */
+ protected $ignoreErrors = [];
public function implicitGroupby() {
return false;
}
public function __construct( array $params ) {
- $this->mPort = $params['port'];
- $this->mUseWindowsAuth = $params['UseWindowsAuth'];
+ $this->serverPort = $params['port'];
+ $this->useWindowsAuth = $params['UseWindowsAuth'];
parent::__construct( $params );
}
// Decide which auth scenerio to use
// if we are using Windows auth, then don't add credentials to $connectionInfo
- if ( !$this->mUseWindowsAuth ) {
+ if ( !$this->useWindowsAuth ) {
$connectionInfo['UID'] = $user;
$connectionInfo['PWD'] = $password;
}
// needed if we want to be able to seek around the result set), however CLIENT_BUFFERED
// has a bug in the sqlsrv driver where wchar_t types (such as nvarchar) that are empty
// strings make php throw a fatal error "Severe error translating Unicode"
- if ( $this->mScrollableCursor ) {
+ if ( $this->scrollableCursor ) {
$scrollArr = [ 'Scrollable' => SQLSRV_CURSOR_STATIC ];
} else {
$scrollArr = [];
}
- if ( $this->mPrepareStatements ) {
+ if ( $this->prepareStatements ) {
// we do prepare + execute so we can get its field metadata for later usage if desired
$stmt = sqlsrv_prepare( $this->conn, $sql, [], $scrollArr );
$success = sqlsrv_execute( $stmt );
}
// Make a copy to ensure what we add below does not get reflected in future queries
- $ignoreErrors = $this->mIgnoreErrors;
+ $ignoreErrors = $this->ignoreErrors;
- if ( $this->mIgnoreDupKeyErrors ) {
+ if ( $this->ignoreDupKeyErrors ) {
// ignore duplicate key errors
// this emulates INSERT IGNORE in MySQL
$ignoreErrors[] = '2601'; // duplicate key error caused by unique index
}
}
// remember number of rows affected
- $this->mAffectedRows = sqlsrv_rows_affected( $stmt );
+ $this->lastAffectedRowCount = sqlsrv_rows_affected( $stmt );
return $stmt;
}
* @return int|null
*/
public function insertId() {
- return $this->mInsertId;
+ return $this->lastInsertId;
}
/**
* @return int
*/
protected function fetchAffectedRowCount() {
- return $this->mAffectedRows;
+ return $this->lastAffectedRowCount;
}
/**
$sql = $this->selectSQLText( $table, $vars, $conds, $fname, $options, $join_conds );
if ( isset( $options['EXPLAIN'] ) ) {
try {
- $this->mScrollableCursor = false;
- $this->mPrepareStatements = false;
+ $this->scrollableCursor = false;
+ $this->prepareStatements = false;
$this->query( "SET SHOWPLAN_ALL ON" );
$ret = $this->query( $sql, $fname );
$this->query( "SET SHOWPLAN_ALL OFF" );
} else {
// someone actually wanted the query plan instead of an est row count
// let them know of the error
- $this->mScrollableCursor = true;
- $this->mPrepareStatements = true;
+ $this->scrollableCursor = true;
+ $this->prepareStatements = true;
throw $dqe;
}
}
- $this->mScrollableCursor = true;
- $this->mPrepareStatements = true;
+ $this->scrollableCursor = true;
+ $this->prepareStatements = true;
return $ret;
}
return $this->query( $sql, $fname );
public function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds,
$fname = __METHOD__
) {
- $this->mScrollableCursor = false;
+ $this->scrollableCursor = false;
try {
parent::deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname );
} catch ( Exception $e ) {
- $this->mScrollableCursor = true;
+ $this->scrollableCursor = true;
throw $e;
}
- $this->mScrollableCursor = true;
+ $this->scrollableCursor = true;
}
public function delete( $table, $conds, $fname = __METHOD__ ) {
- $this->mScrollableCursor = false;
+ $this->scrollableCursor = false;
try {
parent::delete( $table, $conds, $fname );
} catch ( Exception $e ) {
- $this->mScrollableCursor = true;
+ $this->scrollableCursor = true;
throw $e;
}
- $this->mScrollableCursor = true;
+ $this->scrollableCursor = true;
}
/**
// remove IGNORE from options list and set ignore flag to true
if ( in_array( 'IGNORE', $options ) ) {
$options = array_diff( $options, [ 'IGNORE' ] );
- $this->mIgnoreDupKeyErrors = true;
+ $this->ignoreDupKeyErrors = true;
}
$ret = null;
$sql .= ')' . $sqlPost;
// Run the query
- $this->mScrollableCursor = false;
+ $this->scrollableCursor = false;
try {
$ret = $this->query( $sql );
} catch ( Exception $e ) {
- $this->mScrollableCursor = true;
- $this->mIgnoreDupKeyErrors = false;
+ $this->scrollableCursor = true;
+ $this->ignoreDupKeyErrors = false;
throw $e;
}
- $this->mScrollableCursor = true;
+ $this->scrollableCursor = true;
if ( $ret instanceof ResultWrapper && !is_null( $identity ) ) {
// Then we want to get the identity column value we were assigned and save it off
$row = $ret->fetchObject();
if ( is_object( $row ) ) {
- $this->mInsertId = $row->$identity;
+ $this->lastInsertId = $row->$identity;
// It seems that mAffectedRows is -1 sometimes when OUTPUT INSERTED.identity is
// used if we got an identity back, we know for sure a row was affected, so
// adjust that here
- if ( $this->mAffectedRows == -1 ) {
- $this->mAffectedRows = 1;
+ if ( $this->lastAffectedRowCount == -1 ) {
+ $this->lastAffectedRowCount = 1;
}
}
}
}
- $this->mIgnoreDupKeyErrors = false;
+ $this->ignoreDupKeyErrors = false;
return $ret;
}
* @param array $insertOptions
* @param array $selectOptions
* @param array $selectJoinConds
- * @return null|ResultWrapper
+ * @return bool
* @throws Exception
*/
public function nativeInsertSelect( $destTable, $srcTable, $varMap, $conds, $fname = __METHOD__,
$insertOptions = [], $selectOptions = [], $selectJoinConds = []
) {
- $this->mScrollableCursor = false;
+ $this->scrollableCursor = false;
try {
$ret = parent::nativeInsertSelect(
$destTable,
$selectJoinConds
);
} catch ( Exception $e ) {
- $this->mScrollableCursor = true;
+ $this->scrollableCursor = true;
throw $e;
}
- $this->mScrollableCursor = true;
+ $this->scrollableCursor = true;
return $ret;
}
$sql .= " WHERE " . $this->makeList( $conds, LIST_AND, $binaryColumns );
}
- $this->mScrollableCursor = false;
+ $this->scrollableCursor = false;
try {
$this->query( $sql );
} catch ( Exception $e ) {
- $this->mScrollableCursor = true;
+ $this->scrollableCursor = true;
throw $e;
}
- $this->mScrollableCursor = true;
+ $this->scrollableCursor = true;
return true;
}
$postOrder = '';
$first = $offset + 1;
$last = $offset + $limit;
- $sub1 = 'sub_' . $this->mSubqueryId;
- $sub2 = 'sub_' . ( $this->mSubqueryId + 1 );
- $this->mSubqueryId += 2;
+ $sub1 = 'sub_' . $this->subqueryId;
+ $sub2 = 'sub_' . ( $this->subqueryId + 1 );
+ $this->subqueryId += 2;
if ( !$s1 ) {
// wat
throw new DBUnexpectedError( $this, "Attempting to LIMIT a non-SELECT query\n" );
public function buildGroupConcatField( $delim, $table, $field, $conds = '',
$join_conds = []
) {
- $gcsq = 'gcsq_' . $this->mSubqueryId;
- $this->mSubqueryId++;
+ $gcsq = 'gcsq_' . $this->subqueryId;
+ $this->subqueryId++;
$delimLen = strlen( $delim );
$fld = "{$field} + {$this->addQuotes( $delim )}";
$tableRawArr = explode( '.', preg_replace( '#\[([^\]]*)\]#', '$1', $table ) );
$tableRaw = array_pop( $tableRawArr );
- if ( $this->mBinaryColumnCache === null ) {
+ if ( $this->binaryColumnCache === null ) {
$this->populateColumnCaches();
}
- return isset( $this->mBinaryColumnCache[$tableRaw] )
- ? $this->mBinaryColumnCache[$tableRaw]
+ return isset( $this->binaryColumnCache[$tableRaw] )
+ ? $this->binaryColumnCache[$tableRaw]
: [];
}
$tableRawArr = explode( '.', preg_replace( '#\[([^\]]*)\]#', '$1', $table ) );
$tableRaw = array_pop( $tableRawArr );
- if ( $this->mBitColumnCache === null ) {
+ if ( $this->bitColumnCache === null ) {
$this->populateColumnCaches();
}
- return isset( $this->mBitColumnCache[$tableRaw] )
- ? $this->mBitColumnCache[$tableRaw]
+ return isset( $this->bitColumnCache[$tableRaw] )
+ ? $this->bitColumnCache[$tableRaw]
: [];
}
'DATA_TYPE' => [ 'varbinary', 'binary', 'image', 'bit' ]
] );
- $this->mBinaryColumnCache = [];
- $this->mBitColumnCache = [];
+ $this->binaryColumnCache = [];
+ $this->bitColumnCache = [];
foreach ( $res as $row ) {
if ( $row->DATA_TYPE == 'bit' ) {
- $this->mBitColumnCache[$row->TABLE_NAME][$row->COLUMN_NAME] = $row;
+ $this->bitColumnCache[$row->TABLE_NAME][$row->COLUMN_NAME] = $row;
} else {
- $this->mBinaryColumnCache[$row->TABLE_NAME][$row->COLUMN_NAME] = $row;
+ $this->binaryColumnCache[$row->TABLE_NAME][$row->COLUMN_NAME] = $row;
}
}
}
* @return bool|null
*/
public function prepareStatements( $value = null ) {
- $old = $this->mPrepareStatements;
+ $old = $this->prepareStatements;
if ( $value !== null ) {
- $this->mPrepareStatements = $value;
+ $this->prepareStatements = $value;
}
return $old;
* @return bool|null
*/
public function scrollableCursor( $value = null ) {
- $old = $this->mScrollableCursor;
+ $old = $this->scrollableCursor;
if ( $value !== null ) {
- $this->mScrollableCursor = $value;
+ $this->scrollableCursor = $value;
}
return $old;