From e9e4a4a672bc1176e8a8fda18f16c7b093e4a76e Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sun, 22 Jan 2012 17:55:12 +0100 Subject: [PATCH] MDL-27982 convert all signed to unsigned and prevent adding of new unsigned columns Conflicts, amended to use .02 versions: lib/db/upgrade.php, version.php --- lib/db/upgrade.php | 9 +++++++++ lib/ddl/database_manager.php | 3 ++- lib/ddl/mssql_sql_generator.php | 1 - lib/ddl/oracle_sql_generator.php | 1 - lib/ddl/postgres_sql_generator.php | 1 - lib/ddl/simpletest/testddl.php | 14 -------------- lib/ddl/sql_generator.php | 11 +---------- lib/ddl/sqlite_sql_generator.php | 1 - version.php | 2 +- 9 files changed, 13 insertions(+), 30 deletions(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 8aa90d81c62..d335eb43482 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -196,6 +196,15 @@ function xmldb_main_upgrade($oldversion) { upgrade_main_savepoint(true, 2012030100.01); } + if ($oldversion < 2012030100.02) { + // migrate all numbers to signed - it should be safe to interrupt this and continue later + upgrade_mysql_fix_unsigned_columns(); + + // Main savepoint reached + upgrade_main_savepoint(true, 2012030100.02); + } + + return true; } diff --git a/lib/ddl/database_manager.php b/lib/ddl/database_manager.php index 476b9e1f4b0..e1b9453403e 100644 --- a/lib/ddl/database_manager.php +++ b/lib/ddl/database_manager.php @@ -659,12 +659,13 @@ class database_manager { /** * This function will change the unsigned/signed of the field in the table passed as arguments * + * @deprecated since 2.3, only singed numbers are allowed now, migration is automatic * @param xmldb_table $xmldb_table Table object (just the name is mandatory). * @param xmldb_field $xmldb_field Field object (full specs are required). * @return void */ public function change_field_unsigned(xmldb_table $xmldb_table, xmldb_field $xmldb_field) { - /// Just a wrapper over change_field_type. Does exactly the same processing + debugging('All unsigned numbers are converted to signed automatically during Moodle upgrade.'); $this->change_field_type($xmldb_table, $xmldb_field); } diff --git a/lib/ddl/mssql_sql_generator.php b/lib/ddl/mssql_sql_generator.php index fa7cbadabc4..e11176f2878 100644 --- a/lib/ddl/mssql_sql_generator.php +++ b/lib/ddl/mssql_sql_generator.php @@ -42,7 +42,6 @@ class mssql_sql_generator extends sql_generator { public $number_type = 'DECIMAL'; // Proper type for NUMBER(x) in this DB - public $unsigned_allowed = false; // To define in the generator must handle unsigned information public $default_for_char = ''; // To define the default to set for NOT NULLs CHARs without default (null=do nothing) public $specify_nulls = true; //To force the generator if NULL clauses must be specified. It shouldn't be necessary diff --git a/lib/ddl/oracle_sql_generator.php b/lib/ddl/oracle_sql_generator.php index 80039a5df7e..133b4ba8f86 100644 --- a/lib/ddl/oracle_sql_generator.php +++ b/lib/ddl/oracle_sql_generator.php @@ -43,7 +43,6 @@ class oracle_sql_generator extends sql_generator { public $number_type = 'NUMBER'; // Proper type for NUMBER(x) in this DB - public $unsigned_allowed = false; // To define in the generator must handle unsigned information public $default_for_char = ' '; // To define the default to set for NOT NULLs CHARs without default (null=do nothing) // Using this whitespace here because Oracle doesn't distinguish empty and null! :-( diff --git a/lib/ddl/postgres_sql_generator.php b/lib/ddl/postgres_sql_generator.php index acde9d2d4a1..5dc170e1cd8 100644 --- a/lib/ddl/postgres_sql_generator.php +++ b/lib/ddl/postgres_sql_generator.php @@ -40,7 +40,6 @@ class postgres_sql_generator extends sql_generator { public $number_type = 'NUMERIC'; // Proper type for NUMBER(x) in this DB - public $unsigned_allowed = false; // To define in the generator must handle unsigned information public $default_for_char = ''; // To define the default to set for NOT NULLs CHARs without default (null=do nothing) public $sequence_extra_code = false; //Does the generator need to add extra code to generate the sequence fields diff --git a/lib/ddl/simpletest/testddl.php b/lib/ddl/simpletest/testddl.php index 7c547c58f4e..7f950868397 100644 --- a/lib/ddl/simpletest/testddl.php +++ b/lib/ddl/simpletest/testddl.php @@ -901,20 +901,6 @@ class ddl_test extends UnitTestCase { //TODO: check the rest of attributes } - public function testChangeFieldSign() { - $dbman = $this->tdb->get_manager(); -// TODO: verify the signed is changed in db - - $table = $this->create_deftable('test_table1'); - $field = new xmldb_field('grade'); - $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', XMLDB_UNSIGNED, null, null, null); - $dbman->change_field_unsigned($table, $field); - - $field = new xmldb_field('grade'); - $field->set_attributes(XMLDB_TYPE_NUMBER, '10,2', null, null, null, null); - $dbman->change_field_unsigned($table, $field); - } - public function testChangeFieldNullability() { $DB = $this->tdb; // do not use global $DB! $dbman = $this->tdb->get_manager(); diff --git a/lib/ddl/sql_generator.php b/lib/ddl/sql_generator.php index f70ab21e312..dfa8d1c4a63 100644 --- a/lib/ddl/sql_generator.php +++ b/lib/ddl/sql_generator.php @@ -65,8 +65,6 @@ abstract class sql_generator { /** @var string Proper type for NUMBER(x) in this DB. */ public $number_type = 'NUMERIC'; - /** @var bool To define in the generator must handle unsigned information.*/ - public $unsigned_allowed = true; /** @var string To define the default to set for NOT NULLs CHARs without default (null=do nothing).*/ public $default_for_char = null; @@ -489,14 +487,7 @@ abstract class sql_generator { /// The type and length $field .= ' ' . $this->getTypeSQL($xmldb_field->getType(), $xmldb_field->getLength(), $xmldb_field->getDecimals()); } - /// The unsigned if supported - if ($this->unsigned_allowed && ($xmldb_field->getType() == XMLDB_TYPE_INTEGER || - $xmldb_field->getType() == XMLDB_TYPE_NUMBER || - $xmldb_field->getType() == XMLDB_TYPE_FLOAT)) { - if ($xmldb_field->getUnsigned()) { - $field .= ' unsigned'; - } - } + /// note: unsigned is not supported any more since moodle 2.3, all numbers are signed /// Calculate the not null clause $notnull = ''; /// Only if we don't want to skip it diff --git a/lib/ddl/sqlite_sql_generator.php b/lib/ddl/sqlite_sql_generator.php index d190d070659..3977b95fe1f 100644 --- a/lib/ddl/sqlite_sql_generator.php +++ b/lib/ddl/sqlite_sql_generator.php @@ -53,7 +53,6 @@ class sqlite_sql_generator extends sql_generator { public $sequence_only = true; //To avoid to output the rest of the field specs, leaving only the name and the sequence_name publiciable public $sequence_extra_code = false; //Does the generator need to add extra code to generate the sequence fields public $sequence_name = 'INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL'; //Particular name for inline sequences in this generator - public $unsigned_allowed = false; // To define in the generator must handle unsigned information public $enum_inline_code = true; //Does the generator need to add inline code in the column definition public $enum_extra_code = false; //Does the generator need to add extra code to generate code for the enums in the table diff --git a/version.php b/version.php index 190f235d90f..78370bb0235 100644 --- a/version.php +++ b/version.php @@ -30,7 +30,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2012030100.01; // YYYYMMDD = weekly release date of this DEV branch +$version = 2012030100.02; // YYYYMMDD = weekly release date of this DEV branch // RR = release increments - 00 in DEV branches // .XX = incremental changes