Skip to content

Commit

Permalink
MDL-21834 DDL tests - fix concurrent temp tables for mssql + 1 incorr…
Browse files Browse the repository at this point in the history
…ect test
  • Loading branch information
stronk7 committed Mar 17, 2010
1 parent 00511e2 commit d61b3d0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions lib/ddl/mssql_sql_generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,29 @@ public function getCheckConstraintsFromDB($xmldb_table, $xmldb_field = null) {
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)
Expand Down
2 changes: 1 addition & 1 deletion lib/ddl/simpletest/testddl.php
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,7 @@ public function test_temp_tables() {
// 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);
Expand Down

0 comments on commit d61b3d0

Please sign in to comment.