db_bind_var_substitution (public)

 db_bind_var_substitution sql [ bind ]

Defined in packages/acs-tcl/tcl/01-database-procs.tcl

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 driver to support plsql calls. This is only used for the db_exec_plpgsql function.

Parameters:
sql (required)
bind (optional)

Partial Call Graph (max 5 caller/called nodes):
%3 test_db_bind_var_substitution db_bind_var_substitution (test acs-tcl) db_bind_var_substitution db_bind_var_substitution test_db_bind_var_substitution->db_bind_var_substitution db_bind_var_quoted_p db_bind_var_quoted_p (private) db_bind_var_substitution->db_bind_var_quoted_p ns_dbquotevalue ns_dbquotevalue db_bind_var_substitution->ns_dbquotevalue db_exec_lob_postgresql db_exec_lob_postgresql (private) db_exec_lob_postgresql->db_bind_var_substitution db_exec_plpgsql db_exec_plpgsql (private) db_exec_plpgsql->db_bind_var_substitution ds_collect_db_call ds_collect_db_call (public) ds_collect_db_call->db_bind_var_substitution

Testcases:
db_bind_var_substitution
Source code:
    if {$bind eq ""} {
        upvar __db_sql lsql
        set lsql $sql
        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]
                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]
                    if {$__db_tcl_var eq ""} {
                        set __db_tcl_var null
                    } else {
                        set __db_tcl_var "[::ns_dbquotevalue $__db_tcl_var]"
                    }
                    set __db_sql [string replace $__db_sql $__db_ws $__db_we $__db_tcl_var]
                }
            }
        }
    } else {

        array set bind_vars $bind

        set lsql $sql
        set lst [regexp -inline -indices -all -- {:?:\w+} $sql]
        for {set i [expr {[llength $lst] - 1}]} {$i >= 0} {incr i -1} {
            set ws [lindex $lst $i 0]
            set we [lindex $lst $i 1]
            set bind_var [string range $sql $ws $we]
            if {![string match "::*" $bind_var] && ![db_bind_var_quoted_p $lsql $ws $we]} {
                set tcl_var [string range $bind_var 1 end]
                set val $bind_vars($tcl_var)
                if {$val eq ""} {
                    set val null
                } else {
                    set val "[::ns_dbquotevalue $val]"
                }
                set lsql [string replace $lsql $ws $we $val]
            }
        }
    }

    return $lsql
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: