From c5ac44c69e9692c7c504bb2822bc145b78c1b149 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sun, 8 Oct 2006 09:38:09 +0000 Subject: [PATCH] Added find_sequence_name() to be used by insert_record() to get the correct sequence --- lib/ddllib.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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 -- 2.39.5