home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
komix
/
DATA.Z
/
genupdproc.tcl
< prev
next >
Wrap
Text File
|
1996-06-05
|
8KB
|
241 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 : @(#)genupdproc.tcl 2.1 (2.1)
# Original date : 18-8-1992
# Description : Tcl script for generating update procedures
#
#---------------------------------------------------------------------------
#
# @(#)genupdproc.tcl 2.1 (2.1)\t19 Apr 1996 Copyright 1992-1996 Cadre Technologies, Inc.
#
#---------------------------------------------------------------------------
# Generate the procedure body for an update procedure
#
proc gen_update_proc { current_section currtab } {
global empty_imports_procs
global empty_exports_procs
if { [ get empty_imports_procs(upd,$currtab) 0] &&
[ get empty_exports_procs(upd,$currtab) 0] } {
return
}
set tab_name [ $currtab getUniqueName]
set imports [ $currtab importSet]
set exports [ $currtab exportSet]
$current_section pushIndent
expand_text $current_section {
CREATE PROCEDURE pupd_~$tab_name
(
~[ gen_simple_data_decl_4gl $current_section $currtab "KEYS"\
"old" " ,\n" ] ,
~[ $current_section pushIndent
gen_simple_data_decl_4gl $current_section $currtab "KEYS"\
"new" " ,\n"
gen_upd_decl_imp_fields $current_section $currtab
$current_section popIndent]
)
AS DECLARE
msg varchar(127) NOT NULL;
counter integer;
BEGIN
~[ gen_chk_upd_key $current_section $currtab ]
~[ gen_upd_imp $current_section $currtab $imports ]
RETURN 1;
END
\\p\\g
}
$current_section popIndent
}
# Generate for foreign keys the code to check the RI
#
proc gen_upd_imp { current_section currtab imports } {
$current_section pushIndent
foreach link $imports {
if { [ $link getUpdType] == "none" } {
continue;
}
gen_if_updated $current_section $currtab $link
}
$current_section popIndent
}
# Check if the key is updated
#
proc gen_chk_upd_key { current_section currtab } {
set columns [ get_col_list $currtab "KEYS" ]
set tab_name [$currtab getUniqueName]
$current_section pushIndent
expand_text $current_section {
/*
* CHECK: UPDATE OF THE KEYS
*/
IF NOT( ~[ gen_comparec $current_section $columns \
"old" "" "new" "" " AND\n" ]) THEN
msg = 'Update of key attributes of table ~$tab_name is not allowed';
RAISE ERROR 99012 :msg;
RETURN 0;
ENDIF; }
$current_section popIndent
}
# Generate code to check if the new values of a foreign key
# (can be more than one column!) are the same as the old
# ones, if not, check the RI
#
proc gen_if_updated { current_section currtab link } {
if { [$link getImportType] == "key"} {
return;
}
set columns [ $link columnSet]
set master [ $link master]
set master_name [ $master getUniqueName]
set tab_name [ $currtab getUniqueName]
$current_section pushIndent
expand_text $current_section {
/*
* CHECK: FOREIGN KEY
*
* Check if the foreign key from table '~$master_name'
* is updated, if so, check the RI
*/
IF NOT( ~[ gen_comparec $current_section $columns \
"old" "" "new" "" " AND\n" ]) THEN
~[ $current_section pushIndent
gen_ri_upd_m $current_section $currtab $link
$current_section popIndent
]
ENDIF;
}
$current_section popIndent
}
# Generate the SQL code to check for a link (can be more than one column)
# the RI between the current table and the master table
#
proc gen_ri_upd_m { current_section currtab link } {
set master [ $link master]
set rule_type [ $link getUpdType]
set tab_name [ $currtab getUniqueName]
if { [get empty_imports_procs(upd,$currtab) 0]} {
return
}
$current_section pushIndent
expand_text $current_section {
/*
* RI: CHECK RI FOR MASTER
*
* Check the referential integrity after an update of
* table '~$tab_name'
*
*/
~[ set riproc [ get import_rules(upd,$rule_type)]
if { $riproc != "" } {
upd_$riproc $current_section $currtab $master $link
} else {
m4_error $E_NO_TCL_UPD_RULE $rule_type [$currtab getUniqueName]
} ]
}
$current_section popIndent
}
# Generate the declaration for the imported fields
# for the CREATE RULE AFTER UPDATE statement if there are any
#
proc gen_upd_decl_imp_fields { current_section currtab } {
set i_columns ""
set i_columns [ get_col_list $currtab "IMPFIELDS" ];
if { ![lempty $i_columns] } {
$current_section append " ,\n"
expand_text $current_section {
~[ gen_simple_data_decl_4glc $current_section $i_columns\
"old" " ,\n"] ,
~[ gen_simple_data_decl_4glc $current_section $i_columns\
"new" " ,\n"] }
}
}
# Nullify the exported key in the detail table
#
proc upd_nullify_detail { current_section currtab detail link } {
gen_nullify_in_detail $current_section $currtab $detail $link
}
# Reject on not exist foreign key in master table
#
proc upd_rej_not_exist { current_section currtab master link } {
set tab_name [ $currtab getUniqueName]
set mas_name [ $master getUniqueName]
set columns [ $link columnSet]
set detail [ $link detail]
gen_exist_in_master_link $current_section $detail $master $link ":new"
gen_error_upd_rej_not_exist $current_section $tab_name $mas_name
}
# Casade insert into master table, this will only work
# if the non keys of the master are nullable!!
#
proc upd_ins_in_master { current_section currtab master link } {
set columns [ $link columnSet]
gen_ins_in_master $current_section $master $columns
}
# Update the exported key in the detail table
#
proc upd_upd_in_detail { current_section currtab detail link } {
upd_in_detail $current_section $detail $link
}
# Reject the update if the exported key exist in the detail table
#
proc upd_rej_exist { current_section currtab detail link } {
set detail_name [ $detail getUniqueName]
$current_section pushIndent
gen_exist_in_detail_link $current_section $currtab $detail $link ":old"
gen_error_upd_rej_exist $current_section $detail_name
$current_section popIndent
}