Skip to content

Commit

Permalink
MDL-24322 detecting duplicate keys/fields and indexes - this prevents…
Browse files Browse the repository at this point in the history
… infinite looks later in code
  • Loading branch information
skodak committed Sep 21, 2010
1 parent f2a9be5 commit 6496a01
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/xmldb/xmldb_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ function __construct($name) {
*/
function addField(&$field, $after=NULL) {

/// Detect duplicates first
if ($this->getField($field->getName())) {
throw new coding_exception('Duplicate field '.$field->getName().' specified in table '.$this->getName());
}

/// Calculate the previous and next fields
$prevfield = NULL;
$nextfield = NULL;
Expand Down Expand Up @@ -95,6 +100,11 @@ function addField(&$field, $after=NULL) {
*/
function addKey(&$key, $after=NULL) {

/// Detect duplicates first
if ($this->getKey($key->getName())) {
throw new coding_exception('Duplicate key '.$key->getName().' specified in table '.$this->getName());
}

/// Calculate the previous and next keys
$prevkey = NULL;
$nextkey = NULL;
Expand Down Expand Up @@ -140,6 +150,11 @@ function addKey(&$key, $after=NULL) {
*/
function addIndex(&$index, $after=NULL) {

/// Detect duplicates first
if ($this->getIndex($index->getName())) {
throw new coding_exception('Duplicate index '.$index->getName().' specified in table '.$this->getName());
}

/// Calculate the previous and next indexes
$previndex = NULL;
$nextindex = NULL;
Expand Down

0 comments on commit 6496a01

Please sign in to comment.