}
return $results;
}
+
+ /**
+ * This function will return the name of the sequence created for the pk of the table specified
+ * Just one simple wrapper over generators. Returns false if not found
+ * Note that not all DB use sequences (only Oracle and PostgreSQL)
+ */
+ function getSequenceFromDB($dbtype, $prefix) {
+
+ $classname = 'XMLDB' . $dbtype;
+ $generator = new $classname();
+ $generator->setPrefix($prefix);
+ return $generator->getSequenceFromDB($this);
+ }
}
?>
}
}
+ /**
+ * Returns the name (string) of the sequence used in the table for the autonumeric pk
+ * Only some DB have this implemented
+ */
+ function getSequenceFromDB($xmldb_table) {
+ return false;
+ }
+
+
/// ALL THESE FUNCTION MUST BE CUSTOMISED BY ALL THE XMLDGenerator classes
/**
return $results;
}
+ /**
+ * Given one XMLDBTable returns one string with the sequence of the table
+ * in the table (fetched from DB)
+ * The sequence name for oracle is calculated by looking the corresponding
+ * trigger and retrieving the sequence name from it (because sequences are
+ * independent elements)
+ * If no sequence is found, returns false
+ */
+ function getSequenceFromDB($xmldb_table) {
+
+ $tablename = strtoupper($this->getTableName($xmldb_table));
+ $sequencename = false;
+
+ if ($trigger = get_record_sql("SELECT trigger_name, trigger_body
+ FROM user_triggers
+ WHERE table_name = '{$tablename}'")) {
+ /// If trigger found, regexp it looking for the sequence name
+ preg_match('/.*SELECT (.*)\.nextval/i', $trigger->trigger_body, $matches);
+ if (isset($matches[1])) {
+ $sequencename = $matches[1];
+ }
+ }
+
+ return $sequencename;
+ }
+
/**
* Returns an array of reserved words (lowercase) for this DB
*/