if {![info exists ::db::sequences]} {
ns_log notice "-- creating per thread sequence table"foreach s [::xo::dc list relnames "select relname 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 sequenceName t_$sequenceset nextval [::xo::dc get_value nextval "select nextval(:sequenceName)"]
} elseif {[info exists ::db::sequences($sequence)]} {
#ns_log notice "-- found $sequence"set sequenceName $sequenceset nextval [::xo::dc get_value nextval "select nextval(:sequenceName)"]
} elseif { [::xo::dc 0or1row nextval_sequence {
select nextval(:sequence) as nextval
where (select relkind
from pg_class
where relname = :sequence) = 'S'
}]} {
## We do not have an according sequence-table. Use the system catalog to check# for the sequence## ... the query sets nextval if it succeeds#
} else {
## finally, there might be a view with a nextval#ns_log debug "db_nextval: sequence($sequence) is not a real sequence. Perhaps it uses the view hack."set nextval [::xo::dc get_value nextval "select nextval from :sequence"]
}
return$nextval