home *** CD-ROM | disk | FTP | other *** search
/ PC World 1998 October / PCWorld_1998-10_cd.bin / software / prehled / komix / DATA.Z / genrules.tcl < prev    next >
Text File  |  1996-06-05  |  4KB  |  113 lines

  1. #---------------------------------------------------------------------------
  2. #
  3. # Copyright (c) 1992-1996 by Cadre Technologies, Inc.
  4. #
  5. # This software is furnished under a license and may be used only in
  6. # accordance with the terms of such license and with the inclusion of
  7. # the above copyright notice. This software or any other copies thereof
  8. # may not be provided or otherwise made available to any other person.
  9. # No title to and ownership of the software is hereby transferred.
  10. #
  11. # The information in this software is subject to change without notice
  12. # and should not be construed as a commitment by Cadre Technologies, Inc.
  13. #
  14. #---------------------------------------------------------------------------
  15. #
  16. #    File        : @(#)genrules.tcl    2.1 (2.1)
  17. #    Original date    : 18-8-1992
  18. #    Description    : Tcl script for generating SQL rules
  19. #
  20. #---------------------------------------------------------------------------
  21. #
  22. # @(#)genrules.tcl    2.1 (2.1)\t19 Apr 1996 Copyright 1992-1996 Cadre Technologies, Inc.
  23. #
  24. #---------------------------------------------------------------------------
  25.  
  26.  
  27. # Generate if nessecary an insert, delete and update
  28. # rule for a table
  29. #
  30. proc gen_rules { current_section currtab } {
  31.  
  32.     global impossible_procs
  33.     global empty_imports_procs
  34.     global empty_exports_procs
  35.     set tab_name [ $currtab getUniqueName]
  36.     $current_section pushIndent
  37.     if {![ get impossible_procs(ins,$currtab) 0]       &&
  38.        ( ![ get empty_imports_procs(ins,$currtab) 0]   ||
  39.          ![ get empty_exports_procs(ins,$currtab) 0] ) } {
  40.         expand_text $current_section {
  41.             /*
  42.              * Create insert rule for table '~$tab_name'
  43.              */
  44.             CREATE RULE       ins_~$tab_name
  45.             AFTER INSERT INTO ~$tab_name
  46.             EXECUTE PROCEDURE pins_~$tab_name
  47.             (
  48.                 ~[ gen_compare $current_section $currtab "ALL" "new" ""\
  49.                    "new." "" " ,\n"]
  50.             );
  51.             \\p\\g
  52.         }
  53.     }
  54.     if {![ get impossible_procs(del,$currtab) 0] &&
  55.        ( ![ get empty_imports_procs(del,$currtab) 0] || 
  56.          ![ get empty_exports_procs(del,$currtab) 0]  ) } {
  57.         expand_text $current_section {
  58.             /*
  59.              * Create delete rule for table '~$tab_name'
  60.              */
  61.             CREATE RULE       del_~$tab_name
  62.             AFTER DELETE FROM ~$tab_name
  63.             EXECUTE PROCEDURE pdel_~$tab_name
  64.             (
  65.                 ~[ gen_compare $current_section $currtab "KEYS_IMPFIELDS"\
  66.                    "old" "" "old." "" " ,\n"]
  67.             );
  68.             \\p\\g
  69.         }
  70.     }
  71.     if {![ get impossible_procs(upd,$currtab) 0] &&
  72.        ( ![ get empty_imports_procs(upd,$currtab) 0] ||
  73.          ![ get empty_exports_procs(upd,$currtab) 0]  )} {
  74.         expand_text $current_section {
  75.             /*
  76.              * Create update rule for table '~$tab_name'
  77.              */
  78.             CREATE RULE       upd_~$tab_name
  79.             AFTER UPDATE OF   ~$tab_name
  80.             EXECUTE PROCEDURE pupd_~$tab_name
  81.             (
  82.                 ~[ gen_compare $current_section $currtab "KEYS" "old" ""\
  83.                    "old." "" " ,\n"] ,
  84.                 ~[ $current_section pushIndent
  85.                    gen_compare $current_section $currtab "KEYS" "new" ""\
  86.                    "new." "" " ,\n"
  87.                    gen_rule_upd_imp_fields $current_section $currtab
  88.                    $current_section popIndent ]
  89.             );
  90.             \\p\\g
  91.         }
  92.     }
  93.     $current_section popIndent
  94. }
  95.  
  96.  
  97. # Generate the declaration for the imported fields
  98. # for the CREATE RULE AFTER UPDATE statement if there are any
  99. #
  100. proc gen_rule_upd_imp_fields { current_section currtab } {
  101.  
  102.     set i_columns ""
  103.     set i_columns [ get_col_list $currtab "IMPFIELDS" ]
  104.     if { ![lempty $i_columns] } then {
  105.         $current_section append " ,\n"
  106.         expand_text $current_section {
  107.             ~[ gen_comparec $current_section $i_columns\
  108.                "old" "" "old." "" " ,\n"] ,
  109.             ~[ gen_comparec $current_section $i_columns\
  110.                "new" "" "new." "" " ,\n"] }
  111.     }
  112. }
  113.