Skip to content

Commit

Permalink
Instead of looking for current default value, fetch from
Browse files Browse the repository at this point in the history
the generator the *real* default value that the table will have.
  • Loading branch information
stronk7 committed Aug 11, 2007
1 parent 2c5e52e commit b794dc2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions lib/ddllib.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ function field_exists($table, $field) {
$exists = false;
}

/// Re-set original debug
/// Re-set original debug
$db->debug = $olddbdebug;

return $exists;
Expand Down Expand Up @@ -348,7 +348,7 @@ function index_exists($table, $index) {
$exists = false;
}

/// Re-set original debug
/// Re-set original debug
$db->debug = $olddbdebug;

return $exists;
Expand Down Expand Up @@ -746,14 +746,20 @@ function add_field($table, $field, $continue=true, $feedback=true) {
return false;
}

/// Load the needed generator
$classname = 'XMLDB' . $CFG->dbtype;
$generator = new $classname();
$generator->setPrefix($CFG->prefix);

/// Check the field doesn't exist
if (field_exists($table, $field)) {
debugging('Field ' . $field->getName() . ' exists. Create skipped', DEBUG_DEVELOPER);
return true;
}

/// If NOT NULL and no default given, check the table is empty
if ($field->getNotNull() && $field->getDefault() === NULL && count_records($table->getName())) {
/// If NOT NULL and no default given (we ask the generator about the
/// *real* default that will be used) check the table is empty
if ($field->getNotNull() && $generator->getDefaultValue($field) === NULL && count_records($table->getName())) {
debugging('Field ' . $field->getName() . ' cannot be added. Not null fields added to non empty tables require default value. Create skipped', DEBUG_DEVELOPER);
return true;
}
Expand Down

0 comments on commit b794dc2

Please sign in to comment.