home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
gendelproc.tcl
< prev
next >
Wrap
Text File
|
1996-06-05
|
7KB
|
215 lines
#---------------------------------------------------------------------------
#
# 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 : @(#)gendelproc.tcl 2.1 (2.1)
# Original date : 18-8-1992
# Description : Tcl script for generating delete database
# procedures
#
#---------------------------------------------------------------------------
#
# @(#)gendelproc.tcl 2.1 (2.1)\t19 Apr 1996 Copyright 1992-1996 Cadre Technologies, Inc.
#
#---------------------------------------------------------------------------
# Generate the procedure body for a delete procedure
#
proc gen_delete_proc { current_section currtab } {
global empty_imports_procs
global empty_exports_procs
if { [ get empty_imports_procs(del,$currtab) 0] &&
[ get empty_exports_procs(del,$currtab) 0] } {
return
}
$current_section pushIndent
expand_text $current_section {
CREATE PROCEDURE pdel_~[ $currtab getUniqueName]
(
~[ gen_simple_data_decl_4gl $current_section $currtab\
"KEYS_IMPFIELDS" "old" " ,\n" ]
)
~[ gen_as_declare $current_section ]
BEGIN
~[ gen_del_block $current_section $currtab ]
RETURN 1;
END
\\p\\g
}
$current_section popIndent
}
#
#
proc gen_del_block { current_section currtab } {
set tab_name [ $currtab getUniqueName]
$current_section pushIndent
if { ![ get empty_exports_procs(del,$currtab) 0]} {
set exports [ $currtab exportSet]
expand_text $current_section {
/*
* RI: CHECK RI FOR DETAILS
*
* Check referential integrity after a delete
* from table '~$tab_name'
*/
}
gen_ri_del_exports $current_section $currtab $exports
}
if { ![ get empty_imports_procs(del,$currtab) 0]} {
set imports [ $currtab importSet]
expand_text $current_section {
/*
* RI: CHECK RI FOR MASTERS
*
* Check referential integrity after a delete
* from table '~$tab_name'
*/
}
gen_ri_del_imports $current_section $currtab $imports
}
$current_section popIndent
}
# Walk through the list of exports and check the RI
# i.e. visit all detail tables
#
proc gen_ri_del_exports { current_section currtab links } {
global export_rules
$current_section pushIndent
foreach link $links {
set detail [ $link detail]
set detail_name [ $detail getUniqueName]
set rule_type [ $link getDelType]
if { $rule_type == "none" } then {
continue
}
set riproc [ get export_rules(del,$rule_type)]
if { $riproc != "" } then {
del_$riproc $current_section $currtab $detail $link
} else {
m4_error $E_NO_TCL_DEL_RULE $rule_type [ $currtab getUniqueName]
}
if { $rule_type == "rej_last" } {
del_rej_last $current_section $currtab $detail $link
}
}
$current_section popIndent
}
# Walk through the list of imports and depending on the
# rule type check if no referential integrity is violated
# i.e. visit some master tables
#
proc gen_ri_del_imports { current_section currtab links } {
global import_rules
$current_section pushIndent
foreach link $links {
set master [ $link master]
set master_name [ $master getUniqueName]
set rule_type [ $link getDelType]
set tab_role "master"
if { $rule_type == "none" } then {
continue;
}
set riproc [ get import_rules(del,$rule_type)]
if { $riproc != "" } then {
del_$riproc $current_section $currtab $master $link
} else {
m4_error $E_NO_TCL_DEL_RULE $rule_type [ $currtab getUniqueName]
}
}
$current_section popIndent
}
# Nullify the exported key in the detail table
#
proc del_nullify_detail { current_section currtab detail link } {
gen_nullify_in_detail $current_section $currtab $detail $link
}
# Reject on exist foreign key in other table
#
proc del_rej_exist { current_section currtab other link } {
set other_name [ $other getUniqueName]
gen_exist_in_detail_link $current_section $currtab $other $link ":old"
gen_error_del_rej $current_section [$currtab getUniqueName] $other_name
}
# Casade delete for foreign key in master
#
proc del_del_in_master { current_section currtab master link } {
set columns [ $link columnSet]
del_in_master $current_section $columns $master
}
# Casade delete for the exported key in detail
#
proc del_del_in_detail {current_section currtab detail link } {
if { [ $link getLinkType] == "export" } {
set link [ $link friendLink]
}
set columns [ $link columnSet]
del_in_detail $current_section $columns $detail
}
# If there is just one row in the master table with a
# reference to the deleted tuple, reject the delete
#
proc del_rej_last_in_master { current_section currtab master link } {
set tab_name [ $currtab getUniqueName]
gen_exist_in_master_link $current_section $currtab $master $link ":old"
gen_error_del_rej_last $current_section $tab_name
}
# Reject the delete if the last tuple of the current
# table was deleted
#
proc del_rej_last { current_section currtab other link } {
set tab_name [ $currtab getUniqueName]
$current_section pushIndent
expand_text $current_section {
/*
* RI : REJECT LAST
*/
~[ gen_exist_last $current_section $currtab $link ":old" ]
~[ gen_error_del_rej_last $current_section $tab_name ] }
$current_section popIndent
}