On postgres, the divergence of sequences between those that use the
view hack and those that do not is starting to cause a lot of problems.
One big problem that is cropping up in a number of places is that the
abstraction of the view hack is broken between the sql and tcl layers.
db_nextval assumes you are using the view hack, and fails on any
sequences that use the postgres syntax (what we would expect new OACS
postgres developers to use by default, right...?)
I am still searching for an end-all solution to this problem which
_doesn't_ require splitting all queries that use nextval into
-postgresql and -oracle files. For now, I have a hack to the hack.
Here is my proposed new db_nextval for the file
acs-tcl/tcl/00-database-procs-postgresql.tcl:
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. } {
set sequence_datatype_hack [db_string get_hack_type "select
relkind from pg_class where relname='${sequence}'"]
switch "$sequence_datatype_hack" {
"S" {
return [db_string nextval "select nextval('${sequence}')"]
}
"v" {
return [db_string nextval "select ${sequence}.nextval"]
}
default {
ns_log notice "db_nextval error: uh oh.. ${sequence} does
not appear to be of type sequence OR view."
return
}
}
}
This function checks to see if the sequence is a real sequence (return
val 'S') or a view (return val 'v'). It then runs the correct query
to get the nextval.
If there are no objections, I am going to commit this into the tree.
If someone has a good end-all solution to the nextval problem, I'd
love to hear that, too.
Request notifications