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 -N -r1.106 -r1.107 --- openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl 25 Jul 2018 01:38:32 -0000 1.106 +++ openacs-4/packages/acs-tcl/tcl/00-database-procs.tcl 25 Jul 2018 01:50:00 -0000 1.107 @@ -837,9 +837,7 @@ 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'" + ns_db dml $db "create function $function_name () returns varchar as [::ns_dbquotevalue $proc_sql] language 'plpgsql'" set ret_val [ns_db 0or1row $db "select $function_name ()"] @@ -929,7 +927,7 @@ if {$__db_tcl_var eq ""} { set __db_tcl_var null } else { - set __db_tcl_var "'[DoubleApos $__db_tcl_var]'" + set __db_tcl_var "[::ns_dbquotevalue $__db_tcl_var]" } set __db_sql [string replace $__db_sql $__db_ws $__db_we $__db_tcl_var] } @@ -951,7 +949,7 @@ if {$val eq ""} { set val null } else { - set val "'[DoubleApos $val]'" + set val "[::ns_dbquotevalue $val]" } set lsql [string replace $lsql $ws $we $val] } Index: openacs-4/packages/acs-tcl/tcl/json-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/json-procs.tcl,v diff -u -N -r1.9 -r1.10 --- openacs-4/packages/acs-tcl/tcl/json-procs.tcl 27 Mar 2018 12:22:17 -0000 1.9 +++ openacs-4/packages/acs-tcl/tcl/json-procs.tcl 25 Jul 2018 01:50:00 -0000 1.10 @@ -448,7 +448,7 @@ true { return 1 } null - "" { return null } - default { return "'[DoubleApos $value]'" } + default { return "[::ns_dbquotevalue $value]" } } } Index: openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl,v diff -u -N -r1.163 -r1.164 --- openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 24 Jul 2018 08:10:28 -0000 1.163 +++ openacs-4/packages/acs-tcl/tcl/utilities-procs.tcl 25 Jul 2018 01:50:00 -0000 1.164 @@ -257,17 +257,23 @@ -ad_proc -private DoubleApos {string} { - if the user types "O'Malley" and you try to insert that into an SQL - database, you will lose big time because the single quote is magic - in SQL and the insert has to look like 'O''Malley'. +ad_proc -deprecated DoubleApos {string} { + + When the value "O'Malley" is inserted int an SQL database, the + single quote can cause troubles in SQL, one has to insert + 'O''Malley' instead. +

- You should be using bind variables rather than - calling DoubleApos + In general, one should be using bind variables rather than + calling DoubleApos. @return string with single quotes converted to a pair of single quotes } { - regsub -all ' "$string" '' result + set result [ns_dbquotevalue $string] + # remove the leading quote if necessary + if {[string range $result 0 0] eq '} { + set result [string range $result 1 end-1] + } return $result }