home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1997 November
/
PCWorld_1997-11_cd.bin
/
software
/
programy
/
komix
/
DATA.Z
/
libnesql.tcl
< prev
next >
Wrap
Text File
|
1997-06-04
|
11KB
|
356 lines
#---------------------------------------------------------------------------
#
# Copyright (c) 1994-1996 by Cayenne Software 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 Cayenne Software Inc.
#
#---------------------------------------------------------------------------
#
# File : @(#)libnesql.tcl /main/hindenburg/3
# Original date : 17-12-1994
# Description : Redefine some procedures (used by NewEra code
# generation) previously defined in libsql.tcl.
# So source this tcl file after libsql.tcl.
# Also define some new procedures.
#
#---------------------------------------------------------------------------
#
# Return the string for one assignment
#
proc assign_elem {col {prefix1 ""} {postfix1 ""} {prefix2 ""} {postfix2 ""} \
{sect "src"}} {
set name [$col getUniqueName]
return "LET $prefix1$name$postfix1 = $prefix2$name$postfix2\n"
}
# Return the string for one assignment in a master-detail relationship
#
proc assign_elem_md {col {prefix1 ""} {postfix1 ""} {prefix2 ""} \
{postfix2 ""} {sect "src"}} {
set name [$col getUniqueName]
set fname [$col getForeignName]
return "LET $prefix1$name$postfix1 = $prefix2$fname$postfix2\n"
}
# Return a string containing a series of question marks separated by commas
#
proc gen_dyn_place_holders {section table selector} {
set columns [get_col_list $table $selector]
if { [lempty $columns] } {
return ""
}
lvarpop columns
set str "?"
while { ![lempty $columns] } {
append str ", ?"
lvarpop columns
}
return $str
}
# Generate a compare of column names with dynamic placeholders
#
proc gen_dyn_comparec {section columns {prefix1 ""} {postfix1 ""} \
{separator ", "} {newline ""}} {
if { [lempty $columns] } {
return;
}
$section pushIndent
set newpf $separator$newline$prefix1
set col [lvarpop columns]
set name [$col getUniqueName]
expand_text $section {~$prefix1~$name~$postfix1 = ?}
while { ![lempty $columns] } {
set col [lvarpop columns]
set name [$col getUniqueName]
expand_text $section {
~$newpf~$name~$postfix1 = ?}
}
$section append $newline
$section popIndent
}
proc gen_dyn_compare {section table selector {prefix1 ""} {postfix1 ""} \
{separator ", "} {newline ""}} {
gen_dyn_comparec $section [get_col_list $table $selector] $prefix1 \
$postfix1 $separator $newline
}
# Generate setParam statements to replace placeholders
#
proc gen_setparamc {section table pnr selectors rowname} {
upvar $pnr param_nr
$section pushIndent
set columns [$table columnSet]
foreach selector $selectors {
foreach col $columns {
if [expr $column_selector($selector)] {
expand_text $section {
CALL stmt.setParam(~$param_nr, ~${rowname}.getVal(~[get_column_nr $col]))
}
incr param_nr
}
}
}
$section popIndent
}
proc gen_setparamc_name {section table selectors} {
set param_nr 1
$section pushIndent
set columns [$table columnSet]
foreach selector $selectors {
foreach col $columns {
if [expr $column_selector($selector)] {
set ixval [map_fgl2ixval [$col getType3GL]]
set name [$col getUniqueName]
expand_text $section {
CALL stmt.setParam(~$param_nr, ~$name)
}
incr param_nr
}
}
}
$section popIndent
}
# Generate setParam statements to replace placeholders
#
proc gen_setparam_cl {section link pnr rowname} {
upvar $pnr param_nr
$section pushIndent
if { [$link getLinkType] == "export" } {
set link [$link friendLink]
}
set columns [$link columnSet]
foreach col $columns {
expand_text $section {
CALL stmt.setParam(~$param_nr, ~${rowname}.getVal(~[get_foreign_column_nr $col]))
}
incr param_nr
}
$section popIndent
}
# Generate a compare list with dynamic placeholders for imported/exported
# columns i.e. the list of columns must have obj_type "imp_column".
# If the link is a export_link get the friend of the link
#
proc gen_dyn_compare_cl {section link {prefix1 ""} {postfix1 ""} \
{separator ", "} {newline ""}} {
if { [$link getLinkType] == "export" } {
set link [$link friendLink]
}
set columns [$link columnSet]
if { [lempty $columns] } {
return ;
}
set col [lvarpop columns]
set tcol_nm [$col getUniqueName]
$section pushIndent
expand_text $section {~$prefix1~$tcol_nm~$postfix1 = ?}
set newpf $separator$newline$prefix1
while {![lempty $columns]} {
set col [lvarpop columns]
set tcol_nm [$col getUniqueName]
expand_text $section {~$newpf~$tcol_nm~$postfix1 = ?}
}
$section popIndent
$section append $newline
}
# Generate a list of getVal calls for values in a row. The values correspond
# to the columns.
#
proc gen_rowgetval_c {section columns {prefix ""} {postfix ""} \
{separator ", "} {newline ""}} {
if { [lempty $columns] } {
return ;
}
set col [lvarpop columns]
$section pushIndent
set ixval [map_fgl2ixval [$col getType3GL]]
expand_text $section {~${prefix}.getVal(~[get_column_nr $col])~$postfix\
CAST ~$ixval}
set newpf $separator$newline$prefix
while {![lempty $columns]} {
set col [lvarpop columns]
set ixval [map_fgl2ixval [$col getType3GL]]
expand_text $section {~${newpf}.getVal(~[get_column_nr $col])~$postfix\
CAST ~$ixval}
}
$section popIndent
$section append $newline
}
proc gen_rowgetval {section table selector {prefix ""} {postfix ""} \
{separator ", "} {newline ""}} {
gen_rowgetval_c $section [get_col_list $table $selector] $prefix \
$postfix $separator $newline
}
proc gen_rowgetval_l {section link {prefix ""} {postfix ""} {separator ", "} \
{newline ""}} {
gen_rowgetval_c $section [$link columnSet] $prefix $postfix \
$separator $newline
}
# Generate a list of getVal calls for values in a row. The values correspond
# to the columns. These procs are the same as the gen_rowgetval* procs, except
# that the index used to get values from a row, is not the column_nr, but an
# incremental index ("inc" in gen_rowgetvalinc* stands for "incremental").
#
proc gen_rowgetvalinc_c {section columns {prefix ""} {postfix ""} \
{separator ", "} {newline ""}} {
if { [lempty $columns] } {
return ;
}
set col [lvarpop columns]
$section pushIndent
set ixval [map_fgl2ixval [$col getType3GL]]
set i 1
expand_text $section {~${prefix}.getVal(~$i)~$postfix CAST ~$ixval}
set newpf $separator$newline$prefix
while {![lempty $columns]} {
set col [lvarpop columns]
set ixval [map_fgl2ixval [$col getType3GL]]
incr i
expand_text $section {~${newpf}.getVal(~$i)~$postfix CAST ~$ixval}
}
$section popIndent
$section append $newline
}
proc gen_rowgetvalinc {section table selector {prefix ""} {postfix ""} \
{separator ", "}} {
gen_rowgetvalinc_c $section [get_col_list $table $selector] $prefix \
$postfix $separator
}
proc gen_rowgetvalinc_l {section link {prefix ""} {postfix ""} \
{separator ", "}} {
gen_rowgetvalinc_c $section [$link columnSet] $prefix $postfix \
$separator
}
# nullify columns
#
proc gen_assign_nullc {section columns {prefix1 ""} {postfix1 ""}} {
$section pushIndent
foreach col $columns {
$section append \
[assign_elem_null $col $prefix1 $postfix1]
}
$section popIndent
}
# see gen_assign_nullc
#
proc gen_assign_null {section table selector {prefix1 ""} {postfix1 ""}} {
gen_assign_nullc $section [get_col_list $table $selector] $prefix1 \
$postfix1
}
# Return the string for one null assignment
#
proc assign_elem_null {col {prefix1 ""} {postfix1 ""}} {
set colnr [get_column_nr $col]
return "CALL $prefix1.getVal($colnr).setNull()\n"
}
# Redefine for NewEra
# Return the string for one assignment
#
proc assign_elem {col {prefix1 ""} {postfix1 ""} {prefix2 ""}
{postfix2 ""} {sect "src"} {retvarname retVal}} {
set name [$col getUniqueName]
set colnr [get_column_nr $col]
return "LET $retvarname = $prefix1.setVal(COPY $name, $colnr)\n"
}
# Redefine for NewEra
# Return the string for one assignment in a master-detail relationship
#
proc assign_elem_md {col {prefix1 ""} {postfix1 ""} {prefix2 ""}
{postfix2 ""} {sect "src"} {retvarname retVal}} {
set colnr [get_column_nr $col]
set fcolnr [get_foreign_column_nr $col]
return "LET $retvarname = $prefix1.setVal(COPY $prefix2.getVal($fcolnr), $colnr)\n"
}
# Special for initByRow
#
proc gen_assign_initrow {section table selector rowname initrowname} {
set columns [get_col_list $table $selector]
$section pushIndent
set i 1
foreach col $columns {
set colnr [get_column_nr $col]
expand_text $section {
LET retVal =\
~${rowname}.setVal(~${initrowname}.getVal(~${i}),\
~${colnr})
}
if {[$col getColumnType] == "key"} {
incr i
} else {
expand_text $section {
LET retVal = ~${initrowname}.delete(~${i})
}
}
}
$section popIndent
}
# add a "column_nr" attribute to (imported) column objects in the model
# add a "foreign_column_nr" attribute to imported column objects in the model
#
proc add_column_nr_attrs {} {
global oomodel
set tables [[$oomodel sqlModel] tableSet]
foreach table $tables {
set column_nr 1
set columns [$table columnSet]
foreach col $columns {
add_attr $col column_nr $column_nr
incr column_nr
if { [$col get_obj_type] == "imp_column" } {
set foreign_column_nr 1
set fcolumns [[$col master] columnSet]
foreach fcol $fcolumns {
if { [$col column] == $fcol } {
add_attr $col foreign_column_nr $foreign_column_nr
break
}
incr foreign_column_nr
}
}
}
}
}
proc get_column_nr {col} {
return [$col getPropertyValue column_nr]
}
proc get_foreign_column_nr {col} {
return [$col getPropertyValue foreign_column_nr]
}