From d61b3d02695a7eb38c8a6fe99ec0c278910f1017 Mon Sep 17 00:00:00 2001 From: Eloy Lafuente Date: Wed, 17 Mar 2010 01:34:29 +0000 Subject: [PATCH] MDL-21834 DDL tests - fix concurrent temp tables for mssql + 1 incorrect test --- lib/ddl/mssql_sql_generator.php | 23 +++++++++++++++++++++++ lib/ddl/simpletest/testddl.php | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/ddl/mssql_sql_generator.php b/lib/ddl/mssql_sql_generator.php index e5dbcfcc936..4dfdaa93e02 100644 --- a/lib/ddl/mssql_sql_generator.php +++ b/lib/ddl/mssql_sql_generator.php @@ -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) diff --git a/lib/ddl/simpletest/testddl.php b/lib/ddl/simpletest/testddl.php index 2126586d444..d4b7500e64f 100755 --- a/lib/ddl/simpletest/testddl.php +++ b/lib/ddl/simpletest/testddl.php @@ -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);