db_dml (public)

 db_dml [ -dbn dbn ] [ -subst subst ] statement_name sql [ args... ]

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

Do a DML statement.

args can be one of: -clobs, -blobs, -clob_files or -blob_files. See the db-api doc referenced below for more information.

Switches:
-dbn (optional)
The database name to use. If empty_string, uses the default database.
-subst (optional, defaults to "all")
Perform Tcl substitution in xql-files. Possible values: all, none, vars, commands
Parameters:
statement_name (required)
sql (required)
See Also:

Partial Call Graph (max 5 caller/called nodes):
%3 test_apm__test_info_file apm__test_info_file (test acs-tcl) db_dml db_dml test_apm__test_info_file->db_dml test_db__transaction db__transaction (test acs-tcl) test_db__transaction->db_dml test_db__transaction_bug_3440 db__transaction_bug_3440 (test acs-tcl) test_db__transaction_bug_3440->db_dml ad_arg_parser ad_arg_parser (public) db_dml->ad_arg_parser db_driverkey db_driverkey (public) db_dml->db_driverkey db_exec db_exec (public) db_dml->db_exec db_qd_get_fullname db_qd_get_fullname (public) db_dml->db_qd_get_fullname db_with_handle db_with_handle (public) db_dml->db_with_handle aa_log_final aa_log_final (private) aa_log_final->db_dml aa_log_result aa_log_result (public) aa_log_result->db_dml aa_run_testcase aa_run_testcase (private) aa_run_testcase->db_dml acs::test::user::delete acs::test::user::delete (public) acs::test::user::delete->db_dml acs_mail_lite::after_upgrade acs_mail_lite::after_upgrade (private) acs_mail_lite::after_upgrade->db_dml

Testcases:
apm__test_info_file, db__transaction, db__transaction_bug_3440
Source code:
    ad_arg_parser { clobs blobs clob_files blob_files bind } $args
    set driverkey [db_driverkey $dbn]

    switch -- $driverkey {
        postgresql {
            set postgres_p 1
        }
        oracle -
        nsodbc -
        default {
            set postgres_p 0
        }
    }

    # Query Dispatcher (OpenACS - ben)
    set full_statement_name [db_qd_get_fullname $statement_name]

    # This "only one of..." check didn't exist in the PostgreSQL
    # version, but it shouldn't't hurt anything: --atp@piskorski.com,
    # 2003/04/08 06:19 EDT

    # Only one of clobs, blobs, clob_files, and blob_files is allowed.
    # Remember which one (if any) is provided:

    set lob_argc 0
    set lob_argv [list]
    set command "dml"
    if { [info exists clobs] } {
        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
    }
    if { [info exists clob_files] } {
        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
    }
    if { $lob_argc > 1 } {
        error "Only one of -clobs, -blobs, -clob_files, or -blob_files may be specified as an argument to db_dml"
    }

    if { ! $postgres_p } {
        # Oracle:
        db_with_handle -dbn $dbn db {
            if { $lob_argc == 1 } {
                # Bind :1, :2, ..., :n as LOBs (where n = [llength $lob_argv])
                set bind_vars [list]
                for { set i 1 } { $i <= [llength $lob_argv] } { incr i } {
                    lappend bind_vars $i
                }
                eval [list db_exec -subst $subst "${command}_bind" $db $full_statement_name $sql 2 $bind_vars$lob_argv
            } else {
                eval [list db_exec -subst $subst $command $db $full_statement_name $sql$lob_argv
            }
        }

    } elseif {$command eq "blob_dml_file"} {
        # PostgreSQL:
        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
            # Oracle, you would do something like:

            # 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
            # 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.
            # (DanW - Openacs)

            db_exec -subst $subst dml $db $full_statement_name $sql
            if {[uplevel {info exists __lob_id}]} {
                ns_pg blob_dml_file $db [uplevel {set __lob_id}] $blob_files
                uplevel {unset __lob_id}
            }
        }

    } else {
        # PostgreSQL:
        db_with_handle -dbn $dbn db {
            db_exec -subst $subst dml $db $full_statement_name $sql
        }
    }
XQL Not present:
Generic, PostgreSQL, Oracle
[ hide source ] | [ make this the default ]
Show another procedure: