mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
Adding getSequenceFromDB() for Oracle in order to detect the correct
sequence name in the insert_record() function.
This commit is contained in:
parent
1c55ce748d
commit
abbd460ff9
3 changed files with 48 additions and 0 deletions
|
@ -1035,6 +1035,19 @@ class XMLDBTable extends XMLDBObject {
|
|||
}
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will return the name of the sequence created for the pk of the table specified
|
||||
* Just one simple wrapper over generators. Returns false if not found
|
||||
* Note that not all DB use sequences (only Oracle and PostgreSQL)
|
||||
*/
|
||||
function getSequenceFromDB($dbtype, $prefix) {
|
||||
|
||||
$classname = 'XMLDB' . $dbtype;
|
||||
$generator = new $classname();
|
||||
$generator->setPrefix($prefix);
|
||||
return $generator->getSequenceFromDB($this);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
|
@ -1066,6 +1066,15 @@ class XMLDBgenerator {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name (string) of the sequence used in the table for the autonumeric pk
|
||||
* Only some DB have this implemented
|
||||
*/
|
||||
function getSequenceFromDB($xmldb_table) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// ALL THESE FUNCTION MUST BE CUSTOMISED BY ALL THE XMLDGenerator classes
|
||||
|
||||
/**
|
||||
|
|
|
@ -500,6 +500,32 @@ class XMLDBoci8po extends XMLDBgenerator {
|
|||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given one XMLDBTable returns one string with the sequence of the table
|
||||
* in the table (fetched from DB)
|
||||
* The sequence name for oracle is calculated by looking the corresponding
|
||||
* trigger and retrieving the sequence name from it (because sequences are
|
||||
* independent elements)
|
||||
* If no sequence is found, returns false
|
||||
*/
|
||||
function getSequenceFromDB($xmldb_table) {
|
||||
|
||||
$tablename = strtoupper($this->getTableName($xmldb_table));
|
||||
$sequencename = false;
|
||||
|
||||
if ($trigger = get_record_sql("SELECT trigger_name, trigger_body
|
||||
FROM user_triggers
|
||||
WHERE table_name = '{$tablename}'")) {
|
||||
/// If trigger found, regexp it looking for the sequence name
|
||||
preg_match('/.*SELECT (.*)\.nextval/i', $trigger->trigger_body, $matches);
|
||||
if (isset($matches[1])) {
|
||||
$sequencename = $matches[1];
|
||||
}
|
||||
}
|
||||
|
||||
return $sequencename;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of reserved words (lowercase) for this DB
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue