Index: openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl,v diff -u -r1.88.2.11 -r1.88.2.12 --- openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl 15 Nov 2016 01:25:12 -0000 1.88.2.11 +++ openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl 10 Jan 2017 08:39:15 -0000 1.88.2.12 @@ -76,8 +76,8 @@ # # --atp@piskorski.com, 2003/03/16 21:30 EST -# NOTE: don't forget to add your new pools into the -# ns_section ns/db/pools +# NOTE: don't forget to add your new pools into the +# ns_section ns/db/pools # The "driverkey" indirection layer: @@ -165,8 +165,8 @@ ad_proc -private db_driverkey { - {-handle_p 0} - dbn + {-handle_p 0} + dbn } { Normally, a dbn is passed to this proc. Unfortunately, there are one or two cases where a proc that needs to call this one has only @@ -245,13 +245,13 @@ } ad_proc -public db_compatible_rdbms_p { db_type } { - @return 1 if the given db_type is compatible with the current RDBMS. + @return 1 if the given db_type is compatible with the current RDBMS. } { return [expr { $db_type eq "" || [db_type] eq $db_type }] } ad_proc -deprecated db_package_supports_rdbms_p { db_type_list } { - @return 1 if db_type_list contains the current RDMBS type. A package intended to run with a given RDBMS must note this in it's package info file regardless of whether or not it actually uses the database. + @return 1 if db_type_list contains the current RDMBS type. A package intended to run with a given RDBMS must note this in it's package info file regardless of whether or not it actually uses the database. @see apm_package_supports_rdbms_p } { @@ -280,7 +280,7 @@ ad_proc -public db_version {} { @return the RDBMS version (i.e. 8.1.6 is a recent Oracle version; 7.1 a - recent PostgreSQL version. + recent PostgreSQL version) } { return [nsv_get ad_database_version .] } @@ -294,7 +294,7 @@ ad_proc -public db_known_database_types {} { @return a list of three-element lists describing the database engines known to OpenACS. Each sublist contains the internal database name (used in file - paths, etc), the driver name, and a "pretty name" to be used in selection + paths, etc), the driver name, and a "pretty name" to be used in selection forms displayed to the user. The nsv containing the list is initialized by the bootstrap script and should @@ -318,8 +318,8 @@ return "" } -ad_proc -public db_quote { string } { - Quotes a string value to be placed in a SQL statement. +ad_proc -public db_quote { string } { + Quotes a string value to be placed in a SQL statement. } { regsub -all {'} "$string" {''} result return $result @@ -347,15 +347,15 @@ } ad_proc -public db_nextval { - { -dbn "" } - sequence + { -dbn "" } + sequence } { Example: -
-     set new_object_id [db_nextval acs_object_id_seq]
-     
+
+    set new_object_id [db_nextval acs_object_id_seq]
+    
@return the next value for a sequence. This can utilize a pool of sequence values. @@ -374,98 +374,98 @@ 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 -# } - # - # 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, - # whether the specified sequence is a real sequence or a - # view. This change makes this function more than a factor - # of 2 faster than before. - # - # Note, that solely the per-thread information won't work for - # freshly created sequences. Therefore, we keep the old - # code for checking at runtime in the database for such - # occurrences. - # - # Note, that the sequence handling in OpenACS is quite a - # mess. Some sequences are named t_SEQUENCE (10 in dotlrn), - # others are are called just SEQUENCE (18 in dotlrn), for - # some sequences, additional views are defined with an - # attribute 'nextval', and on top of this, db_nextval is - # called sometimes with the view name and sometimes with the - # sequence name. Checking this at runtime is unnecessary - # complex and costly. - # - # The best solution would certainly be to call "db_nextval" - # only with real sequence names (as defined in SQL). In that - # case, the whole function would for postgres would collapse - # to a single line, without any need for sequence name - # caching. But in that case, one should rename the sequences - # from t_SEQUENCE to SEQUENCE for postgres. - # - # However, since Oracle uses the pseudo column ".nextval", - # which is emulated via the view, it is not clear, how - # feasible this is to remove all such views without breaking - # installed applications. We keep for such cases the view, - # but nevertheless, the function "db_nextval" should always - # be called with names without the "t_" prefix to achieve - # Oracle compatibility. - - 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')"] - if {[string match t_* $sequence]} { - ad_log Warning "For portability, db_nextval should be called without the leading 't_' prefix: 't_$sequence'" - } - } elseif { [db_0or1row -dbn $dbn nextval_sequence " + # 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 + # } + # + # 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, + # whether the specified sequence is a real sequence or a + # view. This change makes this function more than a factor + # of 2 faster than before. + # + # Note, that solely the per-thread information won't work for + # freshly created sequences. Therefore, we keep the old + # code for checking at runtime in the database for such + # occurrences. + # + # Note, that the sequence handling in OpenACS is quite a + # mess. Some sequences are named t_SEQUENCE (10 in dotlrn), + # others are are called just SEQUENCE (18 in dotlrn), for + # some sequences, additional views are defined with an + # attribute 'nextval', and on top of this, db_nextval is + # called sometimes with the view name and sometimes with the + # sequence name. Checking this at runtime is unnecessary + # complex and costly. + # + # The best solution would certainly be to call "db_nextval" + # only with real sequence names (as defined in SQL). In that + # case, the whole function would for postgres would collapse + # to a single line, without any need for sequence name + # caching. But in that case, one should rename the sequences + # from t_SEQUENCE to SEQUENCE for postgres. + # + # However, since Oracle uses the pseudo column ".nextval", + # which is emulated via the view, it is not clear, how + # feasible this is to remove all such views without breaking + # installed applications. We keep for such cases the view, + # but nevertheless, the function "db_nextval" should always + # be called with names without the "t_" prefix to achieve + # Oracle compatibility. + + 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')"] + if {[string match t_* $sequence]} { + ad_log Warning "For portability, db_nextval should be called without the leading 't_' prefix: 't_$sequence'" + } + } elseif { [db_0or1row -dbn $dbn nextval_sequence " select nextval('${sequence}') as nextval - where (select relkind - from pg_class + 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 - # - ad_log Warning "Probably deprecated sequence name '$sequence' is used (no sequence table found)" - } 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 [db_string -dbn $dbn nextval "select nextval from $sequence"] - ad_log Warning "Using deprecated sequence view hack for '$sequence'. Is there not real sequence?" - } + # + # We do not have an according sequence-table. Use the system catalog to check + # for the sequence + # + # ... the query sets nextval if it succeeds + # + ad_log Warning "Probably deprecated sequence name '$sequence' is used (no sequence table found)" + } 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 [db_string -dbn $dbn nextval "select nextval from $sequence"] + ad_log Warning "Using deprecated sequence view hack for '$sequence'. Is there not real sequence?" + } - return $nextval + return $nextval } oracle - @@ -477,10 +477,10 @@ } ad_proc -public db_nth_pool_name { - { -dbn "" } - n -} { - @return the name of the pool used for the nth-nested selection (0-relative). + { -dbn "" } + n +} { + @return the name of the pool used for the nth-nested selection (0-relative). @param dbn The database name to use. If empty_string, uses the default database. } { set available_pools [db_available_pools $dbn] @@ -495,8 +495,8 @@ ad_proc -public db_with_handle { - { -dbn "" } - db code_block + { -dbn "" } + db code_block } { Places a usable database handle in db and executes code_block. @@ -549,28 +549,28 @@ } if { $errno == 2 } { - + # The code block called a "return", so pass the message through but don't try # to return errorCode or errorInfo since they may not exist - + return -code $errno $error } } ad_proc -public db_exec_plsql { - {-dbn ""} - statement_name - sql - args + {-dbn ""} + statement_name + sql + args } { - Oracle: + Oracle: Executes a PL/SQL statement, and returns the variable of bind variable :1.

