mirror of
https://github.com/moodle/moodle.git
synced 2025-04-16 14:02:32 +02:00
MDL-14679 temporary tables: modify approach so name changes are
now phisically stored and not only calculated on the fly. Oracle will need that.
This commit is contained in:
parent
6e5f318c53
commit
4b1ee2b3c4
@ -46,7 +46,7 @@ class moodle_temptables {
|
||||
|
||||
protected $mdb; // circular reference, to be able to use DB facilities here if needed
|
||||
protected $prefix; // prefix to be used for all the DB objects
|
||||
protected $temptables; // simple array of 'tablename' => 'tablename'
|
||||
protected $temptables; // simple array of moodle, not prefixed 'tablename' => DB, final (prefixed) 'tablename'
|
||||
|
||||
/**
|
||||
* Creates new moodle_temptables instance
|
||||
@ -61,6 +61,12 @@ class moodle_temptables {
|
||||
/**
|
||||
* Add one temptable to the store
|
||||
*
|
||||
* Given one moodle temptable name (without prefix), add it to the store, with the
|
||||
* key being the original moodle name and the value being the real db temptable name
|
||||
* already prefixed
|
||||
*
|
||||
* Override and use this *only* if the database requires modification in the table name.
|
||||
*
|
||||
* @param string $tablename name without prefix of the table created as temptable
|
||||
*/
|
||||
public function add_temptable($tablename) {
|
||||
@ -84,7 +90,7 @@ class moodle_temptables {
|
||||
* @return array containing all the tablenames in the store (tablename both key and value)
|
||||
*/
|
||||
public function get_temptables() {
|
||||
return $this->temptables;
|
||||
return array_keys($this->temptables);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -93,19 +99,21 @@ class moodle_temptables {
|
||||
* @param string $tablename name without prefix of the table we are asking about
|
||||
* @return bool true if the table is a temp table (based in the store info), false if not
|
||||
*/
|
||||
function is_temptable ($tablename) {
|
||||
public function is_temptable($tablename) {
|
||||
return !empty($this->temptables[$tablename]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one tablename (no prefix), return the name of the corresponding temporary table,
|
||||
* usually the same name but some databases could require changes (like '#' prefix in mssql)
|
||||
* If the table isn't a "registered" temp table, returns null
|
||||
*
|
||||
* Override and use this *only* if the database requires modification in the table name.
|
||||
*
|
||||
* @param string $tablename name without prefix which corresponding temp tablename nees to calculate
|
||||
* @param string $tablename name without prefix which corresponding temp tablename needs to know
|
||||
* @return mixed DB name of the temp table or null if it isn't a temp table
|
||||
*/
|
||||
public function get_correct_name($tablename) {
|
||||
return $this->prefix . $tablename; // No change in name is the usual behaviour
|
||||
if ($this->is_temptable($tablename)) {
|
||||
return $this->temptables[$tablename];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@ -312,7 +312,11 @@ class mssql_native_moodle_database extends moodle_database {
|
||||
if (preg_match_all('/\{([a-z][a-z0-9_]*)\}/', $sql, $matches)) {
|
||||
foreach($matches[0] as $key=>$match) {
|
||||
$name = $matches[1][$key];
|
||||
$sql = str_replace($match, $this->temptables->get_correct_name($name), $sql);
|
||||
if ($this->temptables->is_temptable($name)) {
|
||||
$sql = str_replace($match, $this->temptables->get_correct_name($name), $sql);
|
||||
} else {
|
||||
$sql = str_replace($match, $this->prefix.$name, $sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $sql;
|
||||
|
@ -31,18 +31,22 @@ require_once($CFG->libdir.'/dml/moodle_temptables.php');
|
||||
class mssql_native_moodle_temptables extends moodle_temptables {
|
||||
|
||||
/**
|
||||
* Override the method to return the correct real name (prefix = '#') of
|
||||
* temporary mssql databases. Widely used in the corresponding mssql sql
|
||||
* generator and database driver
|
||||
* Add one temptable to the store.
|
||||
*
|
||||
* @param string $tablename name without prefix which corresponding temp tablename nees to calculate
|
||||
* Overriden because MSSQL requires to add # for local (session) temporary
|
||||
* tables before the prefix.
|
||||
*
|
||||
* Given one moodle temptable name (without prefix), add it to the store, with the
|
||||
* key being the original moodle name and the value being the real db temptable name
|
||||
* already prefixed
|
||||
*
|
||||
* Override and use this *only* if the database requires modification in the table name.
|
||||
*
|
||||
* @param string $tablename name without prefix of the table created as temptable
|
||||
*/
|
||||
public function get_correct_name($tablename) {
|
||||
// TODO: throw exception if not exists
|
||||
if (!empty($this->temptables[$tablename])) {
|
||||
return '#' . $this->prefix . $tablename;
|
||||
} else {
|
||||
return $this->prefix . $tablename;
|
||||
}
|
||||
public function add_temptable($tablename) {
|
||||
// TODO: throw exception if exists: if ($this->is_temptable...
|
||||
$this->temptables[$tablename] = '#' . $this->prefix . $tablename;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user