Merge branch 'w16_MDL-38972_m25_oraindex' of git://github.com/skodak/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2013-04-24 02:02:20 +02:00
commit 01159be8de
3 changed files with 67 additions and 0 deletions

View File

@ -1229,6 +1229,51 @@ class ddl_testcase extends database_driver_testcase {
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course', 'name'));
$dbman->add_index($table, $index);
$this->assertTrue($dbman->index_exists($table, $index));
try {
$dbman->add_index($table, $index);
$this->fail('Exception expected for duplicate indexes');
} catch (Exception $e) {
$this->assertInstanceOf('ddl_exception', $e);
}
$index = new xmldb_index('third');
$index->set_attributes(XMLDB_INDEX_NOTUNIQUE, array('course'));
try {
$dbman->add_index($table, $index);
$this->fail('Exception expected for duplicate indexes');
} catch (Exception $e) {
$this->assertInstanceOf('ddl_exception', $e);
}
$table = new xmldb_table('test_table_cust0');
$table->add_field('id', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('onenumber', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('name', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'Moodle');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_key('onenumber', XMLDB_KEY_FOREIGN, array('onenumber'));
try {
$table->add_index('onenumber', XMLDB_INDEX_NOTUNIQUE, array('onenumber'));
$this->fail('Coding exception expected');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
$table = new xmldb_table('test_table_cust0');
$table->add_field('id', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null);
$table->add_field('onenumber', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('name', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, 'Moodle');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_index('onenumber', XMLDB_INDEX_NOTUNIQUE, array('onenumber'));
try {
$table->add_key('onenumber', XMLDB_KEY_FOREIGN, array('onenumber'));
$this->fail('Coding exception expected');
} catch (Exception $e) {
$this->assertInstanceOf('coding_exception', $e);
}
}
public function testFindIndexName() {

View File

@ -65,6 +65,8 @@ information provided here is intended especially for developers.
Database (DML) layer:
* $DB->sql_empty() is deprecated, you have to use sql parameters with empty values instead,
please note hardcoding of empty strings in SQL queries breaks execution in Oracle database.
* Indexes must not be defined on the same columns as keys, this is now reported as fatal problem.
Please note that internally we create indexes instead of foreign keys.
YUI changes:
* M.util.help_icon has been deprecated. Code should be updated to use moodle-core-popuphelp

View File

@ -125,6 +125,16 @@ class xmldb_table extends xmldb_object {
throw new coding_exception('Duplicate key '.$key->getName().' specified in table '.$this->getName());
}
// Make sure there are no duplicate keys because the indexes would collide.
$newfields = $key->getFields();
$allindexes = $this->getIndexes();
foreach ($allindexes as $index) {
$fields = $index->getFields();
if ($fields === $newfields) {
throw new coding_exception('Index '.$index->getName().' collides with key'.$key->getName().' specified in table '.$this->getName());
}
}
// Calculate the previous and next keys
$prevkey = null;
$nextkey = null;
@ -177,6 +187,16 @@ class xmldb_table extends xmldb_object {
throw new coding_exception('Duplicate index '.$index->getName().' specified in table '.$this->getName());
}
// Make sure there are no duplicate keys because the indexes would collide.
$newfields = $index->getFields();
$allkeys = $this->getKeys();
foreach ($allkeys as $key) {
$fields = $key->getFields();
if ($fields === $newfields) {
throw new coding_exception('Key '.$key->getName().' collides with index'.$index->getName().' specified in table '.$this->getName());
}
}
// Calculate the previous and next indexes
$previndex = null;
$nextindex = null;