home *** CD-ROM | disk | FTP | other *** search
- #---------------------------------------------------------------------------
- #
- # Copyright (c) 1992-1996 by Cadre Technologies, Inc.
- #
- # This software is furnished under a license and may be used only in
- # accordance with the terms of such license and with the inclusion of
- # the above copyright notice. This software or any other copies thereof
- # may not be provided or otherwise made available to any other person.
- # No title to and ownership of the software is hereby transferred.
- #
- # The information in this software is subject to change without notice
- # and should not be construed as a commitment by Cadre Technologies, Inc.
- #
- #---------------------------------------------------------------------------
- #
- # File : @(#)genrules.tcl 2.1 (2.1)
- # Original date : 18-8-1992
- # Description : Tcl script for generating SQL rules
- #
- #---------------------------------------------------------------------------
- #
- # @(#)genrules.tcl 2.1 (2.1)\t19 Apr 1996 Copyright 1992-1996 Cadre Technologies, Inc.
- #
- #---------------------------------------------------------------------------
-
-
- # Generate if nessecary an insert, delete and update
- # rule for a table
- #
- proc gen_rules { current_section currtab } {
-
- global impossible_procs
- global empty_imports_procs
- global empty_exports_procs
- set tab_name [ $currtab getUniqueName]
- $current_section pushIndent
- if {![ get impossible_procs(ins,$currtab) 0] &&
- ( ![ get empty_imports_procs(ins,$currtab) 0] ||
- ![ get empty_exports_procs(ins,$currtab) 0] ) } {
- expand_text $current_section {
- /*
- * Create insert rule for table '~$tab_name'
- */
- CREATE RULE ins_~$tab_name
- AFTER INSERT INTO ~$tab_name
- EXECUTE PROCEDURE pins_~$tab_name
- (
- ~[ gen_compare $current_section $currtab "ALL" "new" ""\
- "new." "" " ,\n"]
- );
- \\p\\g
- }
- }
- if {![ get impossible_procs(del,$currtab) 0] &&
- ( ![ get empty_imports_procs(del,$currtab) 0] ||
- ![ get empty_exports_procs(del,$currtab) 0] ) } {
- expand_text $current_section {
- /*
- * Create delete rule for table '~$tab_name'
- */
- CREATE RULE del_~$tab_name
- AFTER DELETE FROM ~$tab_name
- EXECUTE PROCEDURE pdel_~$tab_name
- (
- ~[ gen_compare $current_section $currtab "KEYS_IMPFIELDS"\
- "old" "" "old." "" " ,\n"]
- );
- \\p\\g
- }
- }
- if {![ get impossible_procs(upd,$currtab) 0] &&
- ( ![ get empty_imports_procs(upd,$currtab) 0] ||
- ![ get empty_exports_procs(upd,$currtab) 0] )} {
- expand_text $current_section {
- /*
- * Create update rule for table '~$tab_name'
- */
- CREATE RULE upd_~$tab_name
- AFTER UPDATE OF ~$tab_name
- EXECUTE PROCEDURE pupd_~$tab_name
- (
- ~[ gen_compare $current_section $currtab "KEYS" "old" ""\
- "old." "" " ,\n"] ,
- ~[ $current_section pushIndent
- gen_compare $current_section $currtab "KEYS" "new" ""\
- "new." "" " ,\n"
- gen_rule_upd_imp_fields $current_section $currtab
- $current_section popIndent ]
- );
- \\p\\g
- }
- }
- $current_section popIndent
- }
-
-
- # Generate the declaration for the imported fields
- # for the CREATE RULE AFTER UPDATE statement if there are any
- #
- proc gen_rule_upd_imp_fields { current_section currtab } {
-
- set i_columns ""
- set i_columns [ get_col_list $currtab "IMPFIELDS" ]
- if { ![lempty $i_columns] } then {
- $current_section append " ,\n"
- expand_text $current_section {
- ~[ gen_comparec $current_section $i_columns\
- "old" "" "old." "" " ,\n"] ,
- ~[ gen_comparec $current_section $i_columns\
- "new" "" "new." "" " ,\n"] }
- }
- }
-