From: stronk7 Date: Sun, 8 Oct 2006 09:38:09 +0000 (+0000) Subject: Added find_sequence_name() to be used by insert_record() to get the correct sequence X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c5ac44c69e9692c7c504bb2822bc145b78c1b149;p=moodle.git Added find_sequence_name() to be used by insert_record() to get the correct sequence --- diff --git a/lib/ddllib.php b/lib/ddllib.php index b541993b59..713559b422 100644 --- a/lib/ddllib.php +++ b/lib/ddllib.php @@ -469,6 +469,41 @@ function find_index_name($table, $index) { return false; } +/** + * Given one XMLDBTable, the function returns the name of its sequence in DB (if exists) + * of false if it doesn't exist + * + * @param XMLDBTable the table to be searched + * @return string sequence name of false + */ +function find_sequence_name($table) { + + global $CFG, $db; + + $sequencename = false; + +/// Do this function silenty (to avoid output in install/upgrade process) + $olddbdebug = $db->debug; + $db->debug = false; + + if (strtolower(get_class($table)) != 'xmldbtable') { + $db->debug = $olddbdebug; //Re-set original $db->debug + return false; + } + +/// Check table exists + if (!table_exists($table)) { + debugging('Table ' . $table->getName() . ' do not exist. Sequence not found', DEBUG_DEVELOPER); + $db->debug = $olddbdebug; //Re-set original $db->debug + return false; //Table doesn't exist, nothing to do + } + + $sequencename = $table->getSequenceFromDB($CFG->dbtype, $CFG->prefix); + + $db->debug = $olddbdebug; //Re-set original $db->debug + return $sequencename; +} + /** * This function will load one entire XMLDB file, generating all the needed * SQL statements, specific for each RDBMS ($CFG->dbtype) and, finally, it