- PostgreSQL: + PostgreSQL: Performs a pl/pgsql function or procedure call. The caller must perform a select query that returns the value of the function. @@ -599,13 +599,13 @@ set new_note_id [db_exec_plsql create_note { begin :1 := note.new( - owner_id => :user_id, - title => :title, - body => :body, - creation_user => :user_id, - creation_ip => :peeraddr, - context_id => :package_id - ); + owner_id => :user_id, + title => :title, + body => :body, + creation_user => :user_id, + creation_ip => :peeraddr, + context_id => :package_id + ); end; }] @@ -648,7 +648,7 @@ If you are using xql files then put the body of the query in a - yourfilename-oracle.xql or yourfilename-postgresql.xql file, as appropriate. E.g. the first example + yourfilename-oracle.xql or yourfilename-postgresql.xql file, as appropriate. E.g. the first example transformed to use xql files looks like this: @@ -662,22 +662,22 @@ yourfilename-oracle.xql:

-    <fullquery name="delete_note">      
-      <querytext>
-        begin
-        note.del(:note_id);
-        end;
-      </querytext>
+    <fullquery name="delete_note">
+    <querytext>
+    begin
+    note.del(:note_id);
+    end;
+    </querytext>
     </fullquery>

yourfilename-postgresql.xql:

-    <fullquery name="delete_note">      
-      <querytext>
-        select note__delete(:note_id);
-      </querytext>
+    <fullquery name="delete_note">
+    <querytext>
+    select note__delete(:note_id);
+    </querytext>
     </fullquery>
@@ -691,7 +691,7 @@ set full_statement_name [db_qd_get_fullname $statement_name] if { [info exists bind_output] } { - return -code error "the -bind_output switch is not currently supported" + return -code error "the -bind_output switch is not currently supported" } set driverkey [db_driverkey $dbn] @@ -740,7 +740,7 @@ } db_with_handle -dbn $dbn db { - # plsql calls that are simple selects bypass the plpgsql + # plsql calls that are simple selects bypass the plpgsql # mechanism for creating anonymous functions (OpenACS - Dan). # 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] @@ -772,14 +772,14 @@

Low level replacement for db_exec which replaces inline code with a proc. - db proc is dropped after execution. This is a temporary fix until we can + db proc is dropped after execution. This is a temporary fix until we can port all of the db_exec_plsql calls to simple selects of the inline code wrapped in function calls.

- emulation of plsql calls from oracle. This routine takes the plsql + emulation of plsql calls from oracle. This routine takes the plsql statements and wraps them in a function call, calls the function, and then - drops the function. Future work might involve converting this to cache the + drops the function. Future work might involve converting this to cache the function calls

@@ -802,36 +802,36 @@ } ns_log Debug "PLPGSQL: converted: $sql to: select $function_name ()" - # create a function definition statement for the inline code + # create a function definition statement for the inline code # binding is emulated in tcl. (OpenACS - Dan) set errno [catch { - upvar bind bind - if { [info exists bind] && [llength $bind] != 0 } { - if { [llength $bind] == 1 } { + upvar bind bind + if { [info exists bind] && [llength $bind] != 0 } { + if { [llength $bind] == 1 } { set bind_vars [list] set len [ns_set size $bind] for {set i 0} {$i < $len} {incr i} { lappend bind_vars [ns_set key $bind $i] \ - [ns_set value $bind $i] + [ns_set value $bind $i] } set proc_sql [db_bind_var_substitution $sql $bind_vars] - } else { + } else { set proc_sql [db_bind_var_substitution $sql $bind] - } - } else { + } + } else { set proc_sql [uplevel 2 [list db_bind_var_substitution $sql]] - } + } ns_db dml $db "create function $function_name () returns varchar as ' [DoubleApos $proc_sql] ' language 'plpgsql'" set ret_val [ns_db 0or1row $db "select $function_name ()"] - + # drop the anonymous function (OpenACS - Dan) # JCD: ignore return code -- maybe we should be smarter about this though. - catch {ns_db dml $db "drop function $function_name ()"} + catch {ns_db dml $db "drop function $function_name ()"} return $ret_val @@ -843,7 +843,7 @@ ds_collect_db_call $db 0or1row $statement_name $sql $start_time $errno $error if { $errno == 2 } { - return $error + return $error } else { catch {ns_db dml $db "drop function $function_name ()"} } @@ -857,11 +857,11 @@ not attempt bind var substitution inside quotes. Examples:

