Index: openacs-4/contrib/packages/bcms/tcl/bcms-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/contrib/packages/bcms/tcl/bcms-procs.tcl,v diff -u -r1.4 -r1.5 --- openacs-4/contrib/packages/bcms/tcl/bcms-procs.tcl 5 Oct 2003 12:28:03 -0000 1.4 +++ openacs-4/contrib/packages/bcms/tcl/bcms-procs.tcl 27 Oct 2003 10:09:10 -0000 1.5 @@ -215,3 +215,58 @@ return $file_id } + +ad_proc -public bcms::parse_properties { + {-properties:required} + {-return_format:required} + {-uplevel_level 1} +} { + parses properties returns strings to be used for insert or update sql strings + + @param properites a list of properties / columns to insert format: {property value ... property value} + {property:noquote value} will directly use what is in value + @param return_format either "insert_values", "insert_columns" or "update" + @param uplevel_level if you need to set the quoted vars to another level use this to set the proper uplevel +} { + + # create the properties + set properties_list {} + set values_list {} + foreach one_property $properties { + set property [lindex $one_property 0] + set value [lrange $one_property 1 [llength $one_property]] + if {[regexp {(.+):noquote$} $property match property]} { + #if noquote then use what is in the value + lappend values_list $value + } else { + lappend values_list :__$property + upvar $uplevel_level "__$property" localvar + set localvar $value + } + lappend properties_list $property + } + + switch -exact $return_format { + insert_values { + set insert_values "[join $values_list ","]" + return $insert_values + } + insert_columns { + set insert_columns "[join $properties_list ","]" + return $insert_columns + } + update { + set index 0 + set update_list {} + foreach one_property $properties_list { + lappend update_list "$one_property = [lindex $values_list $index]" + incr index + } + set update_string "[join $update_list ", "]" + return $update_string + } + default { + error "invalid return_format" + } + } +}