Index: openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl,v diff -u -N -r1.31 -r1.32 --- openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl 22 Dec 2001 21:52:24 -0000 1.31 +++ openacs-4/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl 6 Aug 2002 04:56:28 -0000 1.32 @@ -7,8 +7,24 @@ @cvs-id $Id$ } -proc_doc db_nextval { sequence } { Returns the next value for a sequence. This can utilize a pool of sequence values to save hits to the database. } { - return [db_string nextval "select ${sequence}.nextval"] +proc_doc db_nextval { sequence } { + Returns the next value for a sequence. + This can utilize a pool of sequence values to save hits to the database. +} { + # the following query will return a nextval if the sequnce + # is of relkind = 'S' (a sequnce). if it is not of relkind = 'S' + # we will try querying it as a view + db_0or1row nextval_sequence "select nextval('${sequence}') as nextval + where (select relkind + from pg_class + where relname = '${sequence}') = 'S'" + if {[info exists nextval]} { + return $nextval + } else { + ns_log notice "db_nextval: sequence($sequence) is not a real sequence. perhaps it uses the view hack." + db_0or1row nextval_view "select ${sequence}.nextval as nextval" + return $nextval + } } proc_doc db_exec_plsql { statement_name sql args } {