-        sql          return value
-       {'a'}           {0 2}      
-       {'a''}           {}
-      {'a'a'a'}       {0 2 4 6}
-      {a'b'c'd'}      {1 3 5 7}
+    sql          return value
+    {'a'}           {0 2}
+    {'a''}           {}
+    {'a'a'a'}       {0 2 4 6}
+    {a'b'c'd'}      {1 3 5 7}
     
@see db_bind_var_subsitution @@ -895,20 +895,20 @@ ad_proc -private db_bind_var_substitution { sql { bind "" } } { This proc emulates the bind variable substitution in the postgresql driver. - Since this is a temporary hack, we do it in tcl instead of hacking up the + Since this is a temporary hack, we do it in tcl instead of hacking up the driver to support plsql calls. This is only used for the db_exec_plpgsql function. } { if {$bind eq ""} { upvar __db_sql lsql set lsql $sql - uplevel { + uplevel { set __db_lst [regexp -inline -indices -all -- {:?:\w+} $__db_sql] for {set __db_i [expr {[llength $__db_lst] - 1}]} {$__db_i >= 0} {incr __db_i -1} { set __db_ws [lindex $__db_lst $__db_i 0] set __db_we [lindex $__db_lst $__db_i 1] - set __db_bind_var [string range $__db_sql $__db_ws $__db_we] + set __db_bind_var [string range $__db_sql $__db_ws $__db_we] if {![string match "::*" $__db_bind_var] && ![db_bind_var_quoted_p $__db_sql $__db_ws $__db_we]} { set __db_tcl_var [string range $__db_bind_var 1 end] set __db_tcl_var [set $__db_tcl_var] @@ -918,7 +918,7 @@ set __db_tcl_var "'[DoubleApos $__db_tcl_var]'" } set __db_sql [string replace $__db_sql $__db_ws $__db_we $__db_tcl_var] - } + } } } } else { @@ -940,7 +940,7 @@ set val "'[DoubleApos $val]'" } set lsql [string replace $lsql $ws $we $val] - } + } } } @@ -965,9 +965,9 @@ set db [lindex $db_state(handles) $index_to_examine] # Stop now if the handle is part of a transaction. - if { [info exists db_state(transaction_level,$db)] - && $db_state(transaction_level,$db) > 0 - } { + if { [info exists db_state(transaction_level,$db)] + && $db_state(transaction_level,$db) > 0 + } { break } @@ -1102,7 +1102,7 @@ # If we took more than 5 seconds yack about it. if { [clock clicks -milliseconds] - $start_time > 5000 } { ns_log Warning "db_exec: longdb [expr {[clock seconds] - $start_time_fine}] seconds $db $type $statement_name" - } else { + } else { ns_log Debug "db_exec: timing [expr {[clock seconds] - $start_time_fine}] seconds $db $type $statement_name" } @@ -1117,15 +1117,15 @@ ad_proc -public db_string { {-dbn ""} - -cache_key + -cache_key {-cache_pool db_cache_pool} statement_name sql args - } { +} { Usage: db_string statement-name sql [ -default default ] [ -bind bind_set_id | -bind bind_value_list ] - + @return the first column of the result of the SQL query sql. If the query doesn't return a row, returns default or raises an error if no default is provided. @param dbn The database name to use. If empty_string, uses the default database. @@ -1182,7 +1182,7 @@ Usage: db_list statement-name sql [ -bind bind_set_id | -bind bind_value_list ] - @return a Tcl list of the values in the first column of the result of SQL query sql. + @return a Tcl list of the values in the first column of the result of SQL query sql. If sql doesn't return any rows, returns an empty list. @param dbn The database name to use. If empty_string, uses the default database. @@ -1198,17 +1198,17 @@ if { [info exists cache_key] } { return [ns_cache eval $cache_pool $cache_key { - db_with_handle -dbn $dbn db { - set selection [db_exec select $db $full_statement_name $sql] - set result [list] - while { [db_getrow $db $selection] } { - lappend result [ns_set value $selection 0] - } - } - set result - }] + db_with_handle -dbn $dbn db { + set selection [db_exec select $db $full_statement_name $sql] + set result [list] + while { [db_getrow $db $selection] } { + lappend result [ns_set value $selection 0] + } + } + set result + }] } - + db_with_handle -dbn $dbn db { set selection [db_exec select $db $full_statement_name $sql] set result [list] @@ -1232,9 +1232,9 @@ Usage: db_list_of_lists statement-name sql [ -bind bind_set_id | -bind bind_value_list ] - @return a Tcl list, each element of which is a list of all column - values in a row of the result of the SQL querysql. If - sql doesn't return any rows, returns an empty list. + @return a Tcl list, each element of which is a list of all column + values in a row of the result of the SQL querysql. If + sql doesn't return any rows, returns an empty list. It checks if the element is I18N and replaces it, thereby reducing the need to do this with every single package @@ -1258,7 +1258,7 @@ while { [db_getrow $db $selection] } { set this_result [list] for { set i 0 } { $i < [ns_set size $selection] } { incr i } { - lappend this_result [ns_set value $selection $i] + lappend this_result [ns_set value $selection $i] } lappend result $this_result } @@ -1273,7 +1273,7 @@ while { [db_getrow $db $selection] } { set this_result [list] for { set i 0 } { $i < [ns_set size $selection] } { incr i } { - lappend this_result [ns_set value $selection $i] + lappend this_result [ns_set value $selection $i] } lappend result $this_result } @@ -1320,24 +1320,24 @@ ad_proc -public db_foreach { - {-dbn ""} - statement_name - sql - args + {-dbn ""} + statement_name + sql + args } { - Usage: + Usage:
db_foreach statement-name sql [ -bind bind_set_id | -bind bind_value_list ] \ [ -column_array array_name | -column_set set_name ] \ - code_block [ if_no_rows if_no_rows_block ] + code_block [ if_no_rows if_no_rows_block ]

Performs the SQL query sql, executing code_block once for each row with variables set to column values (or a set or array populated if -column_array or - column_set is specified). If the query returns no rows, executes + column_set is specified). If the query returns no rows, executes if_no_rows_block (if provided).

