Index: trunk/phase3/includes/db/DatabaseMysql.php |
— | — | @@ -503,6 +503,56 @@ |
504 | 504 | */ |
505 | 505 | class Database extends DatabaseMysql {} |
506 | 506 | |
| 507 | +/** |
| 508 | + * Utility class. |
| 509 | + * @ingroup Database |
| 510 | + */ |
| 511 | +class MySQLField implements Field { |
| 512 | + private $name, $tablename, $default, $max_length, $nullable, |
| 513 | + $is_pk, $is_unique, $is_multiple, $is_key, $type; |
| 514 | + |
| 515 | + function __construct ( $info ) { |
| 516 | + $this->name = $info->name; |
| 517 | + $this->tablename = $info->table; |
| 518 | + $this->default = $info->def; |
| 519 | + $this->max_length = $info->max_length; |
| 520 | + $this->nullable = !$info->not_null; |
| 521 | + $this->is_pk = $info->primary_key; |
| 522 | + $this->is_unique = $info->unique_key; |
| 523 | + $this->is_multiple = $info->multiple_key; |
| 524 | + $this->is_key = ( $this->is_pk || $this->is_unique || $this->is_multiple ); |
| 525 | + $this->type = $info->type; |
| 526 | + } |
| 527 | + |
| 528 | + function name() { |
| 529 | + return $this->name; |
| 530 | + } |
| 531 | + |
| 532 | + function tableName() { |
| 533 | + return $this->tableName; |
| 534 | + } |
| 535 | + |
| 536 | + function type() { |
| 537 | + return $this->type; |
| 538 | + } |
| 539 | + |
| 540 | + function isNullable() { |
| 541 | + return $this->nullable; |
| 542 | + } |
| 543 | + |
| 544 | + function defaultValue() { |
| 545 | + return $this->default; |
| 546 | + } |
| 547 | + |
| 548 | + function isKey() { |
| 549 | + return $this->is_key; |
| 550 | + } |
| 551 | + |
| 552 | + function isMultipleKey() { |
| 553 | + return $this->is_multiple; |
| 554 | + } |
| 555 | +} |
| 556 | + |
507 | 557 | class MySQLMasterPos { |
508 | 558 | var $file, $pos; |
509 | 559 | |
Index: trunk/phase3/includes/db/DatabaseOracle.php |
— | — | @@ -124,7 +124,7 @@ |
125 | 125 | * Utility class. |
126 | 126 | * @ingroup Database |
127 | 127 | */ |
128 | | -class ORAField { |
| 128 | +class ORAField implements Field { |
129 | 129 | private $name, $tablename, $default, $max_length, $nullable, |
130 | 130 | $is_pk, $is_unique, $is_multiple, $is_key, $type; |
131 | 131 | |
— | — | @@ -157,7 +157,7 @@ |
158 | 158 | return $this->max_length; |
159 | 159 | } |
160 | 160 | |
161 | | - function nullable() { |
| 161 | + function isNullable() { |
162 | 162 | return $this->nullable; |
163 | 163 | } |
164 | 164 | |
Index: trunk/phase3/includes/db/DatabasePostgres.php |
— | — | @@ -6,7 +6,7 @@ |
7 | 7 | * @ingroup Database |
8 | 8 | */ |
9 | 9 | |
10 | | -class PostgresField { |
| 10 | +class PostgresField implements Field { |
11 | 11 | private $name, $tablename, $type, $nullable, $max_length, $deferred, $deferrable, $conname; |
12 | 12 | |
13 | 13 | static function fromText($db, $table, $field) { |
— | — | @@ -69,7 +69,7 @@ |
70 | 70 | return $this->type; |
71 | 71 | } |
72 | 72 | |
73 | | - function nullable() { |
| 73 | + function isNullable() { |
74 | 74 | return $this->nullable; |
75 | 75 | } |
76 | 76 | |
Index: trunk/phase3/includes/db/DatabaseIbm_db2.php |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | * This represents a column in a DB2 database |
15 | 15 | * @ingroup Database |
16 | 16 | */ |
17 | | -class IBM_DB2Field { |
| 17 | +class IBM_DB2Field implements Field { |
18 | 18 | private $name = ''; |
19 | 19 | private $tablename = ''; |
20 | 20 | private $type = ''; |
— | — | @@ -75,7 +75,7 @@ |
76 | 76 | * Can column be null? |
77 | 77 | * @return bool true or false |
78 | 78 | */ |
79 | | - function nullable() { return $this->nullable; } |
| 79 | + function isNullable() { return $this->nullable; } |
80 | 80 | /** |
81 | 81 | * How much can you fit in the column per row? |
82 | 82 | * @return int length |
Index: trunk/phase3/includes/db/Database.php |
— | — | @@ -2646,57 +2646,33 @@ |
2647 | 2647 | } |
2648 | 2648 | |
2649 | 2649 | /** |
2650 | | - * Utility class. |
| 2650 | + * Base for all database-specific classes representing information about database fields |
2651 | 2651 | * @ingroup Database |
2652 | 2652 | */ |
2653 | | -class MySQLField { |
2654 | | - private $name, $tablename, $default, $max_length, $nullable, |
2655 | | - $is_pk, $is_unique, $is_multiple, $is_key, $type; |
| 2653 | +interface Field { |
| 2654 | + /** |
| 2655 | + * Field name |
| 2656 | + * @return string |
| 2657 | + */ |
| 2658 | + function name(); |
2656 | 2659 | |
2657 | | - function __construct ( $info ) { |
2658 | | - $this->name = $info->name; |
2659 | | - $this->tablename = $info->table; |
2660 | | - $this->default = $info->def; |
2661 | | - $this->max_length = $info->max_length; |
2662 | | - $this->nullable = !$info->not_null; |
2663 | | - $this->is_pk = $info->primary_key; |
2664 | | - $this->is_unique = $info->unique_key; |
2665 | | - $this->is_multiple = $info->multiple_key; |
2666 | | - $this->is_key = ( $this->is_pk || $this->is_unique || $this->is_multiple ); |
2667 | | - $this->type = $info->type; |
2668 | | - } |
| 2660 | + /** |
| 2661 | + * Name of table this field belongs to |
| 2662 | + * @return string |
| 2663 | + */ |
| 2664 | + function tableName(); |
2669 | 2665 | |
2670 | | - function name() { |
2671 | | - return $this->name; |
2672 | | - } |
| 2666 | + /** |
| 2667 | + * Database type |
| 2668 | + * @return string |
| 2669 | + */ |
| 2670 | + function type(); |
2673 | 2671 | |
2674 | | - function tableName() { |
2675 | | - return $this->tableName; |
2676 | | - } |
2677 | | - |
2678 | | - function defaultValue() { |
2679 | | - return $this->default; |
2680 | | - } |
2681 | | - |
2682 | | - function maxLength() { |
2683 | | - return $this->max_length; |
2684 | | - } |
2685 | | - |
2686 | | - function nullable() { |
2687 | | - return $this->nullable; |
2688 | | - } |
2689 | | - |
2690 | | - function isKey() { |
2691 | | - return $this->is_key; |
2692 | | - } |
2693 | | - |
2694 | | - function isMultipleKey() { |
2695 | | - return $this->is_multiple; |
2696 | | - } |
2697 | | - |
2698 | | - function type() { |
2699 | | - return $this->type; |
2700 | | - } |
| 2672 | + /** |
| 2673 | + * Whether this field can store NULL values |
| 2674 | + * @return bool |
| 2675 | + */ |
| 2676 | + function isNullable(); |
2701 | 2677 | } |
2702 | 2678 | |
2703 | 2679 | /****************************************************************************** |
Index: trunk/phase3/includes/db/DatabaseMssql.php |
— | — | @@ -1051,7 +1051,7 @@ |
1052 | 1052 | * |
1053 | 1053 | * @ingroup Database |
1054 | 1054 | */ |
1055 | | -class MssqlField { |
| 1055 | +class MssqlField implements Field { |
1056 | 1056 | private $name, $tablename, $default, $max_length, $nullable, $type; |
1057 | 1057 | function __construct ( $info ) { |
1058 | 1058 | $this->name = $info['COLUMN_NAME']; |
— | — | @@ -1077,7 +1077,7 @@ |
1078 | 1078 | return $this->max_length; |
1079 | 1079 | } |
1080 | 1080 | |
1081 | | - function nullable() { |
| 1081 | + function isNullable() { |
1082 | 1082 | return $this->nullable; |
1083 | 1083 | } |
1084 | 1084 | |
Index: trunk/phase3/includes/db/DatabaseSqlite.php |
— | — | @@ -626,7 +626,7 @@ |
627 | 627 | /** |
628 | 628 | * @ingroup Database |
629 | 629 | */ |
630 | | -class SQLiteField { |
| 630 | +class SQLiteField implements Field { |
631 | 631 | private $info, $tableName; |
632 | 632 | function __construct( $info, $tableName ) { |
633 | 633 | $this->info = $info; |
— | — | @@ -651,17 +651,10 @@ |
652 | 652 | return $this->info->dflt_value; |
653 | 653 | } |
654 | 654 | |
655 | | - function maxLength() { |
656 | | - return -1; |
657 | | - } |
658 | | - |
659 | | - function nullable() { |
| 655 | + function isNullable() { |
660 | 656 | return !$this->info->notnull; |
661 | 657 | } |
662 | 658 | |
663 | | - # isKey(), isMultipleKey() not implemented, MySQL-specific concept. |
664 | | - # Suggest removal from base class [TS] |
665 | | - |
666 | 659 | function type() { |
667 | 660 | return $this->info->type; |
668 | 661 | } |
Index: trunk/phase3/includes/installer/MysqlUpdater.php |
— | — | @@ -601,7 +601,7 @@ |
602 | 602 | */ |
603 | 603 | protected function doWatchlistNull() { |
604 | 604 | $info = $this->db->fieldInfo( 'watchlist', 'wl_notificationtimestamp' ); |
605 | | - if ( $info->nullable() ) { |
| 605 | + if ( $info->isNullable() ) { |
606 | 606 | $this->output( "...wl_notificationtimestamp is already nullable.\n" ); |
607 | 607 | return; |
608 | 608 | } |
Index: trunk/phase3/includes/installer/PostgresUpdater.php |
— | — | @@ -442,7 +442,7 @@ |
443 | 443 | $this->output( "... error: expected column $table.$field to exist\n" ); |
444 | 444 | exit( 1 ); |
445 | 445 | } |
446 | | - if ( $fi->nullable() ) { |
| 446 | + if ( $fi->isNullable() ) { |
447 | 447 | # # It's NULL - does it need to be NOT NULL? |
448 | 448 | if ( 'NOT NULL' === $null ) { |
449 | 449 | $this->output( "Changing \"$table.$field\" to not allow NULLs\n" ); |
— | — | @@ -616,7 +616,7 @@ |
617 | 617 | |
618 | 618 | protected function checkRcCurIdNullable(){ |
619 | 619 | $fi = $this->db->fieldInfo( 'recentchanges', 'rc_cur_id' ); |
620 | | - if ( !$fi->nullable() ) { |
| 620 | + if ( !$fi->isNullable() ) { |
621 | 621 | $this->output( "Removing NOT NULL constraint from \"recentchanges.rc_cur_id\"\n" ); |
622 | 622 | $this->applyPatch( 'patch-rc_cur_id-not-null.sql' ); |
623 | 623 | } else { |
Index: trunk/phase3/includes/AutoLoader.php |
— | — | @@ -381,6 +381,7 @@ |
382 | 382 | 'DBQueryError' => 'includes/db/Database.php', |
383 | 383 | 'DBUnexpectedError' => 'includes/db/Database.php', |
384 | 384 | 'FakeResultWrapper' => 'includes/db/Database.php', |
| 385 | + 'Field' => 'includes/db/Database.php', |
385 | 386 | 'IBM_DB2Blob' => 'includes/db/DatabaseIbm_db2.php', |
386 | 387 | 'LBFactory' => 'includes/db/LBFactory.php', |
387 | 388 | 'LBFactory_Multi' => 'includes/db/LBFactory_Multi.php', |
— | — | @@ -389,7 +390,7 @@ |
390 | 391 | 'LoadBalancer' => 'includes/db/LoadBalancer.php', |
391 | 392 | 'LoadMonitor' => 'includes/db/LoadMonitor.php', |
392 | 393 | 'LoadMonitor_MySQL' => 'includes/db/LoadMonitor.php', |
393 | | - 'MySQLField' => 'includes/db/Database.php', |
| 394 | + 'MySQLField' => 'includes/db/DatabaseMysql.php', |
394 | 395 | 'MySQLMasterPos' => 'includes/db/DatabaseMysql.php', |
395 | 396 | 'ORABlob' => 'includes/db/DatabaseOracle.php', |
396 | 397 | 'ORAField' => 'includes/db/DatabaseOracle.php', |