MDL-21834 DDL tests - fix concurrent temp tables for mssql + 1 incorrect test

This commit is contained in:
Eloy Lafuente
2010-03-17 01:34:29 +00:00
parent 00511e2101
commit d61b3d0269
2 changed files with 24 additions and 1 deletions
+23
View File
@@ -557,6 +557,29 @@ class mssql_sql_generator extends sql_generator {
return $results;
}
/**
* Given three strings (table name, list of fields (comma separated) and suffix),
* create the proper object name quoting it if necessary.
*
* IMPORTANT: This function must be used to CALCULATE NAMES of objects TO BE CREATED,
* NEVER TO GUESS NAMES of EXISTING objects!!!
*
* IMPORTANT: We are overriding this function for the MSSQL generator because objects
* belonging to temporary tables aren't searchable in the catalog neither in information
* schema tables. So, for temporary tables, we are going to add 4 randomly named "virtual"
* fields, so the generated names won't cause concurrency problems. Really nasty hack,
* but the alternative involves modifying all the creation table code to avoid naming
* constraints for temp objects and that will dupe a lot of code.
*
*/
public function getNameForObject($tablename, $fields, $suffix='') {
if ($this->temptables->is_temptable($tablename)) { // Is temp table, inject random field names
$random = strtolower(random_string(12)); // 12cc to be split in 4 parts
$fields = $fields . ', ' . implode(', ', str_split($random, 3));
}
return parent::getNameForObject($tablename, $fields, $suffix); // Delegate to parent (common) algorithm
}
/**
* Given one object name and it's type (pk, uk, fk, ck, ix, uix, seq, trg)
* return if such name is currently in use (true) or no (false)
+1 -1
View File
@@ -1294,7 +1294,7 @@ class ddl_test extends UnitTestCase {
// Try to create table with same name, must throw exception
$dupetable = $this->tables['test_table0'];
try {
$dbman->create_temp_table($dupetable);
$dbman->create_table($dupetable);
$this->assertTrue(false);
} catch (Exception $e) {
$this->assertTrue($e instanceof ddl_exception);