Example: @@ -1363,9 +1363,9 @@ set code_block [lindex $args 0] } elseif { $arglength == 3 } { # Should have code block + if_no_rows + code block. - if { [lindex $args 1] ne "if_no_rows" - && [lindex $args 1] ne "else" - } { + if { [lindex $args 1] ne "if_no_rows" + && [lindex $args 1] ne "else" + } { return -code error "Expected if_no_rows as second-to-last argument" } set code_block [lindex $args 0] @@ -1392,7 +1392,7 @@ set counter 0 while { [db_getrow $db $selection] } { incr counter - unset -nocomplain array_val + unset -nocomplain array_val if { ![info exists column_set] } { for { set i 0 } { $i < [ns_set size $selection] } { incr i } { @@ -1445,7 +1445,7 @@ uplevel 1 { if { !$append_p || ![info exists counter]} { set counter 0 - } + } db_with_handle -dbn $dbn db { set selection [db_exec select $db $full_statement_name $sql] @@ -1457,8 +1457,8 @@ # the multirow generation # Also make the 'next_row' array available as a magic __db_multirow__next_row variable upvar 1 __db_multirow__next_row next_row - unset -nocomplain next_row - + unset -nocomplain next_row + set more_rows_p 1 while { 1 } { @@ -1467,7 +1467,7 @@ } else { break } - + # Setup the 'columns' part, now that we know the columns in the result set # And save variables which we might clobber, if '-unclobber' switch is specified. if { $local_counter == 0 } { @@ -1524,18 +1524,18 @@ # There is a code block to execute # Copy next_row to this_row, if it exists - unset -nocomplain this_row + unset -nocomplain this_row set array_get_next_row [array get next_row] if { $array_get_next_row ne "" } { array set this_row [array get next_row] } # Pull values from the query into next_row - unset -nocomplain next_row + unset -nocomplain next_row if { $more_rows_p } { for { set i 0 } { $i < [ns_set size $selection] } { incr i } { set next_row([ns_set key $selection $i]) [ns_set value $selection $i] - } + } } # Process the row @@ -1583,7 +1583,7 @@ error "Unknown return code: $errno" } } - + # Pull the local variables back out and into the array. incr counter upvar $level_up "$var_name:$counter" array_val @@ -1604,7 +1604,7 @@ upvar 1 $col column_value __saved_$col column_save # Unset it first, so the road's paved to restoring - unset -nocomplain column_value + unset -nocomplain column_value # Restore it if { [info exists column_save] } { @@ -1613,14 +1613,14 @@ } else { set column_value $column_save } - + # And then remove the saved col unset column_save } } } # Unset the next_row variable, just in case - unset -nocomplain next_row + unset -nocomplain next_row } } @@ -1636,17 +1636,17 @@ var_name statement_name sql - args + args } { @param dbn The database name to use. If empty_string, uses the default database. @param cache_key Cache the result using given value as the key. Default is to not cache. @param cache_pool Override the default db_cache_pool @param unclobber If set, will cause the proc to not overwrite local variables. Actually, what happens - is that the local variables will be overwritten, so you can access them within the code block. However, + is that the local variables will be overwritten, so you can access them within the code block. However, if you specify -unclobber, we will revert them to their original state after execution of this proc. - Usage: + Usage:

db_multirow [ -local ] [ -upvar_level n_levels_up ] [ -append ] [ -extend column_list ] \ var-name statement-name sql [ -bind bind_set_id | -bind bind_value_list ] \ @@ -1659,7 +1659,7 @@ var_name:1, var_name:2, etc, setting var_name:rowcount to the total number of rows, and setting var_name:columns to a - list of column names. + list of column names.

@@ -1676,7 +1676,7 @@

- Each row also has a column, rownum, automatically + Each row also has a column, rownum, automatically added and set to the row number, starting with 1. Note that this will override any column in the SQL statement named 'rownum', also if you're using the Oracle rownum pseudo-column. @@ -1685,57 +1685,57 @@ If the -local is passed, the variables defined by db_multirow will be set locally (useful if you're compiling dynamic templates - in a function or similar situations). Use the -upvar_level + in a function or similar situations). Use the -upvar_level switch to specify how many levels up the variable should be set.

- You may supply a code block, which will be executed for each row in - the loop. This is very useful if you need to make computations that - are better done in Tcl than in SQL, for example using ns_urlencode - or ad_quotehtml, etc. When the Tcl code is executed, all the columns + You may supply a code block, which will be executed for each row in + the loop. This is very useful if you need to make computations that + are better done in Tcl than in SQL, for example using ns_urlencode + or ad_quotehtml, etc. When the Tcl code is executed, all the columns from the SQL query will be set as local variables in that code. Any changes made to these local variables will be copied back into the multirow.

You may also add additional, computed columns to the multirow, using the - -extend { col_1 col_2 ... } switch. This is - useful for things like constructing a URL for the object retrieved by + -extend { col_1 col_2 ... } switch. This is + useful for things like constructing a URL for the object retrieved by the query.

- If you're constructing your multirow through multiple queries with the - same set of columns, but with different rows, you can use the + If you're constructing your multirow through multiple queries with the + same set of columns, but with different rows, you can use the -append switch. This causes the rows returned by this query to be appended to the rows already in the multirow, instead of starting a clean multirow, as is the normal behavior. The columns must match the columns in the original multirow, or an error will be thrown.

- Your code block may call continue in order to skip a row + Your code block may call continue in order to skip a row and not include it in the multirow. Or you can call break to skip this row and quit looping.

Notice the nonstandard numbering (everything - else in Tcl starts at 0); the reason is that the graphics designer, a non + else in Tcl starts at 0); the reason is that the graphics designer, a non programmer, may wish to work with row numbers.

- Example: -

