MediaWiki
REL1_20
|
00001 <?php 00031 class DatabaseMysql extends DatabaseBase { 00032 00036 function getType() { 00037 return 'mysql'; 00038 } 00039 00044 protected function doQuery( $sql ) { 00045 if( $this->bufferResults() ) { 00046 $ret = mysql_query( $sql, $this->mConn ); 00047 } else { 00048 $ret = mysql_unbuffered_query( $sql, $this->mConn ); 00049 } 00050 return $ret; 00051 } 00052 00061 function open( $server, $user, $password, $dbName ) { 00062 global $wgAllDBsAreLocalhost, $wgDBmysql5, $wgSQLMode; 00063 wfProfileIn( __METHOD__ ); 00064 00065 # Load mysql.so if we don't have it 00066 wfDl( 'mysql' ); 00067 00068 # Fail now 00069 # Otherwise we get a suppressed fatal error, which is very hard to track down 00070 if ( !function_exists( 'mysql_connect' ) ) { 00071 throw new DBConnectionError( $this, "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" ); 00072 } 00073 00074 # Debugging hack -- fake cluster 00075 if ( $wgAllDBsAreLocalhost ) { 00076 $realServer = 'localhost'; 00077 } else { 00078 $realServer = $server; 00079 } 00080 $this->close(); 00081 $this->mServer = $server; 00082 $this->mUser = $user; 00083 $this->mPassword = $password; 00084 $this->mDBname = $dbName; 00085 00086 $connFlags = 0; 00087 if ( $this->mFlags & DBO_SSL ) { 00088 $connFlags |= MYSQL_CLIENT_SSL; 00089 } 00090 if ( $this->mFlags & DBO_COMPRESS ) { 00091 $connFlags |= MYSQL_CLIENT_COMPRESS; 00092 } 00093 00094 wfProfileIn( "dbconnect-$server" ); 00095 00096 # The kernel's default SYN retransmission period is far too slow for us, 00097 # so we use a short timeout plus a manual retry. Retrying means that a small 00098 # but finite rate of SYN packet loss won't cause user-visible errors. 00099 $this->mConn = false; 00100 if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) { 00101 $numAttempts = 2; 00102 } else { 00103 $numAttempts = 1; 00104 } 00105 $this->installErrorHandler(); 00106 for ( $i = 0; $i < $numAttempts && !$this->mConn; $i++ ) { 00107 if ( $i > 1 ) { 00108 usleep( 1000 ); 00109 } 00110 if ( $this->mFlags & DBO_PERSISTENT ) { 00111 $this->mConn = mysql_pconnect( $realServer, $user, $password, $connFlags ); 00112 } else { 00113 # Create a new connection... 00114 $this->mConn = mysql_connect( $realServer, $user, $password, true, $connFlags ); 00115 } 00116 #if ( $this->mConn === false ) { 00117 #$iplus = $i + 1; 00118 #wfLogDBError("Connect loop error $iplus of $max ($server): " . mysql_errno() . " - " . mysql_error()."\n"); 00119 #} 00120 } 00121 $error = $this->restoreErrorHandler(); 00122 00123 wfProfileOut( "dbconnect-$server" ); 00124 00125 # Always log connection errors 00126 if ( !$this->mConn ) { 00127 if ( !$error ) { 00128 $error = $this->lastError(); 00129 } 00130 wfLogDBError( "Error connecting to {$this->mServer}: $error\n" ); 00131 wfDebug( "DB connection error\n" . 00132 "Server: $server, User: $user, Password: " . 00133 substr( $password, 0, 3 ) . "..., error: " . $error . "\n" ); 00134 00135 wfProfileOut( __METHOD__ ); 00136 $this->reportConnectionError( $error ); 00137 } 00138 00139 if ( $dbName != '' ) { 00140 wfSuppressWarnings(); 00141 $success = mysql_select_db( $dbName, $this->mConn ); 00142 wfRestoreWarnings(); 00143 if ( !$success ) { 00144 wfLogDBError( "Error selecting database $dbName on server {$this->mServer}\n" ); 00145 wfDebug( "Error selecting database $dbName on server {$this->mServer} " . 00146 "from client host " . wfHostname() . "\n" ); 00147 00148 wfProfileOut( __METHOD__ ); 00149 $this->reportConnectionError( "Error selecting database $dbName" ); 00150 } 00151 } 00152 00153 // Tell the server we're communicating with it in UTF-8. 00154 // This may engage various charset conversions. 00155 if( $wgDBmysql5 ) { 00156 $this->query( 'SET NAMES utf8', __METHOD__ ); 00157 } else { 00158 $this->query( 'SET NAMES binary', __METHOD__ ); 00159 } 00160 // Set SQL mode, default is turning them all off, can be overridden or skipped with null 00161 if ( is_string( $wgSQLMode ) ) { 00162 $mode = $this->addQuotes( $wgSQLMode ); 00163 $this->query( "SET sql_mode = $mode", __METHOD__ ); 00164 } 00165 00166 $this->mOpened = true; 00167 wfProfileOut( __METHOD__ ); 00168 return true; 00169 } 00170 00174 protected function closeConnection() { 00175 return mysql_close( $this->mConn ); 00176 } 00177 00182 function freeResult( $res ) { 00183 if ( $res instanceof ResultWrapper ) { 00184 $res = $res->result; 00185 } 00186 wfSuppressWarnings(); 00187 $ok = mysql_free_result( $res ); 00188 wfRestoreWarnings(); 00189 if ( !$ok ) { 00190 throw new DBUnexpectedError( $this, "Unable to free MySQL result" ); 00191 } 00192 } 00193 00199 function fetchObject( $res ) { 00200 if ( $res instanceof ResultWrapper ) { 00201 $res = $res->result; 00202 } 00203 wfSuppressWarnings(); 00204 $row = mysql_fetch_object( $res ); 00205 wfRestoreWarnings(); 00206 00207 $errno = $this->lastErrno(); 00208 // Unfortunately, mysql_fetch_object does not reset the last errno. 00209 // Only check for CR_SERVER_LOST and CR_UNKNOWN_ERROR, as 00210 // these are the only errors mysql_fetch_object can cause. 00211 // See http://dev.mysql.com/doc/refman/5.0/es/mysql-fetch-row.html. 00212 if( $errno == 2000 || $errno == 2013 ) { 00213 throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) ); 00214 } 00215 return $row; 00216 } 00217 00223 function fetchRow( $res ) { 00224 if ( $res instanceof ResultWrapper ) { 00225 $res = $res->result; 00226 } 00227 wfSuppressWarnings(); 00228 $row = mysql_fetch_array( $res ); 00229 wfRestoreWarnings(); 00230 00231 $errno = $this->lastErrno(); 00232 // Unfortunately, mysql_fetch_array does not reset the last errno. 00233 // Only check for CR_SERVER_LOST and CR_UNKNOWN_ERROR, as 00234 // these are the only errors mysql_fetch_object can cause. 00235 // See http://dev.mysql.com/doc/refman/5.0/es/mysql-fetch-row.html. 00236 if( $errno == 2000 || $errno == 2013 ) { 00237 throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) ); 00238 } 00239 return $row; 00240 } 00241 00247 function numRows( $res ) { 00248 if ( $res instanceof ResultWrapper ) { 00249 $res = $res->result; 00250 } 00251 wfSuppressWarnings(); 00252 $n = mysql_num_rows( $res ); 00253 wfRestoreWarnings(); 00254 if( $this->lastErrno() ) { 00255 throw new DBUnexpectedError( $this, 'Error in numRows(): ' . htmlspecialchars( $this->lastError() ) ); 00256 } 00257 return $n; 00258 } 00259 00264 function numFields( $res ) { 00265 if ( $res instanceof ResultWrapper ) { 00266 $res = $res->result; 00267 } 00268 return mysql_num_fields( $res ); 00269 } 00270 00276 function fieldName( $res, $n ) { 00277 if ( $res instanceof ResultWrapper ) { 00278 $res = $res->result; 00279 } 00280 return mysql_field_name( $res, $n ); 00281 } 00282 00286 function insertId() { 00287 return mysql_insert_id( $this->mConn ); 00288 } 00289 00295 function dataSeek( $res, $row ) { 00296 if ( $res instanceof ResultWrapper ) { 00297 $res = $res->result; 00298 } 00299 return mysql_data_seek( $res, $row ); 00300 } 00301 00305 function lastErrno() { 00306 if ( $this->mConn ) { 00307 return mysql_errno( $this->mConn ); 00308 } else { 00309 return mysql_errno(); 00310 } 00311 } 00312 00316 function lastError() { 00317 if ( $this->mConn ) { 00318 # Even if it's non-zero, it can still be invalid 00319 wfSuppressWarnings(); 00320 $error = mysql_error( $this->mConn ); 00321 if ( !$error ) { 00322 $error = mysql_error(); 00323 } 00324 wfRestoreWarnings(); 00325 } else { 00326 $error = mysql_error(); 00327 } 00328 if( $error ) { 00329 $error .= ' (' . $this->mServer . ')'; 00330 } 00331 return $error; 00332 } 00333 00337 function affectedRows() { 00338 return mysql_affected_rows( $this->mConn ); 00339 } 00340 00348 function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseMysql::replace' ) { 00349 return $this->nativeReplace( $table, $rows, $fname ); 00350 } 00351 00364 public function estimateRowCount( $table, $vars='*', $conds='', $fname = 'DatabaseMysql::estimateRowCount', $options = array() ) { 00365 $options['EXPLAIN'] = true; 00366 $res = $this->select( $table, $vars, $conds, $fname, $options ); 00367 if ( $res === false ) { 00368 return false; 00369 } 00370 if ( !$this->numRows( $res ) ) { 00371 return 0; 00372 } 00373 00374 $rows = 1; 00375 foreach ( $res as $plan ) { 00376 $rows *= $plan->rows > 0 ? $plan->rows : 1; // avoid resetting to zero 00377 } 00378 return $rows; 00379 } 00380 00386 function fieldInfo( $table, $field ) { 00387 $table = $this->tableName( $table ); 00388 $res = $this->query( "SELECT * FROM $table LIMIT 1", __METHOD__, true ); 00389 if ( !$res ) { 00390 return false; 00391 } 00392 $n = mysql_num_fields( $res->result ); 00393 for( $i = 0; $i < $n; $i++ ) { 00394 $meta = mysql_fetch_field( $res->result, $i ); 00395 if( $field == $meta->name ) { 00396 return new MySQLField($meta); 00397 } 00398 } 00399 return false; 00400 } 00401 00411 function indexInfo( $table, $index, $fname = 'DatabaseMysql::indexInfo' ) { 00412 # SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not. 00413 # SHOW INDEX should work for 3.x and up: 00414 # http://dev.mysql.com/doc/mysql/en/SHOW_INDEX.html 00415 $table = $this->tableName( $table ); 00416 $index = $this->indexName( $index ); 00417 $sql = 'SHOW INDEX FROM ' . $table; 00418 $res = $this->query( $sql, $fname ); 00419 00420 if ( !$res ) { 00421 return null; 00422 } 00423 00424 $result = array(); 00425 00426 foreach ( $res as $row ) { 00427 if ( $row->Key_name == $index ) { 00428 $result[] = $row; 00429 } 00430 } 00431 00432 return empty( $result ) ? false : $result; 00433 } 00434 00439 function selectDB( $db ) { 00440 $this->mDBname = $db; 00441 return mysql_select_db( $db, $this->mConn ); 00442 } 00443 00449 function strencode( $s ) { 00450 $sQuoted = mysql_real_escape_string( $s, $this->mConn ); 00451 00452 if($sQuoted === false) { 00453 $this->ping(); 00454 $sQuoted = mysql_real_escape_string( $s, $this->mConn ); 00455 } 00456 return $sQuoted; 00457 } 00458 00466 public function addIdentifierQuotes( $s ) { 00467 return "`" . $this->strencode( $s ) . "`"; 00468 } 00469 00474 public function isQuotedIdentifier( $name ) { 00475 return strlen( $name ) && $name[0] == '`' && substr( $name, -1, 1 ) == '`'; 00476 } 00477 00481 function ping() { 00482 $ping = mysql_ping( $this->mConn ); 00483 if ( $ping ) { 00484 return true; 00485 } 00486 00487 mysql_close( $this->mConn ); 00488 $this->mOpened = false; 00489 $this->mConn = false; 00490 $this->open( $this->mServer, $this->mUser, $this->mPassword, $this->mDBname ); 00491 return true; 00492 } 00493 00501 function getLag() { 00502 if ( !is_null( $this->mFakeSlaveLag ) ) { 00503 wfDebug( "getLag: fake slave lagged {$this->mFakeSlaveLag} seconds\n" ); 00504 return $this->mFakeSlaveLag; 00505 } 00506 00507 return $this->getLagFromSlaveStatus(); 00508 } 00509 00513 function getLagFromSlaveStatus() { 00514 $res = $this->query( 'SHOW SLAVE STATUS', __METHOD__ ); 00515 if ( !$res ) { 00516 return false; 00517 } 00518 $row = $res->fetchObject(); 00519 if ( !$row ) { 00520 return false; 00521 } 00522 if ( strval( $row->Seconds_Behind_Master ) === '' ) { 00523 return false; 00524 } else { 00525 return intval( $row->Seconds_Behind_Master ); 00526 } 00527 } 00528 00534 function getLagFromProcesslist() { 00535 wfDeprecated( __METHOD__, '1.19' ); 00536 $res = $this->query( 'SHOW PROCESSLIST', __METHOD__ ); 00537 if( !$res ) { 00538 return false; 00539 } 00540 # Find slave SQL thread 00541 foreach( $res as $row ) { 00542 /* This should work for most situations - when default db 00543 * for thread is not specified, it had no events executed, 00544 * and therefore it doesn't know yet how lagged it is. 00545 * 00546 * Relay log I/O thread does not select databases. 00547 */ 00548 if ( $row->User == 'system user' && 00549 $row->State != 'Waiting for master to send event' && 00550 $row->State != 'Connecting to master' && 00551 $row->State != 'Queueing master event to the relay log' && 00552 $row->State != 'Waiting for master update' && 00553 $row->State != 'Requesting binlog dump' && 00554 $row->State != 'Waiting to reconnect after a failed master event read' && 00555 $row->State != 'Reconnecting after a failed master event read' && 00556 $row->State != 'Registering slave on master' 00557 ) { 00558 # This is it, return the time (except -ve) 00559 if ( $row->Time > 0x7fffffff ) { 00560 return false; 00561 } else { 00562 return $row->Time; 00563 } 00564 } 00565 } 00566 return false; 00567 } 00568 00576 function masterPosWait( DBMasterPos $pos, $timeout ) { 00577 $fname = 'DatabaseBase::masterPosWait'; 00578 wfProfileIn( $fname ); 00579 00580 # Commit any open transactions 00581 if ( $this->mTrxLevel ) { 00582 $this->commit( __METHOD__ ); 00583 } 00584 00585 if ( !is_null( $this->mFakeSlaveLag ) ) { 00586 $status = parent::masterPosWait( $pos, $timeout ); 00587 wfProfileOut( $fname ); 00588 return $status; 00589 } 00590 00591 # Call doQuery() directly, to avoid opening a transaction if DBO_TRX is set 00592 $encFile = $this->addQuotes( $pos->file ); 00593 $encPos = intval( $pos->pos ); 00594 $sql = "SELECT MASTER_POS_WAIT($encFile, $encPos, $timeout)"; 00595 $res = $this->doQuery( $sql ); 00596 00597 if ( $res && $row = $this->fetchRow( $res ) ) { 00598 wfProfileOut( $fname ); 00599 return $row[0]; 00600 } else { 00601 wfProfileOut( $fname ); 00602 return false; 00603 } 00604 } 00605 00611 function getSlavePos() { 00612 if ( !is_null( $this->mFakeSlaveLag ) ) { 00613 return parent::getSlavePos(); 00614 } 00615 00616 $res = $this->query( 'SHOW SLAVE STATUS', 'DatabaseBase::getSlavePos' ); 00617 $row = $this->fetchObject( $res ); 00618 00619 if ( $row ) { 00620 $pos = isset( $row->Exec_master_log_pos ) ? $row->Exec_master_log_pos : $row->Exec_Master_Log_Pos; 00621 return new MySQLMasterPos( $row->Relay_Master_Log_File, $pos ); 00622 } else { 00623 return false; 00624 } 00625 } 00626 00632 function getMasterPos() { 00633 if ( $this->mFakeMaster ) { 00634 return parent::getMasterPos(); 00635 } 00636 00637 $res = $this->query( 'SHOW MASTER STATUS', 'DatabaseBase::getMasterPos' ); 00638 $row = $this->fetchObject( $res ); 00639 00640 if ( $row ) { 00641 return new MySQLMasterPos( $row->File, $row->Position ); 00642 } else { 00643 return false; 00644 } 00645 } 00646 00650 function getServerVersion() { 00651 return mysql_get_server_info( $this->mConn ); 00652 } 00653 00658 function useIndexClause( $index ) { 00659 return "FORCE INDEX (" . $this->indexName( $index ) . ")"; 00660 } 00661 00665 function lowPriorityOption() { 00666 return 'LOW_PRIORITY'; 00667 } 00668 00672 public static function getSoftwareLink() { 00673 return '[http://www.mysql.com/ MySQL]'; 00674 } 00675 00679 public function setSessionOptions( array $options ) { 00680 if ( isset( $options['connTimeout'] ) ) { 00681 $timeout = (int)$options['connTimeout']; 00682 $this->query( "SET net_read_timeout=$timeout" ); 00683 $this->query( "SET net_write_timeout=$timeout" ); 00684 } 00685 } 00686 00687 public function streamStatementEnd( &$sql, &$newLine ) { 00688 if ( strtoupper( substr( $newLine, 0, 9 ) ) == 'DELIMITER' ) { 00689 preg_match( '/^DELIMITER\s+(\S+)/' , $newLine, $m ); 00690 $this->delimiter = $m[1]; 00691 $newLine = ''; 00692 } 00693 return parent::streamStatementEnd( $sql, $newLine ); 00694 } 00695 00704 public function lockIsFree( $lockName, $method ) { 00705 $lockName = $this->addQuotes( $lockName ); 00706 $result = $this->query( "SELECT IS_FREE_LOCK($lockName) AS lockstatus", $method ); 00707 $row = $this->fetchObject( $result ); 00708 return ( $row->lockstatus == 1 ); 00709 } 00710 00717 public function lock( $lockName, $method, $timeout = 5 ) { 00718 $lockName = $this->addQuotes( $lockName ); 00719 $result = $this->query( "SELECT GET_LOCK($lockName, $timeout) AS lockstatus", $method ); 00720 $row = $this->fetchObject( $result ); 00721 00722 if( $row->lockstatus == 1 ) { 00723 return true; 00724 } else { 00725 wfDebug( __METHOD__." failed to acquire lock\n" ); 00726 return false; 00727 } 00728 } 00729 00736 public function unlock( $lockName, $method ) { 00737 $lockName = $this->addQuotes( $lockName ); 00738 $result = $this->query( "SELECT RELEASE_LOCK($lockName) as lockstatus", $method ); 00739 $row = $this->fetchObject( $result ); 00740 return ( $row->lockstatus == 1 ); 00741 } 00742 00749 public function lockTables( $read, $write, $method, $lowPriority = true ) { 00750 $items = array(); 00751 00752 foreach( $write as $table ) { 00753 $tbl = $this->tableName( $table ) . 00754 ( $lowPriority ? ' LOW_PRIORITY' : '' ) . 00755 ' WRITE'; 00756 $items[] = $tbl; 00757 } 00758 foreach( $read as $table ) { 00759 $items[] = $this->tableName( $table ) . ' READ'; 00760 } 00761 $sql = "LOCK TABLES " . implode( ',', $items ); 00762 $this->query( $sql, $method ); 00763 } 00764 00768 public function unlockTables( $method ) { 00769 $this->query( "UNLOCK TABLES", $method ); 00770 } 00771 00778 public function getSearchEngine() { 00779 return 'SearchMySQL'; 00780 } 00781 00786 public function setBigSelects( $value = true ) { 00787 if ( $value === 'default' ) { 00788 if ( $this->mDefaultBigSelects === null ) { 00789 # Function hasn't been called before so it must already be set to the default 00790 return; 00791 } else { 00792 $value = $this->mDefaultBigSelects; 00793 } 00794 } elseif ( $this->mDefaultBigSelects === null ) { 00795 $this->mDefaultBigSelects = (bool)$this->selectField( false, '@@sql_big_selects' ); 00796 } 00797 $encValue = $value ? '1' : '0'; 00798 $this->query( "SET sql_big_selects=$encValue", __METHOD__ ); 00799 } 00800 00811 function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabaseBase::deleteJoin' ) { 00812 if ( !$conds ) { 00813 throw new DBUnexpectedError( $this, 'DatabaseBase::deleteJoin() called with empty $conds' ); 00814 } 00815 00816 $delTable = $this->tableName( $delTable ); 00817 $joinTable = $this->tableName( $joinTable ); 00818 $sql = "DELETE $delTable FROM $delTable, $joinTable WHERE $delVar=$joinVar "; 00819 00820 if ( $conds != '*' ) { 00821 $sql .= ' AND ' . $this->makeList( $conds, LIST_AND ); 00822 } 00823 00824 return $this->query( $sql, $fname ); 00825 } 00826 00832 function getServerUptime() { 00833 $vars = $this->getMysqlStatus( 'Uptime' ); 00834 return (int)$vars['Uptime']; 00835 } 00836 00842 function wasDeadlock() { 00843 return $this->lastErrno() == 1213; 00844 } 00845 00851 function wasLockTimeout() { 00852 return $this->lastErrno() == 1205; 00853 } 00854 00861 function wasErrorReissuable() { 00862 return $this->lastErrno() == 2013 || $this->lastErrno() == 2006; 00863 } 00864 00870 function wasReadOnlyError() { 00871 return $this->lastErrno() == 1223 || 00872 ( $this->lastErrno() == 1290 && strpos( $this->lastError(), '--read-only' ) !== false ); 00873 } 00874 00881 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseMysql::duplicateTableStructure' ) { 00882 $tmp = $temporary ? 'TEMPORARY ' : ''; 00883 $newName = $this->addIdentifierQuotes( $newName ); 00884 $oldName = $this->addIdentifierQuotes( $oldName ); 00885 $query = "CREATE $tmp TABLE $newName (LIKE $oldName)"; 00886 $this->query( $query, $fname ); 00887 } 00888 00896 function listTables( $prefix = null, $fname = 'DatabaseMysql::listTables' ) { 00897 $result = $this->query( "SHOW TABLES", $fname); 00898 00899 $endArray = array(); 00900 00901 foreach( $result as $table ) { 00902 $vars = get_object_vars($table); 00903 $table = array_pop( $vars ); 00904 00905 if( !$prefix || strpos( $table, $prefix ) === 0 ) { 00906 $endArray[] = $table; 00907 } 00908 } 00909 00910 return $endArray; 00911 } 00912 00918 public function dropTable( $tableName, $fName = 'DatabaseMysql::dropTable' ) { 00919 if( !$this->tableExists( $tableName, $fName ) ) { 00920 return false; 00921 } 00922 return $this->query( "DROP TABLE IF EXISTS " . $this->tableName( $tableName ), $fName ); 00923 } 00924 00928 protected function getDefaultSchemaVars() { 00929 $vars = parent::getDefaultSchemaVars(); 00930 $vars['wgDBTableOptions'] = str_replace( 'TYPE', 'ENGINE', $GLOBALS['wgDBTableOptions'] ); 00931 $vars['wgDBTableOptions'] = str_replace( 'CHARSET=mysql4', 'CHARSET=binary', $vars['wgDBTableOptions'] ); 00932 return $vars; 00933 } 00934 00941 function getMysqlStatus( $which = "%" ) { 00942 $res = $this->query( "SHOW STATUS LIKE '{$which}'" ); 00943 $status = array(); 00944 00945 foreach ( $res as $row ) { 00946 $status[$row->Variable_name] = $row->Value; 00947 } 00948 00949 return $status; 00950 } 00951 00952 } 00953 00959 class Database extends DatabaseMysql {} 00960 00965 class MySQLField implements Field { 00966 private $name, $tablename, $default, $max_length, $nullable, 00967 $is_pk, $is_unique, $is_multiple, $is_key, $type; 00968 00969 function __construct ( $info ) { 00970 $this->name = $info->name; 00971 $this->tablename = $info->table; 00972 $this->default = $info->def; 00973 $this->max_length = $info->max_length; 00974 $this->nullable = !$info->not_null; 00975 $this->is_pk = $info->primary_key; 00976 $this->is_unique = $info->unique_key; 00977 $this->is_multiple = $info->multiple_key; 00978 $this->is_key = ( $this->is_pk || $this->is_unique || $this->is_multiple ); 00979 $this->type = $info->type; 00980 } 00981 00985 function name() { 00986 return $this->name; 00987 } 00988 00992 function tableName() { 00993 return $this->tableName; 00994 } 00995 00999 function type() { 01000 return $this->type; 01001 } 01002 01006 function isNullable() { 01007 return $this->nullable; 01008 } 01009 01010 function defaultValue() { 01011 return $this->default; 01012 } 01013 01017 function isKey() { 01018 return $this->is_key; 01019 } 01020 01024 function isMultipleKey() { 01025 return $this->is_multiple; 01026 } 01027 } 01028 01029 class MySQLMasterPos implements DBMasterPos { 01030 var $file, $pos; 01031 01032 function __construct( $file, $pos ) { 01033 $this->file = $file; 01034 $this->pos = $pos; 01035 } 01036 01037 function __toString() { 01038 return "{$this->file}/{$this->pos}"; 01039 } 01040 }