3 * This is the MySQL database abstraction layer.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Database abstraction object for MySQL.
26 * Defines methods independent on used MySQL extension.
32 abstract class DatabaseMysqlBase
extends DatabaseBase
{
33 /** @var MysqlMasterPos */
34 protected $lastKnownSlavePos;
44 * @param $server string
46 * @param $password string
47 * @param $dbName string
49 * @throws DBConnectionError
51 function open( $server, $user, $password, $dbName ) {
52 global $wgAllDBsAreLocalhost, $wgDBmysql5, $wgSQLMode;
53 wfProfileIn( __METHOD__
);
55 # Debugging hack -- fake cluster
56 if ( $wgAllDBsAreLocalhost ) {
57 $realServer = 'localhost';
59 $realServer = $server;
62 $this->mServer
= $server;
64 $this->mPassword
= $password;
65 $this->mDBname
= $dbName;
67 wfProfileIn( "dbconnect-$server" );
69 # The kernel's default SYN retransmission period is far too slow for us,
70 # so we use a short timeout plus a manual retry. Retrying means that a small
71 # but finite rate of SYN packet loss won't cause user-visible errors.
73 $this->installErrorHandler();
75 $this->mConn
= $this->mysqlConnect( $realServer );
76 } catch ( Exception
$ex ) {
77 wfProfileOut( "dbconnect-$server" );
78 wfProfileOut( __METHOD__
);
81 $error = $this->restoreErrorHandler();
83 wfProfileOut( "dbconnect-$server" );
85 # Always log connection errors
86 if ( !$this->mConn
) {
88 $error = $this->lastError();
90 wfLogDBError( "Error connecting to {$this->mServer}: $error\n" );
91 wfDebug( "DB connection error\n" .
92 "Server: $server, User: $user, Password: " .
93 substr( $password, 0, 3 ) . "..., error: " . $error . "\n" );
95 wfProfileOut( __METHOD__
);
96 return $this->reportConnectionError( $error );
99 if ( $dbName != '' ) {
100 wfSuppressWarnings();
101 $success = $this->selectDB( $dbName );
104 wfLogDBError( "Error selecting database $dbName on server {$this->mServer}\n" );
105 wfDebug( "Error selecting database $dbName on server {$this->mServer} " .
106 "from client host " . wfHostname() . "\n" );
108 wfProfileOut( __METHOD__
);
109 return $this->reportConnectionError( "Error selecting database $dbName" );
113 // Tell the server we're communicating with it in UTF-8.
114 // This may engage various charset conversions.
116 $this->query( 'SET NAMES utf8', __METHOD__
);
118 $this->query( 'SET NAMES binary', __METHOD__
);
120 // Set SQL mode, default is turning them all off, can be overridden or skipped with null
121 if ( is_string( $wgSQLMode ) ) {
122 $mode = $this->addQuotes( $wgSQLMode );
123 $this->query( "SET sql_mode = $mode", __METHOD__
);
126 $this->mOpened
= true;
127 wfProfileOut( __METHOD__
);
132 * Open a connection to a MySQL server
134 * @param $realServer string
135 * @return mixed Raw connection
136 * @throws DBConnectionError
138 abstract protected function mysqlConnect( $realServer );
141 * @param $res ResultWrapper
142 * @throws DBUnexpectedError
144 function freeResult( $res ) {
145 if ( $res instanceof ResultWrapper
) {
148 wfSuppressWarnings();
149 $ok = $this->mysqlFreeResult( $res );
152 throw new DBUnexpectedError( $this, "Unable to free MySQL result" );
159 * @param $res Raw result
162 abstract protected function mysqlFreeResult( $res );
165 * @param $res ResultWrapper
166 * @return object|bool
167 * @throws DBUnexpectedError
169 function fetchObject( $res ) {
170 if ( $res instanceof ResultWrapper
) {
173 wfSuppressWarnings();
174 $row = $this->mysqlFetchObject( $res );
177 $errno = $this->lastErrno();
178 // Unfortunately, mysql_fetch_object does not reset the last errno.
179 // Only check for CR_SERVER_LOST and CR_UNKNOWN_ERROR, as
180 // these are the only errors mysql_fetch_object can cause.
181 // See http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-row.html.
182 if ( $errno == 2000 ||
$errno == 2013 ) {
183 throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) );
189 * Fetch a result row as an object
191 * @param $res Raw result
194 abstract protected function mysqlFetchObject( $res );
197 * @param $res ResultWrapper
199 * @throws DBUnexpectedError
201 function fetchRow( $res ) {
202 if ( $res instanceof ResultWrapper
) {
205 wfSuppressWarnings();
206 $row = $this->mysqlFetchArray( $res );
209 $errno = $this->lastErrno();
210 // Unfortunately, mysql_fetch_array does not reset the last errno.
211 // Only check for CR_SERVER_LOST and CR_UNKNOWN_ERROR, as
212 // these are the only errors mysql_fetch_array can cause.
213 // See http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-row.html.
214 if ( $errno == 2000 ||
$errno == 2013 ) {
215 throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) );
221 * Fetch a result row as an associative and numeric array
223 * @param $res Raw result
226 abstract protected function mysqlFetchArray( $res );
229 * @throws DBUnexpectedError
230 * @param $res ResultWrapper
233 function numRows( $res ) {
234 if ( $res instanceof ResultWrapper
) {
237 wfSuppressWarnings();
238 $n = $this->mysqlNumRows( $res );
240 // Unfortunately, mysql_num_rows does not reset the last errno.
241 // We are not checking for any errors here, since
242 // these are no errors mysql_num_rows can cause.
243 // See http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-row.html.
244 // See https://bugzilla.wikimedia.org/42430
249 * Get number of rows in result
251 * @param $res Raw result
254 abstract protected function mysqlNumRows( $res );
257 * @param $res ResultWrapper
260 function numFields( $res ) {
261 if ( $res instanceof ResultWrapper
) {
264 return $this->mysqlNumFields( $res );
268 * Get number of fields in result
270 * @param $res Raw result
273 abstract protected function mysqlNumFields( $res );
276 * @param $res ResultWrapper
280 function fieldName( $res, $n ) {
281 if ( $res instanceof ResultWrapper
) {
284 return $this->mysqlFieldName( $res, $n );
288 * Get the name of the specified field in a result
290 * @param $res Raw result
294 abstract protected function mysqlFieldName( $res, $n );
297 * @param $res ResultWrapper
301 function dataSeek( $res, $row ) {
302 if ( $res instanceof ResultWrapper
) {
305 return $this->mysqlDataSeek( $res, $row );
309 * Move internal result pointer
311 * @param $res Raw result
315 abstract protected function mysqlDataSeek( $res, $row );
320 function lastError() {
321 if ( $this->mConn
) {
322 # Even if it's non-zero, it can still be invalid
323 wfSuppressWarnings();
324 $error = $this->mysqlError( $this->mConn
);
326 $error = $this->mysqlError();
330 $error = $this->mysqlError();
333 $error .= ' (' . $this->mServer
. ')';
339 * Returns the text of the error message from previous MySQL operation
341 * @param $conn Raw connection
344 abstract protected function mysqlError( $conn = null );
347 * @param $table string
348 * @param $uniqueIndexes
350 * @param $fname string
351 * @return ResultWrapper
353 function replace( $table, $uniqueIndexes, $rows, $fname = __METHOD__
) {
354 return $this->nativeReplace( $table, $rows, $fname );
358 * Estimate rows in dataset
359 * Returns estimated count, based on EXPLAIN output
360 * Takes same arguments as Database::select()
362 * @param $table string|array
363 * @param $vars string|array
364 * @param $conds string|array
365 * @param $fname string
366 * @param $options string|array
369 public function estimateRowCount( $table, $vars = '*', $conds = '', $fname = __METHOD__
, $options = array() ) {
370 $options['EXPLAIN'] = true;
371 $res = $this->select( $table, $vars, $conds, $fname, $options );
372 if ( $res === false ) {
375 if ( !$this->numRows( $res ) ) {
380 foreach ( $res as $plan ) {
381 $rows *= $plan->rows
> 0 ?
$plan->rows
: 1; // avoid resetting to zero
387 * @param $table string
388 * @param $field string
389 * @return bool|MySQLField
391 function fieldInfo( $table, $field ) {
392 $table = $this->tableName( $table );
393 $res = $this->query( "SELECT * FROM $table LIMIT 1", __METHOD__
, true );
397 $n = $this->mysqlNumFields( $res->result
);
398 for ( $i = 0; $i < $n; $i++
) {
399 $meta = $this->mysqlFetchField( $res->result
, $i );
400 if ( $field == $meta->name
) {
401 return new MySQLField( $meta );
408 * Get column information from a result
410 * @param $res Raw result
414 abstract protected function mysqlFetchField( $res, $n );
417 * Get information about an index into an object
418 * Returns false if the index does not exist
420 * @param $table string
421 * @param $index string
422 * @param $fname string
423 * @return bool|array|null False or null on failure
425 function indexInfo( $table, $index, $fname = __METHOD__
) {
426 # SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not.
427 # SHOW INDEX should work for 3.x and up:
428 # http://dev.mysql.com/doc/mysql/en/SHOW_INDEX.html
429 $table = $this->tableName( $table );
430 $index = $this->indexName( $index );
432 $sql = 'SHOW INDEX FROM ' . $table;
433 $res = $this->query( $sql, $fname );
441 foreach ( $res as $row ) {
442 if ( $row->Key_name
== $index ) {
446 return empty( $result ) ?
false : $result;
454 function strencode( $s ) {
455 $sQuoted = $this->mysqlRealEscapeString( $s );
457 if ( $sQuoted === false ) {
459 $sQuoted = $this->mysqlRealEscapeString( $s );
465 * MySQL uses `backticks` for identifier quoting instead of the sql standard "double quotes".
471 public function addIdentifierQuotes( $s ) {
472 // Characters in the range \u0001-\uFFFF are valid in a quoted identifier
473 // Remove NUL bytes and escape backticks by doubling
474 return '`' . str_replace( array( "\0", '`' ), array( '', '``' ), $s ) . '`';
478 * @param $name string
481 public function isQuotedIdentifier( $name ) {
482 return strlen( $name ) && $name[0] == '`' && substr( $name, -1, 1 ) == '`';
489 $ping = $this->mysqlPing();
494 $this->closeConnection();
495 $this->mOpened
= false;
496 $this->mConn
= false;
497 $this->open( $this->mServer
, $this->mUser
, $this->mPassword
, $this->mDBname
);
502 * Ping a server connection or reconnect if there is no connection
506 abstract protected function mysqlPing();
511 * This will do a SHOW SLAVE STATUS
516 if ( !is_null( $this->mFakeSlaveLag
) ) {
517 wfDebug( "getLag: fake slave lagged {$this->mFakeSlaveLag} seconds\n" );
518 return $this->mFakeSlaveLag
;
521 return $this->getLagFromSlaveStatus();
527 function getLagFromSlaveStatus() {
528 $res = $this->query( 'SHOW SLAVE STATUS', __METHOD__
);
532 $row = $res->fetchObject();
536 if ( strval( $row->Seconds_Behind_Master
) === '' ) {
539 return intval( $row->Seconds_Behind_Master
);
544 * @deprecated in 1.19, use getLagFromSlaveStatus
548 function getLagFromProcesslist() {
549 wfDeprecated( __METHOD__
, '1.19' );
550 $res = $this->query( 'SHOW PROCESSLIST', __METHOD__
);
554 # Find slave SQL thread
555 foreach ( $res as $row ) {
556 /* This should work for most situations - when default db
557 * for thread is not specified, it had no events executed,
558 * and therefore it doesn't know yet how lagged it is.
560 * Relay log I/O thread does not select databases.
562 if ( $row->User
== 'system user' &&
563 $row->State
!= 'Waiting for master to send event' &&
564 $row->State
!= 'Connecting to master' &&
565 $row->State
!= 'Queueing master event to the relay log' &&
566 $row->State
!= 'Waiting for master update' &&
567 $row->State
!= 'Requesting binlog dump' &&
568 $row->State
!= 'Waiting to reconnect after a failed master event read' &&
569 $row->State
!= 'Reconnecting after a failed master event read' &&
570 $row->State
!= 'Registering slave on master'
572 # This is it, return the time (except -ve)
573 if ( $row->Time
> 0x7fffffff ) {
584 * Wait for the slave to catch up to a given master position.
585 * @TODO: return values for this and base class are rubbish
587 * @param $pos DBMasterPos object
588 * @param $timeout Integer: the maximum number of seconds to wait for synchronisation
589 * @return bool|string
591 function masterPosWait( DBMasterPos
$pos, $timeout ) {
592 if ( $this->lastKnownSlavePos
&& $this->lastKnownSlavePos
->hasReached( $pos ) ) {
593 return '0'; // http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html
596 wfProfileIn( __METHOD__
);
597 # Commit any open transactions
598 $this->commit( __METHOD__
, 'flush' );
600 if ( !is_null( $this->mFakeSlaveLag
) ) {
601 $status = parent
::masterPosWait( $pos, $timeout );
602 wfProfileOut( __METHOD__
);
606 # Call doQuery() directly, to avoid opening a transaction if DBO_TRX is set
607 $encFile = $this->addQuotes( $pos->file
);
608 $encPos = intval( $pos->pos
);
609 $sql = "SELECT MASTER_POS_WAIT($encFile, $encPos, $timeout)";
610 $res = $this->doQuery( $sql );
613 if ( $res && $row = $this->fetchRow( $res ) ) {
614 $status = $row[0]; // can be NULL, -1, or 0+ per the MySQL manual
615 if ( ctype_digit( $status ) ) { // success
616 $this->lastKnownSlavePos
= $pos;
620 wfProfileOut( __METHOD__
);
625 * Get the position of the master from SHOW SLAVE STATUS
627 * @return MySQLMasterPos|bool
629 function getSlavePos() {
630 if ( !is_null( $this->mFakeSlaveLag
) ) {
631 return parent
::getSlavePos();
634 $res = $this->query( 'SHOW SLAVE STATUS', 'DatabaseBase::getSlavePos' );
635 $row = $this->fetchObject( $res );
638 $pos = isset( $row->Exec_master_log_pos
) ?
$row->Exec_master_log_pos
: $row->Exec_Master_Log_Pos
;
639 return new MySQLMasterPos( $row->Relay_Master_Log_File
, $pos );
646 * Get the position of the master from SHOW MASTER STATUS
648 * @return MySQLMasterPos|bool
650 function getMasterPos() {
651 if ( $this->mFakeMaster
) {
652 return parent
::getMasterPos();
655 $res = $this->query( 'SHOW MASTER STATUS', 'DatabaseBase::getMasterPos' );
656 $row = $this->fetchObject( $res );
659 return new MySQLMasterPos( $row->File
, $row->Position
);
669 function useIndexClause( $index ) {
670 return "FORCE INDEX (" . $this->indexName( $index ) . ")";
676 function lowPriorityOption() {
677 return 'LOW_PRIORITY';
683 public function getSoftwareLink() {
684 return '[http://www.mysql.com/ MySQL]';
688 * @param $options array
690 public function setSessionOptions( array $options ) {
691 if ( isset( $options['connTimeout'] ) ) {
692 $timeout = (int)$options['connTimeout'];
693 $this->query( "SET net_read_timeout=$timeout" );
694 $this->query( "SET net_write_timeout=$timeout" );
698 public function streamStatementEnd( &$sql, &$newLine ) {
699 if ( strtoupper( substr( $newLine, 0, 9 ) ) == 'DELIMITER' ) {
700 preg_match( '/^DELIMITER\s+(\S+)/', $newLine, $m );
701 $this->delimiter
= $m[1];
704 return parent
::streamStatementEnd( $sql, $newLine );
708 * Check to see if a named lock is available. This is non-blocking.
710 * @param string $lockName name of lock to poll
711 * @param string $method name of method calling us
715 public function lockIsFree( $lockName, $method ) {
716 $lockName = $this->addQuotes( $lockName );
717 $result = $this->query( "SELECT IS_FREE_LOCK($lockName) AS lockstatus", $method );
718 $row = $this->fetchObject( $result );
719 return ( $row->lockstatus
== 1 );
723 * @param $lockName string
724 * @param $method string
725 * @param $timeout int
728 public function lock( $lockName, $method, $timeout = 5 ) {
729 $lockName = $this->addQuotes( $lockName );
730 $result = $this->query( "SELECT GET_LOCK($lockName, $timeout) AS lockstatus", $method );
731 $row = $this->fetchObject( $result );
733 if ( $row->lockstatus
== 1 ) {
736 wfDebug( __METHOD__
. " failed to acquire lock\n" );
742 * FROM MYSQL DOCS: http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_release-lock
743 * @param $lockName string
744 * @param $method string
747 public function unlock( $lockName, $method ) {
748 $lockName = $this->addQuotes( $lockName );
749 $result = $this->query( "SELECT RELEASE_LOCK($lockName) as lockstatus", $method );
750 $row = $this->fetchObject( $result );
751 return ( $row->lockstatus
== 1 );
756 * @param $write array
757 * @param $method string
758 * @param $lowPriority bool
761 public function lockTables( $read, $write, $method, $lowPriority = true ) {
764 foreach ( $write as $table ) {
765 $tbl = $this->tableName( $table ) .
766 ( $lowPriority ?
' LOW_PRIORITY' : '' ) .
770 foreach ( $read as $table ) {
771 $items[] = $this->tableName( $table ) . ' READ';
773 $sql = "LOCK TABLES " . implode( ',', $items );
774 $this->query( $sql, $method );
779 * @param $method string
782 public function unlockTables( $method ) {
783 $this->query( "UNLOCK TABLES", $method );
788 * Get search engine class. All subclasses of this
789 * need to implement this if they wish to use searching.
793 public function getSearchEngine() {
794 return 'SearchMySQL';
801 public function setBigSelects( $value = true ) {
802 if ( $value === 'default' ) {
803 if ( $this->mDefaultBigSelects
=== null ) {
804 # Function hasn't been called before so it must already be set to the default
807 $value = $this->mDefaultBigSelects
;
809 } elseif ( $this->mDefaultBigSelects
=== null ) {
810 $this->mDefaultBigSelects
= (bool)$this->selectField( false, '@@sql_big_selects' );
812 $encValue = $value ?
'1' : '0';
813 $this->query( "SET sql_big_selects=$encValue", __METHOD__
);
817 * DELETE where the condition is a join. MySql uses multi-table deletes.
818 * @param $delTable string
819 * @param $joinTable string
820 * @param $delVar string
821 * @param $joinVar string
822 * @param $conds array|string
823 * @param bool|string $fname bool
824 * @throws DBUnexpectedError
825 * @return bool|ResultWrapper
827 function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = __METHOD__
) {
829 throw new DBUnexpectedError( $this, 'DatabaseBase::deleteJoin() called with empty $conds' );
832 $delTable = $this->tableName( $delTable );
833 $joinTable = $this->tableName( $joinTable );
834 $sql = "DELETE $delTable FROM $delTable, $joinTable WHERE $delVar=$joinVar ";
836 if ( $conds != '*' ) {
837 $sql .= ' AND ' . $this->makeList( $conds, LIST_AND
);
840 return $this->query( $sql, $fname );
844 * @param string $table
846 * @param array $uniqueIndexes
848 * @param string $fname
849 * @param array $options
852 public function upsert(
853 $table, array $rows, array $uniqueIndexes, array $set, $fname = __METHOD__
855 if ( !count( $rows ) ) {
856 return true; // nothing to do
858 $rows = is_array( reset( $rows ) ) ?
$rows : array( $rows );
860 $table = $this->tableName( $table );
861 $columns = array_keys( $rows[0] );
863 $sql = "INSERT INTO $table (" . implode( ',', $columns ) . ') VALUES ';
864 $rowTuples = array();
865 foreach ( $rows as $row ) {
866 $rowTuples[] = '(' . $this->makeList( $row ) . ')';
868 $sql .= implode( ',', $rowTuples );
869 $sql .= " ON DUPLICATE KEY UPDATE " . $this->makeList( $set, LIST_SET
);
871 return (bool)$this->query( $sql, $fname );
875 * Determines how long the server has been up
879 function getServerUptime() {
880 $vars = $this->getMysqlStatus( 'Uptime' );
881 return (int)$vars['Uptime'];
885 * Determines if the last failure was due to a deadlock
889 function wasDeadlock() {
890 return $this->lastErrno() == 1213;
894 * Determines if the last failure was due to a lock timeout
898 function wasLockTimeout() {
899 return $this->lastErrno() == 1205;
903 * Determines if the last query error was something that should be dealt
904 * with by pinging the connection and reissuing the query
908 function wasErrorReissuable() {
909 return $this->lastErrno() == 2013 ||
$this->lastErrno() == 2006;
913 * Determines if the last failure was due to the database being read-only.
917 function wasReadOnlyError() {
918 return $this->lastErrno() == 1223 ||
919 ( $this->lastErrno() == 1290 && strpos( $this->lastError(), '--read-only' ) !== false );
925 * @param $temporary bool
926 * @param $fname string
928 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = __METHOD__
) {
929 $tmp = $temporary ?
'TEMPORARY ' : '';
930 $newName = $this->addIdentifierQuotes( $newName );
931 $oldName = $this->addIdentifierQuotes( $oldName );
932 $query = "CREATE $tmp TABLE $newName (LIKE $oldName)";
933 $this->query( $query, $fname );
937 * List all tables on the database
939 * @param string $prefix Only show tables with this prefix, e.g. mw_
940 * @param string $fname calling function name
943 function listTables( $prefix = null, $fname = __METHOD__
) {
944 $result = $this->query( "SHOW TABLES", $fname );
948 foreach ( $result as $table ) {
949 $vars = get_object_vars( $table );
950 $table = array_pop( $vars );
952 if ( !$prefix ||
strpos( $table, $prefix ) === 0 ) {
953 $endArray[] = $table;
962 * @param $fName string
963 * @return bool|ResultWrapper
965 public function dropTable( $tableName, $fName = __METHOD__
) {
966 if ( !$this->tableExists( $tableName, $fName ) ) {
969 return $this->query( "DROP TABLE IF EXISTS " . $this->tableName( $tableName ), $fName );
975 protected function getDefaultSchemaVars() {
976 $vars = parent
::getDefaultSchemaVars();
977 $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $GLOBALS['wgDBTableOptions'] );
978 $vars['wgDBTableOptions'] = str_replace( 'CHARSET=mysql4', 'CHARSET=binary', $vars['wgDBTableOptions'] );
983 * Get status information from SHOW STATUS in an associative array
985 * @param $which string
988 function getMysqlStatus( $which = "%" ) {
989 $res = $this->query( "SHOW STATUS LIKE '{$which}'" );
992 foreach ( $res as $row ) {
993 $status[$row->Variable_name
] = $row->Value
;
1007 class MySQLField
implements Field
{
1008 private $name, $tablename, $default, $max_length, $nullable,
1009 $is_pk, $is_unique, $is_multiple, $is_key, $type, $binary;
1011 function __construct( $info ) {
1012 $this->name
= $info->name
;
1013 $this->tablename
= $info->table
;
1014 $this->default = $info->def
;
1015 $this->max_length
= $info->max_length
;
1016 $this->nullable
= !$info->not_null
;
1017 $this->is_pk
= $info->primary_key
;
1018 $this->is_unique
= $info->unique_key
;
1019 $this->is_multiple
= $info->multiple_key
;
1020 $this->is_key
= ( $this->is_pk ||
$this->is_unique ||
$this->is_multiple
);
1021 $this->type
= $info->type
;
1022 $this->binary
= isset( $info->binary
) ?
$info->binary
: false;
1035 function tableName() {
1036 return $this->tableName
;
1049 function isNullable() {
1050 return $this->nullable
;
1053 function defaultValue() {
1054 return $this->default;
1061 return $this->is_key
;
1067 function isMultipleKey() {
1068 return $this->is_multiple
;
1071 function isBinary() {
1072 return $this->binary
;
1076 class MySQLMasterPos
implements DBMasterPos
{
1079 function __construct( $file, $pos ) {
1080 $this->file
= $file;
1084 function __toString() {
1085 // e.g db1034-bin.000976/843431247
1086 return "{$this->file}/{$this->pos}";
1090 * @return array|false (int, int)
1092 protected function getCoordinates() {
1094 if ( preg_match( '!\.(\d+)/(\d+)$!', (string)$this, $m ) ) {
1095 return array( (int)$m[1], (int)$m[2] );
1100 function hasReached( MySQLMasterPos
$pos ) {
1101 $thisPos = $this->getCoordinates();
1102 $thatPos = $pos->getCoordinates();
1103 return ( $thisPos && $thatPos && $thisPos >= $thatPos );