]> git.mjollnir.org Git - moodle.git/commitdiff
Added support for getSequenceFromDB() to PG.
authorstronk7 <stronk7>
Mon, 16 Oct 2006 17:36:13 +0000 (17:36 +0000)
committerstronk7 <stronk7>
Mon, 16 Oct 2006 17:36:13 +0000 (17:36 +0000)
Merged from MOODLE_17_STABLE

lib/xmldb/classes/generators/postgres7/postgres7.class.php

index 6cf983b5fb565e3214ed8d35e2c12b71c562c34e..9dcf4b00e6ad7fd32310922366f366d7bb89be07 100644 (file)
@@ -446,6 +446,29 @@ class XMLDBpostgres7 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 Postgres has one standard name convention: 
+ *     tablename_fieldname_seq
+ * so we just calculate it and confirm it's present in pg_class
+ * If no sequence is found, returns false
+ */
+function getSequenceFromDB($xmldb_table) {
+
+    $tablename = $this->getTableName($xmldb_table);
+    $sequencename = $tablename . '_id_seq';
+
+    if (!get_record_sql("SELECT *
+                     FROM pg_class
+                     WHERE relname = '{$sequencename}'
+                       AND relkind = 'S'")) {
+        $sequencename = false;
+    }
+
+    return $sequencename;
+}
+
     /**
      * Returns an array of reserved words (lowercase) for this DB
      */