Index: openacs-4/packages/acs-subsite/tcl/attribute-procs-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/tcl/attribute-procs-oracle.xql,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-subsite/tcl/attribute-procs-oracle.xql 22 Nov 2017 14:50:28 -0000 1.5 +++ openacs-4/packages/acs-subsite/tcl/attribute-procs-oracle.xql 5 Jul 2018 11:12:28 -0000 1.6 @@ -52,7 +52,7 @@ -begin acs_attribute.drop_attribute(:object_type, :attribute_name); end; +begin acs_attribute.drop_attribute(:object_type, :attribute_name, :drop_table_column_p); end; Index: openacs-4/packages/acs-subsite/tcl/attribute-procs-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/tcl/attribute-procs-postgresql.xql,v diff -u -r1.6 -r1.7 --- openacs-4/packages/acs-subsite/tcl/attribute-procs-postgresql.xql 22 Nov 2017 14:50:28 -0000 1.6 +++ openacs-4/packages/acs-subsite/tcl/attribute-procs-postgresql.xql 5 Jul 2018 11:12:28 -0000 1.7 @@ -62,7 +62,7 @@ - select acs_attribute__drop_attribute(:object_type, :attribute_name) + select acs_attribute__drop_attribute(:object_type, :attribute_name, :drop_table_column_p) Index: openacs-4/packages/acs-subsite/tcl/attribute-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/tcl/attribute-procs.tcl,v diff -u -r1.17 -r1.18 --- openacs-4/packages/acs-subsite/tcl/attribute-procs.tcl 9 May 2018 15:33:28 -0000 1.17 +++ openacs-4/packages/acs-subsite/tcl/attribute-procs.tcl 5 Jul 2018 11:12:28 -0000 1.18 @@ -18,19 +18,17 @@ @creation-date 12/30/2000 } { - if { [db_string attribute_for_dynamic_object_p { - select case when exists (select 1 - from acs_attributes a, acs_object_types t - where t.dynamic_p = 't' - and a.object_type = t.object_type - and a.attribute_id = :value) - then 1 else 0 end - from dual - }] } { - return 1 + set dynamic_p [db_string attribute_for_dynamic_object_p { + select exists (select 1 from acs_attributes a, acs_object_types t + where t.dynamic_p = 't' + and a.object_type = t.object_type + and a.attribute_id = :value) + from dual + }] + if {!$dynamic_p} { + ad_complain "Attribute does not belong to a dynamic object and cannot be modified" } - ad_complain "Attribute does not belong to a dynamic object and cannot be modified" - return 0 + return $dynamic_p } @@ -231,27 +229,29 @@ } { - # 1. Drop the column - # 2. Drop the attribute - # 3. Return + # 1. Drop the attribute with its column + # 2. Return - if { ![db_0or1row select_attr_info {}] } { + if { ![db_0or1row select_attr_info { + select a.object_type, a.attribute_name, + case when a.storage = 'type_specific' then t.table_name else a.table_name end as table_name, + coalesce(a.column_name, a.attribute_name) as column_name + from acs_attributes a, acs_object_types t + where a.attribute_id = :attribute_id + and t.object_type = a.object_type + }] } { # Attribute doesn't exist return 0 } + if { $table_name eq "" || $column_name eq "" } { # We have to have both a non-empty table name and column name error "We do not have enough information to automatically remove this attribute. Namely, we are missing either the table name or the column name" } - set plsql {drop_attribute FOO db_exec_plsql} - if { [db_column_exists $table_name $column_name] } { - lappend plsql {drop_attr_column FOO db_dml} - } + set drop_table_column_p [expr {[db_column_exists $table_name $column_name] ? "t" : "f"}] - foreach cmd $plsql { - {*}$cmd - } + db_exec_plsql drop_attribute {} return 1 } Index: openacs-4/packages/acs-subsite/tcl/attribute-procs.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/acs-subsite/tcl/attribute-procs.xql,v diff -u -r1.5 -r1.6 --- openacs-4/packages/acs-subsite/tcl/attribute-procs.xql 22 Nov 2017 14:50:28 -0000 1.5 +++ openacs-4/packages/acs-subsite/tcl/attribute-procs.xql 5 Jul 2018 11:12:28 -0000 1.6 @@ -133,10 +133,4 @@ - - - alter table $table_name drop column $column_name - - -