From d5eff6795e951bd9e691cfd25ea5458a0eaace3c Mon Sep 17 00:00:00 2001 From: stronk7 Date: Mon, 16 Oct 2006 17:36:13 +0000 Subject: [PATCH] Added support for getSequenceFromDB() to PG. Merged from MOODLE_17_STABLE --- .../generators/postgres7/postgres7.class.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/xmldb/classes/generators/postgres7/postgres7.class.php b/lib/xmldb/classes/generators/postgres7/postgres7.class.php index 6cf983b5fb5..9dcf4b00e6a 100644 --- a/lib/xmldb/classes/generators/postgres7/postgres7.class.php +++ b/lib/xmldb/classes/generators/postgres7/postgres7.class.php @@ -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 */