]> git.mjollnir.org Git - moodle.git/commitdiff
Added find_sequence_name() to be used by insert_record() to get the correct sequence
authorstronk7 <stronk7>
Sun, 8 Oct 2006 09:38:09 +0000 (09:38 +0000)
committerstronk7 <stronk7>
Sun, 8 Oct 2006 09:38:09 +0000 (09:38 +0000)
lib/ddllib.php

index b541993b595707061c2bd5608dd17c184d7c5867..713559b42240d0a8611a73057ac05bf6afb13d0b 100644 (file)
@@ -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