* Made them all implement one common interface (might add more functions to it later)
* Moved MySQLField to DatabaseMysql.php
* Renamed nullable() to isNullable()
* Removed maxLength() from:
** SQLiteField: makes no sense
** MySQLField: doesn't do what people may think, useless for this class' purpose of assisting querying the DB schema
'DBQueryError' => 'includes/db/Database.php',
'DBUnexpectedError' => 'includes/db/Database.php',
'FakeResultWrapper' => 'includes/db/Database.php',
+ 'Field' => 'includes/db/Database.php',
'IBM_DB2Blob' => 'includes/db/DatabaseIbm_db2.php',
'LBFactory' => 'includes/db/LBFactory.php',
'LBFactory_Multi' => 'includes/db/LBFactory_Multi.php',
'LoadBalancer' => 'includes/db/LoadBalancer.php',
'LoadMonitor' => 'includes/db/LoadMonitor.php',
'LoadMonitor_MySQL' => 'includes/db/LoadMonitor.php',
- 'MySQLField' => 'includes/db/Database.php',
+ 'MySQLField' => 'includes/db/DatabaseMysql.php',
'MySQLMasterPos' => 'includes/db/DatabaseMysql.php',
'ORABlob' => 'includes/db/DatabaseOracle.php',
'ORAField' => 'includes/db/DatabaseOracle.php',
}
/**
- * Utility class.
+ * Base for all database-specific classes representing information about database fields
* @ingroup Database
*/
-class MySQLField {
- private $name, $tablename, $default, $max_length, $nullable,
- $is_pk, $is_unique, $is_multiple, $is_key, $type;
-
- function __construct ( $info ) {
- $this->name = $info->name;
- $this->tablename = $info->table;
- $this->default = $info->def;
- $this->max_length = $info->max_length;
- $this->nullable = !$info->not_null;
- $this->is_pk = $info->primary_key;
- $this->is_unique = $info->unique_key;
- $this->is_multiple = $info->multiple_key;
- $this->is_key = ( $this->is_pk || $this->is_unique || $this->is_multiple );
- $this->type = $info->type;
- }
-
- function name() {
- return $this->name;
- }
-
- function tableName() {
- return $this->tableName;
- }
-
- function defaultValue() {
- return $this->default;
- }
-
- function maxLength() {
- return $this->max_length;
- }
-
- function nullable() {
- return $this->nullable;
- }
+interface Field {
+ /**
+ * Field name
+ * @return string
+ */
+ function name();
- function isKey() {
- return $this->is_key;
- }
+ /**
+ * Name of table this field belongs to
+ * @return string
+ */
+ function tableName();
- function isMultipleKey() {
- return $this->is_multiple;
- }
+ /**
+ * Database type
+ * @return string
+ */
+ function type();
- function type() {
- return $this->type;
- }
+ /**
+ * Whether this field can store NULL values
+ * @return bool
+ */
+ function isNullable();
}
/******************************************************************************
* This represents a column in a DB2 database
* @ingroup Database
*/
-class IBM_DB2Field {
+class IBM_DB2Field implements Field {
private $name = '';
private $tablename = '';
private $type = '';
* Can column be null?
* @return bool true or false
*/
- function nullable() { return $this->nullable; }
+ function isNullable() { return $this->nullable; }
/**
* How much can you fit in the column per row?
* @return int length
*
* @ingroup Database
*/
-class MssqlField {
+class MssqlField implements Field {
private $name, $tablename, $default, $max_length, $nullable, $type;
function __construct ( $info ) {
$this->name = $info['COLUMN_NAME'];
return $this->max_length;
}
- function nullable() {
+ function isNullable() {
return $this->nullable;
}
*/
class Database extends DatabaseMysql {}
+/**
+ * Utility class.
+ * @ingroup Database
+ */
+class MySQLField implements Field {
+ private $name, $tablename, $default, $max_length, $nullable,
+ $is_pk, $is_unique, $is_multiple, $is_key, $type;
+
+ function __construct ( $info ) {
+ $this->name = $info->name;
+ $this->tablename = $info->table;
+ $this->default = $info->def;
+ $this->max_length = $info->max_length;
+ $this->nullable = !$info->not_null;
+ $this->is_pk = $info->primary_key;
+ $this->is_unique = $info->unique_key;
+ $this->is_multiple = $info->multiple_key;
+ $this->is_key = ( $this->is_pk || $this->is_unique || $this->is_multiple );
+ $this->type = $info->type;
+ }
+
+ function name() {
+ return $this->name;
+ }
+
+ function tableName() {
+ return $this->tableName;
+ }
+
+ function type() {
+ return $this->type;
+ }
+
+ function isNullable() {
+ return $this->nullable;
+ }
+
+ function defaultValue() {
+ return $this->default;
+ }
+
+ function isKey() {
+ return $this->is_key;
+ }
+
+ function isMultipleKey() {
+ return $this->is_multiple;
+ }
+}
+
class MySQLMasterPos {
var $file, $pos;
* Utility class.
* @ingroup Database
*/
-class ORAField {
+class ORAField implements Field {
private $name, $tablename, $default, $max_length, $nullable,
$is_pk, $is_unique, $is_multiple, $is_key, $type;
return $this->max_length;
}
- function nullable() {
+ function isNullable() {
return $this->nullable;
}
* @ingroup Database
*/
-class PostgresField {
+class PostgresField implements Field {
private $name, $tablename, $type, $nullable, $max_length, $deferred, $deferrable, $conname;
static function fromText($db, $table, $field) {
return $this->type;
}
- function nullable() {
+ function isNullable() {
return $this->nullable;
}
/**
* @ingroup Database
*/
-class SQLiteField {
+class SQLiteField implements Field {
private $info, $tableName;
function __construct( $info, $tableName ) {
$this->info = $info;
return $this->info->dflt_value;
}
- function maxLength() {
- return -1;
- }
-
- function nullable() {
+ function isNullable() {
return !$this->info->notnull;
}
- # isKey(), isMultipleKey() not implemented, MySQL-specific concept.
- # Suggest removal from base class [TS]
-
function type() {
return $this->info->type;
}
*/
protected function doWatchlistNull() {
$info = $this->db->fieldInfo( 'watchlist', 'wl_notificationtimestamp' );
- if ( $info->nullable() ) {
+ if ( $info->isNullable() ) {
$this->output( "...wl_notificationtimestamp is already nullable.\n" );
return;
}
$this->output( "... error: expected column $table.$field to exist\n" );
exit( 1 );
}
- if ( $fi->nullable() ) {
+ if ( $fi->isNullable() ) {
# # It's NULL - does it need to be NOT NULL?
if ( 'NOT NULL' === $null ) {
$this->output( "Changing \"$table.$field\" to not allow NULLs\n" );
protected function checkRcCurIdNullable(){
$fi = $this->db->fieldInfo( 'recentchanges', 'rc_cur_id' );
- if ( !$fi->nullable() ) {
+ if ( !$fi->isNullable() ) {
$this->output( "Removing NOT NULL constraint from \"recentchanges.rc_cur_id\"\n" );
$this->applyPatch( 'patch-rc_cur_id-not-null.sql' );
} else {