attribute::add (public)
attribute::add [ -default default ] [ -min_n_values min_n_values ] \ [ -max_n_values max_n_values ] object_type datatype pretty_name \ pretty_plural
Defined in packages/acs-subsite/tcl/attribute-procs.tcl
wrapper for the
acs_attribute.create_attribute
call. Note that this procedure assumes type-specific storage.
- Switches:
- -default (optional)
- -min_n_values (optional)
- -max_n_values (optional)
- Parameters:
- object_type (required)
- datatype (required)
- pretty_name (required)
- pretty_plural (required)
- Returns:
- The
attribute_id
of the newly created attribute- Author:
- Michael Bryzek <mbryzek@arsdigita.com>
- Created:
- 12/2000
- Partial Call Graph (max 5 caller/called nodes):
- Testcases:
- acs_subsite_attributes
Source code: set default_value $default # We always use type-specific storage. Grab the tablename from the # object_type if { ![db_0or1row select_table { select t.table_name from acs_object_types t where t.object_type = :object_type }] } { error "Specified object type \"$object_type\" does not exist" } # In OpenACS, where we care that SQL must be separate from code, we don't # use these annoying formatting procs on our SQL. We write out the queries in full. (ben) # Attribute name returned from this function will be oracle # friendly and is thus used as the column name set attribute_name [plsql_utility::generate_oracle_name $pretty_name] # set attr_list [list] # lappend attr_list [list "object_type" '$object_type'] # lappend attr_list [list "attribute_name" '$attribute_name'] # lappend attr_list [list "min_n_values" '$min_n_values'] # lappend attr_list [list "max_n_values" '$max_n_values'] # lappend attr_list [list "default_value" '$default'] # lappend attr_list [list "datatype" '$datatype'] # lappend attr_list [list "pretty_name" '$pretty_name'] # lappend attr_list [list "pretty_plural" '$pretty_plural'] # A note (by ben, OpenACS) # the queries are empty because they are pulled out later in db_exec_plsql set plsql [list] lappend plsql_drop [list db_exec_plsql "drop_attribute" "FOO"] lappend plsql [list db_exec_plsql "create_attribute" "FOO"] set sql_type [datatype_to_sql_type -default $default_value $table_name $attribute_name $datatype] lappend plsql_drop [list db_dml "drop_attr_column" "FOO"] lappend plsql [list db_dml "add_column" "FOO"] for { set i 0 } { $i < [llength $plsql] } { incr i } { set cmd [lindex $plsql $i] if { [catch $cmd err_msg] } { # Rollback what we've done so far. The loop conditionals are: # start at the end of the plsql_drop list (Drop things in reverse order of creation) # execute drop statements until we reach position $i+1 # This position represents the operation on which we failed, and thus # is not executed for { set inner [expr {[llength $plsql_drop] - 1}] } { $inner > $i + 1 } { incr inner -1 } { set drop_cmd [lindex $plsql_drop $inner] if { [catch $drop_cmd err_msg_2] } { append err_msg "\nAdditional error while trying to roll back: $err_msg_2" return -code error $err_msg } } return -code error $err_msg } } return [db_string select_attribute_id { select a.attribute_id from acs_attributes a where a.object_type = :object_type and a.attribute_name = :attribute_name }]Generic XQL file: <fullquery name="attribute::add.drop_attr_column"> <querytext> alter table $table_name drop column $attribute_name </querytext> </fullquery> <fullquery name="attribute::add.add_column"> <querytext> alter table $table_name add $attribute_name $sql_type </querytext> </fullquery>packages/acs-subsite/tcl/attribute-procs.xql
PostgreSQL XQL file: <fullquery name="attribute::add.drop_attribute"> <querytext> select acs_attribute__drop_attribute(:object_type, :attribute_name) </querytext> </fullquery> <fullquery name="attribute::add.create_attribute"> <querytext> select acs_attribute__create_attribute ( '$object_type', '$attribute_name', '$datatype', '$pretty_name', '$pretty_plural', NULL, NULL, '$default_value', '$min_n_values', '$max_n_values', NULL, 'type_specific', 'f' ); </querytext> </fullquery>packages/acs-subsite/tcl/attribute-procs-postgresql.xql
Oracle XQL file: <fullquery name="attribute::add.drop_attribute"> <querytext> begin acs_attribute.drop_attribute(:object_type, :attribute_name); end; </querytext> </fullquery> <fullquery name="attribute::add.create_attribute"> <querytext> declare attr_id acs_attributes.attribute_id%TYPE; begin attr_id := acs_attribute.create_attribute ( object_type => '$object_type', attribute_name => '$attribute_name', min_n_values => '$min_n_values', max_n_values => '$max_n_values', default_value => '$default_value', datatype => '$datatype', pretty_name => '$pretty_name', pretty_plural => '$pretty_plural' ); end; </querytext> </fullquery>packages/acs-subsite/tcl/attribute-procs-oracle.xql