Index: openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/Attic/00-database-procs.tcl,v diff -u -r1.71 -r1.72 --- openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl 23 Jan 2008 19:12:58 -0000 1.71 +++ openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl 18 May 2008 16:27:31 -0000 1.72 @@ -360,23 +360,28 @@ switch $driverkey { postgresql { -# # 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: + # 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: -# if { [db_0or1row -dbn $dbn nextval_sequence " -# select nextval('${sequence}') as nextval -# where (select relkind -# from pg_class -# where relname = '${sequence}') = 'S' -# "]} { -# return $nextval -# } else { -# ns_log debug "db_nextval: sequence($sequence) is not a real sequence. perhaps it uses the view hack." -# db_0or1row -dbn $dbn nextval_view "select nextval from ${sequence}" -# return $nextval -# } + if { [db_0or1row -dbn $dbn nextval_sequence " + select nextval('${sequence}') as nextval + where (select relkind + from pg_class + where relname = '${sequence}') = 'S' + "]} { + return $nextval + } else { + ns_log debug "db_nextval: sequence($sequence) is not a real sequence. perhaps it uses the view hack." + db_0or1row -dbn $dbn nextval_view "select nextval from ${sequence}" + return $nextval + } + # DRB: I've restored the above code because Gustaf's "improved" version + # does not work in all cases, as documented by him below. This is not + # acceptable. It breaks any call to db_nextval by an initial install + # script or a package apm install callback. No! You don't get to do that! # + # # The code above is just for documentation, how it worked # before the change below. We keep now a per-thread table of # the "known" sequences to avoid at runtime the query, @@ -392,25 +397,25 @@ # # - gustaf neumann (17.9.2007) # - if {![info exists ::db::sequences]} { - ns_log notice "-- creating per thread sequence table" - namespace eval ::db {} - foreach s [db_list -dbn $dbn relnames "select relname, relkind from pg_class where relkind = 'S'"] { - set ::db::sequences($s) 1 - } - } - if {[info exists ::db::sequences(t_$sequence)]} { - #ns_log notice "-- found t_$sequence" - set nextval [db_string -dbn $dbn "nextval" "select nextval('t_$sequence')"] - } elseif {[info exists ::db::sequences($sequence)]} { - #ns_log notice "-- found $sequence" - set nextval [db_string -dbn $dbn "nextval" "select nextval('$sequence')"] - } else { - #ns_log notice "-- use view" - set nextval [db_string -dbn $dbn "nextval" "select nextval from $sequence"] - } - return $nextval - } +# if {![info exists ::db::sequences]} { +# ns_log notice "-- creating per thread sequence table" +# namespace eval ::db {} +# foreach s [db_list -dbn $dbn relnames "select relname, relkind from pg_class where relkind = 'S'"] { +# set ::db::sequences($s) 1 +# } +# } +# if {[info exists ::db::sequences(t_$sequence)]} { +# #ns_log notice "-- found t_$sequence" +# set nextval [db_string -dbn $dbn "nextval" "select nextval('t_$sequence')"] +# } elseif {[info exists ::db::sequences($sequence)]} { +# #ns_log notice "-- found $sequence" +# set nextval [db_string -dbn $dbn "nextval" "select nextval('$sequence')"] +# } else { +# #ns_log notice "-- use view" +# set nextval [db_string -dbn $dbn "nextval" "select nextval from $sequence"] +# } +# return $nextval +# } oracle - nsodbc -