Skip to content

Commit

Permalink
MDL-21868 mssql generator - improve integer meta type detection
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Mar 21, 2010
1 parent 09b2ffb commit 32feeb0
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/xmldb/classes/generators/mssql/mssql.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,28 @@ function getAlterFieldSQL($xmldb_table, $xmldb_field) {
$typechanged = false;
}

/// If the new field specs are for integer, lett'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) {
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 (adodb metatype is buggy!)
$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) {
Expand Down

0 comments on commit 32feeb0

Please sign in to comment.