=== modified file 'includes/database.mysql-common.inc'
--- includes/database.mysql-common.inc	2007-06-05 12:13:20 +0000
+++ includes/database.mysql-common.inc	2007-06-07 18:20:08 +0000
@@ -8,7 +8,7 @@
  */
 
 /**
- * @ingroup schemaapi
+ * @ingroup database
  * @{
  */
 
@@ -48,6 +48,44 @@ function db_query($query) {
   return _db_query($query);
 }
 
+
+/**
+ * Returns the last insert id.
+ *
+ * @param $table
+ *   The name of the table you inserted into.
+ * @param $field
+ *   The name of the autoincrement field.
+ */
+function db_last_insert_id($table, $field) {
+  $last_insert_id = db_result(db_query('SELECT LAST_INSERT_ID()'));
+  db_query("REPLACE INTO {sequences} (name, id) VALUES ('%s', %d)", db_prefix_tables('{'. $table .'}') . '_'. $field, $last_insert_id);
+  return $last_insert_id;
+}
+
+/**
+ *
+ * Returns the value of an autoincrement field. It is stored outside of the
+ * database table in question.
+ *
+ * @param $table
+ *   The name of the table containg $field.
+ * @param $field
+ *   The name of the autoincrement field.
+ */
+function db_counter($table, $field) {
+  return db_result(db_query("SELECT id FROM {sequences} WHERE name ='%s'", db_prefix_tables('{'. $table .'}') . '_'. $field));
+}
+
+/**
+ * @} End of "ingroup database".
+ */
+
+/**
+ * @ingroup schemaapi
+ * @{
+ */
+
 /**
  *  Generate SQL to create a new table from a Drupal schema definition.
  *
@@ -447,20 +485,7 @@ function db_update_field(&$ret, $table, 
   db_change_field($ret, $table, $field, $field, $spec['fields'][$field]);
 }
 
-/**
- * Returns the last insert id.
- *
- * @param $table
- *   The name of the table you inserted into.
- * @param $field
- *   The name of the autoincrement field.
- */
-function db_last_insert_id($table, $field) {
-  return db_result(db_query('SELECT LAST_INSERT_ID()'));
-}
 
 /**
  * @} End of "ingroup schemaapi".
  */
-
-?>
\ No newline at end of file

=== modified file 'includes/database.pgsql.inc'
--- includes/database.pgsql.inc	2007-06-05 12:13:20 +0000
+++ includes/database.pgsql.inc	2007-06-07 18:19:34 +0000
@@ -264,6 +264,21 @@ function db_last_insert_id($table, $fiel
 }
 
 /**
+ *
+ * Returns the value of an autoincrement field. It is stored outside of the
+ * database table in question.
+ *
+ * @param $table
+ *   The name of the table containg $field.
+ * @param $field
+ *   The name of the autoincrement field.
+ */
+function db_counter($table, $field) {
+  return db_result(db_query("SELECT currval('%s_seq')", db_prefix_tables('{'. $table .'}') . '_'. $field));
+}
+
+
+/**
  * Determine the number of rows changed by the preceding query.
  */
 function db_affected_rows() {

