MDL-21868 mssql generator - improve integer meta type detection + test

This commit is contained in:
Eloy Lafuente
2010-03-21 19:36:50 +00:00
parent 070dea52cb
commit 2ab686ee71
2 changed files with 33 additions and 2 deletions
+22
View File
@@ -321,6 +321,28 @@ class mssql_sql_generator extends sql_generator {
$typechanged = false;
}
/// If the new field (and old) specs are for integer, let's be a bit more specific diferentiating
/// types of integers. Else, some combinations can cause things like MDL-21868
if ($xmldb_field->getType() == XMLDB_TYPE_INTEGER && $oldmetatype == 'I') {
if ($xmldb_field->getLength() > 9) { // Convert our new lenghts to detailed meta types
$newmssqlinttype = 'I8';
} else if ($xmldb_field->getLength() > 4) {
$newmssqlinttype = 'I';
} else {
$newmssqlinttype = 'I2';
}
if ($metac->type == 'bigint') { // Convert current DB type to detailed meta type (our metatype is not enough!)
$oldmssqlinttype = 'I8';
} else if ($metac->type == 'smallint') {
$oldmssqlinttype = 'I2';
} else {
$oldmssqlinttype = 'I';
}
if ($newmssqlinttype != $oldmssqlinttype) { // Compare new and old meta types
$typechanged = true; // Change in meta type means change in type at all effects
}
}
/// Detect if we are changing the length of the column, not always necessary to drop defaults
/// if only the length changes, but it's safe to do it always
if ($xmldb_field->getLength() == $oldlength) {
+11 -2
View File
@@ -815,14 +815,23 @@ class ddl_test extends UnitTestCase {
$this->assertEqual($columns['grade']->meta_type, 'N');
//TODO: chek the rest of attributes
// change integer field from 10 to 6
// change integer field from 10 to 2
$field = new xmldb_field('userid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$field->set_attributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0');
$dbman->change_field_precision($table, $field);
$columns = $DB->get_columns('test_table1');
$this->assertEqual($columns['userid']->meta_type, 'I');
//TODO: chek the rest of attributes
// change the column from integer (2) to integer (6) (forces change of type in some DBs)
$field = new xmldb_field('userid');
$field->set_attributes(XMLDB_TYPE_INTEGER, '6', XMLDB_UNSIGNED, null, null, null);
$dbman->change_field_precision($table, $field);
// column is integer 6 null default null now
$columns = $DB->get_columns('test_table1');
$this->assertEqual($columns['userid']->meta_type, 'I');
//TODO: chek the rest of attributes
// insert one record with 6-digit field
$record = new object();
$record->course = 10;