* @package MediaWiki
*/
-/**
- * Depends on the CacheManager
- */
-require_once( 'CacheManager.php' );
-
/** See Database::makeList() */
define( 'LIST_COMMA', 0 );
define( 'LIST_AND', 1 );
return $this->getMessage() . "\n";
}
+ function getLogMessage() {
+ # Don't send to the exception log
+ return false;
+ }
+
function getPageTitle() {
global $wgSitename;
return "$wgSitename has a problem";
}
}
+ function getLogMessage() {
+ # Don't send to the exception log
+ return false;
+ }
+
function getPageTitle() {
return $this->msg( 'databaseerror', 'Database error' );
}
protected $mTrxLevel = 0;
protected $mErrorCount = 0;
protected $mLBInfo = array();
+ protected $mCascadingDeletes = false;
+ protected $mCleanupTriggers = false;
+ protected $mStrictIPs = false;
#------------------------------------------------------------------------------
# Accessors
* Output page, used for reporting errors
* FALSE means discard output
*/
- function &setOutputPage( &$out ) {
- $this->mOut =& $out;
+ function setOutputPage( $out ) {
+ $this->mOut = $out;
}
/**
}
}
+ /**
+ * Returns true if this database supports (and uses) cascading deletes
+ */
+ function cascadingDeletes() {
+ return $this->mCascadingDeletes;
+ }
+
+ /**
+ * Returns true if this database supports (and uses) triggers (e.g. on the page table)
+ */
+ function cleanupTriggers() {
+ return $this->mCleanupTriggers;
+ }
+
+ /**
+ * Returns true if this database is strict about what can be put into an IP field.
+ * Specifically, it uses a NULL value instead of an empty string.
+ */
+ function strictIPs() {
+ return $this->mStrictIPs;
+ }
+
/**#@+
* Get function
*/
*/
function open( $server, $user, $password, $dbName ) {
global $wguname;
+ wfProfileIn( __METHOD__ );
# Test for missing mysql.so
# First try to load it
$success = (bool)$this->mConn;
}
- if ( !$success ) {
+ if ( $success ) {
+ global $wgDBmysql5;
+ if( $wgDBmysql5 ) {
+ // Tell the server we're communicating with it in UTF-8.
+ // This may engage various charset conversions.
+ $this->query( 'SET NAMES utf8' );
+ }
+ } else {
$this->reportConnectionError();
}
- global $wgDBmysql5;
- if( $wgDBmysql5 ) {
- // Tell the server we're communicating with it in UTF-8.
- // This may engage various charset conversions.
- $this->query( 'SET NAMES utf8' );
- }
-
$this->mOpened = $success;
+ wfProfileOut( __METHOD__ );
return $success;
}
/**@}}*/
*/
function fetchObject( $res ) {
@/**/$row = mysql_fetch_object( $res );
- if( mysql_errno() ) {
- throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( mysql_error() ) );
+ if( $this->lastErrno() ) {
+ throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) );
}
return $row;
}
*/
function fetchRow( $res ) {
@/**/$row = mysql_fetch_array( $res );
- if (mysql_errno() ) {
- throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( mysql_error() ) );
+ if ( $this->lastErrno() ) {
+ throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) );
}
return $row;
}
*/
function numRows( $res ) {
@/**/$n = mysql_num_rows( $res );
- if( mysql_errno() ) {
- throw new DBUnexpectedError( $this, 'Error in numRows(): ' . htmlspecialchars( mysql_error() ) );
+ if( $this->lastErrno() ) {
+ throw new DBUnexpectedError( $this, 'Error in numRows(): ' . htmlspecialchars( $this->lastError() ) );
}
return $n;
}
* @return string slashed string.
*/
function strencode( $s ) {
- return addslashes( $s );
+ return mysql_real_escape_string( $s, $this->mConn );
}
/**
# dubious, but unfortunately there's no easy rigorous way
$slaveThreads = 0;
while ( $row = $this->fetchObject( $res ) ) {
- if ( $row->User == 'system user' ) {
- if ( ++$slaveThreads == 2 ) {
- # This is it, return the time (except -ve)
- if ( $row->Time > 0x7fffffff ) {
- return false;
- } else {
- return $row->Time;
- }
+ /* This should work for most situations - when default db
+ * for thread is not specified, it had no events executed,
+ * and therefore it doesn't know yet how lagged it is.
+ *
+ * Relay log I/O thread does not select databases.
+ */
+ if ( $row->User == 'system user' &&
+ $row->State != 'Waiting for master to send event' &&
+ $row->State != 'Connecting to master' &&
+ $row->State != 'Queueing master event to the relay log' &&
+ $row->State != 'Waiting for master update' &&
+ $row->State != 'Requesting binlog dump'
+ ) {
+ # This is it, return the time (except -ve)
+ if ( $row->Time > 0x7fffffff ) {
+ return false;
+ } else {
+ return $row->Time;
}
}
}
return $b;
}
+ function decodeBlob($b) {
+ return $b;
+ }
+
/**
* Read and execute SQL commands from a file.
* Returns true on success, error string on failure
function sourceFile( $filename ) {
$fp = fopen( $filename, 'r' );
if ( false === $fp ) {
- return "Could not open \"{$fname}\".\n";
+ return "Could not open \"{$filename}\".\n";
}
$cmd = "";
// Ordinary variables
foreach ( $varnames as $var ) {
if( isset( $GLOBALS[$var] ) ) {
- $val = addslashes( $GLOBALS[$var] );
+ $val = addslashes( $GLOBALS[$var] ); // FIXME: safety check?
$ins = str_replace( '{$' . $var . '}', $val, $ins );
$ins = str_replace( '/*$' . $var . '*/`', '`' . $val, $ins );
$ins = str_replace( '/*$' . $var . '*/', $val, $ins );