home *** CD-ROM | disk | FTP | other *** search
- #---------------------------------------------------------------------------
- #
- # Copyright (c) 1995 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 : @(#)libora.tcl /main/hindenburg/1
- # Original date : November 1995
- # Description : Oracle specific routines
- #
- #---------------------------------------------------------------------------
- #
- # @(#)libora.tcl /main/hindenburg/1 9 Dec 1996 Copyright 1995 Cadre Technologies Inc.
- #
- #---------------------------------------------------------------------------
-
- #
- # Procedures to support mapping of standard type "sequence"
- #
-
- proc is_sequence {type} {
- return [regexp {sequence*} $type]
- }
-
- #
- # The "normal" way to get the 4gl type. Always does the mapping
- #
-
- proc get_ora_type_4gl {column} {
-
- if [is_sequence [$column getTypeStd]] {
- return NUMBER
- }
-
- return [$column getType4GL]
- }
-
-
- #
- # Generate declaration of variables for selected columns in table
- # For character arrays the hosttype VARCHAR is used.
- #
-
- proc gen_ora_decl {section table selector {prefix ""} {postfix ""} \
- {separator ";\n"}} {
- gen_ora_decl_columns $section [get_col_list $table $selector] \
- $prefix $postfix $separator
- }
-
- #
- # Generate declaration of variables for columns in link
- # For character arrays the hosttype VARCHAR is used.
- #
-
- proc gen_ora_decl_link {section link {prefix ""} {postfix ""}
- {separator ";\n"}} {
- gen_ora_decl_columns $section [$link columnSet] $prefix $postfix $separator
- }
-
- #
- # Generate declaration of variables for each column in column list
- # For character arrays the hosttype VARCHAR is used.
- #
-
- proc gen_ora_decl_columns {section columns {prefix ""} {postfix ""}
- {separator ";\n"}} {
- $section pushIndent
-
- foreach col $columns {
- $section append [mk_ora_decl $col $prefix $postfix]$separator
- }
-
- $section popIndent
- }
-
- #
- # Generate declaration of variable: use VARCHAR type for character arrays
- #
-
- proc mk_ora_decl {col {prefix ""} {postfix ""}} {
- set name [$col getUniqueName]
- set type [$col getType3GL]
-
- if [regsub {(var)?char\[} $type "VARCHAR $prefix$name\[" type] {
- regexp {\[(.*)\]$} $type dummy index
- set index [expr {$index + 1}]
- regsub {\[(.*)\]$} $type "$postfix\[$index]" type
- return $type
- }
-
- return "$type $prefix$name$postfix"
- }
-
- #
- # Generate pointers to struct
- #
-
- proc gen_ptr_decl_assign {section table selector {pref1 ""} {post1 ""} \
- {pref2 ""} {post2 ""} {separator ";\n"}} {
- $section pushIndent
-
- foreach col [get_col_list $table $selector] {
- set colName [$col getUniqueName]
- set lside $pref1$colName$post1
- set type3GL [$col getType3GL]
-
- if {[string first "\[" $type3GL] == -1} {
- set rside &($pref2$colName$post2)
- } else {
- set rside $pref2$colName$post2
- }
-
- set typeName [lindex [split [$col getType3GL] "\["] 0]
- $section append "const $typeName *$lside = $rside$separator"
- }
-
- $section popIndent
- }
-
- #
- # Generate pointers to indicator struct
- #
-
- proc gen_ind_decl_assign {section table selector {pref1 ""} {post1 ""} \
- {pref2 ""} {post2 ""} {separator ";\n"}} {
- $section pushIndent
-
- foreach col [get_col_list $table $selector] {
- set colName [$col getUniqueName]
- set lside $pref1$colName$post1
- set rside &($pref2$colName$post2)
-
- $section append "short *$lside = $rside$separator"
- }
-
- $section popIndent
- }
-
- #
- # Generate assignment statement for Oracle columns (may need VARCHAR type)
- #
-
- proc gen_ora_assign {section table selector {pref1 ""} {post1 ""}
- {pref2 ""} {post2 ""} {flag1 ""} {flag2 ""}} {
- $section pushIndent
-
- foreach col [get_col_list $table $selector] {
- $section append [assign_ora_elem $section $col $pref1 $post1 \
- $pref2 $post2 $flag1 $flag2]
- }
-
- $section popIndent
- }
-
- #
- # Generate assignment statement for Oracle columns (may need VARCHAR type)
- #
-
- proc gen_ora_assign_cl {section link {pref1 ""} {post1 ""}
- {pref2 ""} {post2 ""} {flag1 ""} {flag2 ""}} {
- $section pushIndent
- foreach col [$link columnSet] {
- $section append [assign_ora_elem_md $section $col \
- $pref1 $post1 $pref2 $post2 $flag1 $flag2]
- }
- $section popIndent
- }
-
- #
- # Generate assignment statement for Oracle columns (may need VARCHAR type)
- #
-
- proc gen_ora_assign_link {section link {pref1 ""} {post1 ""}
- {pref2 ""} {post2 ""} {flag1 ""} {flag2 ""}} {
- $section pushIndent
- foreach col [$link columnSet] {
- $section append [assign_ora_elem $section $col \
- $pref1 $post1 $pref2 $post2 $flag1 $flag2]
- }
- $section popIndent
- }
-
- #
- # Generate assignment for Oracle columns (may need VARCHAR type)
- #
-
- proc assign_ora_elem {section column {pref1 ""} {post1 ""}
- {pref2 ""} {post2 ""} {flag1 ""} {flag2 ""}} {
- set name [$column getUniqueName]
-
- set part1 $pref1$name$post1
- set part2 $pref2$name$post2
-
- if [type_is_char_array $column] {
- add_[determine_sect_type $section]_inc_name "string" "h"
-
- if {($flag1 == "") && ($flag2 == "")} {
- return "strcpy($part1, $part2);\n"
- }
-
- return [assign_ora_char_type $part1 $part2 $flag1 $flag2]
- }
-
- return "$part1 = $part2;\n"
- }
-
- #
- # Generate assignment for Oracle columns (may need VARCHAR type)
- #
-
- proc assign_ora_elem_md {sect col {pref1 ""} {post1 ""} {pref2 ""} {post2 ""}
- {flag1 ""} {flag2 ""}} {
- set name [$col getUniqueName]
- set fname [$col getForeignName]
-
- set part1 $pref1$name$post1
- set part2 $pref2$fname$post2
-
- if [type_is_char_array $col] {
- add_[determine_sect_type $sect]_inc_name "string" "h"
-
- if {($flag1 == "") && ($flag2 == "")} {
- return "strcpy($part1, $part2);\n"
- }
-
- return [assign_ora_char_type $part1 $part2 $flag1 $flag2]
- }
-
- return "$part1 = $part2;\n"
- }
-
- #
- # Generate assignment for Oracle VARCHAR type
- #
-
- proc assign_ora_char_type {part1 part2 {flag1 ""} {flag2 ""}} {
- if {($flag1 == "ora") && ($flag2 == "ora")} {
- set line1 "strncpy((char *)${part1}.arr, (char *)${part2}.arr, ${part2}.len);\n"
- set line2 "${part1}.len = ${part2}.len;\n"
- return $line1$line2
- }
-
- if {$flag1 == "ora"} {
- set line1 "strcpy((char *)${part1}.arr, $part2);\n"
- set line2 "${part1}.len = strlen($part2);\n"
- return $line1$line2
- }
-
- if {$flag2 == "ora"} {
- set line1 "strncpy(${part1}, (char *)${part2}.arr, ${part2}.len);\n"
- set line2 "${part1}\[${part2}.len\] = '\\0';\n"
- return $line1$line2
- }
-
- return "strcpy($part1, $part2);\n"
- }
-
- #
- #
- #
-
- proc init_base_sequences {section class} {
- $section pushIndent
-
- foreach col [get_col_list [$class table] IMPKEYS] {
- if [is_sequence [$col getTypeStd]] {
- set colName [$col getUniqueName]
- set baseCol [$col column]
- set baseColName [$baseCol getUniqueName]
-
- foreach inhGroup [$class genNodeSet] {
- set baseClass [$inhGroup superClass]
- if {![$baseClass isPersistent]} {
- continue
- }
- set baseTable [$baseClass table]
-
- if {[$baseCol table] == $baseTable} {
- set baseClassName [$baseClass getName]
-
- expand_text $section {
- data.~$colName = ~$baseClassName::data.~$baseColName;
- }
- }
- }
- }
- }
-
- $section popIndent
- }
-