MDL-17020 dml: native pgsql driver - fixing/improving unittests; fixed column names in indexes

This commit is contained in:
skodak 2008-10-27 12:33:09 +00:00
parent 334ce0266d
commit 80ffbad34b
2 changed files with 21 additions and 11 deletions

View File

@ -187,8 +187,10 @@ class pgsql_native_moodle_database extends moodle_database {
if ($matches[4] === 'id') {
continue;
}
$columns = explode(',', $matches[4]);
$columns = array_map('trim', $columns);
$indexes[$matches[2]] = array('unique'=>!empty($matches[1]),
'columns'=>explode(',', $matches[4]));
'columns'=>$columns);
}
pg_free_result($result);
}

View File

@ -222,23 +222,31 @@ class dml_test extends UnitTestCase {
$table = $this->get_test_table($dbman, "testtable");
$table->add_field('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$table->add_index('course', XMLDB_INDEX_NOTUNIQUE, array('course'));
$table->add_index('course-id', XMLDB_INDEX_UNIQUE, array('course', 'id'));
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table);
$this->tables[$table->getName()] = $table;
$this->assertTrue($indices = $DB->get_indexes('testtable'));
$this->assertTrue(count($indices) == 2);
sort($indices);
$this->assertFalse($indices[0]['unique']);
$this->assertTrue($indices[1]['unique']);
$this->assertEqual(1, count($indices[0]['columns']));
$this->assertEqual(2, count($indices[1]['columns']));
$this->assertEqual('course', $indices[0]['columns'][0]);
$this->assertEqual('course', $indices[1]['columns'][0]);
$this->assertEqual('id', $indices[1]['columns'][1]);
// we do not cvare about index names for now
$first = array_shift($indices);
$second = array_shift($indices);
if (count($first['columns']) == 2) {
$composed = $first;
$single = $second;
} else {
$composed = $second;
$single = $first;
}
$this->assertFalse($single['unique']);
$this->assertTrue($composed['unique']);
$this->assertEqual(1, count($single['columns']));
$this->assertEqual(2, count($composed['columns']));
$this->assertEqual('course', $single['columns'][0]);
$this->assertEqual('course', $composed['columns'][0]);
$this->assertEqual('id', $composed['columns'][1]);
}
public function testGetColumns() {