db_multirow -extend { user_url } users users_query {
-    select user_id first_names, last_name, email from cc_users
-} {
-    set user_url [acs_community_member_url -user_id $user_id]
-}
+ Example: +
db_multirow -extend { user_url } users users_query {
+        select user_id first_names, last_name, email from cc_users
+    } {
+        set user_url [acs_community_member_url -user_id $user_id]
+    }
- @see template::multirow + @see template::multirow } { # Query Dispatcher (OpenACS - ben) set full_statement_name [db_qd_get_fullname $statement_name] @@ -1758,9 +1758,9 @@ set code_block [lindex $args 0] } elseif { $arglength == 3 } { # Should have code block + if_no_rows + code block. - if { [lindex $args 1] ne "if_no_rows" - && [lindex $args 1] ne "else" - } { + if { [lindex $args 1] ne "if_no_rows" + && [lindex $args 1] ne "else" + } { return -code error "Expected if_no_rows as second-to-last argument" } set code_block [lindex $args 0] @@ -1772,9 +1772,9 @@ upvar $level_up "$var_name:rowcount" counter upvar $level_up "$var_name:columns" columns - if { [info exists cache_key] - && $append_p - && [info exists counter] && $counter > 0 + if { [info exists cache_key] + && $append_p + && [info exists counter] && $counter > 0 } { return -code error "Can't append and cache a non-empty multirow datasource simultaneously" } @@ -1794,13 +1794,13 @@ return [list $counter $columns $values] }] - lassign $value counter columns values + lassign $value counter columns values set count 1 foreach value $values { - upvar $level_up "$var_name:[expr {$count}]" array_val - array set array_val $value - incr count + upvar $level_up "$var_name:[expr {$count}]" array_val + array set array_val $value + incr count } } else { db_multirow_helper @@ -1813,15 +1813,15 @@ } } -ad_proc -public db_multirow_group_last_row_p { +ad_proc -public db_multirow_group_last_row_p { {-column:required} } { - Used inside the code_block to db_multirow to ask whether this row is the last row + Used inside the code_block to db_multirow to ask whether this row is the last row before the value of 'column' changes, or the last row of the result set.

- This is useful when you want to build up a multirow for a master/slave table pair, + This is useful when you want to build up a multirow for a master/slave table pair, where you only want one row per row in the master table, but you want to include data from the slave table in a column of the multirow. @@ -1835,13 +1835,13 @@ # Start building the multirow. We add the dynamic column 'lines_pretty', which will # contain the pretty summary of the order lines. - db_multirow -extend { lines_pretty } orders select_orders_and_lines { - select o.order_id, - o.customer_name, - l.item_name, - l.quantity + db_multirow -extend { lines_pretty } orders select_orders_and_lines { + select o.order_id, + o.customer_name, + l.item_name, + l.quantity from orders o, - order_lines l + order_lines l where l.order_id = o.order_id order by o.order_id, l.item_name } { @@ -1859,7 +1859,7 @@ continue } } - + @author Lars Pind (lars@collaboraid.biz) @@ -1874,7 +1874,7 @@ } upvar 1 $column column_value # Otherwise, it's the last row in the group if the next row has a different value than this row - return [expr {$column_value ne $next_row($column) }] + return [expr {$column_value ne $next_row($column) }] } @@ -1917,27 +1917,27 @@ set lob_argv [list] set command "dml" if { [info exists clobs] } { - set command "clob_dml" - set lob_argv $clobs - incr lob_argc + set command "clob_dml" + set lob_argv $clobs + incr lob_argc } if { [info exists blobs] } { - set command "blob_dml" - set lob_argv $blobs - incr lob_argc + set command "blob_dml" + set lob_argv $blobs + incr lob_argc } if { [info exists clob_files] } { - set command "clob_dml_file" - set lob_argv $clob_files - incr lob_argc + set command "clob_dml_file" + set lob_argv $clob_files + incr lob_argc } if { [info exists blob_files] } { - set command "blob_dml_file" - set lob_argv $blob_files - incr lob_argc + set command "blob_dml_file" + set lob_argv $blob_files + incr lob_argc } if { $lob_argc > 1 } { - error "Only one of -clobs, -blobs, -clob_files, or -blob_files may be specified as an argument to db_dml" + error "Only one of -clobs, -blobs, -clob_files, or -blob_files may be specified as an argument to db_dml" } if { ! $postgres_p } { @@ -1960,18 +1960,18 @@ db_with_handle -dbn $dbn db { # another ugly hack to avoid munging tcl files. # __lob_id needs to be set inside of a query (.xql) file for this - # to work. Say for example that you need to create a lob. In + # to work. Say for example that you need to create a lob. In # Oracle, you would do something like: - # db_dml update_photo "update foo set bar = empty_blob() - # where bar = :bar + # db_dml update_photo "update foo set bar = empty_blob() + # where bar = :bar # returning foo into :1" -blob_files [list $file] # for postgresql we can do the equivalent by placing the following # in a query file: # update foo set bar = [set __lob_id [db_string get_id "select empty_lob()"]] # where bar = :bar - # __lob_id acts as a flag that signals that blob_dml_file is + # __lob_id acts as a flag that signals that blob_dml_file is # required, and it is also used to pass along the lob_id. It # is unsert afterwards to avoid name clashes with other invocations # of this routine. @@ -2025,19 +2025,19 @@ statement_name sql args -} { +} { - Usage: + Usage:

db_0or1row statement-name sql [ -bind bind_set_id | -bind bind_value_list ] \ [ -column_array array_name | -column_set set_name ] - +
-

Performs the SQL query sql. If a row is returned, sets variables - to column values (or a set or array populated if -column_array - or column_set is specified) and returns 1. If no rows are returned, - returns 0. +

Performs the SQL query sql. If a row is returned, sets variables + to column values (or a set or array populated if -column_array + or column_set is specified) and returns 1. If no rows are returned, + returns 0. @return 1 if variables are set, 0 if no rows are returned. If more than one row is returned, throws an error. @@ -2056,14 +2056,14 @@ if { [info exists column_array] } { upvar 1 $column_array array_val - unset -nocomplain array_val + unset -nocomplain array_val } if { [info exists column_set] } { upvar 1 $column_set selection } - if { [info exists cache_key] } { + if { [info exists cache_key] } { set values [ns_cache eval $cache_pool $cache_key { db_with_handle -dbn $dbn db { set selection [db_exec 0or1row $db $full_statement_name $sql] @@ -2082,7 +2082,7 @@ if { $values eq "" } { set selection "" - } else { + } else { set selection [ns_set create] foreach value $values { @@ -2112,16 +2112,16 @@ ad_proc -public db_1row { args } { - Usage: + Usage:

db_1row statement-name sql [ -bind bind_set_id | -bind bind_value_list ] \ [ -column_array array_name | -column_set set_name ] - +
-

Performs the SQL query sql. If a row is returned, sets variables - to column values (or a set or array populated if -column_array - or column_set is specified). If no rows are returned, +

Performs the SQL query sql. If a row is returned, sets variables + to column values (or a set or array populated if -column_array + or column_set is specified). If no rows are returned, throws an error. @return 1 if variables are set. @@ -2143,7 +2143,7 @@ within transaction_code are committed to the database or none of them are. Multiple db_transactions may be nested (end transaction is transparently ns_db dml'ed when the outermost transaction completes).

- To handle errors, use db_transaction {transaction_code} on_error {error_code_block}. Any error generated in + To handle errors, use db_transaction {transaction_code} on_error {error_code_block}. Any error generated in transaction_code will be caught automatically and process control will transfer to error_code_block with a variable errmsg set. The error_code block can then clean up after the error, such as presenting a usable error message to the user. Following the execution of error_code_block the transaction will be aborted. @@ -2168,7 +2168,7 @@ db_dml test {insert into footest values(1)} nonsense db_dml test {insert into footest values(2)} - } + } @param dbn The database name to use. If empty_string, uses the default database. @@ -2197,7 +2197,7 @@ db_with_handle -dbn $dbn db { # Preserve the handle, since db_with_handle kills it after executing # this block. - set dbh $db + set dbh $db # Remember that there's a transaction happening on this handle. if { ![info exists db_state(transaction_level,$dbh)] } { set db_state(transaction_level,$dbh) 0 @@ -2209,7 +2209,7 @@ } # Execute the transaction code. set errno [catch { - uplevel 1 $transaction_code + uplevel 1 $transaction_code } errmsg] incr db_state(transaction_level,$dbh) -1 @@ -2237,18 +2237,18 @@ } if { $err_p || [db_abort_transaction_p -dbn $dbn]} { - # An error was triggered or the transaction has been aborted. + # An error was triggered or the transaction has been aborted. db_abort_transaction -dbn $dbn if { [info exists on_error] && $on_error ne "" } { - if {"postgresql" eq [db_type]} { + if {"postgresql" eq [db_type]} { - # JCD: with postgres we abort the transaction prior to - # executing the on_error block since there is nothing - # you can do to "fix it" and keeping it meant things like + # JCD: with postgres we abort the transaction prior to + # executing the on_error block since there is nothing + # you can do to "fix it" and keeping it meant things like # queries in the on_error block would then fail. - # - # Note that the semantics described in the proc doc + # + # Note that the semantics described in the proc doc # are not possible to support on postresql. # DRB: I removed the db_release_unused_handles call that @@ -2280,7 +2280,7 @@ 0 { # TCL_OK } - + 2 { # TCL_RETURN } @@ -2305,7 +2305,7 @@ # We're at the top level, so we abort the transaction. set db_state(db_abort_p,$dbh) 0 ns_db dml $dbh "abort transaction" - } + } # We throw this error because it was thrown from the error handling code that the programmer must fix. error $on_errmsg $::errorInfo $::errorCode } else { @@ -2316,7 +2316,7 @@ set db_state(db_abort_p,$dbh) 0 ns_db dml $dbh "abort transaction" # We still have the transaction generated error. We don't want to throw it, so we log it. - ns_log Error "Aborting transaction due to error:\n$errmsg" + ns_log Error "Aborting transaction due to error:\n$errmsg" } else { # Propagate the error up to the next level. error $errmsg $::errorInfo $::errorCode @@ -2335,19 +2335,19 @@ set db_state(db_abort_p,$dbh) 0 ns_db dml $dbh "abort transaction" error "Transaction aborted: $errmsg" $::errorInfo $::errorCode - } else { + } else { db_abort_transaction -dbn $dbn error $errmsg $::errorInfo $::errorCode } } } else { - # There was no error from the transaction code. + # There was no error from the transaction code. if { [db_abort_transaction_p -dbn $dbn] } { # The user requested the transaction be aborted. if { $level == 1 } { set db_state(db_abort_p,$dbh) 0 ns_db dml $dbh "abort transaction" - } + } } elseif { $level == 1 } { # Success! No errors and no requested abort. Commit. ns_db dml $dbh "end transaction" @@ -2358,8 +2358,8 @@ ad_proc -public db_abort_transaction {{-dbn ""}} { - Aborts all levels of a transaction. That is if this is called within - several nested transactions, all of them are terminated. Use this + Aborts all levels of a transaction. That is if this is called within + several nested transactions, all of them are terminated. Use this instead of db_dml "abort" "abort transaction". @param dbn The database name to use. If empty_string, uses the default database. @@ -2379,7 +2379,7 @@ upvar "#0" [db_state_array_name_is -dbn $dbn] db_state db_with_handle -dbn $dbn db { - if { [info exists db_state(db_abort_p,$db)] } { + if { [info exists db_state(db_abort_p,$db)] } { return $db_state(db_abort_p,$db) } else { # No abort flag registered, so we assume everything is ok. @@ -2409,7 +2409,7 @@ @param dbn The database name to use. If empty_string, uses the default database. } { set pool [lindex [db_available_pools $dbn] 0] - return [ns_config "ns/db/pool/$pool" User] + return [ns_config "ns/db/pool/$pool" User] } ad_proc -public db_get_password {{-dbn ""}} { @@ -2436,11 +2436,11 @@ @param dbn The database name to use. If empty_string, uses the default database. } { set pool [lindex [db_available_pools $dbn] 0] - set datasource [ns_config "ns/db/pool/$pool" DataSource] + set datasource [ns_config "ns/db/pool/$pool" DataSource] if { $datasource ne "" && ![string is space $datasource] } { - return "[ns_config ns/db/pool/$pool User]/[ns_config ns/db/pool/$pool Password]@$datasource" + return "[ns_config ns/db/pool/$pool User]/[ns_config ns/db/pool/$pool Password]@$datasource" } else { - return "[ns_config ns/db/pool/$pool User]/[ns_config ns/db/pool/$pool Password]" + return "[ns_config ns/db/pool/$pool User]/[ns_config ns/db/pool/$pool Password]" } } @@ -2453,7 +2453,7 @@ @param dbn The database name to use. If empty_string, uses the default database. } { set pool [lindex [db_available_pools $dbn] 0] - set driver [ns_config "ns/db/pool/$pool" Driver] + set driver [ns_config "ns/db/pool/$pool" Driver] return [ns_config "ns/db/driver/$driver" pgbin] } @@ -2479,8 +2479,8 @@ set first_colon_pos [string first ":" $datasource] if { $first_colon_pos == $last_colon_pos || ($last_colon_pos - $first_colon_pos) == 1 } { - # No port specified - return "" + # No port specified + return "" } return [string range $datasource $first_colon_pos+1 $last_colon_pos-1] @@ -2491,14 +2491,14 @@ PostgreSQL only.

- @return the database name from the first database pool. It assumes the + @return the database name from the first database pool. It assumes the datasource is properly formatted since we've already verified that we can connect to the pool. @param dbn The database name to use. If empty_string, uses the default database. } { set pool [lindex [db_available_pools $dbn] 0] - set datasource [ns_config "ns/db/pool/$pool" DataSource] + set datasource [ns_config "ns/db/pool/$pool" DataSource] set last_colon_pos [string last ":" $datasource] if { $last_colon_pos == -1 } { ns_log Error "datasource contains no \":\"? datasource = $datasource" @@ -2507,21 +2507,21 @@ return [string range $datasource $last_colon_pos+1 end] } - + ad_proc -public db_get_dbhost { {-dbn ""} } { PostgreSQL only.

- @return the name of the database host from the first database pool. - It assumes the datasource is properly formatted since we've already + @return the name of the database host from the first database pool. + It assumes the datasource is properly formatted since we've already verified that we can connect to the pool. @param dbn The database name to use. If empty_string, uses the default database. } { set pool [lindex [db_available_pools $dbn] 0] - set datasource [ns_config "ns/db/pool/$pool" DataSource] + set datasource [ns_config "ns/db/pool/$pool" DataSource] set first_colon_pos [string first ":" $datasource] if { $first_colon_pos == -1 } { ns_log Error "datasource contains no \":\"? datasource = $datasource" @@ -2584,14 +2584,14 @@ # maintainer we shouldn't break existing code over such trivialities... # GN: windows requires $pghost "-h ..." - if { ([db_get_dbhost] eq "localhost" || [db_get_dbhost] eq "") - && $::tcl_platform(platform) ne "windows" - } { + if { ([db_get_dbhost] eq "localhost" || [db_get_dbhost] eq "") + && $::tcl_platform(platform) ne "windows" + } { set pghost "" } else { set pghost "-h [db_get_dbhost]" } - + set errno [catch { cd [file dirname $file] set fp [open "|[file join [db_get_pgbin] psql] $pghost $pgport $pguser -f $file [db_get_database] $pgpass" "r"] @@ -2651,8 +2651,8 @@ ad_proc -public db_load_sql_data { {-dbn ""} - {-callback apm_ns_write_callback} - file + {-callback apm_ns_write_callback} + file } { Loads a CSV formatted file into a table using PostgreSQL's COPY command or Oracle's SQL*Loader utility. The file name format consists of a sequence @@ -2663,8 +2663,8 @@ @param dbn The database name to use. If empty_string, uses the default database. @param file Filename in the format dd-table-name.ctl where 'dd' is a sequence number - used to control the order in which data is loaded. This file is an - RDBMS-specific data loader control file. + used to control the order in which data is loaded. This file is an + RDBMS-specific data loader control file. } { @@ -2679,7 +2679,7 @@ close $fd set file_contents [subst $file_contents] - + set fd1 [open "${tmpnam}.ctl" w] puts $fd1 $file_contents close $fd1 @@ -2718,21 +2718,21 @@ } else { set pghost "-h [db_get_dbhost]" } - + set fd [open $file r] set copy_command [subst -nobackslashes [read $fd]] close $fd set copy_file [ns_mktemp /tmp/psql-copyfile-XXXXXX] set fd [open $copy_file "CREAT EXCL WRONLY" 0600] puts $fd $copy_command close $fd - + if { $::tcl_platform(platform) eq "windows" } { set fp [open "|[file join [db_get_pgbin] psql] -f $copy_file $pghost $pgport $pguser [db_get_database]" "r"] } else { set fp [open "|[file join [db_get_pgbin] psql] -f $copy_file $pghost $pgport $pguser [db_get_database] $pgpass" "r"] } - + while { [gets $fp line] >= 0 } { # Don't bother writing out lines which are purely whitespace. if { ![string is space $line] } { @@ -2785,8 +2785,8 @@ ad_proc -public db_source_sqlj_file { {-dbn ""} - {-callback apm_ns_write_callback} - file + {-callback apm_ns_write_callback} + file } { Oracle only.

@@ -2801,15 +2801,15 @@ # The output is generated as an error when you attempt to close the input stream as # done below. while { [gets $fp line] >= 0 } { - # Don't bother writing out lines which are purely whitespace. - if { ![string is space $line] } { - apm_callback_and_log $callback "[ns_quotehtml $line]\n" - } + # Don't bother writing out lines which are purely whitespace. + if { ![string is space $line] } { + apm_callback_and_log $callback "[ns_quotehtml $line]\n" + } } if { [catch { - close $fp + close $fp } errmsg] } { - apm_callback_and_log $callback "[ns_quotehtml $errmsg]\n" + apm_callback_and_log $callback "[ns_quotehtml $errmsg]\n" } } @@ -2869,13 +2869,13 @@ if { [info exists pattern] } { db_foreach -dbn $dbn table_names_with_pattern \ $sql_table_names_with_pattern { - lappend tables $table_name - } + lappend tables $table_name + } } else { db_foreach -dbn $dbn table_names_without_pattern \ $sql_table_names_without_pattern { - lappend tables $table_name - } + lappend tables $table_name + } } return $tables @@ -2905,7 +2905,7 @@ set n_rows [db_string -dbn $dbn table_count { select count(*) from pg_class where relname = lower(:table_name) and - relname !~ '^pg_' and relkind = 'r' + relname !~ '^pg_' and relkind = 'r' }] } @@ -2954,10 +2954,10 @@ # Works for both Oracle and PostgreSQL: set n_rows [db_string -dbn $dbn column_exists { - select count(*) - from user_tab_columns - where table_name = upper(:table_name) - and column_name = upper(:column_name) + select count(*) + from user_tab_columns + where table_name = upper(:table_name) + and column_name = upper(:column_name) }] return [expr {$n_rows > 0}] @@ -2974,22 +2974,22 @@ @author Yon Feldman (yon@arsdigita.com) @change-log 10 July, 2000: changed to return error - if column name doesn't exist - (mdettinger@arsdigita.com) + if column name doesn't exist + (mdettinger@arsdigita.com) - @change-log 11 July, 2000: changed to return lower case data types - (yon@arsdigita.com) + @change-log 11 July, 2000: changed to return lower case data types + (yon@arsdigita.com) @change-log 11 July, 2000: changed to return error using the db_string default clause - (yon@arsdigita.com) + (yon@arsdigita.com) } { # Works for both Oracle and PostgreSQL: return [db_string -dbn $dbn column_type_select " - select data_type as data_type - from user_tab_columns - where upper(table_name) = upper(:table_name) - and upper(column_name) = upper(:column_name) + select data_type as data_type + from user_tab_columns + where upper(table_name) = upper(:table_name) + and upper(column_name) = upper(:column_name) " -default "-1"] } @@ -3007,11 +3007,11 @@ set column_type [db_column_type -dbn $dbn $table_name $column_name] if { $column_type == -1 } { - return "Either table $table_name doesn't exist or column $column_name doesn't exist" + return "Either table $table_name doesn't exist or column $column_name doesn't exist" } elseif {$column_type ne "NUMBER" } { - return "numeric" + return "numeric" } else { - return "text" + return "text" } } @@ -3054,8 +3054,8 @@ } { ad_arg_parser { bind } $args set full_statement_name [db_qd_get_fullname $statement_name] - db_with_handle -dbn $dbn db { - db_exec_lob write_blob $db $full_statement_name $sql + db_with_handle -dbn $dbn db { + db_exec_lob write_blob $db $full_statement_name $sql } } @@ -3124,7 +3124,7 @@ set pre_sql $sql set full_statement_name [db_qd_get_fullname $statement_name] set sql [db_qd_replace_sql $full_statement_name $pre_sql] - + # insert tcl variable values (borrowed from Dan W - olah) if {$sql ne $pre_sql } { set sql [uplevel 2 [list subst -nobackslashes $sql]] @@ -3143,12 +3143,12 @@ ad_proc -private db_exec_lob { - {-ulevel 2} - type - db - statement_name - pre_sql - {file ""} + {-ulevel 2} + type + db + statement_name + pre_sql + {file ""} } { A helper procedure to execute a SQL statement, potentially binding depending on the value of the $bind variable in the calling environment @@ -3191,12 +3191,12 @@ ad_proc -private db_exec_lob_oracle { - {-ulevel 2} - type - db - statement_name - pre_sql - {file ""} + {-ulevel 2} + type + db + statement_name + pre_sql + {file ""} } { A helper procedure to execute a SQL statement, potentially binding depending on the value of the $bind variable in the calling environment @@ -3210,7 +3210,7 @@ if {$sql ne $pre_sql } { set sql [uplevel $ulevel [list subst -nobackslashes $sql]] } - + set file_storage_p 0 upvar $ulevel storage_type storage_type @@ -3225,42 +3225,42 @@ } set errno [catch { - upvar bind bind + upvar bind bind # Below, note that 'ns_ora blob_get_file' takes 3 parameters, # while 'ns_ora write_blob' takes only 2. So if file is empty # string (which it always will/should be for $qtype # write_blob), we must not pass any 3rd parameter to the # ns_ora command: --atp@piskorski.com, 2003/04/09 15:10 EDT - if { [info exists bind] && [llength $bind] != 0 } { - if { [llength $bind] == 1 } { + if { [info exists bind] && [llength $bind] != 0 } { + if { [llength $bind] == 1 } { if { $file eq "" } { - # gn: not sure, why the eval was ever needed (4 times) + # gn: not sure, why the eval was ever needed (4 times) set selection [eval [list ns_ora $qtype $db -bind $bind $sql]] } else { set selection [eval [list ns_ora $qtype $db -bind $bind $sql $file]] } - } else { - set bind_vars [ns_set create] - foreach { name value } $bind { - ns_set put $bind_vars $name $value - } + } else { + set bind_vars [ns_set create] + foreach { name value } $bind { + ns_set put $bind_vars $name $value + } if { $file eq "" } { set selection [eval [list ns_ora $qtype $db -bind $bind_vars $sql]] } else { set selection [eval [list ns_ora $qtype $db -bind $bind_vars $sql $file]] } - } + } - } else { + } else { if { $file eq "" } { set selection [uplevel $ulevel [list ns_ora $qtype $db $sql]] } else { set selection [uplevel $ulevel [list ns_ora $qtype $db $sql $file]] } - } + } if {$file_storage_p} { set content [ns_set value $selection 0] @@ -3280,7 +3280,7 @@ } else { error "file: $content doesn't exist" } - } + } write_blob { @@ -3303,20 +3303,20 @@ ds_collect_db_call $db $type $statement_name $sql $start_time $errno $error if { $errno == 2 } { - return $error + return $error } return -code $errno -errorinfo $::errorInfo -errorcode $::errorCode $error } ad_proc -private db_exec_lob_postgresql { - {-ulevel 2} - type - db - statement_name - pre_sql - {file ""} + {-ulevel 2} + type + db + statement_name + pre_sql + {file ""} } { A helper procedure to execute a SQL statement, potentially binding depending on the value of the $bind variable in the calling environment @@ -3334,29 +3334,29 @@ if {$sql ne $pre_sql } { set sql [uplevel $ulevel [list subst -nobackslashes $sql]] } - # create a function definition statement for the inline code + # create a function definition statement for the inline code # binding is emulated in tcl. (OpenACS - Dan) set errno [catch { - upvar bind bind - if { [info exists bind] && [llength $bind] != 0 } { - if { [llength $bind] == 1 } { + upvar bind bind + if { [info exists bind] && [llength $bind] != 0 } { + if { [llength $bind] == 1 } { set bind_vars [list] set len [ns_set size $bind] for {set i 0} {$i < $len} {incr i} { lappend bind_vars [ns_set key $bind $i] \ - [ns_set value $bind $i] + [ns_set value $bind $i] } set lob_sql [db_bind_var_substitution $sql $bind_vars] - } else { + } else { set lob_sql [db_bind_var_substitution $sql $bind] - } - } else { + } + } else { set lob_sql [uplevel $ulevel [list db_bind_var_substitution $sql]] - } + } # get the content - asssume it is in column 0, or optionally it can - # be returned as "content" with the storage type indicated by the + # be returned as "content" with the storage type indicated by the # "storage_type" column. set selection [ns_db 1row $db $lob_sql] @@ -3517,7 +3517,7 @@ ds_collect_db_call $db 0or1row $statement_name $sql $start_time $errno $error if { $errno == 2 } { - return $error + return $error } return -code $errno -errorinfo $errinfo -errorcode $errcode $error @@ -3530,8 +3530,7 @@ Flush the given cache of entries with keys that match the given pattern. - @param cache_key_pattern The "string match" pattern used to flush keys (default is - to flush all entries) + @param cache_key_pattern The "string match" pattern used to flush keys (default is to flush all entries) @param cache_pool The pool to flush (default is to flush db_cache_pool) @author Don Baccus (dhogasa@pacifier.com) @@ -3550,7 +3549,7 @@ } } -ad_proc -public db_bounce_pools {{-dbn ""}} { +ad_proc -public db_bounce_pools {{-dbn ""}} { @return Call ns_db bouncepool on all pools for the named database. @param dbn The database name to use. Uses the default database if not supplied. } {