Index: openacs.org-dev/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs.org-dev/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl,v diff -u -r1.1.1.1 -r1.1.1.2 --- openacs.org-dev/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl 9 Jul 2002 17:34:59 -0000 1.1.1.1 +++ openacs.org-dev/packages/acs-tcl/tcl/00-database-procs-postgresql.tcl 8 Oct 2002 15:46:49 -0000 1.1.1.2 @@ -7,8 +7,23 @@ @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 + if {[db_0or1row 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 nextval_view "select nextval from ${sequence}" + return $nextval + } } proc_doc db_exec_plsql { statement_name sql args } { @@ -40,14 +55,14 @@ # if a table is being created, we need to bypass things, too (OpenACS - Ben). set test_sql [db_qd_replace_sql $full_statement_name $sql] if {[regexp -nocase -- {^\s*select} $test_sql match]} { - db_qd_log Debug "PLPGSQL: bypassed anon function" + db_qd_log QDDebug "PLPGSQL: bypassed anon function" set selection [db_exec 0or1row $db $full_statement_name $sql] } elseif {[regexp -nocase -- {^\s*create table} $test_sql match] || [regexp -nocase -- {^\s*drop table} $test_sql match]} { - db_qd_log Debug "PLPGSQL: bypassed anon function -- create/drop table" + db_qd_log QDDebug "PLPGSQL: bypassed anon function -- create/drop table" set selection [db_exec dml $db $full_statement_name $sql] return "" } else { - db_qd_log Debug "PLPGSQL: using anonymous function" + db_qd_log QDDebug "PLPGSQL: using anonymous function" set selection [db_exec_plpgsql $db $full_statement_name $sql \ $statement_name] } @@ -74,12 +89,12 @@ } { set start_time [clock clicks] - db_qd_log Debug "PRE-QD: the SQL is $pre_sql" + db_qd_log QDDebug "PRE-QD: the SQL is $pre_sql" # Query Dispatcher (OpenACS - ben) set sql [db_qd_replace_sql $statement_name $pre_sql] - db_qd_log Debug "POST-QD: the SQL is $sql" + db_qd_log QDDebug "POST-QD: the SQL is $sql" set unique_id [db_nextval "anon_func_seq"] @@ -89,7 +104,7 @@ if {![string equal $sql $pre_sql]} { set sql [uplevel 2 [list subst -nobackslashes $sql]] } - db_qd_log Debug "PLPGSQL: converted: $sql to: select $function_name ()" + db_qd_log QDDebug "PLPGSQL: converted: $sql to: select $function_name ()" # create a function definition statement for the inline code # binding is emulated in tcl. (OpenACS - Dan) @@ -203,7 +218,7 @@ } { set start_time [clock clicks] - db_qd_log Debug "PRE-QD: the SQL is $pre_sql for $statement_name" + db_qd_log QDDebug "PRE-QD: the SQL is $pre_sql for $statement_name" # Query Dispatcher (OpenACS - ben) set sql [db_qd_replace_sql $statement_name $pre_sql] @@ -213,7 +228,7 @@ set sql [uplevel $ulevel [list subst -nobackslashes $sql]] } - db_qd_log Debug "POST-QD: the SQL is $sql" + db_qd_log QDDebug "POST-QD: the SQL is $sql" set errno [catch { upvar bind bind @@ -720,7 +735,7 @@ @param pattern Will be used as LIKE 'pattern%' to limit the number of tables returned. - @author Don Baccus dhogaza@pacifier.com + @author Don Baccus (dhogaza@pacifier.com) } { set tables [list] @@ -749,7 +764,7 @@ ad_proc -public db_table_exists { table_name } { Returns 1 if a table with the specified name exists in the database, otherwise 0. - @author Don Baccus dhogaza@pacifier.com + @author Don Baccus (dhogaza@pacifier.com) } { set n_rows [db_string table_count {