* @see Database
*/
class DatabaseMysql extends DatabaseBase {
+
+ /**
+ * @return string
+ */
function getType() {
return 'mysql';
}
}
if ( $success ) {
- $version = $this->getServerVersion();
- if ( version_compare( $version, '4.1' ) >= 0 ) {
- // Tell the server we're communicating with it in UTF-8.
- // This may engage various charset conversions.
- global $wgDBmysql5;
- if( $wgDBmysql5 ) {
- $this->query( 'SET NAMES utf8', __METHOD__ );
- } else {
- $this->query( 'SET NAMES binary', __METHOD__ );
- }
- // Set SQL mode, default is turning them all off, can be overridden or skipped with null
- global $wgSQLMode;
- if ( is_string( $wgSQLMode ) ) {
- $mode = $this->addQuotes( $wgSQLMode );
- $this->query( "SET sql_mode = $mode", __METHOD__ );
- }
+ // Tell the server we're communicating with it in UTF-8.
+ // This may engage various charset conversions.
+ global $wgDBmysql5;
+ if( $wgDBmysql5 ) {
+ $this->query( 'SET NAMES utf8', __METHOD__ );
+ } else {
+ $this->query( 'SET NAMES binary', __METHOD__ );
+ }
+ // Set SQL mode, default is turning them all off, can be overridden or skipped with null
+ global $wgSQLMode;
+ if ( is_string( $wgSQLMode ) ) {
+ $mode = $this->addQuotes( $wgSQLMode );
+ $this->query( "SET sql_mode = $mode", __METHOD__ );
}
// Turn off strict mode if it is on
return $success;
}
+ /**
+ * @return bool
+ */
function close() {
$this->mOpened = false;
if ( $this->mConn ) {
return $row;
}
+ /**
+ * @throws DBUnexpectedError
+ * @param $res
+ * @return int
+ */
function numRows( $res ) {
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
return $n;
}
+ /**
+ * @param $res
+ * @return int
+ */
function numFields( $res ) {
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
return mysql_num_fields( $res );
}
+ /**
+ * @param $res
+ * @param $n
+ * @return string
+ */
function fieldName( $res, $n ) {
if ( $res instanceof ResultWrapper ) {
$res = $res->result;
return mysql_field_name( $res, $n );
}
- function insertId() { return mysql_insert_id( $this->mConn ); }
+ /**
+ * @return int
+ */
+ function insertId() {
+ return mysql_insert_id( $this->mConn );
+ }
function dataSeek( $res, $row ) {
if ( $res instanceof ResultWrapper ) {
return $error;
}
- function affectedRows() { return mysql_affected_rows( $this->mConn ); }
+ /**
+ * @return int
+ */
+ function affectedRows() {
+ return mysql_affected_rows( $this->mConn );
+ }
function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseMysql::replace' ) {
return $this->nativeReplace( $table, $rows, $fname );
* Estimate rows in dataset
* Returns estimated count, based on EXPLAIN output
* Takes same arguments as Database::select()
+ *
+ * @return int
*/
public function estimateRowCount( $table, $vars='*', $conds='', $fname = 'DatabaseMysql::estimateRowCount', $options = array() ) {
$options['EXPLAIN'] = true;
return $rows;
}
+ /**
+ * @param $table string
+ * @param $field string
+ * @return bool|MySQLField
+ */
function fieldInfo( $table, $field ) {
$table = $this->tableName( $table );
$res = $this->query( "SELECT * FROM $table LIMIT 1", __METHOD__, true );
/**
* Get information about an index into an object
* Returns false if the index does not exist
+ *
+ * @return false|array
*/
function indexInfo( $table, $index, $fname = 'DatabaseMysql::indexInfo' ) {
# SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not.
return empty( $result ) ? false : $result;
}
+ /**
+ * @param $db
+ * @return bool
+ */
function selectDB( $db ) {
$this->mDBname = $db;
return mysql_select_db( $db, $this->mConn );
}
+ /**
+ * @param $s string
+ *
+ * @return string
+ */
function strencode( $s ) {
$sQuoted = mysql_real_escape_string( $s, $this->mConn );
/**
* MySQL uses `backticks` for identifier quoting instead of the sql standard "double quotes".
+ *
+ * @param $s string
+ *
+ * @return string
*/
public function addIdentifierQuotes( $s ) {
return "`" . $this->strencode( $s ) . "`";
}
+ /**
+ * @param $name string
+ * @return bool
+ */
public function isQuotedIdentifier( $name ) {
- return strlen($name) && $name[0] == '`' && substr( $name, -1, 1 ) == '`';
+ return strlen( $name ) && $name[0] == '`' && substr( $name, -1, 1 ) == '`';
}
+ /**
+ * @return bool
+ */
function ping() {
$ping = mysql_ping( $this->mConn );
if ( $ping ) {
/**
* Returns slave lag.
*
- * On MySQL 4.1.9 and later, this will do a SHOW SLAVE STATUS. On earlier
- * versions of MySQL, it uses SHOW PROCESSLIST, which requires the PROCESS
- * privilege.
+ * On MySQL 4.1.9 and later, this will do a SHOW SLAVE STATUS
*
* @return int
*/
return $this->mFakeSlaveLag;
}
- /*if ( version_compare( $this->getServerVersion(), '4.1.9', '>=' ) ) {
- return $this->getLagFromSlaveStatus();
- } else */{
- return $this->getLagFromProcesslist();
- }
+ return $this->getLagFromSlaveStatus();
}
/**
}
/**
+ * @deprecated in 1.19, use getLagFromSlaveStatus
+ *
* @return bool|int
*/
function getLagFromProcesslist() {
}
}
+ /**
+ * @return string
+ */
function getServerVersion() {
return mysql_get_server_info( $this->mConn );
}
+ /**
+ * @param $index
+ * @return string
+ */
function useIndexClause( $index ) {
return "FORCE INDEX (" . $this->indexName( $index ) . ")";
}
+ /**
+ * @return string
+ */
function lowPriorityOption() {
return 'LOW_PRIORITY';
}
+ /**
+ * @return string
+ */
public static function getSoftwareLink() {
return '[http://www.mysql.com/ MySQL]';
}
/**
* Determines if the last failure was due to a deadlock
+ *
+ * @return bool
*/
function wasDeadlock() {
return $this->lastErrno() == 1213;
/**
* Determines if the last query error was something that should be dealt
* with by pinging the connection and reissuing the query
+ *
+ * @return bool
*/
function wasErrorReissuable() {
return $this->lastErrno() == 2013 || $this->lastErrno() == 2006;
/**
* Determines if the last failure was due to the database being read-only.
+ *
+ * @return bool
*/
function wasReadOnlyError() {
return $this->lastErrno() == 1223 ||
function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseMysql::duplicateTableStructure' ) {
$tmp = $temporary ? 'TEMPORARY ' : '';
- if ( strcmp( $this->getServerVersion(), '4.1' ) < 0 ) {
- # Hack for MySQL versions < 4.1, which don't support
- # "CREATE TABLE ... LIKE". Note that
- # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
- # would not create the indexes we need....
- #
- # Note that we don't bother changing around the prefixes here be-
- # cause we know we're using MySQL anyway.
-
- $res = $this->query( 'SHOW CREATE TABLE ' . $this->addIdentifierQuotes( $oldName ) );
- $row = $this->fetchRow( $res );
- $oldQuery = $row[1];
- $query = preg_replace( '/CREATE TABLE `(.*?)`/',
- "CREATE $tmp TABLE " . $this->addIdentifierQuotes( $newName ), $oldQuery );
- if ($oldQuery === $query) {
- # Couldn't do replacement
- throw new MWException( "could not create temporary table $newName" );
- }
- } else {
- $newName = $this->addIdentifierQuotes( $newName );
- $oldName = $this->addIdentifierQuotes( $oldName );
- $query = "CREATE $tmp TABLE $newName (LIKE $oldName)";
- }
+ $newName = $this->addIdentifierQuotes( $newName );
+ $oldName = $this->addIdentifierQuotes( $oldName );
+ $query = "CREATE $tmp TABLE $newName (LIKE $oldName)";
$this->query( $query, $fname );
}
return $endArray;
}
+ /**
+ * @param $tableName
+ * @param $fName string
+ * @return bool|ResultWrapper
+ */
public function dropTable( $tableName, $fName = 'DatabaseMysql::dropTable' ) {
- if( !$this->tableExists( $tableName ) ) {
+ if( !$this->tableExists( $tableName, $fName ) ) {
return false;
}
return $this->query( "DROP TABLE IF EXISTS " . $this->tableName( $tableName ), $fName );
}
+ /**
+ * @return array
+ */
protected function getDefaultSchemaVars() {
$vars = parent::getDefaultSchemaVars();
- $vars['wgDBTableOptions'] = $GLOBALS['wgDBTableOptions'];
+ $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $GLOBALS['wgDBTableOptions'] );
+ $vars['wgDBTableOptions'] = str_replace( 'CHARSET=mysql4', 'CHARSET=binary', $GLOBALS['wgDBTableOptions'] );
return $vars;
}
/**
* Legacy support: Database == DatabaseMysql
+ *
+ * @deprecated in 1.16
*/
class Database extends DatabaseMysql {}
$this->type = $info->type;
}
+ /**
+ * @return string
+ */
function name() {
return $this->name;
}
+ /**
+ * @return string
+ */
function tableName() {
return $this->tableName;
}
return $this->type;
}
+ /**
+ * @return bool
+ */
function isNullable() {
return $this->nullable;
}
return $this->default;
}
+ /**
+ * @return bool
+ */
function isKey() {
return $this->is_key;
}
+ /**
+ * @return bool
+ */
function isMultipleKey() {
return $this->is_multiple;
}