314b6edd8b9da1fe005d7c03ec32c9800ebad2a3
[lhc/web/wiklou.git] / includes / db / DatabaseMysql.php
1 <?php
2 /**
3 * This is the MySQL database abstraction layer.
4 *
5 * @file
6 * @ingroup Database
7 */
8
9 /**
10 * Database abstraction object for mySQL
11 * Inherit all methods and properties of Database::Database()
12 *
13 * @ingroup Database
14 * @see Database
15 */
16 class DatabaseMysql extends DatabaseBase {
17 function getType() {
18 return 'mysql';
19 }
20
21 protected function doQuery( $sql ) {
22 if( $this->bufferResults() ) {
23 $ret = mysql_query( $sql, $this->mConn );
24 } else {
25 $ret = mysql_unbuffered_query( $sql, $this->mConn );
26 }
27 return $ret;
28 }
29
30 function open( $server, $user, $password, $dbName ) {
31 global $wgAllDBsAreLocalhost;
32 wfProfileIn( __METHOD__ );
33
34 # Load mysql.so if we don't have it
35 wfDl( 'mysql' );
36
37 # Fail now
38 # Otherwise we get a suppressed fatal error, which is very hard to track down
39 if ( !function_exists( 'mysql_connect' ) ) {
40 throw new DBConnectionError( $this, "MySQL functions missing, have you compiled PHP with the --with-mysql option?\n" );
41 }
42
43 # Debugging hack -- fake cluster
44 if ( $wgAllDBsAreLocalhost ) {
45 $realServer = 'localhost';
46 } else {
47 $realServer = $server;
48 }
49 $this->close();
50 $this->mServer = $server;
51 $this->mUser = $user;
52 $this->mPassword = $password;
53 $this->mDBname = $dbName;
54
55 wfProfileIn("dbconnect-$server");
56
57 # The kernel's default SYN retransmission period is far too slow for us,
58 # so we use a short timeout plus a manual retry. Retrying means that a small
59 # but finite rate of SYN packet loss won't cause user-visible errors.
60 $this->mConn = false;
61 if ( ini_get( 'mysql.connect_timeout' ) <= 3 ) {
62 $numAttempts = 2;
63 } else {
64 $numAttempts = 1;
65 }
66 $this->installErrorHandler();
67 for ( $i = 0; $i < $numAttempts && !$this->mConn; $i++ ) {
68 if ( $i > 1 ) {
69 usleep( 1000 );
70 }
71 if ( $this->mFlags & DBO_PERSISTENT ) {
72 $this->mConn = mysql_pconnect( $realServer, $user, $password );
73 } else {
74 # Create a new connection...
75 $this->mConn = mysql_connect( $realServer, $user, $password, true );
76 }
77 #if ( $this->mConn === false ) {
78 #$iplus = $i + 1;
79 #wfLogDBError("Connect loop error $iplus of $max ($server): " . mysql_errno() . " - " . mysql_error()."\n");
80 #}
81 }
82 $phpError = $this->restoreErrorHandler();
83 # Always log connection errors
84 if ( !$this->mConn ) {
85 $error = $this->lastError();
86 if ( !$error ) {
87 $error = $phpError;
88 }
89 wfLogDBError( "Error connecting to {$this->mServer}: $error\n" );
90 wfDebug( "DB connection error\n" );
91 wfDebug( "Server: $server, User: $user, Password: " .
92 substr( $password, 0, 3 ) . "..., error: " . mysql_error() . "\n" );
93 }
94
95 wfProfileOut("dbconnect-$server");
96
97 if ( $dbName != '' && $this->mConn !== false ) {
98 wfSuppressWarnings();
99 $success = mysql_select_db( $dbName, $this->mConn );
100 wfRestoreWarnings();
101 if ( !$success ) {
102 $error = "Error selecting database $dbName on server {$this->mServer} " .
103 "from client host " . wfHostname() . "\n";
104 wfLogDBError(" Error selecting database $dbName on server {$this->mServer} \n");
105 wfDebug( $error );
106 }
107 } else {
108 # Delay USE query
109 $success = (bool)$this->mConn;
110 }
111
112 if ( $success ) {
113 $version = $this->getServerVersion();
114 if ( version_compare( $version, '4.1' ) >= 0 ) {
115 // Tell the server we're communicating with it in UTF-8.
116 // This may engage various charset conversions.
117 global $wgDBmysql5;
118 if( $wgDBmysql5 ) {
119 $this->query( 'SET NAMES utf8', __METHOD__ );
120 } else {
121 $this->query( 'SET NAMES binary', __METHOD__ );
122 }
123 // Set SQL mode, default is turning them all off, can be overridden or skipped with null
124 global $wgSQLMode;
125 if ( is_string( $wgSQLMode ) ) {
126 $mode = $this->addQuotes( $wgSQLMode );
127 $this->query( "SET sql_mode = $mode", __METHOD__ );
128 }
129 }
130
131 // Turn off strict mode if it is on
132 } else {
133 $this->reportConnectionError( $phpError );
134 }
135
136 $this->mOpened = $success;
137 wfProfileOut( __METHOD__ );
138 return $success;
139 }
140
141 function close() {
142 $this->mOpened = false;
143 if ( $this->mConn ) {
144 if ( $this->trxLevel() ) {
145 $this->commit();
146 }
147 return mysql_close( $this->mConn );
148 } else {
149 return true;
150 }
151 }
152
153 function freeResult( $res ) {
154 if ( $res instanceof ResultWrapper ) {
155 $res = $res->result;
156 }
157 wfSuppressWarnings();
158 $ok = mysql_free_result( $res );
159 wfRestoreWarnings();
160 if ( !$ok ) {
161 throw new DBUnexpectedError( $this, "Unable to free MySQL result" );
162 }
163 }
164
165 function fetchObject( $res ) {
166 if ( $res instanceof ResultWrapper ) {
167 $res = $res->result;
168 }
169 wfSuppressWarnings();
170 $row = mysql_fetch_object( $res );
171 wfRestoreWarnings();
172 if( $this->lastErrno() ) {
173 throw new DBUnexpectedError( $this, 'Error in fetchObject(): ' . htmlspecialchars( $this->lastError() ) );
174 }
175 return $row;
176 }
177
178 function fetchRow( $res ) {
179 if ( $res instanceof ResultWrapper ) {
180 $res = $res->result;
181 }
182 wfSuppressWarnings();
183 $row = mysql_fetch_array( $res );
184 wfRestoreWarnings();
185 if ( $this->lastErrno() ) {
186 throw new DBUnexpectedError( $this, 'Error in fetchRow(): ' . htmlspecialchars( $this->lastError() ) );
187 }
188 return $row;
189 }
190
191 function numRows( $res ) {
192 if ( $res instanceof ResultWrapper ) {
193 $res = $res->result;
194 }
195 wfSuppressWarnings();
196 $n = mysql_num_rows( $res );
197 wfRestoreWarnings();
198 if( $this->lastErrno() ) {
199 throw new DBUnexpectedError( $this, 'Error in numRows(): ' . htmlspecialchars( $this->lastError() ) );
200 }
201 return $n;
202 }
203
204 function numFields( $res ) {
205 if ( $res instanceof ResultWrapper ) {
206 $res = $res->result;
207 }
208 return mysql_num_fields( $res );
209 }
210
211 function fieldName( $res, $n ) {
212 if ( $res instanceof ResultWrapper ) {
213 $res = $res->result;
214 }
215 return mysql_field_name( $res, $n );
216 }
217
218 function insertId() { return mysql_insert_id( $this->mConn ); }
219
220 function dataSeek( $res, $row ) {
221 if ( $res instanceof ResultWrapper ) {
222 $res = $res->result;
223 }
224 return mysql_data_seek( $res, $row );
225 }
226
227 function lastErrno() {
228 if ( $this->mConn ) {
229 return mysql_errno( $this->mConn );
230 } else {
231 return mysql_errno();
232 }
233 }
234
235 function lastError() {
236 if ( $this->mConn ) {
237 # Even if it's non-zero, it can still be invalid
238 wfSuppressWarnings();
239 $error = mysql_error( $this->mConn );
240 if ( !$error ) {
241 $error = mysql_error();
242 }
243 wfRestoreWarnings();
244 } else {
245 $error = mysql_error();
246 }
247 if( $error ) {
248 $error .= ' (' . $this->mServer . ')';
249 }
250 return $error;
251 }
252
253 function affectedRows() { return mysql_affected_rows( $this->mConn ); }
254
255 function replace( $table, $uniqueIndexes, $rows, $fname = 'DatabaseMysql::replace' ) {
256 return $this->nativeReplace( $table, $rows, $fname );
257 }
258
259 /**
260 * Estimate rows in dataset
261 * Returns estimated count, based on EXPLAIN output
262 * Takes same arguments as Database::select()
263 */
264 public function estimateRowCount( $table, $vars='*', $conds='', $fname = 'DatabaseMysql::estimateRowCount', $options = array() ) {
265 $options['EXPLAIN'] = true;
266 $res = $this->select( $table, $vars, $conds, $fname, $options );
267 if ( $res === false ) {
268 return false;
269 }
270 if ( !$this->numRows( $res ) ) {
271 return 0;
272 }
273
274 $rows = 1;
275 foreach ( $res as $plan ) {
276 $rows *= $plan->rows > 0 ? $plan->rows : 1; // avoid resetting to zero
277 }
278 return $rows;
279 }
280
281 function fieldInfo( $table, $field ) {
282 $table = $this->tableName( $table );
283 $res = $this->query( "SELECT * FROM $table LIMIT 1", __METHOD__, true );
284 if ( !$res ) {
285 return false;
286 }
287 $n = mysql_num_fields( $res->result );
288 for( $i = 0; $i < $n; $i++ ) {
289 $meta = mysql_fetch_field( $res->result, $i );
290 if( $field == $meta->name ) {
291 return new MySQLField($meta);
292 }
293 }
294 return false;
295 }
296
297 /**
298 * Get information about an index into an object
299 * Returns false if the index does not exist
300 */
301 function indexInfo( $table, $index, $fname = 'DatabaseMysql::indexInfo' ) {
302 # SHOW INDEX works in MySQL 3.23.58, but SHOW INDEXES does not.
303 # SHOW INDEX should work for 3.x and up:
304 # http://dev.mysql.com/doc/mysql/en/SHOW_INDEX.html
305 $table = $this->tableName( $table );
306 $index = $this->indexName( $index );
307 $sql = 'SHOW INDEX FROM ' . $table;
308 $res = $this->query( $sql, $fname );
309
310 if ( !$res ) {
311 return null;
312 }
313
314 $result = array();
315
316 foreach ( $res as $row ) {
317 if ( $row->Key_name == $index ) {
318 $result[] = $row;
319 }
320 }
321
322 return empty( $result ) ? false : $result;
323 }
324
325 function selectDB( $db ) {
326 $this->mDBname = $db;
327 return mysql_select_db( $db, $this->mConn );
328 }
329
330 function strencode( $s ) {
331 $sQuoted = mysql_real_escape_string( $s, $this->mConn );
332
333 if($sQuoted === false) {
334 $this->ping();
335 $sQuoted = mysql_real_escape_string( $s, $this->mConn );
336 }
337 return $sQuoted;
338 }
339
340 /**
341 * MySQL uses `backticks` for identifier quoting instead of the sql standard "double quotes".
342 */
343 public function addIdentifierQuotes( $s ) {
344 return "`" . $this->strencode( $s ) . "`";
345 }
346
347 public function isQuotedIdentifier( $name ) {
348 return strlen($name) && $name[0] == '`' && substr( $name, -1, 1 ) == '`';
349 }
350
351 function ping() {
352 $ping = mysql_ping( $this->mConn );
353 if ( $ping ) {
354 return true;
355 }
356
357 mysql_close( $this->mConn );
358 $this->mOpened = false;
359 $this->mConn = false;
360 $this->open( $this->mServer, $this->mUser, $this->mPassword, $this->mDBname );
361 return true;
362 }
363
364 /**
365 * Returns slave lag.
366 *
367 * On MySQL 4.1.9 and later, this will do a SHOW SLAVE STATUS. On earlier
368 * versions of MySQL, it uses SHOW PROCESSLIST, which requires the PROCESS
369 * privilege.
370 *
371 * @return int
372 */
373 function getLag() {
374 if ( !is_null( $this->mFakeSlaveLag ) ) {
375 wfDebug( "getLag: fake slave lagged {$this->mFakeSlaveLag} seconds\n" );
376 return $this->mFakeSlaveLag;
377 }
378
379 if ( version_compare( $this->getServerVersion(), '4.1.9', '>=' ) ) {
380 return $this->getLagFromSlaveStatus();
381 } else {
382 return $this->getLagFromProcesslist();
383 }
384 }
385
386 /**
387 * @return bool|int
388 */
389 function getLagFromSlaveStatus() {
390 $res = $this->query( 'SHOW SLAVE STATUS', __METHOD__ );
391 if ( !$res ) {
392 return false;
393 }
394 $row = $res->fetchObject();
395 if ( !$row ) {
396 return false;
397 }
398 if ( strval( $row->Seconds_Behind_Master ) === '' ) {
399 return false;
400 } else {
401 return intval( $row->Seconds_Behind_Master );
402 }
403 }
404
405 /**
406 * @return bool|int
407 */
408 function getLagFromProcesslist() {
409 $res = $this->query( 'SHOW PROCESSLIST', __METHOD__ );
410 if( !$res ) {
411 return false;
412 }
413 # Find slave SQL thread
414 foreach( $res as $row ) {
415 /* This should work for most situations - when default db
416 * for thread is not specified, it had no events executed,
417 * and therefore it doesn't know yet how lagged it is.
418 *
419 * Relay log I/O thread does not select databases.
420 */
421 if ( $row->User == 'system user' &&
422 $row->State != 'Waiting for master to send event' &&
423 $row->State != 'Connecting to master' &&
424 $row->State != 'Queueing master event to the relay log' &&
425 $row->State != 'Waiting for master update' &&
426 $row->State != 'Requesting binlog dump' &&
427 $row->State != 'Waiting to reconnect after a failed master event read' &&
428 $row->State != 'Reconnecting after a failed master event read' &&
429 $row->State != 'Registering slave on master'
430 ) {
431 # This is it, return the time (except -ve)
432 if ( $row->Time > 0x7fffffff ) {
433 return false;
434 } else {
435 return $row->Time;
436 }
437 }
438 }
439 return false;
440 }
441
442 /**
443 * Wait for the slave to catch up to a given master position.
444 *
445 * @param $pos DBMasterPos object
446 * @param $timeout Integer: the maximum number of seconds to wait for synchronisation
447 */
448 function masterPosWait( DBMasterPos $pos, $timeout ) {
449 $fname = 'DatabaseBase::masterPosWait';
450 wfProfileIn( $fname );
451
452 # Commit any open transactions
453 if ( $this->mTrxLevel ) {
454 $this->commit();
455 }
456
457 if ( !is_null( $this->mFakeSlaveLag ) ) {
458 $status = parent::masterPosWait( $pos, $timeout );
459 wfProfileOut( $fname );
460 return $status;
461 }
462
463 # Call doQuery() directly, to avoid opening a transaction if DBO_TRX is set
464 $encFile = $this->addQuotes( $pos->file );
465 $encPos = intval( $pos->pos );
466 $sql = "SELECT MASTER_POS_WAIT($encFile, $encPos, $timeout)";
467 $res = $this->doQuery( $sql );
468
469 if ( $res && $row = $this->fetchRow( $res ) ) {
470 wfProfileOut( $fname );
471 return $row[0];
472 } else {
473 wfProfileOut( $fname );
474 return false;
475 }
476 }
477
478 /**
479 * Get the position of the master from SHOW SLAVE STATUS
480 *
481 * @return MySQLMasterPos|false
482 */
483 function getSlavePos() {
484 if ( !is_null( $this->mFakeSlaveLag ) ) {
485 return parent::getSlavePos();
486 }
487
488 $res = $this->query( 'SHOW SLAVE STATUS', 'DatabaseBase::getSlavePos' );
489 $row = $this->fetchObject( $res );
490
491 if ( $row ) {
492 $pos = isset( $row->Exec_master_log_pos ) ? $row->Exec_master_log_pos : $row->Exec_Master_Log_Pos;
493 return new MySQLMasterPos( $row->Relay_Master_Log_File, $pos );
494 } else {
495 return false;
496 }
497 }
498
499 /**
500 * Get the position of the master from SHOW MASTER STATUS
501 *
502 * @return MySQLMasterPos|false
503 */
504 function getMasterPos() {
505 if ( $this->mFakeMaster ) {
506 return parent::getMasterPos();
507 }
508
509 $res = $this->query( 'SHOW MASTER STATUS', 'DatabaseBase::getMasterPos' );
510 $row = $this->fetchObject( $res );
511
512 if ( $row ) {
513 return new MySQLMasterPos( $row->File, $row->Position );
514 } else {
515 return false;
516 }
517 }
518
519 function getServerVersion() {
520 return mysql_get_server_info( $this->mConn );
521 }
522
523 function useIndexClause( $index ) {
524 return "FORCE INDEX (" . $this->indexName( $index ) . ")";
525 }
526
527 function lowPriorityOption() {
528 return 'LOW_PRIORITY';
529 }
530
531 public static function getSoftwareLink() {
532 return '[http://www.mysql.com/ MySQL]';
533 }
534
535 function standardSelectDistinct() {
536 return false;
537 }
538
539 public function setTimeout( $timeout ) {
540 $this->query( "SET net_read_timeout=$timeout" );
541 $this->query( "SET net_write_timeout=$timeout" );
542 }
543
544 public function lock( $lockName, $method, $timeout = 5 ) {
545 $lockName = $this->addQuotes( $lockName );
546 $result = $this->query( "SELECT GET_LOCK($lockName, $timeout) AS lockstatus", $method );
547 $row = $this->fetchObject( $result );
548
549 if( $row->lockstatus == 1 ) {
550 return true;
551 } else {
552 wfDebug( __METHOD__." failed to acquire lock\n" );
553 return false;
554 }
555 }
556
557 /**
558 * FROM MYSQL DOCS: http://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_release-lock
559 */
560 public function unlock( $lockName, $method ) {
561 $lockName = $this->addQuotes( $lockName );
562 $result = $this->query( "SELECT RELEASE_LOCK($lockName) as lockstatus", $method );
563 $row = $this->fetchObject( $result );
564 return $row->lockstatus;
565 }
566
567 public function lockTables( $read, $write, $method, $lowPriority = true ) {
568 $items = array();
569
570 foreach( $write as $table ) {
571 $tbl = $this->tableName( $table ) .
572 ( $lowPriority ? ' LOW_PRIORITY' : '' ) .
573 ' WRITE';
574 $items[] = $tbl;
575 }
576 foreach( $read as $table ) {
577 $items[] = $this->tableName( $table ) . ' READ';
578 }
579 $sql = "LOCK TABLES " . implode( ',', $items );
580 $this->query( $sql, $method );
581 }
582
583 public function unlockTables( $method ) {
584 $this->query( "UNLOCK TABLES", $method );
585 }
586
587 /**
588 * Get search engine class. All subclasses of this
589 * need to implement this if they wish to use searching.
590 *
591 * @return String
592 */
593 public function getSearchEngine() {
594 return 'SearchMySQL';
595 }
596
597 public function setBigSelects( $value = true ) {
598 if ( $value === 'default' ) {
599 if ( $this->mDefaultBigSelects === null ) {
600 # Function hasn't been called before so it must already be set to the default
601 return;
602 } else {
603 $value = $this->mDefaultBigSelects;
604 }
605 } elseif ( $this->mDefaultBigSelects === null ) {
606 $this->mDefaultBigSelects = (bool)$this->selectField( false, '@@sql_big_selects' );
607 }
608 $encValue = $value ? '1' : '0';
609 $this->query( "SET sql_big_selects=$encValue", __METHOD__ );
610 }
611
612 /**
613 * DELETE where the condition is a join. MySql uses multi-table deletes.
614 */
615 function deleteJoin( $delTable, $joinTable, $delVar, $joinVar, $conds, $fname = 'DatabaseBase::deleteJoin' ) {
616 if ( !$conds ) {
617 throw new DBUnexpectedError( $this, 'DatabaseBase::deleteJoin() called with empty $conds' );
618 }
619
620 $delTable = $this->tableName( $delTable );
621 $joinTable = $this->tableName( $joinTable );
622 $sql = "DELETE $delTable FROM $delTable, $joinTable WHERE $delVar=$joinVar ";
623
624 if ( $conds != '*' ) {
625 $sql .= ' AND ' . $this->makeList( $conds, LIST_AND );
626 }
627
628 return $this->query( $sql, $fname );
629 }
630
631 /**
632 * Determines if the last failure was due to a deadlock
633 */
634 function wasDeadlock() {
635 return $this->lastErrno() == 1213;
636 }
637
638 /**
639 * Determines if the last query error was something that should be dealt
640 * with by pinging the connection and reissuing the query
641 */
642 function wasErrorReissuable() {
643 return $this->lastErrno() == 2013 || $this->lastErrno() == 2006;
644 }
645
646 /**
647 * Determines if the last failure was due to the database being read-only.
648 */
649 function wasReadOnlyError() {
650 return $this->lastErrno() == 1223 ||
651 ( $this->lastErrno() == 1290 && strpos( $this->lastError(), '--read-only' ) !== false );
652 }
653
654 function duplicateTableStructure( $oldName, $newName, $temporary = false, $fname = 'DatabaseMysql::duplicateTableStructure' ) {
655 $tmp = $temporary ? 'TEMPORARY ' : '';
656 if ( strcmp( $this->getServerVersion(), '4.1' ) < 0 ) {
657 # Hack for MySQL versions < 4.1, which don't support
658 # "CREATE TABLE ... LIKE". Note that
659 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
660 # would not create the indexes we need....
661 #
662 # Note that we don't bother changing around the prefixes here be-
663 # cause we know we're using MySQL anyway.
664
665 $res = $this->query( 'SHOW CREATE TABLE ' . $this->addIdentifierQuotes( $oldName ) );
666 $row = $this->fetchRow( $res );
667 $oldQuery = $row[1];
668 $query = preg_replace( '/CREATE TABLE `(.*?)`/',
669 "CREATE $tmp TABLE " . $this->addIdentifierQuotes( $newName ), $oldQuery );
670 if ($oldQuery === $query) {
671 # Couldn't do replacement
672 throw new MWException( "could not create temporary table $newName" );
673 }
674 } else {
675 $newName = $this->addIdentifierQuotes( $newName );
676 $oldName = $this->addIdentifierQuotes( $oldName );
677 $query = "CREATE $tmp TABLE $newName (LIKE $oldName)";
678 }
679 $this->query( $query, $fname );
680 }
681
682 /**
683 * List all tables on the database
684 *
685 * @param $prefix Only show tables with this prefix, e.g. mw_
686 * @param $fname String: calling function name
687 */
688 function listTables( $prefix = null, $fname = 'DatabaseMysql::listTables' ) {
689 $result = $this->query( "SHOW TABLES", $fname);
690
691 $endArray = array();
692
693 foreach( $result as $table ) {
694 $vars = get_object_vars($table);
695 $table = array_pop( $vars );
696
697 if( !$prefix || strpos( $table, $prefix ) === 0 ) {
698 $endArray[] = $table;
699 }
700 }
701
702 return $endArray;
703 }
704
705 public function dropTable( $tableName, $fName = 'DatabaseMysql::dropTable' ) {
706 if( !$this->tableExists( $tableName ) ) {
707 return false;
708 }
709 return $this->query( "DROP TABLE IF EXISTS " . $this->tableName( $tableName ), $fName );
710 }
711
712 protected function getDefaultSchemaVars() {
713 $vars = parent::getDefaultSchemaVars();
714 $vars['wgDBTableOptions'] = $GLOBALS['wgDBTableOptions'];
715 return $vars;
716 }
717
718 /**
719 * Get status information from SHOW STATUS in an associative array
720 *
721 * @return array
722 */
723 function getMysqlStatus( $which = "%" ) {
724 $res = $this->query( "SHOW STATUS LIKE '{$which}'" );
725 $status = array();
726
727 foreach ( $res as $row ) {
728 $status[$row->Variable_name] = $row->Value;
729 }
730
731 return $status;
732 }
733
734 }
735
736 /**
737 * Legacy support: Database == DatabaseMysql
738 */
739 class Database extends DatabaseMysql {}
740
741 /**
742 * Utility class.
743 * @ingroup Database
744 */
745 class MySQLField implements Field {
746 private $name, $tablename, $default, $max_length, $nullable,
747 $is_pk, $is_unique, $is_multiple, $is_key, $type;
748
749 function __construct ( $info ) {
750 $this->name = $info->name;
751 $this->tablename = $info->table;
752 $this->default = $info->def;
753 $this->max_length = $info->max_length;
754 $this->nullable = !$info->not_null;
755 $this->is_pk = $info->primary_key;
756 $this->is_unique = $info->unique_key;
757 $this->is_multiple = $info->multiple_key;
758 $this->is_key = ( $this->is_pk || $this->is_unique || $this->is_multiple );
759 $this->type = $info->type;
760 }
761
762 function name() {
763 return $this->name;
764 }
765
766 function tableName() {
767 return $this->tableName;
768 }
769
770 function type() {
771 return $this->type;
772 }
773
774 function isNullable() {
775 return $this->nullable;
776 }
777
778 function defaultValue() {
779 return $this->default;
780 }
781
782 function isKey() {
783 return $this->is_key;
784 }
785
786 function isMultipleKey() {
787 return $this->is_multiple;
788 }
789 }
790
791 class MySQLMasterPos implements DBMasterPos {
792 var $file, $pos;
793
794 function __construct( $file, $pos ) {
795 $this->file = $file;
796 $this->pos = $pos;
797 }
798
799 function __toString() {
800 return "{$this->file}/{$this->pos}";
801 }
802 }