mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 14:02:32 +02:00
MDL-19057 detect missing unique primary key on id columns
This commit is contained in:
parent
fd31089c76
commit
41a50aa254
@ -186,6 +186,7 @@ $string['ddldependencyerror'] = '{$a->targettype} "{$a->targetname}" cannot be m
|
||||
$string['ddlexecuteerror'] = 'DDL sql execution error';
|
||||
$string['ddlfieldalreadyexists'] = 'Field "{$a}" already exists';
|
||||
$string['ddlfieldnotexist'] = 'Field "{$a->fieldname}" does not exist in table "{$a->tablename}"';
|
||||
$string['ddsequenceerror'] = 'Incorrect table "{$a}" definition; there can be only one auto column and it must be defined as a key.';
|
||||
$string['ddltablealreadyexists'] = 'Table "{$a}" already exists';
|
||||
$string['ddltablenotexist'] = 'Table "{$a}" does not exist';
|
||||
$string['ddlunknownerror'] = 'Unknown DDL library error';
|
||||
|
@ -233,8 +233,13 @@ abstract class sql_generator {
|
||||
return $results;
|
||||
}
|
||||
|
||||
$sequencefield = null;
|
||||
|
||||
/// Add the fields, separated by commas
|
||||
foreach ($xmldb_fields as $xmldb_field) {
|
||||
if ($xmldb_field->getSequence()) {
|
||||
$sequencefield = $xmldb_field->getName();
|
||||
}
|
||||
$table .= "\n " . $this->getFieldSQL($xmldb_field);
|
||||
$table .= ',';
|
||||
}
|
||||
@ -252,8 +257,20 @@ abstract class sql_generator {
|
||||
$table .= "\nCONSTRAINT " . $keytext . ',';
|
||||
}
|
||||
}
|
||||
/// make sure sequence field is unique
|
||||
if ($sequencefield and $xmldb_key->getType() == XMLDB_KEY_PRIMARY) {
|
||||
$field = reset($xmldb_key->getFields());
|
||||
if ($sequencefield === $field) {
|
||||
$sequencefield = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/// throw error if sequence field does not have unique key defined
|
||||
if ($sequencefield) {
|
||||
throw new ddl_exception('ddsequenceerror', $xmldb_table->getName());
|
||||
}
|
||||
|
||||
/// Table footer, trim the latest comma
|
||||
$table = trim($table,',');
|
||||
$table .= "\n)";
|
||||
|
Loading…
x
Reference in New Issue
Block a user