2001-05-23 15:26:42 +02:00
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// PROGRAM: General preprocessor
// MODULE: cob.cpp
// DESCRIPTION: COBOL text generator
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// The contents of this file are subject to the Interbase Public
// License Version 1.0 (the "License"); you may not use this file
// except in compliance with the License. You may obtain a copy
// of the License at http://www.Inprise.com/IPL.html
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Software distributed under the License is distributed on an
// "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
// or implied. See the License for the specific language governing
// rights and limitations under the License.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// The Original Code was created by Inprise Corporation
// and its predecessors. Portions created by Inprise Corporation are
// Copyright (C) Inprise Corporation.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// All Rights Reserved.
// Contributor(s): ______________________________________.
// Solaris x86 changes - Konstantin Kuznetsov, Neil McCalden
2002-07-06 07:32:02 +02:00
// 8-Mar-2002 FSG (Frank Schlottmann-G<> dde) tiny cobol support
// fixed Bug No. 526204*
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
//
//____________________________________________________________
//
2002-10-28 05:42:54 +01:00
//
// 2002.10.27 Sean Leyne - Completed removal of obsolete "DG_X86" port
2002-10-28 05:57:07 +01:00
// 2002.10.27 Sean Leyne - Code Cleanup, removed obsolete "UNIXWARE" port
2002-10-28 05:42:54 +01:00
//
2002-10-29 03:45:09 +01:00
// 2002.10.28 Sean Leyne - Completed removal of obsolete "DGUX" port
2002-10-29 04:37:50 +01:00
// 2002.10.28 Sean Leyne - Completed removal of obsolete "HP700" port
2002-10-29 03:45:09 +01:00
//
2006-11-10 08:50:13 +01:00
// Modified to allow support for RM/Cobol. Actual RM/Cobol code generation
// in rmc.cpp.
// Stephen W. Boyd 31.Aug.2006
2001-05-23 15:26:42 +02:00
//
2001-07-30 01:43:24 +02:00
# include "firebird.h"
2004-04-29 00:36:29 +02:00
# include <stdio.h>
2001-05-23 15:26:42 +02:00
# include "../jrd/common.h"
# include <stdarg.h>
2003-11-08 17:40:17 +01:00
# include "../jrd/ibase.h"
2003-09-28 23:36:05 +02:00
# include "../jrd/gds_proto.h"
2001-05-23 15:26:42 +02:00
# include "../gpre/gpre.h"
# include "../gpre/pat.h"
# include "../gpre/cmp_proto.h"
# include "../gpre/lang_proto.h"
# include "../gpre/pat_proto.h"
2001-07-12 07:46:06 +02:00
# include "../gpre/prett_proto.h"
# include "../gpre/gpre_proto.h"
2005-01-03 09:07:41 +01:00
# include "../common/utils_proto.h"
2001-07-12 07:46:06 +02:00
# ifdef HAVE_STRING_H
# include <string.h>
# endif
2001-05-23 15:26:42 +02:00
2003-10-16 10:51:06 +02:00
static const char * const COMMIT = " commit " ;
static const char * const ROLLBACK = " rollback " ;
2003-10-15 00:22:32 +02:00
2008-01-16 08:15:01 +01:00
# if defined AIX || defined AIX_PPC || defined SOLARIS || defined HP10 || defined HP11 || defined LINUX || defined DARWIN || defined FREEBSD || defined NETBSD || defined WIN_NT
2003-10-16 10:51:06 +02:00
static const char * const OMITTED = " BY VALUE 0 " ;
static const char * const BY_VALUE = " BY VALUE " ;
static const char * const END_VALUE = " " ;
static const char * const BY_REF = " BY REFERENCE " ;
static const char * const BY_DESC = " BY REFERENCE " ;
static const char * const RAW_BLR_TEMPLATE = " 03 %s%d%s%d PIC XXXX USAGE COMP-X VALUE IS % " ULONGFORMAT " . " ;
static const char * const RAW_TPB_TEMPLATE = " 03 %s%d%s%d PIC XXXX USAGE COMP-X VALUE IS % " ULONGFORMAT " . " ;
static const char * const COMP_VALUE = " COMP-5 " ;
2001-05-23 15:26:42 +02:00
# else
2003-10-16 10:51:06 +02:00
static const char * const COMP_VALUE = " COMP " ;
2003-10-15 00:22:32 +02:00
# endif // MICROFOCUS
2003-10-16 10:51:06 +02:00
static const char * const STRING_LENGTH = " \" isc_embed_dsql_length \" " ;
static const char * const ISC_BLOB = " isc_%s_blob " ;
static const char * const CLOSE = " close " ;
static const char * const CANCEL = " cancel " ;
static const char * const ISC_CANCEL_BLOB = " isc_cancel_blob " ;
static const char * const ISC_COMPILE_REQUEST = " isc_compile_request " ;
static const char * const ISC_CREATE_DATABASE = " isc_create_database " ;
static const char * const ISC_DDL = " isc_ddl " ;
static const char * const ISC_COMMIT_TRANSACTION = " isc_commit_transaction " ;
static const char * const ISC_ROLLBACK_TRANSACTION = " isc_rollback_transaction " ;
static const char * const ISC_DROP_DATABASE = " isc_drop_database " ;
static const char * const ISC_CLOSE = " isc_embed_dsql_close " ;
static const char * const ISC_DECLARE = " isc_embed_dsql_declare " ;
static const char * const ISC_DESCRIBE = " isc_embed_dsql_describe " ;
static const char * const ISC_DESCRIBE_BIND = " isc_embed_dsql_describe_bind " ;
static const char * const ISC_EXECUTE = " isc_embed_dsql_execute " ;
static const char * const ISC_EXECUTE2 = " isc_embed_dsql_execute2 " ;
static const char * const ISC_EXECUTE_IMMEDIATE = " isc_embed_dsql_execute_immed " ;
static const char * const ISC_EXECUTE_IMMEDIATE2 = " isc_embed_dsql_execute_immed2 " ;
static const char * const ISC_INSERT = " isc_embed_dsql_insert " ;
static const char * const ISC_OPEN = " isc_embed_dsql_open " ;
static const char * const ISC_OPEN2 = " isc_embed_dsql_open2 " ;
static const char * const ISC_PREPARE = " isc_embed_dsql_prepare " ;
static const char * const ISC_DSQL_ALLOCATE = " isc_dsql_alloc_statement2 " ;
static const char * const ISC_DSQL_EXECUTE = " isc_dsql_execute_m " ;
static const char * const ISC_DSQL_FREE = " isc_dsql_free_statement " ;
static const char * const ISC_DSQL_SET_CURSOR = " isc_dsql_set_cursor_name " ;
static const char * const ISC_COMMIT_ROLLBACK_TRANSACTION = " isc_%s_transaction " ;
static const char * const ISC_DETACH_DATABASE = " isc_detach_database " ;
static const char * const ISC_GET_SLICE = " isc_get_slice " ;
static const char * const ISC_PUT_SLICE = " isc_put_slice " ;
static const char * const ISC_GET_SEGMENT = " isc_get_segment " ;
static const char * const ISC_PUT_SEGMENT = " isc_put_segment " ;
static const char * const ISC_RECEIVE = " isc_receive " ;
static const char * const ISC_RELEASE_REQUEST = " isc_release_request " ;
static const char * const ISC_UNWIND_REQUEST = " isc_unwind_request " ;
static const char * const ISC_SEND = " isc_send " ;
static const char * const ISC_START_TRANSACTION = " isc_start_transaction " ;
static const char * const ISC_START_AND_SEND = " isc_start_and_send " ;
static const char * const ISC_START_REQUEST = " isc_start_request " ;
static const char * const ISC_TRANSACT_REQUEST = " isc_transact_request " ;
static const char * const ISC_COMMIT_RETAINING = " isc_commit_retaining " ;
2008-01-16 08:15:01 +01:00
static const char * const ISC_ROLLBACK_RETAINING = " isc_rollback_retaining " ;
2003-10-16 10:51:06 +02:00
static const char * const ISC_ATTACH_DATABASE_D = " isc_attach_database " ;
static const char * const ISC_ATTACH_DATABASE = " isc_attach_database " ;
static const char * const ISC_MODIFY_DPB = " isc_modify_dpb " ;
static const char * const ISC_FREE = " isc_free " ;
2001-05-23 15:26:42 +02:00
# ifdef GIVING_SUPPORTED
2003-10-16 10:51:06 +02:00
static const char * const ISC_SQLCODE_CALL = " isc_sqlcode " ;
static const char * const ISC_FETCH = " isc_embed_dsql_fetch " ;
static const char * const ISC_EVENT_BLOCK = " isc_event_block_a " ;
2001-05-23 15:26:42 +02:00
# else
2003-10-16 10:51:06 +02:00
static const char * const ISC_SQLCODE_CALL = " isc_sqlcode_s " ;
static const char * const ISC_FETCH = " isc_embed_dsql_fetch_a " ;
static const char * const ISC_EVENT_BLOCK = " isc_event_block_s " ;
2001-05-23 15:26:42 +02:00
# endif
2003-10-16 10:51:06 +02:00
static const char * const ISC_PREPARE_TRANSACTION = " isc_prepare_transaction " ;
static const char * const ISC_EVENT_WAIT = " isc_wait_for_event " ;
static const char * const ISC_EVENT_COUNTS = " isc_event_counts " ;
2001-05-23 15:26:42 +02:00
# ifdef GIVING_SUPPORTED
2003-10-16 10:51:06 +02:00
static const char * const ISC_BADDRESS = " isc_baddress " ;
2001-05-23 15:26:42 +02:00
# else
2003-10-16 10:51:06 +02:00
static const char * const ISC_BADDRESS = " isc_baddress_s " ;
2001-05-23 15:26:42 +02:00
# endif
2003-10-15 00:22:32 +02:00
# ifdef GIVING_SUPPORTED
2003-10-16 10:51:06 +02:00
static const char * const FETCH_CALL_TEMPLATE = " CALL \" %s \" USING %s, %s%s, %s%d%s, %s%s GIVING SQLCODE " ;
static const char * const GET_LEN_CALL_TEMPLATE = " CALL %s USING %s GIVING %s " ;
static const char * const EVENT_MOVE_TEMPLATE = " CALL \" %s \" USING %s(%d) GIVING %s(%d) " ;
static const char * const GET_SEG_CALL_TEMPLATE = " %sCALL \" %s \" USING %s, %s%d, %s%d, %s%d%s, %s%s%d GIVING %s (2) \n " ;
static const char * const PUT_SEG_CALL_TEMPLATE = " %sCALL \" %s \" USING %s, %s%s%d, %s%s%d%s, %s%s%d GIVING %s (2) \n "
static const char * const SQLCODE_CALL_TEMPLATE = " CALL \" %s \" USING %s GIVING SQLCODE " ;
2003-10-15 00:22:32 +02:00
# else
2003-10-16 10:51:06 +02:00
static const char * const FETCH_CALL_TEMPLATE = " CALL \" %s \" USING %s, BY REFERENCE SQLCODE, %s%s, %s%d%s, %s%s " ;
static const char * const GET_LEN_CALL_TEMPLATE = " CALL %s USING %s, %s " ;
static const char * const EVENT_MOVE_TEMPLATE = " CALL \" %s \" USING %s(%d), %s(%d) " ;
static const char * const GET_SEG_CALL_TEMPLATE = " %sCALL \" %s \" USING %s, %s%d, %s%d, %s%d%s, %s%s%d \n " ;
static const char * const PUT_SEG_CALL_TEMPLATE = " %sCALL \" %s \" USING %s, %s%s%d, %s%s%d%s, %s%s%d \n " ;
static const char * const SQLCODE_CALL_TEMPLATE = " CALL \" %s \" USING %s, BY REFERENCE SQLCODE " ;
2003-10-15 00:22:32 +02:00
# endif // GIVING_SUPPORTED
2005-02-17 13:51:13 +01:00
# if defined AIX || defined AIX_PPC || defined SOLARIS || defined HP10 || defined HP11
2003-10-16 10:51:06 +02:00
static const char * const USAGE_COMP = " USAGE IS COMP " ;
2003-10-15 00:22:32 +02:00
# else
2003-10-16 10:51:06 +02:00
static const char * const USAGE_COMP = " USAGE IS COMP " ;
2001-05-23 15:26:42 +02:00
# endif
# ifndef FLOATS_COMPS_DECLARED
2003-10-16 10:51:06 +02:00
static const char * const DCL_FLOAT = " USAGE IS COMP-1 " ;
static const char * const DCL_DOUBLE = " USAGE IS COMP-2 " ;
2001-05-23 15:26:42 +02:00
# endif
2003-04-03 10:52:45 +02:00
# ifdef NOT_USED_OR_REPLACED
2002-07-06 07:32:02 +02:00
static void align ( int column ) ;
2003-04-03 10:52:45 +02:00
# endif
2004-11-28 04:43:42 +01:00
static void asgn_from ( const act * , const ref * ) ;
static void asgn_to ( const act * , ref * ) ;
static void asgn_to_proc ( const ref * ) ;
2003-10-06 11:48:44 +02:00
static void gen_any ( const act * ) ;
static void gen_at_end ( const act * ) ;
static void gen_based ( const act * ) ;
static void gen_blob_close ( const act * ) ;
static void gen_blob_end ( const act * ) ;
static void gen_blob_for ( const act * ) ;
static void gen_blob_open ( const act * ) ;
2003-09-29 14:43:14 +02:00
static void gen_blr ( void * , SSHORT , const char * ) ;
2003-10-06 11:48:44 +02:00
static void gen_clear_handles ( const act * ) ;
static void gen_compile ( const act * ) ;
static void gen_create_database ( const act * ) ;
2004-11-28 04:43:42 +01:00
static void gen_cursor_close ( const act * , const gpre_req * ) ;
2003-10-06 11:48:44 +02:00
static void gen_cursor_init ( const act * ) ;
2004-11-28 04:43:42 +01:00
static void gen_cursor_open ( const act * , const gpre_req * ) ;
2003-10-06 11:48:44 +02:00
static void gen_database ( const act * ) ;
static void gen_ddl ( const act * ) ;
static void gen_dyn_close ( const act * ) ;
static void gen_dyn_declare ( const act * ) ;
static void gen_dyn_describe ( const act * , bool ) ;
static void gen_dyn_execute ( const act * ) ;
static void gen_dyn_fetch ( const act * ) ;
static void gen_dyn_immediate ( const act * ) ;
static void gen_dyn_insert ( const act * ) ;
static void gen_dyn_open ( const act * ) ;
static void gen_dyn_prepare ( const act * ) ;
static void gen_emodify ( const act * ) ;
static void gen_estore ( const act * ) ;
static void gen_end_fetch ( const act * ) ;
static void gen_endfor ( const act * ) ;
static void gen_erase ( const act * ) ;
static SSHORT gen_event_block ( const act * ) ;
static void gen_event_init ( const act * ) ;
static void gen_event_wait ( const act * ) ;
static void gen_fetch ( const act * ) ;
static void gen_finish ( const act * ) ;
static void gen_for ( const act * ) ;
static void gen_function ( const act * ) ;
2004-11-28 04:43:42 +01:00
static void gen_get_or_put_slice ( const act * , const ref * , bool ) ;
2003-10-06 11:48:44 +02:00
static void gen_get_segment ( const act * ) ;
static void gen_loop ( const act * ) ;
2005-01-05 09:25:24 +01:00
static TEXT * gen_name ( TEXT * const , const ref * , bool ) ;
2003-10-06 11:48:44 +02:00
static void gen_on_error ( const act * ) ;
static void gen_procedure ( const act * ) ;
static void gen_put_segment ( const act * ) ;
2004-11-28 04:43:42 +01:00
static void gen_raw ( const UCHAR * , enum req_t , int , int ) ;
2003-10-06 11:48:44 +02:00
static void gen_ready ( const act * ) ;
2004-11-28 04:43:42 +01:00
static void gen_receive ( const act * , const gpre_port * ) ;
2003-10-06 11:48:44 +02:00
static void gen_release ( const act * ) ;
2004-01-28 08:50:41 +01:00
static void gen_request ( gpre_req * ) ;
2003-10-06 11:48:44 +02:00
static void gen_s_end ( const act * ) ;
static void gen_s_fetch ( const act * ) ;
static void gen_s_start ( const act * ) ;
static void gen_segment ( const act * ) ;
static void gen_select ( const act * ) ;
2004-11-28 04:43:42 +01:00
static void gen_send ( const act * , const gpre_port * ) ;
2003-10-06 11:48:44 +02:00
static void gen_slice ( const act * ) ;
2004-11-28 04:43:42 +01:00
static void gen_start ( const act * , const gpre_port * ) ;
2003-10-06 11:48:44 +02:00
static void gen_store ( const act * ) ;
static void gen_t_start ( const act * ) ;
2004-11-28 04:43:42 +01:00
static void gen_tpb ( const tpb * ) ;
2003-10-06 11:48:44 +02:00
static void gen_trans ( const act * ) ;
static void gen_type ( const act * ) ;
static void gen_update ( const act * ) ;
static void gen_variable ( const act * ) ;
2003-11-28 07:48:34 +01:00
static void gen_whenever ( const swe * ) ;
2002-07-06 07:32:02 +02:00
static void make_array_declaration ( REF ) ;
2005-01-05 09:25:24 +01:00
static void make_name ( TEXT * const , const gpre_sym * ) ;
static void make_name_formatted ( TEXT * const , const TEXT * , const gpre_sym * ) ;
2004-01-28 08:50:41 +01:00
static void make_port ( const gpre_port * ) ;
2003-10-29 11:53:47 +01:00
static void make_ready ( const dbb * , const TEXT * , const TEXT * , const gpre_req * ,
USHORT ) ;
2003-10-06 11:48:44 +02:00
static void printa ( const TEXT * , bool , const TEXT * , . . . ) ATTRIBUTE_FORMAT ( 3 , 4 ) ;
2003-04-03 10:52:45 +02:00
# ifdef NOT_USED_OR_REPLACED
2003-10-29 11:53:47 +01:00
static void printb ( const TEXT * , . . . ) ATTRIBUTE_FORMAT ( 1 , 2 ) ;
2003-04-03 10:52:45 +02:00
# endif
2003-10-29 11:53:47 +01:00
static const TEXT * request_trans ( const act * , const gpre_req * ) ;
2003-10-06 11:48:44 +02:00
static void set_sqlcode ( const act * ) ;
static const TEXT * status_vector ( const act * ) ;
2003-10-29 11:53:47 +01:00
static void t_start_auto ( const gpre_req * , const TEXT * , const act * , bool ) ;
2001-05-23 15:26:42 +02:00
static TEXT output_buffer [ 512 ] ;
2003-10-29 11:53:47 +01:00
static bool global_first_flag = false ;
2003-10-06 11:48:44 +02:00
static const TEXT * * names ;
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static const TEXT * vnames [ ] = {
2001-05-23 15:26:42 +02:00
" _ " ,
" ISC_ " ,
" isc_ " ,
" isc_blob_null " ,
" ISC_TPB_ " ,
" ISC_TRANS " ,
" ISC_STATUS_VECTOR " ,
" ISC_STATUS " ,
" ISC_STATUS_VECTOR2 " ,
" ISC_STATUS2 " ,
" ISC_WINDOW " ,
" ISC_WIDTH " ,
" ISC_HEIGHT " ,
2007-04-01 15:04:13 +02:00
" RDB_K_DB_TYPE_GDS " ,
2001-05-23 15:26:42 +02:00
" ISC_ARRAY_LENGTH " ,
2008-12-05 02:20:14 +01:00
" " , // column
" * " , // comment
" - " , // continue
" - \" " , // continue quote
" - \' " , // continue single quote
" " , // column0
" " , // column indent
2001-05-23 15:26:42 +02:00
" ISC_SQLCODE " ,
" ISC_EVENTS_VECTOR " ,
" ISC_EVENTS " ,
" ISC_EVENT_NAMES_VECTOR " ,
" ISC_EVENT_NAMES " ,
" ISC_EVENT_NAMES_VECTOR2 " ,
" ISC_EVENT_NAMES2 " ,
NULL
} ;
2003-10-06 11:48:44 +02:00
static const TEXT * anames [ ] = {
2001-05-23 15:26:42 +02:00
" - " ,
" ISC- " ,
" isc- " ,
" isc-blob-null " ,
" ISC-TPB- " ,
" ISC-TRANS " ,
" ISC-STATUS-VECTOR " ,
" ISC-STATUS " ,
" ISC-STATUS-VECTOR2 " ,
" ISC-STATUS2 " ,
" ISC-WINDOW " ,
" ISC-WIDTH " ,
" ISC-HEIGHT " ,
" RDB-K-DB-TYPE-GDS " ,
" ISC-ARRAY-LENGTH " ,
2008-12-05 02:20:14 +01:00
" " , // column
" * " , // comment
" " , // continue
" - \" " , // continue quote
" - \' " , // continue single quote
" " , // column0
" " , // column indent
2001-05-23 15:26:42 +02:00
" ISC-SQL-CODE " ,
" ISC-EVENTS-VECTOR " ,
" ISC-EVENTS " ,
" ISC-EVENT-NAMES-VECTOR " ,
" ISC-EVENT-NAMES " ,
" ISC-EVENT-NAMES-VECTOR2 " ,
" ISC-EVENT-NAMES2 " ,
NULL
} ;
2003-10-15 00:22:32 +02:00
enum {
UNDER ,
isc_a_pos ,
isc_b_pos ,
isc_blob_null_pos ,
isc_tpb_pos ,
isc_trans_pos ,
isc_status_vector_pos ,
isc_status_pos ,
isc_status_vector2_pos ,
ISC_STATUS2 ,
ISC_WINDOW ,
ISC_WIDTH ,
ISC_HEIGHT ,
2007-04-01 15:04:13 +02:00
RDB_K_DB_TYPE_GDS ,
2003-10-15 00:22:32 +02:00
ISC_ARRAY_LENGTH ,
COLUMN ,
COMMENT ,
CONTINUE ,
CONTINUE_QUOTE ,
CONTINUE_SINGLE_QUOTE ,
COLUMN_0 ,
COLUMN_INDENT ,
ISC_SQLCODE ,
ISC_EVENTS_VECTOR ,
ISC_EVENTS ,
ISC_EVENT_NAMES_VECTOR ,
ISC_EVENT_NAMES ,
ISC_EVENT_NAMES_VECTOR2 ,
ISC_EVENT_NAMES2
} ;
2003-10-16 10:51:06 +02:00
static const char * const INDENT = " " ;
2001-05-23 15:26:42 +02:00
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
void COB_action ( const act * action , int column )
2001-05-23 15:26:42 +02:00
{
if ( action - > act_flags & ACT_break )
2003-10-29 11:53:47 +01:00
global_first_flag = false ;
2001-05-23 15:26:42 +02:00
switch ( action - > act_type ) {
case ACT_alter_database :
case ACT_alter_domain :
case ACT_alter_table :
case ACT_alter_index :
case ACT_create_domain :
case ACT_create_generator :
case ACT_create_index :
case ACT_create_shadow :
case ACT_create_table :
case ACT_create_view :
case ACT_declare_filter :
case ACT_declare_udf :
case ACT_statistics :
case ACT_drop_domain :
case ACT_drop_filter :
case ACT_drop_index :
case ACT_drop_shadow :
case ACT_drop_table :
case ACT_drop_udf :
case ACT_drop_view :
gen_ddl ( action ) ;
break ;
case ACT_any :
gen_any ( action ) ;
return ;
case ACT_at_end :
gen_at_end ( action ) ;
return ;
case ACT_commit :
gen_trans ( action ) ;
break ;
case ACT_commit_retain_context :
gen_trans ( action ) ;
break ;
case ACT_basedon :
gen_based ( action ) ;
return ;
case ACT_b_declare :
gen_database ( action ) ;
return ;
case ACT_blob_cancel :
gen_blob_close ( action ) ;
return ;
case ACT_blob_close :
gen_blob_close ( action ) ;
break ;
case ACT_blob_create :
gen_blob_open ( action ) ;
break ;
case ACT_blob_for :
gen_blob_for ( action ) ;
return ;
case ACT_blob_handle :
gen_segment ( action ) ;
return ;
case ACT_blob_open :
gen_blob_open ( action ) ;
break ;
case ACT_clear_handles :
gen_clear_handles ( action ) ;
break ;
case ACT_close :
gen_s_end ( action ) ;
break ;
case ACT_create_database :
gen_create_database ( action ) ;
break ;
case ACT_cursor :
gen_cursor_init ( action ) ;
return ;
case ACT_database :
gen_database ( action ) ;
return ;
case ACT_disconnect :
gen_finish ( action ) ;
break ;
case ACT_dyn_close :
gen_dyn_close ( action ) ;
break ;
case ACT_dyn_cursor :
gen_dyn_declare ( action ) ;
break ;
case ACT_dyn_describe :
2003-09-10 21:48:53 +02:00
gen_dyn_describe ( action , false ) ;
2001-05-23 15:26:42 +02:00
break ;
case ACT_dyn_describe_input :
2003-09-10 21:48:53 +02:00
gen_dyn_describe ( action , true ) ;
2001-05-23 15:26:42 +02:00
break ;
case ACT_dyn_execute :
gen_dyn_execute ( action ) ;
break ;
case ACT_dyn_fetch :
gen_dyn_fetch ( action ) ;
break ;
case ACT_dyn_grant :
gen_ddl ( action ) ;
break ;
case ACT_dyn_immediate :
gen_dyn_immediate ( action ) ;
break ;
case ACT_dyn_insert :
gen_dyn_insert ( action ) ;
break ;
case ACT_dyn_open :
gen_dyn_open ( action ) ;
break ;
case ACT_dyn_prepare :
gen_dyn_prepare ( action ) ;
break ;
case ACT_dyn_revoke :
gen_ddl ( action ) ;
break ;
case ACT_endblob :
gen_blob_end ( action ) ;
return ;
case ACT_enderror :
sprintf ( output_buffer , " %sEND-IF " , names [ COLUMN ] ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
return ;
case ACT_endfor :
gen_endfor ( action ) ;
break ;
case ACT_endmodify :
gen_emodify ( action ) ;
break ;
case ACT_endstore :
gen_estore ( action ) ;
break ;
case ACT_erase :
gen_erase ( action ) ;
return ;
case ACT_event_init :
gen_event_init ( action ) ;
return ;
case ACT_event_wait :
gen_event_wait ( action ) ;
return ;
case ACT_fetch :
gen_fetch ( action ) ;
break ;
case ACT_finish :
gen_finish ( action ) ;
break ;
case ACT_for :
gen_for ( action ) ;
return ;
case ACT_function :
gen_function ( action ) ;
return ;
case ACT_get_segment :
gen_get_segment ( action ) ;
break ;
case ACT_get_slice :
gen_slice ( action ) ;
return ;
case ACT_hctef :
gen_end_fetch ( action ) ;
return ;
case ACT_insert :
gen_s_start ( action ) ;
break ;
case ACT_loop :
gen_loop ( action ) ;
break ;
case ACT_open :
gen_s_start ( action ) ;
break ;
case ACT_on_error :
gen_on_error ( action ) ;
return ;
case ACT_prepare :
gen_trans ( action ) ;
break ;
case ACT_procedure :
gen_procedure ( action ) ;
break ;
case ACT_put_segment :
gen_put_segment ( action ) ;
break ;
case ACT_put_slice :
gen_slice ( action ) ;
return ;
case ACT_ready :
gen_ready ( action ) ;
return ;
case ACT_release :
gen_release ( action ) ;
break ;
case ACT_rfinish :
gen_finish ( action ) ;
return ;
case ACT_rollback :
gen_trans ( action ) ;
break ;
2008-01-16 08:15:01 +01:00
case ACT_rollback_retain_context :
gen_trans ( action ) ;
break ;
2001-05-23 15:26:42 +02:00
case ACT_routine :
return ;
case ACT_s_end :
gen_s_end ( action ) ;
return ;
case ACT_s_fetch :
gen_s_fetch ( action ) ;
break ;
case ACT_s_start :
gen_s_start ( action ) ;
break ;
case ACT_select :
gen_select ( action ) ;
break ;
case ACT_segment_length :
gen_segment ( action ) ;
return ;
case ACT_segment :
gen_segment ( action ) ;
return ;
case ACT_sql_dialect :
2004-05-24 19:13:38 +02:00
gpreGlob . sw_sql_dialect = ( ( SDT ) action - > act_object ) - > sdt_dialect ;
2001-05-23 15:26:42 +02:00
return ;
case ACT_start :
gen_t_start ( action ) ;
break ;
case ACT_store :
gen_store ( action ) ;
break ;
2003-10-06 11:48:44 +02:00
case ACT_type_number :
2001-05-23 15:26:42 +02:00
gen_type ( action ) ;
return ;
case ACT_update :
gen_update ( action ) ;
break ;
case ACT_variable :
gen_variable ( action ) ;
return ;
default :
return ;
}
if ( ( action - > act_flags & ACT_sql ) & & action - > act_whenever )
gen_whenever ( action - > act_whenever ) ;
else
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , names [ COLUMN ] ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// point 'names' at the appropriate list
// ANSI has no underscores.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-09-10 21:48:53 +02:00
void COB_name_init ( bool ansi )
2001-05-23 15:26:42 +02:00
{
names = ansi ? anames : vnames ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Print a statment, breaking it into
// reasonable 80 character hunks. This
// function now works for COBOL statements
// which are function calls and non-function
// calls.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2004-05-12 21:39:17 +02:00
void COB_print_buffer ( TEXT * output_bufferL ,
2003-09-10 21:48:53 +02:00
bool function_call )
2001-05-23 15:26:42 +02:00
{
2004-11-10 05:26:45 +01:00
TEXT s [ 80 ] ;
2003-09-10 21:48:53 +02:00
bool open_quote = false ;
bool single_quote = false ;
bool save_open_quote ;
bool save_single_quote ;
2001-05-23 15:26:42 +02:00
USHORT max_line ;
2006-11-10 08:50:13 +01:00
if ( isAnsiCobol ( gpreGlob . sw_cob_dialect ) )
2001-05-23 15:26:42 +02:00
max_line = 72 ;
else
max_line = 79 ;
2004-11-10 05:26:45 +01:00
TEXT * p = s ;
2001-05-23 15:26:42 +02:00
2004-05-12 21:39:17 +02:00
for ( const TEXT * q = output_bufferL ; * q ; q + + ) {
2001-05-23 15:26:42 +02:00
* p + + = * q ;
/* If we have a single or double quote, toggle the
quote switch and indicate single or double quote */
if ( * q = = ' \" ' ) {
2003-09-10 21:48:53 +02:00
open_quote = ! open_quote ;
single_quote = false ;
2001-05-23 15:26:42 +02:00
}
else if ( * q = = ' \' ' ) {
2003-09-10 21:48:53 +02:00
open_quote = ! open_quote ;
single_quote = true ;
2001-05-23 15:26:42 +02:00
}
if ( ( p - s ) > max_line ) {
2003-10-06 11:48:44 +02:00
const TEXT * tempq = q ;
2001-05-23 15:26:42 +02:00
save_open_quote = open_quote ;
save_single_quote = single_quote ;
if ( function_call ) {
2008-12-05 02:20:14 +01:00
// Back up until we reach a comma
2001-05-23 15:26:42 +02:00
for ( p - - ; ( p > s ) ; p - - , q - - ) {
if ( * ( p + 1 ) = = ' \" ' | | * ( p + 1 ) = = ' \' ' ) {
/* If we have a single or double quote, toggle the
quote switch and indicate single or double quote */
2003-09-10 21:48:53 +02:00
open_quote = ! open_quote ;
2001-05-23 15:26:42 +02:00
if ( open_quote )
2003-09-10 21:48:53 +02:00
single_quote = ( * ( p + 1 ) = = ' \' ' ) ;
2001-05-23 15:26:42 +02:00
else
2003-09-10 21:48:53 +02:00
single_quote = false ;
2001-05-23 15:26:42 +02:00
}
2008-06-03 08:14:59 +02:00
if ( ! open_quote & & * p = = ' , ' )
2001-05-23 15:26:42 +02:00
break ;
}
/* if p == s, this is a call with no commas. back up to a blank */
if ( p = = s ) {
q = tempq ;
p = s + max_line ;
open_quote = save_open_quote ;
single_quote = save_single_quote ;
for ( p - - ; p > s ; p - - , q - - ) {
if ( * ( p + 1 ) = = ' \" ' | | * ( p + 1 ) = = ' \' ' ) {
/* If we have a single or double quote, toggle the
quote switch and indicate single or double quote */
2003-09-10 21:48:53 +02:00
open_quote = ! open_quote ;
2001-05-23 15:26:42 +02:00
if ( open_quote )
2003-09-10 21:48:53 +02:00
single_quote = ( * ( p + 1 ) = = ' \' ' ) ;
2001-05-23 15:26:42 +02:00
else
2003-09-10 21:48:53 +02:00
single_quote = false ;
2001-05-23 15:26:42 +02:00
}
2008-06-03 08:14:59 +02:00
if ( ! open_quote & & * p = = ' ' )
2001-05-23 15:26:42 +02:00
break ;
}
q - - ;
if ( p = = s ) {
q = tempq - 1 ;
p = s + max_line ;
open_quote = save_open_quote ;
single_quote = save_single_quote ;
}
* p = 0 ;
}
else
* + + p = 0 ;
}
else {
2008-12-05 02:20:14 +01:00
// back up to a blank
2001-05-23 15:26:42 +02:00
for ( p - - ; p > s ; p - - , q - - ) {
if ( * ( p + 1 ) = = ' \" ' | | * ( p + 1 ) = = ' \' ' ) {
/* If we have a single or double quote, toggle the
quote switch and indicate single or double quote */
2003-09-10 21:48:53 +02:00
open_quote = ! open_quote ;
2001-05-23 15:26:42 +02:00
if ( open_quote )
2003-09-10 21:48:53 +02:00
single_quote = ( * ( p + 1 ) = = ' \' ' ) ;
2001-05-23 15:26:42 +02:00
else
2003-09-10 21:48:53 +02:00
single_quote = false ;
2001-05-23 15:26:42 +02:00
}
2008-06-03 08:14:59 +02:00
if ( ! open_quote & & * p = = ' ' )
2001-05-23 15:26:42 +02:00
break ;
}
q - - ;
if ( p = = s ) {
q = tempq - 1 ;
p = s + max_line ;
open_quote = save_open_quote ;
single_quote = save_single_quote ;
}
* p = 0 ;
}
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s \n " , s ) ;
2001-05-23 15:26:42 +02:00
if ( open_quote ) {
if ( single_quote )
strcpy ( s , names [ CONTINUE_SINGLE_QUOTE ] ) ;
else
strcpy ( s , names [ CONTINUE_QUOTE ] ) ;
}
else
strcpy ( s , names [ CONTINUE ] ) ;
for ( p = s ; * p ; p + + ) ;
}
}
* p = 0 ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s " , s ) ;
2004-05-12 21:39:17 +02:00
output_bufferL [ 0 ] = 0 ;
2001-05-23 15:26:42 +02:00
}
2003-04-03 10:52:45 +02:00
# ifdef NOT_USED_OR_REPLACED
2001-05-23 15:26:42 +02:00
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Align output to a specific column for output. If the
// column is negative, don't do anything.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2002-07-06 07:32:02 +02:00
static void align ( int column )
2001-05-23 15:26:42 +02:00
{
if ( column < 0 )
2002-07-06 07:32:02 +02:00
return ;
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
putc ( ' \n ' , gpreGlob . out_file ) ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
int i ;
2001-05-23 15:26:42 +02:00
for ( i = column / 8 ; i ; - - i )
2004-05-24 19:13:38 +02:00
putc ( ' \t ' , gpreGlob . out_file ) ;
2001-05-23 15:26:42 +02:00
for ( i = column % 8 ; i ; - - i )
2004-05-24 19:13:38 +02:00
putc ( ' ' , gpreGlob . out_file ) ;
2001-05-23 15:26:42 +02:00
}
2003-04-03 10:52:45 +02:00
# endif
2001-05-23 15:26:42 +02:00
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Build an assignment from a host language variable to
// a port variable.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
static void asgn_from ( const act * action , const ref * reference )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT name [ MAX_REF_SIZE ] , variable [ MAX_REF_SIZE ] , temp [ MAX_REF_SIZE ] ;
2001-05-23 15:26:42 +02:00
for ( ; reference ; reference = reference - > ref_next ) {
2004-11-28 04:43:42 +01:00
const gpre_fld * field = reference - > ref_field ;
2001-05-23 15:26:42 +02:00
if ( field - > fld_array_info )
if ( ! ( reference - > ref_flags & REF_array_elem ) ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true , " CALL \" isc_qtoq \" USING %s, %s " ,
2003-10-15 00:22:32 +02:00
names [ isc_blob_null_pos ] , gen_name ( name , reference , true ) ) ;
2003-09-10 21:48:53 +02:00
gen_get_or_put_slice ( action , reference , false ) ;
2001-05-23 15:26:42 +02:00
continue ;
}
if ( ! reference - > ref_source & & ! reference - > ref_value )
continue ;
2003-09-10 21:48:53 +02:00
gen_name ( variable , reference , true ) ;
2004-11-28 04:43:42 +01:00
const char * value ;
2001-05-23 15:26:42 +02:00
if ( reference - > ref_source )
2003-09-10 21:48:53 +02:00
value = gen_name ( temp , reference - > ref_source , true ) ;
2001-05-23 15:26:42 +02:00
else
value = reference - > ref_value ;
if ( ! reference - > ref_master | | ( reference - > ref_flags & REF_literal ) )
sprintf ( output_buffer , " %sMOVE %s TO %s \n " ,
names [ COLUMN ] , value , variable ) ;
else {
sprintf ( output_buffer , " %sIF %s < 0 THEN \n " ,
names [ COLUMN ] , value ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer , " %sMOVE -1 TO %s \n " , names [ COLUMN_INDENT ] ,
variable ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer , " %sELSE \n " , names [ COLUMN ] ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer , " %sMOVE 0 TO %s \n " , names [ COLUMN_INDENT ] ,
variable ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer , " %sEND-IF \n " , names [ COLUMN ] ) ;
}
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Build an assignment to a host language variable from
// a port variable.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
static void asgn_to ( const act * action , ref * reference )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_REF_SIZE ] ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
ref * source = reference - > ref_friend ;
const gpre_fld * field = source - > ref_field ;
2003-09-10 21:48:53 +02:00
gen_name ( s , source , true ) ;
2001-05-23 15:26:42 +02:00
if ( field - > fld_array_info ) {
source - > ref_value = reference - > ref_value ;
2003-09-10 21:48:53 +02:00
gen_get_or_put_slice ( action , source , true ) ;
2002-07-06 07:32:02 +02:00
return ;
2001-05-23 15:26:42 +02:00
}
field = reference - > ref_field ;
sprintf ( output_buffer , " %sMOVE %s TO %s \n " ,
names [ COLUMN ] , s , reference - > ref_value ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// Pick up NULL value if one is there
2001-05-23 15:26:42 +02:00
if ( reference = reference - > ref_null ) {
sprintf ( output_buffer , " %sMOVE %s TO %s \n " ,
2003-09-10 21:48:53 +02:00
names [ COLUMN ] , gen_name ( s , reference , true ) ,
2001-05-23 15:26:42 +02:00
reference - > ref_value ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Build an assignment to a host language variable from
// a port variable.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
static void asgn_to_proc ( const ref * reference )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_REF_SIZE ] ;
2001-05-23 15:26:42 +02:00
for ( ; reference ; reference = reference - > ref_next ) {
if ( ! reference - > ref_value )
continue ;
2004-11-28 04:43:42 +01:00
//gpre_fld* field = reference->ref_field;
2003-09-10 21:48:53 +02:00
gen_name ( s , reference , true ) ;
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer , " %sMOVE %s TO %s \n " ,
names [ COLUMN ] , s , reference - > ref_value ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a function call for free standing ANY. Somebody else
// will need to generate the actual function.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_any ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s_r (&%s, &%s " ,
2001-05-23 15:26:42 +02:00
request - > req_handle , request - > req_handle , request - > req_trans ) ;
2004-11-28 04:43:42 +01:00
const gpre_port * port = request - > req_vport ;
if ( port )
for ( const ref * reference = port - > por_references ; reference ;
2001-05-23 15:26:42 +02:00
reference = reference - > ref_next )
2004-11-28 04:43:42 +01:00
{
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " , %s " , reference - > ref_value ) ;
2004-11-28 04:43:42 +01:00
}
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " ) " ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate code for AT END clause of FETCH.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_at_end ( const act * action )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_REF_SIZE ] ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false ,
" IF %s = 0 THEN " , gen_name ( s , request - > req_eof , true ) ) ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , names [ COLUMN ] ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Substitute for a BASED ON <field name> clause.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_based ( const act * action )
2001-05-23 15:26:42 +02:00
{
USHORT datatype ;
2004-11-28 04:43:42 +01:00
const bas * based_on = ( bas * ) action - > act_object ;
const gpre_fld * field = based_on - > bas_field ;
2001-05-23 15:26:42 +02:00
if ( based_on - > bas_flags & BAS_segment ) {
datatype = dtype_text ;
2004-11-28 04:43:42 +01:00
SLONG length = field - > fld_seg_length ;
if ( ! length )
2001-05-23 15:26:42 +02:00
length = 256 ;
}
else if ( field - > fld_array_info ) {
2003-10-15 00:22:32 +02:00
CPR_error ( " Based on currently not implemented for arrays. " ) ;
2004-08-26 23:44:11 +02:00
return ; // silence non initialized warning
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// TBD - messy
// datatype = field->fld_array_info->ary_dtype;
// for (dimension = field->fld_array_info->ary_dimension; dimension;
// dimension = dimension->dim_next)
2008-12-05 02:20:14 +01:00
// {
2004-05-24 19:13:38 +02:00
// fprintf (gpreGlob.out_file, "
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
}
else
datatype = field - > fld_dtype ;
2004-11-28 04:43:42 +01:00
SSHORT digits ;
2001-05-23 15:26:42 +02:00
switch ( datatype ) {
case dtype_short :
case dtype_long :
digits = ( datatype = = dtype_short ) ? 4 : 9 ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %sPIC S " , names [ COLUMN ] ) ;
2001-05-23 15:26:42 +02:00
if ( field - > fld_scale > = - digits & & field - > fld_scale < = 0 ) {
if ( field - > fld_scale > - digits )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " 9(%d) " , digits + field - > fld_scale ) ;
2001-05-23 15:26:42 +02:00
if ( field - > fld_scale )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " V9(%d) " ,
2001-05-23 15:26:42 +02:00
digits - ( digits + field - > fld_scale ) ) ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , USAGE_COMP ) ;
2001-05-23 15:26:42 +02:00
}
else if ( field - > fld_scale > 0 )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " 9(%d)P(%d) " , digits , field - > fld_scale ) ;
2001-05-23 15:26:42 +02:00
else
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " VP(%d)9(%d) " , - ( field - > fld_scale + digits ) ,
2001-05-23 15:26:42 +02:00
digits ) ;
break ;
case dtype_date :
case dtype_blob :
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %sPIC S9(18)%s " , names [ COLUMN ] , USAGE_COMP ) ;
2001-05-23 15:26:42 +02:00
break ;
case dtype_quad :
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %sPIC S9( " , names [ COLUMN ] ) ;
fprintf ( gpreGlob . out_file , " %d) " , 18 + field - > fld_scale ) ;
2001-05-23 15:26:42 +02:00
if ( field - > fld_scale < 0 )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " V9(%d) " , - field - > fld_scale ) ;
2001-05-23 15:26:42 +02:00
else if ( field - > fld_scale > 0 )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " P(%d) " , field - > fld_scale ) ;
fprintf ( gpreGlob . out_file , USAGE_COMP ) ;
2001-05-23 15:26:42 +02:00
break ;
case dtype_text :
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %sPIC X(%d) " , names [ COLUMN ] , field - > fld_length ) ;
2001-05-23 15:26:42 +02:00
break ;
2003-10-15 00:22:32 +02:00
case dtype_real :
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s%s " , names [ COLUMN ] , DCL_FLOAT ) ;
2001-05-23 15:26:42 +02:00
break ;
case dtype_double :
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s%s " , names [ COLUMN ] , DCL_DOUBLE ) ;
2001-05-23 15:26:42 +02:00
break ;
default :
2004-11-28 04:43:42 +01:00
{
TEXT s [ 64 ] ;
sprintf ( s , " datatype %d unknown \n " , field - > fld_dtype ) ;
CPR_error ( s ) ;
return ;
}
2001-05-23 15:26:42 +02:00
}
if ( * based_on - > bas_terminator = = ' . ' )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s \n " , based_on - > bas_terminator ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Make a blob FOR loop.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_blob_close ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const blb * blob ;
2001-05-23 15:26:42 +02:00
if ( action - > act_flags & ACT_sql ) {
gen_cursor_close ( action , action - > act_request ) ;
2004-01-28 08:50:41 +01:00
blob = ( blb * ) action - > act_request - > req_blobs ;
2001-05-23 15:26:42 +02:00
}
else
2004-01-28 08:50:41 +01:00
blob = ( blb * ) action - > act_object ;
2001-05-23 15:26:42 +02:00
2004-10-30 07:30:08 +02:00
const TEXT * command = ( action - > act_type = = ACT_blob_cancel ) ? CANCEL : CLOSE ;
TEXT buffer [ 80 ] ;
2001-05-23 15:26:42 +02:00
sprintf ( buffer , ISC_BLOB , command ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true , " CALL \" %s \" USING %s, %s%s%d " ,
2001-05-23 15:26:42 +02:00
buffer ,
2003-10-15 00:22:32 +02:00
status_vector ( action ) , BY_REF , names [ isc_a_pos ] , blob - > blb_ident ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// End a blob FOR loop.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_blob_end ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const blb * blob = ( blb * ) action - > act_object ;
2001-05-23 15:26:42 +02:00
gen_get_segment ( action ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-PERFORM " ) ;
2001-05-23 15:26:42 +02:00
if ( action - > act_error )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" %sCALL \" %s \" USING %s%s, %s%s%d " ,
INDENT ,
ISC_CANCEL_BLOB ,
2003-10-15 00:22:32 +02:00
BY_REF , names [ isc_status_vector2_pos ] ,
BY_REF , names [ isc_a_pos ] , blob - > blb_ident ) ;
2001-05-23 15:26:42 +02:00
else
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" %sCALL \" %s \" USING %s, %s%s%d " ,
INDENT , ISC_CANCEL_BLOB ,
2003-10-15 00:22:32 +02:00
status_vector ( 0 ) , BY_REF , names [ isc_a_pos ] , blob - > blb_ident ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Make a blob FOR loop.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_blob_for ( const act * action )
2001-05-23 15:26:42 +02:00
{
gen_blob_open ( action ) ;
gen_get_segment ( action ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " PERFORM UNTIL " ) ;
2001-05-23 15:26:42 +02:00
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " %s%s(2) NOT = 0 AND %s(2) NOT = 335544366 " ,
2003-10-15 00:22:32 +02:00
INDENT , names [ isc_status_pos ] , names [ isc_status_pos ] ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate the call to open (or create) a blob.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_blob_open ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-10-30 07:30:08 +02:00
const TEXT * pattern1 =
" CALL \" isc_%IFcreate%ELopen%EN_blob2 \" USING %V1, %RF%DH%RE, %RF%RT%RE, %RF%BH%RE, %RF%FR%RE, %VF%N1%VE, %RF%I1%RE \n " ;
const TEXT * pattern2 =
2001-05-23 15:26:42 +02:00
" CALL \" isc_%IFcreate%ELopen%EN_blob2 \" USING %V1, %RF%DH%RE, %RF%RT%RE, %RF%BH%RE, %RF%FR%RE, %VF0%VE, %VF0%VE \n " ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto & & ( action - > act_flags & ACT_sql ) ) {
2003-09-10 21:48:53 +02:00
t_start_auto ( action - > act_request , status_vector ( action ) , action , true ) ;
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " ,
2001-05-23 15:26:42 +02:00
request_trans ( action , action - > act_request ) ) ;
}
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_REF_SIZE ] ;
2004-11-28 04:43:42 +01:00
const blb * blob ;
2003-10-29 11:53:47 +01:00
const ref * reference ;
2001-05-23 15:26:42 +02:00
if ( action - > act_flags & ACT_sql ) {
gen_cursor_open ( action , action - > act_request ) ;
2004-01-28 08:50:41 +01:00
blob = ( blb * ) action - > act_request - > req_blobs ;
reference = ( ( open_cursor * ) action - > act_object ) - > opn_using ;
2003-09-10 21:48:53 +02:00
gen_name ( s , reference , true ) ;
2001-05-23 15:26:42 +02:00
}
else {
2004-01-28 08:50:41 +01:00
blob = ( blb * ) action - > act_object ;
2001-05-23 15:26:42 +02:00
reference = blob - > blb_reference ;
}
2003-10-29 11:53:47 +01:00
const USHORT column = strlen ( names [ COLUMN ] ) ;
PAT args ;
2003-09-11 04:13:46 +02:00
args . pat_condition = ( action - > act_type = = ACT_blob_create ) ; // open or create blob
args . pat_vector1 = status_vector ( action ) ; // status vector
args . pat_database = blob - > blb_request - > req_database ; // database handle
args . pat_request = blob - > blb_request ; // transaction handle
args . pat_blob = blob ; // blob handle
args . pat_reference = reference ; // blob identifier
args . pat_ident1 = blob - > blb_bpb_ident ; // blob parameter block
2001-05-23 15:26:42 +02:00
if ( ( action - > act_flags & ACT_sql ) & & action - > act_type = = ACT_blob_open )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " MOVE %s TO %s " ,
2001-05-23 15:26:42 +02:00
reference - > ref_value , s ) ;
if ( args . pat_value1 = blob - > blb_bpb_length )
PATTERN_expand ( column , pattern1 , & args ) ;
else
PATTERN_expand ( column , pattern2 , & args ) ;
if ( action - > act_flags & ACT_sql ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
if ( action - > act_type = = ACT_blob_create ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF SQLCODE = 0 THEN " ) ;
printa ( names [ COLUMN ] , false , " MOVE %s TO %s " ,
2001-05-23 15:26:42 +02:00
s , reference - > ref_value ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Callback routine for BLR pretty printer.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-09-29 14:43:14 +02:00
static void gen_blr ( void * user_arg , SSHORT offset , const char * string )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
int max_line , max_diff ;
2006-11-10 08:50:13 +01:00
if ( isAnsiCobol ( gpreGlob . sw_cob_dialect ) ) {
2001-05-23 15:26:42 +02:00
max_line = 70 ;
max_diff = 7 ;
}
else {
max_line = 255 ;
max_diff = 30 ;
}
2004-11-28 04:43:42 +01:00
const int comment = strlen ( names [ COMMENT ] ) ;
int indent = 2 * strlen ( INDENT ) ;
const char * p = string ;
2001-05-23 15:26:42 +02:00
while ( * p = = ' ' ) {
p + + ;
indent + + ;
}
2004-11-28 04:43:42 +01:00
int length = strlen ( p ) ;
2001-05-23 15:26:42 +02:00
if ( comment + indent > max_line )
indent = max_line - comment ;
2004-11-28 04:43:42 +01:00
char buffer [ 256 ] ;
bool first_line = true ;
2001-05-23 15:26:42 +02:00
while ( length > 0 & & length + indent + comment > max_line ) {
/* if we did not find somewhere to break between the 200th and 256th
character just print out 256 characters */
2004-11-28 04:43:42 +01:00
const char * q = p ;
for ( bool open_quote = false ; ( q - p + indent + comment ) < max_line ;
q + + )
{
2001-05-23 15:26:42 +02:00
if ( ( q - p + indent + comment ) > max_line - max_diff & & * q = = ' , '
2003-09-10 21:48:53 +02:00
& & ! open_quote )
{
break ;
}
2001-05-23 15:26:42 +02:00
if ( * q = = ' \' ' & & * ( q - 1 ) ! = ' \\ ' )
open_quote = ! open_quote ;
}
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s " , names [ COMMENT ] ) ;
2004-11-28 04:43:42 +01:00
for ( int i = 0 ; i < indent ; i + + )
2004-05-24 19:13:38 +02:00
fputc ( ' ' , gpreGlob . out_file ) ;
2003-09-28 23:36:05 +02:00
q + + ;
2003-09-29 14:43:14 +02:00
strncpy ( buffer , p , q - p ) ;
buffer [ q - p ] = 0 ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s \n " , buffer ) ;
2001-05-23 15:26:42 +02:00
length = length - ( q - p ) ;
p = q ;
if ( first_line ) {
2003-09-10 21:48:53 +02:00
first_line = false ;
2001-05-23 15:26:42 +02:00
indent + = strlen ( INDENT ) ;
if ( comment + indent > max_line )
indent = max_line - comment ;
}
}
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s " , names [ COMMENT ] ) ;
2004-11-28 04:43:42 +01:00
for ( int i = 0 ; i < indent ; i + + )
2004-05-24 19:13:38 +02:00
fputc ( ' ' , gpreGlob . out_file ) ;
fprintf ( gpreGlob . out_file , " %s \n " , p ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Zap all know handles.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_clear_handles ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
for ( const gpre_req * request = gpreGlob . requests ; request ; request = request - > req_next ) {
2001-05-23 15:26:42 +02:00
if ( ! ( request - > req_flags & REQ_exp_hand ) )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true , " %s = 0; " , request - > req_handle ) ;
2001-05-23 15:26:42 +02:00
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate text to compile a request.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_compile ( const act * action )
2001-05-23 15:26:42 +02:00
{
2003-10-29 11:53:47 +01:00
const gpre_req * request = action - > act_request ;
const dbb * db = request - > req_database ;
2004-01-28 08:50:41 +01:00
const gpre_sym * symbol = db - > dbb_name ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// generate automatic ready if appropriate
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-10 21:48:53 +02:00
t_start_auto ( request , status_vector ( action ) , action , true ) ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// always generate a compile, a test for the success of the compile,
// and an end to the 'if not compiled test
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// generate an 'if not compiled'
2001-05-23 15:26:42 +02:00
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s = 0 THEN " , request - > req_handle ) ;
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto & & action - > act_error )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " ,
2001-05-23 15:26:42 +02:00
request_trans ( action , request ) ) ;
sprintf ( output_buffer ,
" %sCALL \" %s%s \" USING %s, %s%s, %s%s, %s%d%s, %s%s%d \n " ,
names [ COLUMN ] , ISC_COMPILE_REQUEST ,
( request - > req_flags & REQ_exp_hand ) ? " " : " 2 " ,
status_vector ( action ) , BY_REF , symbol - > sym_string , BY_REF ,
request - > req_handle , BY_VALUE , request - > req_length , END_VALUE ,
2003-10-15 00:22:32 +02:00
BY_REF , names [ isc_a_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto & & action - > act_error )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
// If blobs are present, zero out all of the blob handles. After this
2008-12-05 02:20:14 +01:00
// point, the handles are the user's responsibility
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
const blb * blob = request - > req_blobs ;
if ( blob )
2001-05-23 15:26:42 +02:00
for ( ; blob ; blob = blob - > blb_next ) {
sprintf ( output_buffer , " %sMOVE 0 TO %s%d \n " ,
2003-10-15 00:22:32 +02:00
names [ COLUMN ] , names [ isc_a_pos ] , blob - > blb_ident ) ;
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a call to create a database.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_create_database ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
TEXT s1 [ 32 ] , s1Tmp [ 32 ] , s2 [ 32 ] , s2Tmp [ 32 ] ;
2001-05-23 15:26:42 +02:00
2004-01-28 08:50:41 +01:00
gpre_req * request = ( ( mdbb * ) action - > act_object ) - > mdbb_dpb_request ;
DBB db = ( DBB ) request - > req_database ;
2001-05-23 15:26:42 +02:00
if ( request ) {
2003-10-15 00:22:32 +02:00
sprintf ( s1 , " %s%dL " , names [ isc_b_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
if ( request - > req_flags & REQ_extend_dpb )
2003-10-15 00:22:32 +02:00
sprintf ( s2 , " %s%dp " , names [ isc_b_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
else
2003-10-15 00:22:32 +02:00
sprintf ( s2 , " %s%d " , names [ isc_b_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
/* if the dpb needs to be extended at runtime to include items
2008-12-05 02:20:14 +01:00
in host variables , do so here ; this assumes that there is
2001-05-23 15:26:42 +02:00
always a request generated for runtime variables */
if ( request - > req_flags & REQ_extend_dpb ) {
if ( request - > req_length ) {
2005-01-19 09:59:23 +01:00
sprintf ( output_buffer , " %sMOVE %s%d to %s \n " ,
names [ COLUMN ] , names [ isc_b_pos ] , request - > req_ident , s2 ) ;
2001-05-23 15:26:42 +02:00
}
if ( db - > dbb_r_user ) {
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s%s, %s%s, BY VALUE 28, %s %s, %s%d%s \n " ,
names [ COLUMN ] ,
ISC_MODIFY_DPB ,
BY_REF , s2 ,
BY_REF , s1 ,
BY_DESC , db - > dbb_r_user ,
BY_VALUE , strlen ( db - > dbb_r_user ) - 2 , END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
if ( db - > dbb_r_password ) {
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s%s, %s%s, BY VALUE 29, %s %s, %s%d%s \n " ,
names [ COLUMN ] ,
ISC_MODIFY_DPB ,
BY_REF , s2 ,
BY_REF , s1 ,
BY_DESC , db - > dbb_r_password ,
BY_VALUE , strlen ( db - > dbb_r_password ) - 2 , END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
/*
* * = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* * = =
* * = = Process Role Name , isc_dpb_sql_role_name / 60
* * = =
* * = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
if ( db - > dbb_r_sql_role ) {
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s%s, %s%s, BY VALUE 60, %s %s, %s%d%s \n " ,
names [ COLUMN ] ,
ISC_MODIFY_DPB ,
BY_REF , s2 ,
BY_REF , s1 ,
BY_DESC , db - > dbb_r_sql_role ,
BY_VALUE , strlen ( db - > dbb_r_sql_role ) - 2 , END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
if ( db - > dbb_r_lc_messages ) {
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s%s, %s%s, BY VALUE 47, %s %s, %s%d%s \n " ,
names [ COLUMN ] ,
ISC_MODIFY_DPB ,
BY_REF , s2 ,
BY_REF , s1 ,
BY_REF , db - > dbb_r_lc_messages ,
BY_VALUE , strlen ( db - > dbb_r_lc_messages ) - 2 ,
END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
if ( db - > dbb_r_lc_ctype ) {
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s%s %s%s, BY VALUE 48, %s %s, %s%d%s \n " ,
names [ COLUMN ] ,
ISC_MODIFY_DPB ,
BY_REF , s2 ,
BY_REF , s1 ,
BY_REF , db - > dbb_r_lc_ctype ,
BY_VALUE , strlen ( db - > dbb_r_lc_ctype ) - 2 , END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
}
if ( request - > req_flags & REQ_extend_dpb ) {
sprintf ( s1Tmp , " %s%s%s " , BY_VALUE , s1 , END_VALUE ) ;
sprintf ( s2Tmp , " %s%s%s " , BY_VALUE , s2 , END_VALUE ) ;
}
else {
sprintf ( s2Tmp , " %s%s " , BY_REF , s2 ) ;
sprintf ( s1Tmp , " %s%d%s " , BY_VALUE , request - > req_length ,
END_VALUE ) ;
}
}
2005-01-19 09:59:23 +01:00
TEXT dbname [ 128 ] ; // MAXPATHLEN if VMS code is enabled.
2004-11-28 04:43:42 +01:00
for ( const dbb * dbisc = gpreGlob . isc_databases ; dbisc ; dbisc = dbisc - > dbb_next )
2001-05-23 15:26:42 +02:00
if ( strcmp ( dbisc - > dbb_filename , db - > dbb_filename ) = = 0 )
db - > dbb_id = dbisc - > dbb_id ;
2005-01-19 09:59:23 +01:00
sprintf ( dbname , " %s%ddb " , names [ isc_b_pos ] , db - > dbb_id ) ;
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s, %s%d%s, %s%s, %s%s, %s, %s, %s0%s \n " ,
names [ COLUMN ] ,
ISC_CREATE_DATABASE ,
status_vector ( action ) ,
BY_VALUE , strlen ( db - > dbb_filename ) , END_VALUE ,
2005-01-19 09:59:23 +01:00
BY_REF , dbname ,
2001-05-23 15:26:42 +02:00
BY_REF , db - > dbb_name - > sym_string ,
( request - > req_length ) ? s1Tmp : OMITTED ,
( request - > req_length ) ? s2Tmp : OMITTED , BY_VALUE , END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2008-12-05 02:20:14 +01:00
// if the dpb was extended, free it here
2001-05-23 15:26:42 +02:00
if ( request & & request - > req_flags & REQ_extend_dpb ) {
if ( request - > req_length ) {
sprintf ( output_buffer ,
2005-01-19 09:59:23 +01:00
" if (%s != %s%d) " , s2 , names [ isc_b_pos ] , request - > req_ident ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s \n " , names [ COLUMN ] , ISC_FREE , s2Tmp ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// reset the length of the dpb
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer , " %sMOVE %d to %s " ,
names [ COLUMN ] , request - > req_length , s1 ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
2004-11-28 04:43:42 +01:00
const bool save_sw_auto = gpreGlob . sw_auto ;
2004-05-24 19:13:38 +02:00
gpreGlob . sw_auto = true ;
2003-10-15 00:22:32 +02:00
printa ( names [ COLUMN ] , false , " IF %s(2) = 0 THEN " , names [ isc_status_pos ] ) ;
2001-05-23 15:26:42 +02:00
gen_ddl ( action ) ;
2004-05-24 19:13:38 +02:00
gpreGlob . sw_auto = save_sw_auto ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for END_STREAM.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
static void gen_cursor_close ( const act * action , const gpre_req * request )
2001-05-23 15:26:42 +02:00
{
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s%dS NOT = 0 THEN " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , request - > req_ident ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s%dS, %s%d%s " ,
ISC_DSQL_FREE ,
status_vector ( action ) ,
2003-10-15 00:22:32 +02:00
BY_REF , names [ isc_a_pos ] , request - > req_ident , BY_VALUE , 1 , END_VALUE ) ;
printa ( names [ COLUMN ] , false , " IF %s(2) = 0 THEN " , names [ isc_status_pos ] ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate text to initialize a cursor.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_cursor_init ( const act * action )
2001-05-23 15:26:42 +02:00
{
// If blobs are present, zero out all of the blob handles. After this
2008-12-05 02:20:14 +01:00
// point, the handles are the user's responsibility
2001-05-23 15:26:42 +02:00
2008-06-05 13:02:42 +02:00
if ( action - > act_request - > req_flags & ( REQ_sql_blob_open | REQ_sql_blob_create ) )
{
printa ( names [ COLUMN ] , false , " MOVE 0 TO %s%d " , names [ isc_a_pos ] ,
action - > act_request - > req_blobs - > blb_ident ) ;
}
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate text to open an embedded SQL cursor.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
static void gen_cursor_open ( const act * action , const gpre_req * request )
2001-05-23 15:26:42 +02:00
{
if ( action - > act_type ! = ACT_open )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s%dS = 0 THEN " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
else
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF (%s%dS = 0) AND %s NOT = 0 THEN " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , request - > req_ident , request - > req_handle ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " ,
2001-05-23 15:26:42 +02:00
request - > req_database - > dbb_name - > sym_string ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true , " CALL \" %s \" USING %s, %s%s, %s%s%dS " ,
2001-05-23 15:26:42 +02:00
ISC_DSQL_ALLOCATE ,
status_vector ( action ) ,
BY_REF , request - > req_database - > dbb_name - > sym_string ,
2003-10-15 00:22:32 +02:00
BY_REF , names [ isc_a_pos ] , request - > req_ident ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s%dS NOT = 0 THEN " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , request - > req_ident ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " ,
2001-05-23 15:26:42 +02:00
request_trans ( action , request ) ) ;
2008-12-05 02:20:14 +01:00
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_CURSOR_SIZE ] ;
2001-05-23 15:26:42 +02:00
make_name_formatted ( s , " ISC-CONST-%s " ,
2004-01-28 08:50:41 +01:00
( ( open_cursor * ) action - > act_object ) - > opn_cursor ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s%dS, %s%s, %s0%s " ,
ISC_DSQL_SET_CURSOR ,
status_vector ( action ) ,
2003-10-15 00:22:32 +02:00
BY_REF , names [ isc_a_pos ] , request - > req_ident ,
2001-05-23 15:26:42 +02:00
BY_REF , s , BY_VALUE , END_VALUE ) ;
2003-10-15 00:22:32 +02:00
printa ( names [ COLUMN ] , false , " IF %s(2) = 0 THEN " , names [ isc_status_pos ] ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s, %s%s%dS, %s0%s, %s, %s-1%s, %s0%s, %s " ,
ISC_DSQL_EXECUTE ,
status_vector ( action ) ,
BY_REF , request_trans ( action , request ) ,
2003-10-15 00:22:32 +02:00
BY_REF , names [ isc_a_pos ] , request - > req_ident ,
2001-05-23 15:26:42 +02:00
BY_VALUE , END_VALUE ,
OMITTED , BY_VALUE , END_VALUE , BY_VALUE , END_VALUE , OMITTED ) ;
2003-10-15 00:22:32 +02:00
printa ( names [ COLUMN ] , false , " IF %s(2) = 0 THEN " , names [ isc_status_pos ] ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate insertion text for the database statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_database ( const act * action )
2001-05-23 15:26:42 +02:00
{
2003-10-29 11:53:47 +01:00
if ( global_first_flag )
2002-07-06 07:32:02 +02:00
return ;
2003-10-29 11:53:47 +01:00
global_first_flag = true ;
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer , " \n %s**** GDS Preprocessor Definitions **** \n \n " ,
names [ COMMENT ] ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s PIC S9(18) USAGE COMP VALUE IS 0. " ,
2003-10-15 00:22:32 +02:00
names [ isc_blob_null_pos ] ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s PIC S9(9) USAGE COMP EXTERNAL. " ,
2001-05-23 15:26:42 +02:00
names [ ISC_SQLCODE ] ) ;
2003-10-06 11:48:44 +02:00
bool all_static = true ;
bool all_extern = true ;
2004-11-28 04:43:42 +01:00
USHORT count = 0 ;
for ( dbb * db = gpreGlob . isc_databases ; db ; db = db - > dbb_next ) {
2001-05-23 15:26:42 +02:00
all_static = all_static & & ( db - > dbb_scope = = DBB_STATIC ) ;
all_extern = all_extern & & ( db - > dbb_scope = = DBB_EXTERN ) ;
2003-10-06 11:48:44 +02:00
const TEXT * name = db - > dbb_name - > sym_string ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%s PIC S9(9) USAGE COMP%s. " ,
2001-05-23 15:26:42 +02:00
name ,
2004-12-16 04:03:13 +01:00
( all_static ) ? " " : ( all_extern ) ? " IS EXTERNAL " : " IS GLOBAL " ,
( all_extern ) ? " " : " VALUE IS 0 " ) ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// generate variables to hold database name strings for attach call
2001-05-23 15:26:42 +02:00
db - > dbb_id = + + count ;
if ( db - > dbb_runtime ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false ,
2003-10-15 00:22:32 +02:00
" 01 %s%ddb PIC X(%d) VALUE IS \" %s \" . " , names [ isc_b_pos ] ,
2001-05-23 15:26:42 +02:00
db - > dbb_id , strlen ( db - > dbb_runtime ) , db - > dbb_runtime ) ;
}
else if ( db - > dbb_filename ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false ,
2003-10-15 00:22:32 +02:00
" 01 %s%ddb PIC X(%d) VALUE IS \" %s \" . " , names [ isc_b_pos ] ,
2001-05-23 15:26:42 +02:00
db - > dbb_id , strlen ( db - > dbb_filename ) , db - > dbb_filename ) ;
}
2004-11-28 04:43:42 +01:00
for ( const tpb * tpb_iterator = db - > dbb_tpbs ;
2003-09-05 12:14:08 +02:00
tpb_iterator ;
tpb_iterator = tpb_iterator - > tpb_dbb_next )
{
gen_tpb ( tpb_iterator ) ;
}
2001-05-23 15:26:42 +02:00
}
2008-12-05 02:20:14 +01:00
// loop through actions: find readys to generate vars for quoted strings
2001-05-23 15:26:42 +02:00
2005-01-03 09:07:41 +01:00
TEXT fname [ 80 ] , s1 [ MAX_CURSOR_SIZE ] ;
2003-10-06 11:48:44 +02:00
bool dyn_immed = false ;
for ( const act * local_act = action ; local_act ; local_act = local_act - > act_rest )
{
if ( local_act - > act_type = = ACT_create_database ) {
// no statement;
2001-05-23 15:26:42 +02:00
}
2003-10-06 11:48:44 +02:00
else if ( local_act - > act_type = = ACT_ready ) {
2004-11-28 04:43:42 +01:00
for ( rdy * ready = ( rdy * ) local_act - > act_object ; ready ; ready = ready - > rdy_next )
2003-09-13 14:22:11 +02:00
{
2005-01-03 09:07:41 +01:00
const TEXT * s = ready - > rdy_filename ;
2004-11-10 05:32:11 +01:00
if ( s & & ( ( * s = = ' \' ' ) | | ( * s = = ' \" ' ) ) )
2003-09-13 14:22:11 +02:00
{
2005-01-03 09:07:41 +01:00
int len = strlen ( + + s ) ;
if ( len > = sizeof ( fname ) )
len = sizeof ( fname ) ;
strncpy ( fname , s , len ) ;
fname [ len - 1 ] = 0 ;
2001-05-23 15:26:42 +02:00
ready - > rdy_id = + + count ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false ,
2001-05-23 15:26:42 +02:00
" 01 %s%ddb PIC X(%d) VALUE IS \" %s \" . " ,
2003-10-15 00:22:32 +02:00
names [ isc_b_pos ] , ready - > rdy_id , strlen ( fname ) , fname ) ;
2001-05-23 15:26:42 +02:00
}
2003-09-13 14:22:11 +02:00
}
2001-05-23 15:26:42 +02:00
}
2003-10-06 11:48:44 +02:00
else if ( ( local_act - > act_flags & ACT_sql ) & &
( local_act - > act_type = = ACT_dyn_cursor | |
local_act - > act_type = = ACT_dyn_prepare | |
local_act - > act_type = = ACT_open | |
local_act - > act_type = = ACT_blob_open | |
local_act - > act_type = = ACT_blob_create ) )
2003-09-13 14:22:11 +02:00
{
2004-11-28 04:43:42 +01:00
const gpre_sym * cur_stmt ;
2003-10-06 11:48:44 +02:00
if ( local_act - > act_type = = ACT_dyn_cursor )
cur_stmt = ( ( DYN ) local_act - > act_object ) - > dyn_cursor_name ;
else if ( local_act - > act_type = = ACT_dyn_prepare )
cur_stmt = ( ( DYN ) local_act - > act_object ) - > dyn_statement_name ;
2001-05-23 15:26:42 +02:00
else
2004-01-28 08:50:41 +01:00
cur_stmt = ( ( open_cursor * ) local_act - > act_object ) - > opn_cursor ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// Only generate one declaration per cursor or statement name
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
const act * chck_dups ;
for ( chck_dups = local_act - > act_rest ; chck_dups ;
2008-12-05 02:20:14 +01:00
chck_dups = chck_dups - > act_rest )
2003-10-06 11:48:44 +02:00
{
2004-11-10 05:32:11 +01:00
const gpre_sym * dup ;
2001-05-23 15:26:42 +02:00
if ( chck_dups - > act_type = = ACT_dyn_cursor )
dup = ( ( DYN ) chck_dups - > act_object ) - > dyn_cursor_name ;
else if ( chck_dups - > act_type = = ACT_dyn_prepare )
dup = ( ( DYN ) chck_dups - > act_object ) - > dyn_statement_name ;
else if ( ( chck_dups - > act_flags & ACT_sql ) & &
( chck_dups - > act_type = = ACT_open | |
chck_dups - > act_type = = ACT_blob_open | |
chck_dups - > act_type = = ACT_blob_create ) )
2004-11-10 05:32:11 +01:00
{
2004-01-28 08:50:41 +01:00
dup = ( ( open_cursor * ) chck_dups - > act_object ) - > opn_cursor ;
2004-11-10 05:32:11 +01:00
}
2001-05-23 15:26:42 +02:00
else
continue ;
if ( ! strcmp ( dup - > sym_string , cur_stmt - > sym_string ) )
break ;
}
if ( ! chck_dups ) {
make_name ( s1 , cur_stmt ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false ,
2001-05-23 15:26:42 +02:00
" 01 ISC-CONST-%s PIC X(%d) VALUE IS \" %s \" . " ,
s1 , strlen ( s1 ) + 1 , s1 ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false ,
2001-05-23 15:26:42 +02:00
" 01 ISC-CONST-%sL PIC S9(4) USAGE %s. " , s1 ,
COMP_VALUE ) ;
}
}
2003-10-06 11:48:44 +02:00
else if ( local_act - > act_type = = ACT_dyn_immediate ) {
2001-05-23 15:26:42 +02:00
if ( ! dyn_immed ) {
2003-09-10 21:48:53 +02:00
dyn_immed = true ;
printa ( names [ COLUMN_0 ] , false ,
2001-05-23 15:26:42 +02:00
" 01 ISC-CONST-DYN-IMMEDL PIC S9(4) USAGE %s. " ,
COMP_VALUE ) ;
}
}
2003-10-06 11:48:44 +02:00
else if ( local_act - > act_type = = ACT_procedure ) {
2004-11-28 04:43:42 +01:00
const gpre_req * request = local_act - > act_request ;
const gpre_prc * procedure = ( gpre_prc * ) local_act - > act_object ;
const gpre_sym * symbol = procedure - > prc_symbol ;
2003-10-06 11:48:44 +02:00
const char * sname = symbol - > sym_string ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false ,
2001-05-23 15:26:42 +02:00
" 01 %s%dprc PIC X(%d) VALUE IS \" %s \" . " ,
2003-10-15 00:22:32 +02:00
names [ isc_b_pos ] , request - > req_ident , strlen ( sname ) , sname ) ;
2001-05-23 15:26:42 +02:00
}
2003-10-06 11:48:44 +02:00
}
2001-05-23 15:26:42 +02:00
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%s PIC S9(9) USAGE COMP%s. " ,
2003-10-15 00:22:32 +02:00
names [ isc_trans_pos ] ,
2001-05-23 15:26:42 +02:00
( all_static ) ? " " : ( all_extern ) ? " IS EXTERNAL " : " IS GLOBAL " ,
( all_extern ) ? " " : " VALUE IS 0 " ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%s. " ,
2003-10-15 00:22:32 +02:00
names [ isc_status_vector_pos ] ,
2001-05-23 15:26:42 +02:00
( all_static ) ? " " : ( all_extern ) ? " IS EXTERNAL " : " IS GLOBAL " ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false ,
2003-10-15 00:22:32 +02:00
" 03 %s PIC S9(9) USAGE COMP OCCURS 20 TIMES. " , names [ isc_status_pos ] ) ;
printa ( names [ COLUMN_0 ] , false , " 01 %s%s. " , names [ isc_status_vector2_pos ] ,
2001-05-23 15:26:42 +02:00
( all_static ) ? " " : ( all_extern ) ? " IS EXTERNAL " : " IS GLOBAL " ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false ,
2001-05-23 15:26:42 +02:00
" 03 %s PIC S9(9) USAGE COMP OCCURS 20 TIMES. " ,
names [ ISC_STATUS2 ] ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s PIC S9(9) USAGE COMP. " ,
2001-05-23 15:26:42 +02:00
names [ ISC_ARRAY_LENGTH ] ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 SQLCODE%s PIC S9(9) USAGE %s%s. " ,
2001-05-23 15:26:42 +02:00
( all_static ) ? " " : ( all_extern ) ? " IS EXTERNAL " : " IS GLOBAL " ,
COMP_VALUE , ( all_extern ) ? " " : " VALUE IS 0 " ) ;
2004-11-28 04:43:42 +01:00
for ( gpre_req * request = gpreGlob . requests ; request ; request = request - > req_next ) {
2001-05-23 15:26:42 +02:00
gen_request ( request ) ;
2004-11-28 04:43:42 +01:00
gpre_port * port ;
2001-05-23 15:26:42 +02:00
for ( port = request - > req_ports ; port ; port = port - > por_next )
make_port ( port ) ;
2004-11-28 04:43:42 +01:00
for ( const blb * blob = request - > req_blobs ; blob ; blob = blob - > blb_next ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%d PIC S9(9) USAGE COMP. " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , blob - > blb_ident ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%d PIC X(%d). " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , blob - > blb_buff_ident , blob - > blb_seg_length ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%d PIC S9(4) USAGE %s. " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , blob - > blb_len_ident , COMP_VALUE ) ;
2001-05-23 15:26:42 +02:00
}
2008-12-05 02:20:14 +01:00
// Array declarations
2001-05-23 15:26:42 +02:00
if ( port = request - > req_primary )
2003-10-06 11:48:44 +02:00
for ( REF reference = port - > por_references ; reference ;
2001-05-23 15:26:42 +02:00
reference = reference - > ref_next )
2003-10-06 11:48:44 +02:00
{
2001-05-23 15:26:42 +02:00
if ( reference - > ref_field - > fld_array_info )
make_array_declaration ( reference ) ;
2003-10-06 11:48:44 +02:00
}
2001-05-23 15:26:42 +02:00
}
2008-12-05 02:20:14 +01:00
// Generate event parameter block for each event
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
USHORT max_count = 0 ;
2004-11-28 04:43:42 +01:00
for ( const gpre_lls * stack_ptr = gpreGlob . events ; stack_ptr ; stack_ptr = stack_ptr - > lls_next )
{
2003-10-06 11:48:44 +02:00
count = gen_event_block ( ( const act * ) stack_ptr - > lls_object ) ;
2001-05-23 15:26:42 +02:00
max_count = MAX ( count , max_count ) ;
}
if ( max_count ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s. " , names [ ISC_EVENTS_VECTOR ] ) ;
printa ( names [ COLUMN ] , false ,
2001-05-23 15:26:42 +02:00
" 03 %s PIC S9(9) USAGE COMP OCCURS %d TIMES. " ,
names [ ISC_EVENTS ] , max_count ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s. " ,
2001-05-23 15:26:42 +02:00
names [ ISC_EVENT_NAMES_VECTOR ] ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false ,
2001-05-23 15:26:42 +02:00
" 03 %s PIC S9(9) USAGE COMP OCCURS %d TIMES. " ,
names [ ISC_EVENT_NAMES ] , max_count ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s. " ,
2001-05-23 15:26:42 +02:00
names [ ISC_EVENT_NAMES_VECTOR2 ] ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " 03 %s PIC X(31) OCCURS %d TIMES. " ,
2001-05-23 15:26:42 +02:00
names [ ISC_EVENT_NAMES2 ] , max_count ) ;
}
2003-09-10 21:48:53 +02:00
printa ( names [ COMMENT ] , false , " **** end of GPRE definitions **** \n " ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a call to update metadata.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_ddl ( const act * action )
2001-05-23 15:26:42 +02:00
{
2003-10-29 11:53:47 +01:00
// Set up command type for call to RDB$DDL
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
const gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto ) {
2003-09-10 21:48:53 +02:00
t_start_auto ( 0 , status_vector ( action ) , action , true ) ;
2003-10-15 00:22:32 +02:00
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " , names [ isc_trans_pos ] ) ;
2001-05-23 15:26:42 +02:00
}
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s, %s%s, %s%s, %s%d%s, %s%s%d \n " ,
names [ COLUMN ] , ISC_DDL , status_vector ( action ) , BY_REF ,
request - > req_database - > dbb_name - > sym_string , BY_REF ,
2003-10-15 00:22:32 +02:00
names [ isc_trans_pos ] , BY_VALUE , request - > req_length , END_VALUE ,
BY_REF , names [ isc_a_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2003-10-15 00:22:32 +02:00
printa ( names [ COLUMN ] , false , " IF %s(2) = 0 THEN " , names [ isc_status_pos ] ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s " , ISC_COMMIT_TRANSACTION ,
2003-10-15 00:22:32 +02:00
status_vector ( action ) , BY_REF , names [ isc_trans_pos ] ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
printa ( names [ COLUMN ] , false , " IF %s(2) NOT = 0 THEN " ,
2003-10-15 00:22:32 +02:00
names [ isc_status_pos ] ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s " ,
2003-10-15 00:22:32 +02:00
ISC_ROLLBACK_TRANSACTION , OMITTED , BY_REF , names [ isc_trans_pos ] ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a dynamic SQL statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_dyn_close ( const act * action )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_CURSOR_SIZE ] ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const dyn * statement = ( DYN ) action - > act_object ;
2001-05-23 15:26:42 +02:00
make_name_formatted ( s , " ISC-CONST-%s " , statement - > dyn_cursor_name ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s " ,
ISC_CLOSE , status_vector ( action ) , BY_REF , s ) ;
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a dynamic SQL statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_dyn_declare ( const act * action )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s1 [ MAX_CURSOR_SIZE ] , s2 [ MAX_CURSOR_SIZE ] ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const dyn * statement = ( DYN ) action - > act_object ;
2001-05-23 15:26:42 +02:00
make_name_formatted ( s1 , " ISC-CONST-%s " , statement - > dyn_statement_name ) ;
make_name_formatted ( s2 , " ISC-CONST-%s " , statement - > dyn_cursor_name ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s, %s%s " ,
ISC_DECLARE , status_vector ( action ) , BY_REF , s1 , BY_REF , s2 ) ;
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a dynamic SQL statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_dyn_describe ( const act * action ,
2003-09-10 21:48:53 +02:00
bool bind_flag )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_CURSOR_SIZE ] ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const dyn * statement = ( DYN ) action - > act_object ;
2001-05-23 15:26:42 +02:00
make_name_formatted ( s , " ISC-CONST-%s " , statement - > dyn_statement_name ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s, %s%d%s, %s%s " ,
bind_flag ? ISC_DESCRIBE_BIND : ISC_DESCRIBE ,
status_vector ( action ) ,
BY_REF , s ,
2004-05-24 19:13:38 +02:00
BY_VALUE , gpreGlob . sw_sql_dialect , END_VALUE , BY_REF , statement - > dyn_sqlda ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a dynamic SQL statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_dyn_execute ( const act * action )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_CURSOR_SIZE ] ;
2003-09-05 12:14:08 +02:00
gpre_req * request ;
gpre_req req_const ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const dyn * statement = ( DYN ) action - > act_object ;
2003-10-06 11:48:44 +02:00
const TEXT * transaction ;
2001-05-23 15:26:42 +02:00
if ( statement - > dyn_trans ) {
transaction = statement - > dyn_trans ;
request = & req_const ;
request - > req_trans = transaction ;
}
else {
2003-10-15 00:22:32 +02:00
transaction = names [ isc_trans_pos ] ;
2001-05-23 15:26:42 +02:00
request = NULL ;
}
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto ) {
2003-09-10 21:48:53 +02:00
t_start_auto ( request , status_vector ( action ) , action , true ) ;
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " , transaction ) ;
2001-05-23 15:26:42 +02:00
}
make_name_formatted ( s , " ISC-CONST-%s " , statement - > dyn_statement_name ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
( statement - > dyn_sqlda2 ) ?
2004-10-30 07:30:08 +02:00
" CALL \" %s \" USING %s, %s%s, %s%s, %s%d%s, %s%s, %s%s " :
" CALL \" %s \" USING %s, %s%s, %s%s, %s%d%s, %s%s " ,
2001-05-23 15:26:42 +02:00
( statement - > dyn_sqlda2 ) ? ISC_EXECUTE2 : ISC_EXECUTE ,
status_vector ( action ) ,
BY_REF , transaction ,
BY_REF , s ,
2004-05-24 19:13:38 +02:00
BY_VALUE , gpreGlob . sw_sql_dialect , END_VALUE ,
2001-05-23 15:26:42 +02:00
( statement - > dyn_sqlda ) ? BY_REF : " " ,
( statement - > dyn_sqlda ) ? statement - > dyn_sqlda : OMITTED ,
( statement - > dyn_sqlda2 ) ? BY_REF : " " ,
( statement - > dyn_sqlda2 ) ? statement - > dyn_sqlda2 : OMITTED ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a dynamic SQL statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_dyn_fetch ( const act * action )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_CURSOR_SIZE ] ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const dyn * statement = ( DYN ) action - > act_object ;
2001-05-23 15:26:42 +02:00
make_name_formatted ( s , " ISC-CONST-%s " , statement - > dyn_cursor_name ) ;
2003-10-16 10:51:06 +02:00
printa ( names [ COLUMN ] , true , FETCH_CALL_TEMPLATE ,
2001-05-23 15:26:42 +02:00
ISC_FETCH ,
status_vector ( action ) ,
BY_REF , s ,
2004-05-24 19:13:38 +02:00
BY_VALUE , gpreGlob . sw_sql_dialect , END_VALUE ,
2001-05-23 15:26:42 +02:00
( statement - > dyn_sqlda ) ? BY_REF : " " ,
( statement - > dyn_sqlda ) ? statement - > dyn_sqlda : OMITTED ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF SQLCODE NOT = 100 THEN " ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate code for an EXECUTE IMMEDIATE dynamic SQL statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_dyn_immediate ( const act * action )
2001-05-23 15:26:42 +02:00
{
2003-09-05 12:14:08 +02:00
gpre_req * request ;
gpre_req req_const ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const dyn * statement = ( DYN ) action - > act_object ;
2003-10-06 11:48:44 +02:00
const TEXT * transaction ;
2001-05-23 15:26:42 +02:00
if ( statement - > dyn_trans ) {
transaction = statement - > dyn_trans ;
request = & req_const ;
request - > req_trans = transaction ;
}
else {
2003-10-15 00:22:32 +02:00
transaction = names [ isc_trans_pos ] ;
2001-05-23 15:26:42 +02:00
request = NULL ;
}
2003-10-29 11:53:47 +01:00
const dbb * database = statement - > dyn_database ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
TEXT s [ 64 ] ;
2003-10-29 11:53:47 +01:00
const TEXT * s2 = " ISC-CONST-DYN-IMMEDL " ;
2003-10-16 10:51:06 +02:00
printa ( names [ COLUMN ] , true , GET_LEN_CALL_TEMPLATE ,
2001-05-23 15:26:42 +02:00
STRING_LENGTH , statement - > dyn_string , s2 ) ;
sprintf ( s , " %s%s%s, " , BY_VALUE , s2 , END_VALUE ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto ) {
2003-09-10 21:48:53 +02:00
t_start_auto ( request , status_vector ( action ) , action , true ) ;
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " , transaction ) ;
2001-05-23 15:26:42 +02:00
}
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
( statement - > dyn_sqlda2 ) ?
2004-10-30 07:30:08 +02:00
" CALL \" %s \" USING %s, %s%s, %s%s,%s %s%s, %s%d%s, %s%s, %s%s " :
" CALL \" %s \" USING %s, %s%s, %s%s,%s %s%s, %s%d%s, %s%s " ,
2003-10-29 11:53:47 +01:00
( statement - > dyn_sqlda2 ) ?
ISC_EXECUTE_IMMEDIATE2 : ISC_EXECUTE_IMMEDIATE ,
2001-05-23 15:26:42 +02:00
status_vector ( action ) , BY_REF , database - > dbb_name - > sym_string ,
BY_REF , transaction , s , BY_DESC , statement - > dyn_string , BY_VALUE ,
2004-12-16 04:03:13 +01:00
gpreGlob . sw_sql_dialect , END_VALUE ,
( statement - > dyn_sqlda ) ? BY_REF : " " ,
2001-05-23 15:26:42 +02:00
( statement - > dyn_sqlda ) ? statement - > dyn_sqlda : OMITTED ,
( statement - > dyn_sqlda2 ) ? BY_REF : " " ,
( statement - > dyn_sqlda2 ) ? statement - > dyn_sqlda2 : OMITTED ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a dynamic SQL statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_dyn_insert ( const act * action )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_CURSOR_SIZE ] ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const dyn * statement = ( DYN ) action - > act_object ;
2001-05-23 15:26:42 +02:00
make_name_formatted ( s , " ISC-CONST-%s " , statement - > dyn_cursor_name ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s, %s%d%s, %s%s " ,
ISC_INSERT ,
status_vector ( action ) ,
BY_REF , s ,
2004-05-24 19:13:38 +02:00
BY_VALUE , gpreGlob . sw_sql_dialect , END_VALUE ,
2001-05-23 15:26:42 +02:00
( statement - > dyn_sqlda ) ? BY_REF : " " ,
( statement - > dyn_sqlda ) ? statement - > dyn_sqlda : OMITTED ) ;
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a dynamic SQL statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_dyn_open ( const act * action )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_CURSOR_SIZE ] ;
2003-09-05 12:14:08 +02:00
gpre_req * request ;
gpre_req req_const ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const dyn * statement = ( DYN ) action - > act_object ;
2003-10-06 11:48:44 +02:00
const TEXT * transaction ;
2001-05-23 15:26:42 +02:00
if ( statement - > dyn_trans ) {
transaction = statement - > dyn_trans ;
request = & req_const ;
request - > req_trans = transaction ;
}
else {
2003-10-15 00:22:32 +02:00
transaction = names [ isc_trans_pos ] ;
2001-05-23 15:26:42 +02:00
request = NULL ;
}
make_name_formatted ( s , " ISC-CONST-%s " , statement - > dyn_cursor_name ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto ) {
2003-09-10 21:48:53 +02:00
t_start_auto ( request , status_vector ( action ) , action , true ) ;
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " , transaction ) ;
2001-05-23 15:26:42 +02:00
}
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
( statement - > dyn_sqlda2 ) ?
2004-10-30 07:30:08 +02:00
" CALL \" %s \" USING %s, %s%s, %s%s, %s%d%s, %s%s, %s%s " :
" CALL \" %s \" USING %s, %s%s, %s%s, %s%d%s, %s%s " ,
2001-05-23 15:26:42 +02:00
( statement - > dyn_sqlda2 ) ? ISC_OPEN2 : ISC_OPEN ,
status_vector ( action ) ,
BY_REF , transaction ,
BY_REF , s ,
2004-05-24 19:13:38 +02:00
BY_VALUE , gpreGlob . sw_sql_dialect , END_VALUE ,
2001-05-23 15:26:42 +02:00
( statement - > dyn_sqlda ) ? BY_REF : " " ,
( statement - > dyn_sqlda ) ? statement - > dyn_sqlda : OMITTED ,
( statement - > dyn_sqlda2 ) ? BY_REF : " " ,
( statement - > dyn_sqlda2 ) ? statement - > dyn_sqlda2 : OMITTED ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a dynamic SQL statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_dyn_prepare ( const act * action )
2001-05-23 15:26:42 +02:00
{
2003-09-05 12:14:08 +02:00
gpre_req * request ;
gpre_req req_const ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const dyn * statement = ( DYN ) action - > act_object ;
2003-10-29 11:53:47 +01:00
const dbb * database = statement - > dyn_database ;
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
const TEXT * transaction ;
2001-05-23 15:26:42 +02:00
if ( statement - > dyn_trans ) {
transaction = statement - > dyn_trans ;
request = & req_const ;
request - > req_trans = transaction ;
}
else {
2003-10-15 00:22:32 +02:00
transaction = names [ isc_trans_pos ] ;
2001-05-23 15:26:42 +02:00
request = NULL ;
}
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_CURSOR_SIZE ] , s3 [ 80 ] ;
2001-05-23 15:26:42 +02:00
make_name_formatted ( s , " ISC-CONST-%s " , statement - > dyn_statement_name ) ;
2005-01-03 09:07:41 +01:00
TEXT s2 [ MAX_CURSOR_SIZE + 1 ] ;
2001-05-23 15:26:42 +02:00
sprintf ( s2 , " %sL " , s ) ;
2003-10-16 10:51:06 +02:00
printa ( names [ COLUMN ] , true , GET_LEN_CALL_TEMPLATE ,
2001-05-23 15:26:42 +02:00
STRING_LENGTH , statement - > dyn_string , s2 ) ;
2005-01-03 09:07:41 +01:00
fb_utils : : snprintf ( s3 , sizeof ( s3 ) , " %s%s%s, " , BY_VALUE , s2 , END_VALUE ) ;
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto ) {
2003-09-10 21:48:53 +02:00
t_start_auto ( request , status_vector ( action ) , action , true ) ;
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " , transaction ) ;
2001-05-23 15:26:42 +02:00
}
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s, %s%s, %s%s,%s %s%s, %s%d%s, %s%s " ,
ISC_PREPARE ,
status_vector ( action ) ,
BY_REF , database - > dbb_name - > sym_string ,
BY_REF , transaction ,
BY_REF , s ,
s3 ,
BY_DESC , statement - > dyn_string ,
2004-05-24 19:13:38 +02:00
BY_VALUE , gpreGlob . sw_sql_dialect , END_VALUE ,
2001-05-23 15:26:42 +02:00
( statement - > dyn_sqlda ) ? BY_REF : " " ,
( statement - > dyn_sqlda ) ? statement - > dyn_sqlda : OMITTED ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for END_MODIFY.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_emodify ( const act * action )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s1 [ MAX_REF_SIZE ] , s2 [ MAX_REF_SIZE ] ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const upd * modify = ( upd * ) action - > act_object ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
for ( const ref * reference = modify - > upd_port - > por_references ; reference ;
reference = reference - > ref_next )
{
const ref * source = reference - > ref_source ;
if ( ! source )
2001-05-23 15:26:42 +02:00
continue ;
2004-11-28 04:43:42 +01:00
const gpre_fld * field = reference - > ref_field ;
2003-09-10 21:48:53 +02:00
gen_name ( s1 , source , true ) ;
gen_name ( s2 , reference , true ) ;
2001-05-23 15:26:42 +02:00
if ( field - > fld_dtype = = dtype_blob | |
field - > fld_dtype = = dtype_quad | | field - > fld_dtype = = dtype_date )
2004-11-28 04:43:42 +01:00
{
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer , " %sCALL \" isc_qtoq \" USING %s, %s \n " ,
names [ COLUMN ] , s1 , s2 ) ;
2004-11-28 04:43:42 +01:00
}
2001-05-23 15:26:42 +02:00
else
sprintf ( output_buffer , " %sMOVE %s TO %s \n " ,
names [ COLUMN ] , s1 , s2 ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
if ( field - > fld_array_info )
2003-09-10 21:48:53 +02:00
gen_get_or_put_slice ( action , reference , false ) ;
2001-05-23 15:26:42 +02:00
}
gen_send ( action , modify - > upd_port ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for END_STORE.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_estore ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
gen_start ( action , request - > req_primary ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate end-if for AT_END if statement
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_end_fetch ( const act * action )
2001-05-23 15:26:42 +02:00
{
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate definitions associated with a single request.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_endfor ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
if ( request - > req_sync )
gen_send ( action , request - > req_sync ) ;
gen_receive ( action , request - > req_primary ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-PERFORM " ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for ERASE.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_erase ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const upd * erase = ( upd * ) action - > act_object ;
2001-05-23 15:26:42 +02:00
gen_send ( action , erase - > upd_port ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate event parameter blocks for use
// with a particular call to isc_event_wait.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static SSHORT gen_event_block ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
gpre_nod * init = ( GPRE_NOD ) action - > act_object ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
int ident = CMP_next_ident ( ) ;
2006-06-23 10:33:33 +02:00
init - > nod_arg [ 2 ] = ( GPRE_NOD ) ( IPTR ) ident ;
2001-05-23 15:26:42 +02:00
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%dA PIC S9(9) USAGE COMP. " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , ident ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%dB PIC S9(9) USAGE COMP. " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , ident ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%dL PIC S9(4) USAGE COMP. " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , ident ) ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const gpre_nod * list = init - > nod_arg [ 1 ] ;
2001-05-23 15:26:42 +02:00
return list - > nod_count ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for EVENT_INIT.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_event_init ( const act * action )
2001-05-23 15:26:42 +02:00
{
# ifdef GIVING_SUPPORTED
2004-10-30 07:30:08 +02:00
const TEXT * pattern1 =
2001-05-23 15:26:42 +02:00
" CALL \" %S1 \" USING %RF%S4%N1A%RE, %RF%S4%N1B%RE, %VF%N2%VE, %RF%S6%RE GIVING %S4%N1L " ;
# else
2004-10-30 07:30:08 +02:00
const TEXT * pattern1 =
2001-05-23 15:26:42 +02:00
" CALL \" %S1 \" USING %RF%S4%N1A%RE, %RF%S4%N1B%RE, %VF%N2%VE, %RF%S6%RE, %RF%S4%N1L%RE " ;
# endif
2004-10-30 07:30:08 +02:00
const TEXT * pattern2 =
2001-05-23 15:26:42 +02:00
" CALL \" %S2 \" USING %V1, %RF%DH%RE, %VF%S4%N1L%VE, %VF%S4%N1A%VE, %VF%S4%N1B%VE " ;
2004-10-30 07:30:08 +02:00
const TEXT * pattern3 =
2001-05-23 15:26:42 +02:00
" CALL \" %S3 \" USING %S5, %VF%S4%N1L%VE, %VF%S4%N1A%VE, %VF%S4%N1B%VE " ;
2004-11-28 04:43:42 +01:00
const gpre_nod * init = ( GPRE_NOD ) action - > act_object ;
const gpre_nod * event_list = init - > nod_arg [ 1 ] ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const SSHORT column = strlen ( names [ COLUMN ] ) ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
PAT args ;
2001-05-23 15:26:42 +02:00
args . pat_database = ( DBB ) init - > nod_arg [ 3 ] ;
args . pat_vector1 = status_vector ( action ) ;
2006-06-23 10:33:33 +02:00
args . pat_value1 = ( int ) ( IPTR ) init - > nod_arg [ 2 ] ;
2001-05-23 15:26:42 +02:00
args . pat_value2 = ( int ) event_list - > nod_count ;
2003-10-16 10:51:06 +02:00
args . pat_string1 = ISC_EVENT_BLOCK ;
args . pat_string2 = ISC_EVENT_WAIT ;
args . pat_string3 = ISC_EVENT_COUNTS ;
2003-10-15 00:22:32 +02:00
args . pat_string4 = names [ isc_a_pos ] ;
2001-05-23 15:26:42 +02:00
args . pat_string5 = names [ ISC_EVENTS_VECTOR ] ;
args . pat_string6 = names [ ISC_EVENT_NAMES_VECTOR ] ;
2008-12-05 02:20:14 +01:00
// generate call to dynamically generate event blocks
2001-05-23 15:26:42 +02:00
2005-01-03 09:07:41 +01:00
TEXT variable [ MAX_REF_SIZE ] ;
2004-11-28 05:59:31 +01:00
const gpre_nod * const * ptr , * const * end ;
2004-11-28 04:43:42 +01:00
SSHORT count ;
2001-05-23 15:26:42 +02:00
for ( ptr = event_list - > nod_arg , count = 0 , end =
2004-10-30 07:30:08 +02:00
ptr + event_list - > nod_count ; ptr < end ; ptr + + )
{
2001-05-23 15:26:42 +02:00
count + + ;
2004-11-28 04:43:42 +01:00
const gpre_nod * node = * ptr ;
2001-05-23 15:26:42 +02:00
if ( node - > nod_type = = nod_field ) {
2004-11-28 04:43:42 +01:00
const ref * reference = ( REF ) node - > nod_arg [ 0 ] ;
2003-09-10 21:48:53 +02:00
gen_name ( variable , reference , true ) ;
printa ( names [ COLUMN ] , false , " MOVE %s TO %s(%d) " , variable ,
2001-05-23 15:26:42 +02:00
names [ ISC_EVENT_NAMES2 ] , count ) ;
}
else
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " MOVE %s TO %s(%d) " ,
2003-08-09 20:00:14 +02:00
( TEXT * ) node - > nod_arg [ 0 ] , names [ ISC_EVENT_NAMES2 ] , count ) ;
2001-05-23 15:26:42 +02:00
2003-10-16 10:51:06 +02:00
printa ( names [ COLUMN ] , true , EVENT_MOVE_TEMPLATE , ISC_BADDRESS ,
2003-10-15 00:22:32 +02:00
names [ ISC_EVENT_NAMES2 ] , count , names [ ISC_EVENT_NAMES ] , count ) ;
2001-05-23 15:26:42 +02:00
}
PATTERN_expand ( column , pattern1 , & args ) ;
2008-12-05 02:20:14 +01:00
// generate actual call to event_wait
2001-05-23 15:26:42 +02:00
PATTERN_expand ( column , pattern2 , & args ) ;
2008-12-05 02:20:14 +01:00
// get change in event counts, copying event parameter block for reuse
2001-05-23 15:26:42 +02:00
PATTERN_expand ( column , pattern3 , & args ) ;
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for EVENT_WAIT.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_event_wait ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-10-30 07:30:08 +02:00
const TEXT * pattern1 =
2001-05-23 15:26:42 +02:00
" CALL \" %S2 \" USING %V1, %RF%DH%RE, %VF%S4%N1L%VE, %VF%S4%N1A%VE, %VF%S4%N1B%VE " ;
2004-10-30 07:30:08 +02:00
const TEXT * pattern2 =
2001-05-23 15:26:42 +02:00
" CALL \" %S3 \" USING %S5, %VF%S4%N1L%VE, %VF%S4%N1A%VE, %VF%S4%N1B%VE " ;
2004-11-28 04:43:42 +01:00
gpre_sym * event_name = ( gpre_sym * ) action - > act_object ;
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
// go through the stack of gpreGlob.events, checking to see if the
2008-12-05 02:20:14 +01:00
// event has been initialized and getting the event identifier
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const dbb * database = NULL ;
int ident = - 1 ;
for ( const gpre_lls * stack_ptr = gpreGlob . events ; stack_ptr ; stack_ptr = stack_ptr - > lls_next )
{
const act * event_action = ( const act * ) stack_ptr - > lls_object ;
const gpre_nod * event_init = ( GPRE_NOD ) event_action - > act_object ;
const gpre_sym * stack_name = ( gpre_sym * ) event_init - > nod_arg [ 0 ] ;
2001-05-23 15:26:42 +02:00
if ( ! strcmp ( event_name - > sym_string , stack_name - > sym_string ) ) {
2006-06-23 10:33:33 +02:00
ident = ( int ) ( IPTR ) event_init - > nod_arg [ 2 ] ;
2001-05-23 15:26:42 +02:00
database = ( DBB ) event_init - > nod_arg [ 3 ] ;
}
}
if ( ident < 0 ) {
2004-11-28 04:43:42 +01:00
TEXT s [ 64 ] ;
2005-01-19 09:59:23 +01:00
fb_utils : : snprintf ( s , sizeof ( s ) ,
" event handle \" %s \" not found " , event_name - > sym_string ) ;
2003-10-15 00:22:32 +02:00
CPR_error ( s ) ;
2004-08-26 23:44:11 +02:00
return ; // silence non initialized warning
2001-05-23 15:26:42 +02:00
}
2004-11-28 04:43:42 +01:00
const SSHORT column = strlen ( names [ COLUMN ] ) ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
PAT args ;
2001-05-23 15:26:42 +02:00
args . pat_database = database ;
args . pat_vector1 = status_vector ( action ) ;
2005-11-30 07:12:53 +01:00
args . pat_value1 = ident ;
2003-10-16 10:51:06 +02:00
args . pat_string2 = ISC_EVENT_WAIT ;
args . pat_string3 = ISC_EVENT_COUNTS ;
2003-10-15 00:22:32 +02:00
args . pat_string4 = names [ isc_a_pos ] ;
2001-05-23 15:26:42 +02:00
args . pat_string5 = names [ ISC_EVENTS_VECTOR ] ;
2008-12-05 02:20:14 +01:00
// generate calls to wait on the event and to fill out the gpreGlob.events array
2001-05-23 15:26:42 +02:00
PATTERN_expand ( column , pattern1 , & args ) ;
PATTERN_expand ( column , pattern2 , & args ) ;
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate replacement text for the SQL FETCH statement. The
// epilog FETCH statement is handled by GEN_S_FETCH (generate
// stream fetch).
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_fetch ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
# ifdef SCROLLABLE_CURSORS
2004-11-28 04:43:42 +01:00
gpre_port * port = request - > req_aport ;
if ( port ) {
2008-12-05 02:20:14 +01:00
/* set up the reference to point to the correct value
in the linked list of values , and prepare for the
2001-05-23 15:26:42 +02:00
next FETCH statement if applicable */
2004-11-28 04:43:42 +01:00
REF reference ;
2001-05-23 15:26:42 +02:00
for ( reference = port - > por_references ; reference ;
2004-11-28 04:43:42 +01:00
reference = reference - > ref_next )
{
VAL value = reference - > ref_values ;
2001-05-23 15:26:42 +02:00
reference - > ref_value = value - > val_value ;
reference - > ref_values = value - > val_next ;
}
2008-12-05 02:20:14 +01:00
// find the direction and offset parameters
2001-05-23 15:26:42 +02:00
reference = port - > por_references ;
2004-11-28 04:43:42 +01:00
const char * offset = reference - > ref_value ;
2001-05-23 15:26:42 +02:00
reference = reference - > ref_next ;
2004-11-28 04:43:42 +01:00
const char * direction = reference - > ref_value ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
/* the direction in which the engine will scroll is sticky, so check to see
the last direction passed to the engine ; if the direction is the same and
the offset is 1 , then there is no need to pass the message ; this prevents
2001-05-23 15:26:42 +02:00
extra packets and allows for batch fetches in either direction */
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false ,
2003-10-15 00:22:32 +02:00
" IF %s%dDI MOD 2 NOT = %s || %s NOT = 1 THEN " , names [ isc_a_pos ] ,
2001-05-23 15:26:42 +02:00
request - > req_ident , direction , offset ) ;
2008-12-05 02:20:14 +01:00
/* assign the direction and offset parameters to the appropriate message,
2001-05-23 15:26:42 +02:00
then send the message to the engine */
asgn_from ( action , port - > por_references ) ;
gen_send ( action , port ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " MOVE %s TO %s%dDI " ,
2005-01-19 09:59:23 +01:00
direction , names [ isc_a_pos ] , request - > req_ident ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF SQLCODE NOT = 0 THEN " ) ;
2001-05-23 15:26:42 +02:00
}
# endif
if ( request - > req_sync )
gen_send ( action , request - > req_sync ) ;
2005-01-03 09:07:41 +01:00
SCHAR s [ MAX_REF_SIZE ] ;
2001-05-23 15:26:42 +02:00
gen_receive ( action , request - > req_primary ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false ,
" IF %s NOT = 0 THEN " , gen_name ( s , request - > req_eof , true ) ) ;
printa ( names [ COLUMN ] , false , " MOVE 0 TO SQLCODE " ) ;
2004-11-28 04:43:42 +01:00
if ( gpre_nod * var_list = ( GPRE_NOD ) action - > act_object )
for ( int i = 0 ; i < var_list - > nod_count ; i + + ) {
2001-07-12 07:46:06 +02:00
asgn_to ( action , ( REF ) var_list - > nod_arg [ i ] ) ;
2001-05-23 15:26:42 +02:00
}
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " ELSE " ) ;
printa ( names [ COLUMN ] , false , " MOVE 100 TO SQLCODE " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
# ifdef SCROLLABLE_CURSORS
if ( port )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
# endif
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for FINISH
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_finish ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto | | ( ( action - > act_flags & ACT_sql ) & &
2004-05-29 06:55:23 +02:00
( action - > act_type ! = ACT_disconnect ) ) )
{
2003-10-15 00:22:32 +02:00
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " , names [ isc_trans_pos ] ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s " ,
( action - > act_type ! =
ACT_rfinish ) ? ISC_COMMIT_TRANSACTION :
ISC_ROLLBACK_TRANSACTION , status_vector ( action ) , BY_REF ,
2003-10-15 00:22:32 +02:00
names [ isc_trans_pos ] ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
2008-12-05 02:20:14 +01:00
// the user may have supplied one or more handles
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const dbb * db = NULL ;
for ( const rdy * ready = ( rdy * ) action - > act_object ; ready ; ready = ready - > rdy_next ) {
2001-05-23 15:26:42 +02:00
db = ready - > rdy_database ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false ,
2001-05-23 15:26:42 +02:00
" IF %s NOT = 0 THEN " , db - > dbb_name - > sym_string ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s " ,
ISC_DETACH_DATABASE ,
status_vector ( action ) , BY_REF , db - > dbb_name - > sym_string ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
2008-12-05 02:20:14 +01:00
// no handles, so finish all known databases
2001-05-23 15:26:42 +02:00
if ( ! db )
2004-05-24 19:13:38 +02:00
for ( db = gpreGlob . isc_databases ; db ; db = db - > dbb_next ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false ,
2001-05-23 15:26:42 +02:00
" IF %s NOT = 0 THEN " , db - > dbb_name - > sym_string ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s " ,
ISC_DETACH_DATABASE ,
status_vector ( action ) , BY_REF , db - > dbb_name - > sym_string ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for FOR statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_for ( const act * action )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_REF_SIZE ] ;
2001-05-23 15:26:42 +02:00
gen_s_start ( action ) ;
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
gen_receive ( action , request - > req_primary ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " PERFORM UNTIL %s = 0 " ,
gen_name ( s , request - > req_eof , true ) ) ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const gpre_port * port = action - > act_request - > req_primary ;
if ( port )
for ( const ref * reference = port - > por_references ; reference ;
2003-09-13 14:22:11 +02:00
reference = reference - > ref_next )
{
if ( reference - > ref_field - > fld_array_info )
gen_get_or_put_slice ( action , reference , true ) ;
}
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a function for free standing ANY or statistical.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_function ( const act * function )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const ref * reference ;
2001-05-23 15:26:42 +02:00
2004-06-05 11:37:18 +02:00
const act * action = ( const act * ) function - > act_object ;
2001-05-23 15:26:42 +02:00
if ( action - > act_type ! = ACT_any ) {
2003-10-15 00:22:32 +02:00
CPR_error ( " can't generate function " ) ;
2002-07-06 07:32:02 +02:00
return ;
2001-05-23 15:26:42 +02:00
}
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " static %s_r (request, transaction " , request - > req_handle ) ;
2001-05-23 15:26:42 +02:00
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_REF_SIZE ] ;
2004-11-28 04:43:42 +01:00
const gpre_port * port = request - > req_vport ;
2004-06-05 11:37:18 +02:00
if ( port )
2001-05-23 15:26:42 +02:00
for ( reference = port - > por_references ; reference ;
reference = reference - > ref_next )
2004-06-05 11:37:18 +02:00
{
fprintf ( gpreGlob . out_file , " , %s " ,
gen_name ( s , reference - > ref_source , true ) ) ;
}
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file ,
2003-03-27 18:15:48 +01:00
" ) \n isc_req_handle \t request; \n isc_tr_handle \t transaction; \n " ) ;
2001-05-23 15:26:42 +02:00
if ( port )
for ( reference = port - > por_references ; reference ;
2004-06-05 11:37:18 +02:00
reference = reference - > ref_next )
{
2004-11-28 04:43:42 +01:00
const char * dtype ;
const gpre_fld * field = reference - > ref_field ;
2001-05-23 15:26:42 +02:00
switch ( field - > fld_dtype ) {
case dtype_short :
dtype = " short " ;
break ;
case dtype_long :
dtype = " long " ;
break ;
case dtype_cstring :
case dtype_text :
dtype = " char* " ;
break ;
case dtype_quad :
dtype = " ISC_QUAD " ;
break ;
case dtype_date :
case dtype_blob :
dtype = " ISC_QUAD " ;
break ;
case dtype_real :
dtype = " float " ;
break ;
case dtype_double :
dtype = " double " ;
break ;
default :
2003-10-15 00:22:32 +02:00
CPR_error ( " gen_function: unsupported datatype " ) ;
2002-07-06 07:32:02 +02:00
return ;
2001-05-23 15:26:42 +02:00
}
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s \t %s; \n " , dtype ,
2003-09-10 21:48:53 +02:00
gen_name ( s , reference - > ref_source , true ) ) ;
2001-05-23 15:26:42 +02:00
}
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " { \n " ) ;
2001-05-23 15:26:42 +02:00
for ( port = request - > req_ports ; port ; port = port - > por_next )
make_port ( port ) ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " \n \n " ) ;
2001-05-23 15:26:42 +02:00
gen_s_start ( action ) ;
gen_receive ( action , request - > req_primary ) ;
for ( port = request - > req_ports ; port ; port = port - > por_next )
for ( reference = port - > por_references ; reference ;
2003-09-13 14:22:11 +02:00
reference = reference - > ref_next )
{
if ( reference - > ref_field - > fld_array_info )
gen_get_or_put_slice ( action , reference , true ) ;
}
2001-05-23 15:26:42 +02:00
port = request - > req_primary ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " \n return %s; \n } \n " ,
2003-09-10 21:48:53 +02:00
gen_name ( s , port - > por_references , true ) ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a call to isc_get_slice
// or isc_put_slice for an array.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_get_or_put_slice ( const act * action ,
2004-11-28 04:43:42 +01:00
const ref * reference ,
2003-09-10 21:48:53 +02:00
bool get )
2001-05-23 15:26:42 +02:00
{
2004-10-30 07:30:08 +02:00
const TEXT * pattern1 =
2001-05-23 15:26:42 +02:00
" CALL \" %S7 \" USING %V1, %RF%DH%RE, %RF%S1%RE, %RF%S2%RE, %VF%N1%VE, %RF%S3%RE, %VF%N2%VE, %VF%S4%VE, %VF%L1%VE, %RF%S5%RE, %RF%S6%RE " ;
2004-10-30 07:30:08 +02:00
const TEXT * pattern2 =
2001-05-23 15:26:42 +02:00
" CALL \" %S7 \" USING %V1, %RF%DH%RE, %RF%S1%RE, %RF%S2%RE, %VF%N1%VE, %RF%S3%RE, %VF%N2%VE, %VF%S4%VE, %VF%L1%VE, %RF%S5%RE " ;
if ( ! ( reference - > ref_flags & REF_fetch_array ) )
2002-07-06 07:32:02 +02:00
return ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const int column = strlen ( names [ COLUMN ] ) ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
PAT args ;
2003-09-11 04:13:46 +02:00
args . pat_condition = get ; // get or put slice
2003-09-10 21:48:53 +02:00
args . pat_vector1 = status_vector ( action ) ; // status vector
args . pat_database = action - > act_request - > req_database ; // database handle
args . pat_string1 = action - > act_request - > req_trans ; // transaction handle
2001-05-23 15:26:42 +02:00
2005-01-03 09:07:41 +01:00
TEXT s1 [ MAX_REF_SIZE ] ;
2003-09-10 21:48:53 +02:00
gen_name ( s1 , reference , true ) ; // blob handle
2001-05-23 15:26:42 +02:00
args . pat_string2 = s1 ;
2008-12-05 02:20:14 +01:00
args . pat_value1 = reference - > ref_sdl_length ; // slice descr length
2001-05-23 15:26:42 +02:00
2005-01-03 09:07:41 +01:00
TEXT s2 [ MAX_REF_SIZE ] ;
2008-12-05 02:20:14 +01:00
sprintf ( s2 , " %s%d " , names [ isc_a_pos ] , reference - > ref_sdl_ident ) ; // slice description
2001-05-23 15:26:42 +02:00
args . pat_string3 = s2 ;
2008-12-05 02:20:14 +01:00
args . pat_value2 = 0 ; // parameter length
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
args . pat_string4 = " 0 " ; // parameter
2001-05-23 15:26:42 +02:00
args . pat_long1 = reference - > ref_field - > fld_array_info - > ary_size ;
2008-12-05 02:20:14 +01:00
// slice size
2005-01-03 09:07:41 +01:00
TEXT s4 [ MAX_REF_SIZE + 2 ] ;
2001-05-23 15:26:42 +02:00
if ( action - > act_flags & ACT_sql ) {
args . pat_string5 = reference - > ref_value ;
}
else {
2003-10-15 00:22:32 +02:00
sprintf ( s4 , " %s%dL " , names [ isc_a_pos ] ,
2001-05-23 15:26:42 +02:00
reference - > ref_field - > fld_array_info - > ary_ident ) ;
2008-12-05 02:20:14 +01:00
args . pat_string5 = s4 ; // array name
2001-05-23 15:26:42 +02:00
}
2008-12-05 02:20:14 +01:00
args . pat_string6 = names [ ISC_ARRAY_LENGTH ] ; // return length
2004-10-30 07:30:08 +02:00
args . pat_string7 = ( get ) ? ISC_GET_SLICE : ISC_PUT_SLICE ;
2001-05-23 15:26:42 +02:00
PATTERN_expand ( column , ( get ) ? pattern1 : pattern2 , & args ) ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " \n " ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate the code to do a get segment.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_get_segment ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const blb * blob ;
2001-05-23 15:26:42 +02:00
TEXT buffer [ 128 ] ;
if ( action - > act_flags & ACT_sql )
2004-01-28 08:50:41 +01:00
blob = ( blb * ) action - > act_request - > req_blobs ;
2001-05-23 15:26:42 +02:00
else
2004-01-28 08:50:41 +01:00
blob = ( blb * ) action - > act_object ;
2001-05-23 15:26:42 +02:00
2005-01-19 09:59:23 +01:00
strcpy ( buffer , GET_SEG_CALL_TEMPLATE ) ; // Copy seems useless instead of using constant directly.
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer ,
buffer ,
names [ COLUMN ] ,
ISC_GET_SEGMENT ,
2003-10-15 00:22:32 +02:00
names [ isc_status_vector_pos ] ,
names [ isc_a_pos ] , blob - > blb_ident ,
names [ isc_a_pos ] , blob - > blb_len_ident ,
2001-05-23 15:26:42 +02:00
BY_VALUE , blob - > blb_seg_length , END_VALUE ,
2003-10-15 00:22:32 +02:00
BY_REF , names [ isc_a_pos ] , blob - > blb_buff_ident , names [ isc_status_pos ] ) ;
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
if ( action - > act_flags & ACT_sql ) {
2004-11-28 04:43:42 +01:00
const ref * into = action - > act_object ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF SQLCODE = 0 OR SQLCODE = 101 THEN " ) ;
2005-01-19 09:59:23 +01:00
printa ( names [ COLUMN ] , false , " MOVE %s%d TO %s " ,
names [ isc_a_pos ] , blob - > blb_buff_ident , into - > ref_value ) ;
2001-05-23 15:26:42 +02:00
if ( into - > ref_null_value )
2005-01-19 09:59:23 +01:00
printa ( names [ COLUMN ] , false , " MOVE %s%d TO %s " ,
names [ isc_a_pos ] , blob - > blb_len_ident , into - > ref_null_value ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
// Generate text to compile and start a SQL mass update.
//
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_loop ( const act * action )
2001-05-23 15:26:42 +02:00
{
gen_s_start ( action ) ;
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF SQLCODE = 0 THEN " ) ;
2004-11-28 04:43:42 +01:00
const gpre_port * port = request - > req_primary ;
2001-05-23 15:26:42 +02:00
gen_receive ( action , port ) ;
2004-11-28 04:43:42 +01:00
2005-01-03 09:07:41 +01:00
TEXT name [ MAX_REF_SIZE ] ;
2003-09-10 21:48:53 +02:00
gen_name ( name , port - > por_references , true ) ;
printa ( names [ COLUMN ] , false , " IF SQLCODE = 0 AND %s = 0 THEN " , name ) ;
printa ( names [ COLUMN ] , false , " MOVE 100 TO SQLCODE " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a name for a reference. Name is constructed from
// port and parameter idents.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2005-01-05 09:25:24 +01:00
static TEXT * gen_name ( TEXT * const string ,
2003-10-29 11:53:47 +01:00
const ref * reference ,
2003-09-10 21:48:53 +02:00
bool as_blob )
2001-05-23 15:26:42 +02:00
{
if ( reference - > ref_field - > fld_array_info & & ! as_blob )
2005-01-03 09:07:41 +01:00
fb_utils : : snprintf ( string , MAX_REF_SIZE , " %s%d " , names [ isc_a_pos ] ,
2001-05-23 15:26:42 +02:00
reference - > ref_field - > fld_array_info - > ary_ident ) ;
else
2005-01-03 09:07:41 +01:00
fb_utils : : snprintf ( string , MAX_REF_SIZE , " %s%d " , names [ isc_b_pos ] ,
reference - > ref_ident ) ;
2001-05-23 15:26:42 +02:00
return string ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a block to handle errors.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_on_error ( const act * action )
2001-05-23 15:26:42 +02:00
{
2003-10-15 00:22:32 +02:00
printa ( names [ COLUMN ] , false , " IF %s (2) NOT = 0 THEN " , names [ isc_status_pos ] ) ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , names [ COLUMN ] ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate code for an EXECUTE PROCEDURE.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_procedure ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
const gpre_port * in_port = request - > req_vport ;
const gpre_port * out_port = request - > req_primary ;
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
PAT args ;
2003-09-05 12:14:08 +02:00
args . pat_database = request - > req_database ;
2001-05-23 15:26:42 +02:00
args . pat_request = action - > act_request ;
args . pat_vector1 = status_vector ( action ) ;
args . pat_request = request ;
args . pat_port = in_port ;
args . pat_port2 = out_port ;
2003-10-29 11:53:47 +01:00
const TEXT * pattern ;
2001-05-23 15:26:42 +02:00
if ( in_port & & in_port - > por_length )
2008-01-16 08:15:01 +01:00
{
2001-05-23 15:26:42 +02:00
pattern =
" CALL \" isc_transact_request \" USING %V1, %RF%DH%RE, %RF%RT%RE, %VF%RS%VE, %RF%RI%RE, %VF%PL%VE, %RF%PI%RE, %VF%QL%VE, %RF%QI%RE \n " ;
2008-01-16 08:15:01 +01:00
}
2001-05-23 15:26:42 +02:00
else
2008-01-16 08:15:01 +01:00
{
2001-05-23 15:26:42 +02:00
pattern =
" CALL \" isc_transact_request \" USING %V1, %RF%DH%RE, %RF%RT%RE, %VF%RS%VE, %RI, %VF0%VE, 0, %VF%QL%VE, %RF%QI%RE \n " ;
2008-01-16 08:15:01 +01:00
}
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// Get database attach and transaction started
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-10 21:48:53 +02:00
t_start_auto ( 0 , status_vector ( action ) , action , true ) ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// Move in input values
2001-05-23 15:26:42 +02:00
asgn_from ( action , request - > req_values ) ;
2008-12-05 02:20:14 +01:00
// Execute the procedure
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
const USHORT column = strlen ( names [ COLUMN ] ) ;
2001-05-23 15:26:42 +02:00
PATTERN_expand ( column , pattern , & args ) ;
set_sqlcode ( action ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF SQLCODE = 0 THEN " ) ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// Move out output values
2001-05-23 15:26:42 +02:00
asgn_to_proc ( request - > req_references ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate the code to do a put segment.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_put_segment ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const blb * blob ;
2001-05-23 15:26:42 +02:00
if ( action - > act_flags & ACT_sql ) {
2004-01-28 08:50:41 +01:00
blob = ( blb * ) action - > act_request - > req_blobs ;
2004-11-28 04:43:42 +01:00
const ref * from = action - > act_object ;
2005-01-19 09:59:23 +01:00
printa ( names [ COLUMN ] , false , " MOVE %s TO %s%d " ,
from - > ref_value , names [ isc_a_pos ] , blob - > blb_buff_ident ) ;
printa ( names [ COLUMN ] , false , " MOVE %s TO %s%d " ,
from - > ref_null_value , names [ isc_a_pos ] , blob - > blb_len_ident ) ;
2001-05-23 15:26:42 +02:00
}
else
2004-01-28 08:50:41 +01:00
blob = ( blb * ) action - > act_object ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
TEXT buffer [ 128 ] ;
2001-05-23 15:26:42 +02:00
strcpy ( buffer , PUT_SEG_CALL_TEMPLATE ) ;
sprintf ( output_buffer ,
buffer ,
names [ COLUMN ] ,
ISC_PUT_SEGMENT ,
status_vector ( action ) ,
2003-10-15 00:22:32 +02:00
BY_REF , names [ isc_a_pos ] , blob - > blb_ident ,
BY_VALUE , names [ isc_a_pos ] , blob - > blb_len_ident , END_VALUE ,
BY_REF , names [ isc_a_pos ] , blob - > blb_buff_ident , names [ isc_status_pos ] ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate BLR in raw, numeric form. Ughly but dense.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2002-07-06 07:32:02 +02:00
static void gen_raw (
2004-11-28 04:43:42 +01:00
const UCHAR * blr ,
2001-05-23 15:26:42 +02:00
enum req_t request_type , int request_length , int ident )
{
union {
UCHAR bytewise_blr [ 4 ] ;
ULONG longword_blr ;
} blr_hunk ;
2004-11-28 04:43:42 +01:00
int length = 1 ;
int blr_length = request_length ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
TEXT s [ 256 ] ;
2001-05-23 15:26:42 +02:00
while ( blr_length ) {
s [ 0 ] = 0 ;
blr_hunk . longword_blr = 0 ;
2004-11-28 04:43:42 +01:00
for ( UCHAR * c = blr_hunk . bytewise_blr ;
2003-09-11 04:13:46 +02:00
c < blr_hunk . bytewise_blr + sizeof ( SLONG ) ; c + + )
{
2001-05-23 15:26:42 +02:00
if ( - - blr_length )
* c = * blr + + ;
else {
if ( request_type = = REQ_slice )
* c = isc_sdl_eoc ;
else if ( ( request_type = = REQ_ddl ) | |
2003-09-11 04:13:46 +02:00
( request_type = = REQ_create_database ) )
{
* c = * blr + + ;
}
2001-05-23 15:26:42 +02:00
else
* c = blr_eoc ;
break ;
}
}
strcat ( s , names [ COLUMN ] ) ;
strcat ( s , RAW_BLR_TEMPLATE ) ;
strcat ( s , " \n " ) ;
2003-10-15 00:22:32 +02:00
sprintf ( output_buffer , s , names [ isc_a_pos ] , ident , names [ UNDER ] , length + + ,
2001-05-23 15:26:42 +02:00
blr_hunk . longword_blr ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for READY
// This becomes baroque for mpexl where we
// must generate a variable if the user gives us
// a string literal. mpexl cobol doesn't take
// string literals as CALL parameters.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_ready ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-08 04:33:26 +01:00
TEXT dbname [ 96 ] ;
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
const TEXT * vector = status_vector ( action ) ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
for ( const rdy * ready = ( rdy * ) action - > act_object ; ready ; ready = ready - > rdy_next )
{
const dbb * db = ready - > rdy_database ;
const dbb * dbisc = ( DBB ) db - > dbb_name - > sym_object ;
USHORT namelength ;
2004-11-08 04:33:26 +01:00
const TEXT * filename = ready - > rdy_filename ;
if ( ! filename ) {
2001-05-23 15:26:42 +02:00
filename = db - > dbb_runtime ;
if ( filename ) {
namelength = strlen ( filename ) ;
2005-01-19 09:59:23 +01:00
sprintf ( dbname , " %s%ddb " , names [ isc_b_pos ] , dbisc - > dbb_id ) ;
2001-05-23 15:26:42 +02:00
filename = dbname ;
}
else
namelength = 0 ;
}
else
namelength = strlen ( filename ) ;
2008-01-16 08:15:01 +01:00
2001-05-23 15:26:42 +02:00
/* string literal or user defined variable? */
if ( ready - > rdy_id ) {
2005-01-19 09:59:23 +01:00
sprintf ( dbname , " %s%ddb " , names [ isc_b_pos ] , ready - > rdy_id ) ;
2001-05-23 15:26:42 +02:00
filename = dbname ;
namelength - = 2 ;
}
else
namelength = 0 ;
2008-01-16 08:15:01 +01:00
2001-05-23 15:26:42 +02:00
make_ready ( db , filename , vector , ready - > rdy_request , namelength ) ;
set_sqlcode ( action ) ;
}
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , names [ COLUMN ] ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for RELEASE_REQUESTS
// For active databases, call isc_release_request.
// for all others, just zero the handle. For the
// release request calls, ignore error returns, which
// are likely if the request was compiled on a database
// which has been released and re-readied. If there is
// a serious error, it will be caught on the next statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_release ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const dbb * exp_db = ( DBB ) action - > act_object ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
for ( const gpre_req * request = gpreGlob . requests ; request ; request = request - > req_next )
{
const dbb * db = request - > req_database ;
2001-05-23 15:26:42 +02:00
if ( exp_db & & db ! = exp_db )
continue ;
if ( ! ( request - > req_flags & REQ_exp_hand ) ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s = 0 THEN " ,
2001-05-23 15:26:42 +02:00
db - > dbb_name - > sym_string ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true , " CALL \" %s \" USING %s, %s%s " ,
2001-05-23 15:26:42 +02:00
ISC_RELEASE_REQUEST , status_vector ( action ) , BY_REF ,
request - > req_handle ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
printa ( names [ COLUMN ] , false , " MOVE 0 to %s " , request - > req_handle ) ;
2001-05-23 15:26:42 +02:00
}
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a send or receive call for a port.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
static void gen_receive ( const act * action , const gpre_port * port )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s, %s%s, %s%d%s, %s%d%s, %s%s%d, %s%s%s \n " ,
names [ COLUMN ] ,
ISC_RECEIVE ,
status_vector ( action ) ,
BY_REF , request - > req_handle ,
BY_VALUE , port - > por_msg_number , END_VALUE ,
BY_VALUE , port - > por_length , END_VALUE ,
2003-10-15 00:22:32 +02:00
BY_REF , names [ isc_a_pos ] , port - > por_ident ,
2001-05-23 15:26:42 +02:00
BY_VALUE , request - > req_request_level , END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate definitions associated with a single request.
2008-12-05 02:20:14 +01:00
// Requests are generated as raw BLR in longword chunks
2001-05-23 15:26:42 +02:00
// because COBOL is a miserable excuse for a language
// and doesn't allow byte value assignments to character
// fields.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2004-01-28 08:50:41 +01:00
static void gen_request ( gpre_req * request )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
if ( ! ( request - > req_flags & ( REQ_exp_hand | REQ_sql_blob_open
2003-09-11 04:13:46 +02:00
| REQ_sql_blob_create ) ) & & request - > req_type ! = REQ_slice
& & request - > req_type ! = REQ_procedure )
{
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false ,
2001-05-23 15:26:42 +02:00
" 01 %s PIC S9(9) USAGE COMP VALUE IS 0. " ,
request - > req_handle ) ;
2003-09-11 04:13:46 +02:00
}
2001-05-23 15:26:42 +02:00
if ( request - > req_type = = REQ_ready )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false ,
2003-10-15 00:22:32 +02:00
" 01 %s%dL PIC S9(4) USAGE %s VALUE IS %d. " , names [ isc_a_pos ] ,
2001-05-23 15:26:42 +02:00
request - > req_ident , COMP_VALUE , request - > req_length ) ;
// check the case where we need to extend the dpb dynamically at runtime,
2008-12-05 02:20:14 +01:00
// in which case we need dpb length and a pointer to be defined even if
// there is no static dpb defined
2001-05-23 15:26:42 +02:00
if ( request - > req_flags & REQ_extend_dpb ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false ,
2005-01-19 09:59:23 +01:00
" 01 %s%dP PIC S9(9) USAGE COMP-5 VALUE IS 0. " ,
names [ isc_a_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
}
2003-02-27 17:05:18 +01:00
2001-05-23 15:26:42 +02:00
if ( request - > req_flags & ( REQ_sql_blob_open | REQ_sql_blob_create ) )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false ,
2003-10-15 00:22:32 +02:00
" 01 %s%dS PIC S9(9) USAGE COMP VALUE IS 0. " , names [ isc_a_pos ] ,
2001-05-23 15:26:42 +02:00
request - > req_ident ) ;
2008-12-05 02:20:14 +01:00
// generate the request as BLR long words
2001-05-23 15:26:42 +02:00
if ( request - > req_length ) {
if ( request - > req_flags & REQ_sql_cursor )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false ,
2003-10-15 00:22:32 +02:00
" 01 %s%dS PIC S9(9) USAGE COMP VALUE IS 0. " , names [ isc_a_pos ] ,
2001-05-23 15:26:42 +02:00
request - > req_ident ) ;
# ifdef SCROLLABLE_CURSORS
if ( request - > req_flags & REQ_scroll )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false ,
2003-10-15 00:22:32 +02:00
" 01 %s%dDI PIC S9(4) USAGE COMP VALUE IS 0. " , names [ isc_a_pos ] ,
2001-05-23 15:26:42 +02:00
request - > req_ident ) ;
# endif
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%d. " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
gen_raw ( request - > req_blr , request - > req_type , request - > req_length ,
request - > req_ident ) ;
2008-12-05 02:20:14 +01:00
2004-06-05 11:37:18 +02:00
const char * string_type ;
2008-06-03 08:14:59 +02:00
if ( ! gpreGlob . sw_raw ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COMMENT ] , false , " " ) ;
printa ( names [ COMMENT ] , false , " FORMATTED REQUEST BLR FOR %s%d = " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
switch ( request - > req_type ) {
case REQ_create_database :
case REQ_ready :
string_type = " DPB " ;
2003-09-28 23:36:05 +02:00
if ( PRETTY_print_cdb ( request - > req_blr , gen_blr , 0 , 0 ) )
2003-10-15 00:22:32 +02:00
CPR_error ( " internal error during parameter generation " ) ;
2001-05-23 15:26:42 +02:00
break ;
case REQ_ddl :
string_type = " DYN " ;
2003-09-28 23:36:05 +02:00
if ( PRETTY_print_dyn ( request - > req_blr , gen_blr , 0 , 0 ) )
2003-10-15 00:22:32 +02:00
CPR_error ( " internal error during dynamic DDL generation " ) ;
2001-05-23 15:26:42 +02:00
break ;
case REQ_slice :
string_type = " SDL " ;
2003-09-28 23:36:05 +02:00
if ( PRETTY_print_sdl ( request - > req_blr , gen_blr , 0 , 0 ) )
2003-10-15 00:22:32 +02:00
CPR_error ( " internal error during SDL generation " ) ;
2001-05-23 15:26:42 +02:00
break ;
default :
string_type = " BLR " ;
2003-09-28 23:36:05 +02:00
if ( gds__print_blr ( request - > req_blr , gen_blr , 0 , 0 ) )
2003-10-15 00:22:32 +02:00
CPR_error ( " internal error during BLR generation " ) ;
2001-05-23 15:26:42 +02:00
}
}
else {
switch ( request - > req_type ) {
case REQ_create_database :
case REQ_ready :
string_type = " DPB " ;
break ;
case REQ_ddl :
string_type = " DYN " ;
break ;
case REQ_slice :
string_type = " SDL " ;
break ;
default :
string_type = " BLR " ;
}
}
2003-09-10 21:48:53 +02:00
printa ( names [ COMMENT ] , false , " " ) ;
printa ( names [ COMMENT ] , false , " END OF %s STRING FOR REQUEST %s%d \n " ,
2003-10-15 00:22:32 +02:00
string_type , names [ isc_a_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
}
2008-12-05 02:20:14 +01:00
// Print out slice description language if there are arrays associated with request
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
for ( gpre_port * port = request - > req_ports ; port ; port = port - > por_next )
for ( const ref * reference = port - > por_references ; reference ;
2003-09-13 14:22:11 +02:00
reference = reference - > ref_next )
{
if ( reference - > ref_sdl ) {
2003-10-15 00:22:32 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%d. " , names [ isc_a_pos ] ,
2001-05-23 15:26:42 +02:00
reference - > ref_sdl_ident ) ;
2004-06-03 09:31:10 +02:00
gen_raw ( reference - > ref_sdl , REQ_slice ,
2001-05-23 15:26:42 +02:00
reference - > ref_sdl_length , reference - > ref_sdl_ident ) ;
2004-05-24 19:13:38 +02:00
if ( ! gpreGlob . sw_raw )
2003-09-28 23:36:05 +02:00
if ( PRETTY_print_sdl ( reference - > ref_sdl , gen_blr , 0 , 0 ) )
2003-10-15 00:22:32 +02:00
CPR_error ( " internal error during SDL generation " ) ;
2001-05-23 15:26:42 +02:00
2003-09-10 21:48:53 +02:00
printa ( names [ COMMENT ] , false , " " ) ;
printa ( names [ COMMENT ] , false ,
2003-10-15 00:22:32 +02:00
" END OF SDL STRING FOR %s%d */ \n " , names [ isc_a_pos ] ,
2001-05-23 15:26:42 +02:00
reference - > ref_sdl_ident ) ;
}
2003-09-13 14:22:11 +02:00
}
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// Print out any blob parameter blocks required
2004-11-28 04:43:42 +01:00
for ( const blb * blob = request - > req_blobs ; blob ; blob = blob - > blb_next )
2001-05-23 15:26:42 +02:00
if ( blob - > blb_const_from_type | | blob - > blb_const_to_type ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%d. " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , blob - > blb_bpb_ident ) ;
2001-05-23 15:26:42 +02:00
gen_raw ( blob - > blb_bpb , request - > req_type , blob - > blb_bpb_length ,
2006-06-23 10:33:33 +02:00
( int ) ( IPTR ) request ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COMMENT ] , false , " " ) ;
2001-05-23 15:26:42 +02:00
}
2008-12-05 02:20:14 +01:00
// If this is a GET_SLICE/PUT_slice, allocate some variables
2001-05-23 15:26:42 +02:00
if ( request - > req_type = = REQ_slice ) {
2003-10-15 00:22:32 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%dv. " , names [ isc_b_pos ] ,
2001-05-23 15:26:42 +02:00
request - > req_ident ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false ,
2001-05-23 15:26:42 +02:00
" 03 %s%dv_3 PIC S9(9) USAGE COMP OCCURS %d TIMES. " ,
2004-12-16 04:03:13 +01:00
names [ isc_b_pos ] , request - > req_ident ,
MAX ( 1 , request - > req_slice - > slc_parameters ) ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%ds PIC S9(9) USAGE COMP. " ,
2003-10-15 00:22:32 +02:00
names [ isc_b_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for END_STREAM.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_s_end ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
if ( action - > act_type = = ACT_close )
gen_cursor_close ( action , request ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s, %s%s%s " ,
ISC_UNWIND_REQUEST ,
status_vector ( action ) ,
BY_REF , request - > req_handle ,
BY_VALUE , request - > req_request_level , END_VALUE ) ;
if ( action - > act_type = = ACT_close ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for FETCH.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_s_fetch ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
if ( request - > req_sync )
gen_send ( action , request - > req_sync ) ;
gen_receive ( action , request - > req_primary ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate text to compile and start a stream. This is
// used both by START_STREAM and FOR
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_s_start ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
gen_compile ( action ) ;
2004-11-28 04:43:42 +01:00
const gpre_port * port = request - > req_vport ;
if ( port )
2001-05-23 15:26:42 +02:00
asgn_from ( action , port - > por_references ) ;
if ( action - > act_type = = ACT_open )
gen_cursor_open ( action , request ) ;
2008-12-05 02:20:14 +01:00
// Do not call "gen_start" in case if "gen_compile" failed
2001-05-23 15:26:42 +02:00
if ( action - > act_error | | ( action - > act_flags & ACT_sql ) ) {
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 AND %s NOT = 0 THEN " ,
2001-05-23 15:26:42 +02:00
request_trans ( action , request ) , request - > req_handle ) ;
else
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " ,
2001-05-23 15:26:42 +02:00
request - > req_handle ) ;
}
gen_start ( action , port ) ;
if ( action - > act_error | | ( action - > act_flags & ACT_sql ) )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
if ( action - > act_type = = ACT_open ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a send call for a port.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
static void gen_send ( const act * action , const gpre_port * port )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s, %s%s, %s%d%s, %s%d%s, %s%s%d, %s%s%s \n " ,
names [ COLUMN ] ,
ISC_SEND ,
status_vector ( action ) ,
BY_REF , request - > req_handle ,
BY_VALUE , port - > por_msg_number , END_VALUE ,
BY_VALUE , port - > por_length , END_VALUE ,
2003-10-15 00:22:32 +02:00
BY_REF , names [ isc_a_pos ] , port - > por_ident ,
2001-05-23 15:26:42 +02:00
BY_VALUE , request - > req_request_level , END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate support for get/put slice statement.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_slice ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-10-30 07:30:08 +02:00
const TEXT * pattern1 =
2001-05-23 15:26:42 +02:00
" CALL \" %S7 \" USING %V1, %RF%DH%RE, %RF%RT%RE, %RF%FR%RE, %VF%N1%VE, %RF%I1%RE, %VF%N2%VE, %RF%I1v%RE, %VF%I1s%VE, %RF%S5%RE, %RF%S6%RE " ;
2004-10-30 07:30:08 +02:00
const TEXT * pattern2 =
2001-05-23 15:26:42 +02:00
" CALL \" %S7 \" USING %V1, %RF%DH%RE, %RF%RT%RE, %RF%FR%RE, %VF%N1%VE, %RF%I1%RE, %VF%N2%VE, %RF%I1v%RE, %VF%I1s%VE, %RF%S5%RE " ;
2004-11-28 04:43:42 +01:00
const USHORT column = strlen ( names [ COLUMN ] ) ;
const gpre_req * request = action - > act_request ;
const slc * slice = ( slc * ) action - > act_object ;
const gpre_req * parent_request = slice - > slc_parent_request ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// Compute array size
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " COMPUTE %s%ds = %d " ,
2003-10-15 00:22:32 +02:00
names [ isc_b_pos ] ,
2001-05-23 15:26:42 +02:00
request - > req_ident , slice - > slc_field - > fld_array - > fld_length ) ;
2004-11-28 04:43:42 +01:00
const slc : : slc_repeat * tail , * end ;
2001-05-23 15:26:42 +02:00
for ( tail = slice - > slc_rpt , end = tail + slice - > slc_dimensions ;
tail < end ; + + tail )
2004-11-28 04:43:42 +01:00
{
2001-05-23 15:26:42 +02:00
if ( tail - > slc_upper ! = tail - > slc_lower ) {
2004-11-28 04:43:42 +01:00
const ref * lower = ( REF ) tail - > slc_lower - > nod_arg [ 0 ] ;
const ref * upper = ( REF ) tail - > slc_upper - > nod_arg [ 0 ] ;
2001-05-23 15:26:42 +02:00
if ( lower - > ref_value )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " * ( %s - %s + 1) " , upper - > ref_value ,
2001-05-23 15:26:42 +02:00
lower - > ref_value ) ;
else
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " * ( %s + 1) " , upper - > ref_value ) ;
2001-05-23 15:26:42 +02:00
}
2004-11-28 04:43:42 +01:00
}
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " \n " ) ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// Make assignments to variable vector
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const ref * reference ;
2001-05-23 15:26:42 +02:00
for ( reference = request - > req_values ; reference ;
2003-09-10 21:48:53 +02:00
reference = reference - > ref_next )
{
printa ( names [ COLUMN ] , false , " MOVE %s TO %s%dv (%d) " ,
2003-10-15 00:22:32 +02:00
reference - > ref_value , names [ isc_a_pos ] ,
2003-09-10 21:48:53 +02:00
request - > req_ident , reference - > ref_id ) ;
}
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
PAT args ;
2001-05-23 15:26:42 +02:00
args . pat_reference = slice - > slc_field_ref ;
2008-12-05 02:20:14 +01:00
args . pat_request = parent_request ; // blob id request
args . pat_vector1 = status_vector ( action ) ; // status vector
args . pat_database = parent_request - > req_database ; // database handle
args . pat_string1 = action - > act_request - > req_trans ; // transaction handle
args . pat_value1 = request - > req_length ; // slice descr. length
args . pat_ident1 = request - > req_ident ; // request name
args . pat_value2 = slice - > slc_parameters * sizeof ( SLONG ) ; // parameter length
2001-05-23 15:26:42 +02:00
reference = ( REF ) slice - > slc_array - > nod_arg [ 0 ] ;
2008-12-05 02:20:14 +01:00
args . pat_string5 = reference - > ref_value ; // array name
2001-05-23 15:26:42 +02:00
args . pat_string6 = names [ ISC_ARRAY_LENGTH ] ;
args . pat_string7 =
2004-10-30 07:30:08 +02:00
( action - > act_type = = ACT_get_slice ) ? ISC_GET_SLICE : ISC_PUT_SLICE ;
2001-05-23 15:26:42 +02:00
PATTERN_expand ( column ,
( action - > act_type = = ACT_get_slice ) ? pattern1 : pattern2 ,
& args ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Substitute for a segment, segment length, or blob handle.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_segment ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const blb * blob = ( blb * ) action - > act_object ;
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s%d " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] ,
2001-05-23 15:26:42 +02:00
( action - > act_type = = ACT_segment ) ? blob - > blb_buff_ident :
( action - > act_type = =
ACT_segment_length ) ? blob - > blb_len_ident : blob - > blb_ident ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_select ( const act * action )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT name [ MAX_REF_SIZE ] ;
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
const gpre_port * port = request - > req_primary ;
2003-09-10 21:48:53 +02:00
gen_name ( name , request - > req_eof , true ) ;
2001-05-23 15:26:42 +02:00
gen_s_start ( action ) ;
2008-12-05 02:20:14 +01:00
// BUG8321: Do not call "receive" in case if SQLCODE is not equal 0
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF SQLCODE = 0 THEN " ) ;
2001-05-23 15:26:42 +02:00
gen_receive ( action , port ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " , name ) ;
2004-11-28 04:43:42 +01:00
gpre_nod * var_list = ( GPRE_NOD ) action - > act_object ;
if ( var_list )
for ( int i = 0 ; i < var_list - > nod_count ; i + + ) {
2001-07-12 07:46:06 +02:00
asgn_to ( action , ( REF ) var_list - > nod_arg [ i ] ) ;
2001-05-23 15:26:42 +02:00
}
if ( request - > req_database - > dbb_flags & DBB_v3 ) {
gen_receive ( action , port ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s NOT = 0 THEN " , name ) ;
printa ( names [ COLUMN ] , false , " MOVE -1 TO SQLCODE " ) ;
printa ( names [ COLUMN ] , false , " ELSE " ) ;
printa ( names [ COLUMN ] , false , " MOVE 0 TO SQLCODE " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " ELSE " ) ;
printa ( names [ COLUMN ] , false , " MOVE 100 TO SQLCODE " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate either a START or START_AND_SEND depending
// on whether or a not a port is present.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
static void gen_start ( const act * action , const gpre_port * port )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2003-10-06 11:48:44 +02:00
const TEXT * vector = status_vector ( action ) ;
2001-05-23 15:26:42 +02:00
if ( port ) {
2004-11-28 04:43:42 +01:00
for ( const ref * reference = port - > por_references ; reference ;
2003-09-10 21:48:53 +02:00
reference = reference - > ref_next )
{
2003-09-12 11:06:50 +02:00
if ( reference - > ref_field - > fld_array_info )
2003-09-10 21:48:53 +02:00
gen_get_or_put_slice ( action , reference , false ) ;
}
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s, %s%s, %s%s, %s%d%s, %s%d%s, %s%s%d, %s%s%s \n " ,
names [ COLUMN ] ,
ISC_START_AND_SEND ,
vector ,
BY_REF , request - > req_handle ,
BY_REF , request_trans ( action , request ) ,
BY_VALUE , port - > por_msg_number , END_VALUE ,
BY_VALUE , port - > por_length , END_VALUE ,
2003-10-15 00:22:32 +02:00
BY_REF , names [ isc_a_pos ] , port - > por_ident ,
2001-05-23 15:26:42 +02:00
BY_VALUE , request - > req_request_level , END_VALUE ) ;
}
else
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s, %s%s, %s%s, %s%s%s \n " ,
names [ COLUMN ] ,
ISC_START_REQUEST ,
vector ,
BY_REF , request - > req_handle ,
BY_REF , request_trans ( action , request ) ,
BY_VALUE , request - > req_request_level , END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate text for STORE statement. This includes the compile
// call and any variable initialization required.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_store ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const gpre_req * request = action - > act_request ;
2001-05-23 15:26:42 +02:00
gen_compile ( action ) ;
2008-12-05 02:20:14 +01:00
// Initialize any blob fields
2001-05-23 15:26:42 +02:00
2005-01-03 09:07:41 +01:00
TEXT name [ MAX_REF_SIZE ] ;
2004-11-28 04:43:42 +01:00
const gpre_port * port = request - > req_primary ;
for ( const ref * reference = port - > por_references ; reference ;
reference = reference - > ref_next )
{
const gpre_fld * field = reference - > ref_field ;
2001-05-23 15:26:42 +02:00
if ( field - > fld_flags & FLD_blob )
2008-06-05 13:02:42 +02:00
{
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true , " CALL \" isc_qtoq \" USING %s, %s " ,
2003-10-15 00:22:32 +02:00
names [ isc_blob_null_pos ] , gen_name ( name , reference , true ) ) ;
2008-06-05 13:02:42 +02:00
}
2001-05-23 15:26:42 +02:00
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for START_TRANSACTION.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_t_start ( const act * action )
2001-05-23 15:26:42 +02:00
{
2003-10-29 11:53:47 +01:00
TEXT dbname [ 80 ] ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// if this is a purely default transaction, just let it through
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
const gpre_tra * trans ;
2004-01-28 08:50:41 +01:00
if ( ! action | | ! ( trans = ( gpre_tra * ) action - > act_object ) ) {
2003-09-10 21:48:53 +02:00
t_start_auto ( 0 , status_vector ( action ) , action , false ) ;
2002-07-06 07:32:02 +02:00
return ;
2001-05-23 15:26:42 +02:00
}
2008-12-05 02:20:14 +01:00
// build a complete statement, including tpb's. Ready db's as gpre_req.
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
const tpb * tpb_iterator ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto )
2003-09-05 12:14:08 +02:00
for ( tpb_iterator = trans - > tra_tpb ;
tpb_iterator ;
tpb_iterator = tpb_iterator - > tpb_tra_next )
{
2003-10-29 11:53:47 +01:00
const dbb * db = tpb_iterator - > tpb_database ;
const TEXT * filename = db - > dbb_runtime ;
if ( filename | | ! ( db - > dbb_flags & DBB_sqlca ) ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s = 0 THEN " ,
2001-05-23 15:26:42 +02:00
db - > dbb_name - > sym_string ) ;
2003-10-29 11:53:47 +01:00
const USHORT namelength = filename ? strlen ( filename ) : 0 ;
2001-05-23 15:26:42 +02:00
if ( filename ) {
2005-01-19 09:59:23 +01:00
sprintf ( dbname , " %s%ddb " , names [ isc_b_pos ] , db - > dbb_id ) ;
2001-05-23 15:26:42 +02:00
filename = dbname ;
}
make_ready ( db , filename , status_vector ( action ) , 0 ,
namelength ) ;
set_sqlcode ( action ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
}
}
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2001-05-23 15:26:42 +02:00
" CALL \" %s \" USING %s, %s%s, %s%d%s " ,
ISC_START_TRANSACTION ,
status_vector ( action ) ,
2003-10-15 00:22:32 +02:00
BY_REF , ( trans - > tra_handle ) ? trans - > tra_handle : names [ isc_trans_pos ] ,
2001-05-23 15:26:42 +02:00
BY_VALUE , trans - > tra_db_count , END_VALUE ) ;
2003-09-05 12:14:08 +02:00
for ( tpb_iterator = trans - > tra_tpb ;
tpb_iterator ;
tpb_iterator = tpb_iterator - > tpb_tra_next )
{
2003-09-10 21:48:53 +02:00
printa ( names [ CONTINUE ] , true , " , %s%s, %s%d%s, %s%s%d " ,
2003-09-05 12:14:08 +02:00
BY_REF , tpb_iterator - > tpb_database - > dbb_name - > sym_string ,
BY_VALUE , tpb_iterator - > tpb_length , END_VALUE ,
2003-10-15 00:22:32 +02:00
BY_REF , names [ isc_tpb_pos ] , tpb_iterator - > tpb_ident ) ;
2003-09-05 12:14:08 +02:00
}
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Initialize a TPB in the output file
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
static void gen_tpb ( const tpb * tpb_buffer )
2001-05-23 15:26:42 +02:00
{
union {
UCHAR bytewise_tpb [ 4 ] ;
SLONG longword_tpb ;
} tpb_hunk ;
2008-12-05 02:20:14 +01:00
//
// TPBs are generated as raw BLR in longword chunks
2001-05-23 15:26:42 +02:00
// because COBOL is a miserable excuse for a language
// and doesn't allow byte value assignments to character
// fields.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%d. " ,
2003-10-15 00:22:32 +02:00
names [ isc_tpb_pos ] , tpb_buffer - > tpb_ident ) ;
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
const UCHAR * text = tpb_buffer - > tpb_string ;
int char_len = tpb_buffer - > tpb_length ;
int length = 1 ;
2001-05-23 15:26:42 +02:00
while ( char_len ) {
2003-10-29 11:53:47 +01:00
for ( UCHAR * c = tpb_hunk . bytewise_tpb ;
c < tpb_hunk . bytewise_tpb + sizeof ( SLONG ) ; c + + )
{
2001-05-23 15:26:42 +02:00
* c = * text + + ;
2008-06-03 08:14:59 +02:00
if ( ! - - char_len )
2001-05-23 15:26:42 +02:00
break ;
}
2003-10-16 10:51:06 +02:00
printa ( names [ COLUMN ] , false , RAW_TPB_TEMPLATE ,
2003-10-15 00:22:32 +02:00
names [ isc_tpb_pos ] , tpb_buffer - > tpb_ident ,
2001-05-23 15:26:42 +02:00
names [ UNDER ] , length + + , tpb_hunk . longword_tpb ) ;
}
sprintf ( output_buffer , " %sEnd of data for %s%d \n " ,
2003-10-15 00:22:32 +02:00
names [ COMMENT ] , names [ isc_tpb_pos ] , tpb_buffer - > tpb_ident ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , false ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for COMMIT, ROLLBACK, PREPARE, and SAVE
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_trans ( const act * action )
2001-05-23 15:26:42 +02:00
{
2008-01-16 08:15:01 +01:00
if ( action - > act_type = = ACT_commit_retain_context ) {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true , " CALL \" %s \" USING %s, %s%s " ,
2001-05-23 15:26:42 +02:00
ISC_COMMIT_RETAINING ,
status_vector ( action ) ,
BY_REF ,
2004-12-16 04:03:13 +01:00
( action - > act_object ) ?
( const TEXT * ) ( action - > act_object ) : names [ isc_trans_pos ] ) ;
2008-01-16 08:15:01 +01:00
}
else if ( action - > act_type = = ACT_rollback_retain_context ) {
printa ( names [ COLUMN ] , true , " CALL \" %s \" USING %s, %s%s " ,
ISC_ROLLBACK_RETAINING ,
status_vector ( action ) ,
BY_REF ,
( action - > act_object ) ?
( const TEXT * ) ( action - > act_object ) : names [ isc_trans_pos ] ) ;
}
else {
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true , " CALL \" %s \" USING %s, %s%s " ,
2004-12-16 04:03:13 +01:00
( action - > act_type = = ACT_commit ) ?
ISC_COMMIT_TRANSACTION : ( action - > act_type = = ACT_rollback ) ?
ISC_ROLLBACK_TRANSACTION : ISC_PREPARE_TRANSACTION ,
2001-05-23 15:26:42 +02:00
status_vector ( action ) , BY_REF ,
2004-12-16 04:03:13 +01:00
( action - > act_object ) ?
( const TEXT * ) ( action - > act_object ) : names [ isc_trans_pos ] ) ;
2008-01-16 08:15:01 +01:00
}
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Substitute for a variable reference.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_type ( const act * action )
2001-05-23 15:26:42 +02:00
{
2006-06-23 10:33:33 +02:00
printa ( names [ COLUMN ] , true , " %ld " , ( IPTR ) action - > act_object ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for UPDATE ... WHERE CURRENT OF ...
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_update ( const act * action )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
const upd * modify = ( upd * ) action - > act_object ;
const gpre_port * port = modify - > upd_port ;
2001-05-23 15:26:42 +02:00
asgn_from ( action , port - > por_references ) ;
gen_send ( action , port ) ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Substitute for a variable reference.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void gen_variable ( const act * action )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT s [ MAX_REF_SIZE ] ;
2003-10-29 11:53:47 +01:00
const ref * reference = action - > act_object ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " \n %s%s " ,
2003-09-10 21:48:53 +02:00
names [ COLUMN ] , gen_name ( s , reference , false ) ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate tests for any WHENEVER clauses that may have been declared.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-11-28 07:48:34 +01:00
static void gen_whenever ( const swe * label )
2001-05-23 15:26:42 +02:00
{
2003-10-29 11:53:47 +01:00
const TEXT * condition ;
2001-05-23 15:26:42 +02:00
while ( label ) {
switch ( label - > swe_condition ) {
case SWE_error :
condition = " SQLCODE < 0 " ;
break ;
case SWE_warning :
condition = " SQLCODE > 0 AND SQLCODE NOT = 100 " ;
break ;
case SWE_not_found :
condition = " SQLCODE = 100 " ;
break ;
2004-08-26 23:44:11 +02:00
default :
// condition undefined
fb_assert ( false ) ;
return ;
2001-05-23 15:26:42 +02:00
}
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %sIF (%s) THEN GO TO %s " ,
2001-05-23 15:26:42 +02:00
names [ COLUMN ] , condition , label - > swe_label ) ;
if ( label - > swe_condition = = SWE_warning )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " \n %s " , names [ COLUMN_INDENT ] ) ;
2001-05-23 15:26:42 +02:00
label = label - > swe_next ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " END-IF%s " , ( label ) ? " . \n " : " " ) ;
2001-05-23 15:26:42 +02:00
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate a declaration of an array in the
// output file.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2002-07-06 07:32:02 +02:00
static void make_array_declaration ( REF reference )
2001-05-23 15:26:42 +02:00
{
2003-10-29 11:53:47 +01:00
gpre_fld * field = reference - > ref_field ;
2003-10-06 11:48:44 +02:00
const TEXT * name = field - > fld_symbol - > sym_string ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// Don't generate multiple declarations for the array. V3 Bug 569.
2001-05-23 15:26:42 +02:00
if ( field - > fld_array_info - > ary_declared )
2002-07-06 07:32:02 +02:00
return ;
2001-05-23 15:26:42 +02:00
2003-09-11 04:13:46 +02:00
field - > fld_array_info - > ary_declared = true ;
2001-05-23 15:26:42 +02:00
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s01 %s%dL. \n " ,
2003-10-15 00:22:32 +02:00
names [ COLUMN_0 ] , names [ isc_a_pos ] ,
2001-05-23 15:26:42 +02:00
field - > fld_array_info - > ary_ident ) ;
2005-01-03 09:07:41 +01:00
TEXT space [ 128 ] ;
2001-05-23 15:26:42 +02:00
strcpy ( space , " " ) ;
2008-12-05 02:20:14 +01:00
// Print out the dimension part of the declaration
2003-10-29 11:53:47 +01:00
const dim * dimension = field - > fld_array_info - > ary_dimension ;
int i = 3 ;
for ( ; dimension - > dim_next ; dimension = dimension - > dim_next , i + = 2 )
{
2005-01-03 09:07:41 +01:00
const int dimension_size = dimension - > dim_upper - dimension - > dim_lower + 1 ;
2003-09-10 21:48:53 +02:00
printa ( space , false , " %02d %s%d%s%d OCCURS %d TIMES. " ,
2003-10-15 00:22:32 +02:00
i , names [ isc_a_pos ] , field - > fld_array_info - > ary_ident ,
2001-05-23 15:26:42 +02:00
names [ UNDER ] , i , dimension_size ) ;
2005-01-03 09:07:41 +01:00
strcat ( space , " " ) ; // Will overflow at 41 dimensions, is it relevant?
2001-05-23 15:26:42 +02:00
}
2004-11-28 04:43:42 +01:00
TEXT string1 [ 256 ] ;
2003-10-29 11:53:47 +01:00
TEXT * p = string1 ;
2005-01-03 09:07:41 +01:00
const int dimension_size = dimension - > dim_upper - dimension - > dim_lower + 1 ;
2003-03-27 18:15:48 +01:00
sprintf ( p , " %02d %s%d OCCURS %d TIMES " ,
2003-10-15 00:22:32 +02:00
i , names [ isc_a_pos ] , field - > fld_array_info - > ary_ident , dimension_size ) ;
2001-05-23 15:26:42 +02:00
while ( * p )
p + + ;
2003-10-29 11:53:47 +01:00
SSHORT digits , scale ;
2008-12-05 02:20:14 +01:00
2001-05-23 15:26:42 +02:00
switch ( field - > fld_array_info - > ary_dtype ) {
case dtype_short :
case dtype_long :
digits = ( field - > fld_array_info - > ary_dtype = = dtype_short ) ? 4 : 9 ;
scale = field - > fld_array - > fld_scale ;
strcpy ( p , " PIC S " ) ;
while ( * p )
p + + ;
if ( scale > = - digits & & scale < = 0 ) {
if ( scale > - digits )
sprintf ( p , " 9(%d) " , digits + scale ) ;
while ( * p )
p + + ;
if ( scale )
sprintf ( p , " V9(%d) " , digits - ( digits + scale ) ) ;
}
else if ( scale > 0 )
sprintf ( p , " 9(%d)P(%d) " , digits , scale ) ;
else
sprintf ( p , " VP(%d)9(%d) " , - ( scale + digits ) , digits ) ;
while ( * p )
p + + ;
strcpy ( p , USAGE_COMP ) ;
strcat ( p , " . " ) ;
break ;
case dtype_cstring :
case dtype_text :
case dtype_varying :
sprintf ( p , " PIC X(%d). " , field - > fld_array - > fld_length ) ;
break ;
case dtype_date :
strcpy ( p , " PIC S9(18) " ) ;
strcat ( p , USAGE_COMP ) ;
strcat ( p , " . " ) ;
break ;
case dtype_quad :
sprintf ( p , " PIC S9(%d) " , 18 + field - > fld_array - > fld_scale ) ;
while ( * p )
p + + ;
if ( field - > fld_array - > fld_scale < 0 )
sprintf ( p , " V9(%d) " , - field - > fld_array - > fld_scale ) ;
else if ( field - > fld_array - > fld_scale > 0 )
sprintf ( p , " P(%d) " , field - > fld_array - > fld_scale ) ;
while ( * p )
p + + ;
strcpy ( p , USAGE_COMP ) ;
strcat ( p , " . " ) ;
break ;
2003-10-15 00:22:32 +02:00
case dtype_real :
2001-05-23 15:26:42 +02:00
strcpy ( p , DCL_FLOAT ) ;
strcat ( p , " . " ) ;
break ;
case dtype_double :
strcpy ( p , DCL_DOUBLE ) ;
strcat ( p , " . " ) ;
break ;
default :
2005-01-03 09:07:41 +01:00
{
char s [ ERROR_LENGTH ] ;
fb_utils : : snprintf ( s , sizeof ( s ) ,
" datatype %d unknown for field %s " ,
field - > fld_array_info - > ary_dtype , name ) ;
CPR_error ( s ) ;
return ;
}
2001-05-23 15:26:42 +02:00
}
2003-09-10 21:48:53 +02:00
printa ( space , false , string1 ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Turn a symbol into a varying string.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2005-01-05 09:25:24 +01:00
static void make_name ( TEXT * const string , const gpre_sym * symbol )
2001-05-23 15:26:42 +02:00
{
2005-01-05 09:25:24 +01:00
make_name_formatted ( string , " %s " , symbol ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Turn a symbol into a varying string.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2005-01-05 09:25:24 +01:00
static void make_name_formatted ( TEXT * const string , const TEXT * format ,
2004-01-28 08:50:41 +01:00
const gpre_sym * symbol )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
fb_utils : : snprintf ( string , MAX_CURSOR_SIZE , format , symbol - > sym_string ) ;
2003-10-29 11:53:47 +01:00
for ( TEXT * s = string ; * s ; s + + )
2001-05-23 15:26:42 +02:00
if ( * s = = ' _ ' )
* s = ' - ' ;
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Insert a port record description in output.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2004-01-28 08:50:41 +01:00
static void make_port ( const gpre_port * port )
2001-05-23 15:26:42 +02:00
{
SSHORT digits ;
2003-10-15 00:22:32 +02:00
printa ( names [ COLUMN_0 ] , false , " 01 %s%d. " , names [ isc_a_pos ] , port - > por_ident ) ;
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
for ( const ref * reference = port - > por_references ; reference ;
reference = reference - > ref_next )
{
const gpre_fld * field = reference - > ref_field ;
2003-10-06 11:48:44 +02:00
const TEXT * name ;
2004-01-28 08:50:41 +01:00
const gpre_sym * symbol = field - > fld_symbol ;
2003-10-29 11:53:47 +01:00
if ( symbol )
2001-05-23 15:26:42 +02:00
name = symbol - > sym_string ;
else
name = " <expression> " ;
if ( reference - > ref_value & & ( reference - > ref_flags & REF_array_elem ) )
field = field - > fld_array ;
switch ( field - > fld_dtype ) {
case dtype_short :
case dtype_long :
digits = ( field - > fld_dtype = = dtype_short ) ? 4 : 9 ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s03 %s%d PIC S " ,
2003-10-15 00:22:32 +02:00
names [ COLUMN ] , names [ isc_a_pos ] , reference - > ref_ident ) ;
2001-05-23 15:26:42 +02:00
if ( field - > fld_scale > = - digits & & field - > fld_scale < = 0 ) {
if ( field - > fld_scale > - digits )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " 9(%d) " , digits + field - > fld_scale ) ;
2001-05-23 15:26:42 +02:00
if ( field - > fld_scale )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " V9(%d) " ,
2001-05-23 15:26:42 +02:00
digits - ( digits + field - > fld_scale ) ) ;
}
else if ( field - > fld_scale > 0 )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " 9(%d)P(%d) " , digits , field - > fld_scale ) ;
2001-05-23 15:26:42 +02:00
else
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " VP(%d)9(%d) " ,
2001-05-23 15:26:42 +02:00
- ( field - > fld_scale + digits ) , digits ) ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s. \n " , USAGE_COMP ) ;
2001-05-23 15:26:42 +02:00
break ;
case dtype_cstring :
case dtype_text :
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " 03 %s%d PIC X(%d). " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , reference - > ref_ident , field - > fld_length ) ;
2001-05-23 15:26:42 +02:00
break ;
case dtype_date :
case dtype_quad :
case dtype_blob :
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %s03 %s%d PIC S9( " ,
2003-10-15 00:22:32 +02:00
names [ COLUMN ] , names [ isc_a_pos ] , reference - > ref_ident ) ;
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %d) " , 18 + field - > fld_scale ) ;
2001-05-23 15:26:42 +02:00
if ( field - > fld_scale < 0 )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " V9(%d) " , - field - > fld_scale ) ;
2001-05-23 15:26:42 +02:00
else if ( field - > fld_scale > 0 )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " P(%d) " , field - > fld_scale ) ;
fprintf ( gpreGlob . out_file , " %s. \n " , USAGE_COMP ) ;
2001-05-23 15:26:42 +02:00
break ;
2003-10-15 00:22:32 +02:00
case dtype_real :
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " 03 %s%d %s. " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , reference - > ref_ident , DCL_FLOAT ) ;
2001-05-23 15:26:42 +02:00
break ;
case dtype_double :
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " 03 %s%d %s. " ,
2003-10-15 00:22:32 +02:00
names [ isc_a_pos ] , reference - > ref_ident , DCL_DOUBLE ) ;
2001-05-23 15:26:42 +02:00
break ;
default :
2003-10-29 11:53:47 +01:00
{
2005-01-03 09:07:41 +01:00
TEXT s [ ERROR_LENGTH ] ;
fb_utils : : snprintf ( s , sizeof ( s ) ,
" datatype %d unknown for field %s, msg %d " ,
2003-10-29 11:53:47 +01:00
field - > fld_dtype , name , port - > por_msg_number ) ;
CPR_error ( s ) ;
return ;
}
2001-05-23 15:26:42 +02:00
}
}
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " " ) ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate the actual ready call.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2002-07-06 07:32:02 +02:00
static void make_ready (
2003-10-29 11:53:47 +01:00
const dbb * db ,
2003-10-06 11:48:44 +02:00
const TEXT * filename ,
2003-10-29 11:53:47 +01:00
const TEXT * vector ,
const gpre_req * request , USHORT namelength )
2001-05-23 15:26:42 +02:00
{
2004-11-28 04:43:42 +01:00
TEXT s1 [ 32 ] , s1Tmp [ 32 ] , s2 [ 32 ] , s2Tmp [ 32 ] ;
2003-10-29 11:53:47 +01:00
const dbb * dbisc = ( DBB ) db - > dbb_name - > sym_object ;
2001-05-23 15:26:42 +02:00
if ( request ) {
2003-10-15 00:22:32 +02:00
sprintf ( s1 , " %s%dL " , names [ isc_b_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
if ( request - > req_flags & REQ_extend_dpb )
2003-10-15 00:22:32 +02:00
sprintf ( s2 , " %s%dp " , names [ isc_b_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
else
2003-10-15 00:22:32 +02:00
sprintf ( s2 , " %s%d " , names [ isc_b_pos ] , request - > req_ident ) ;
2001-05-23 15:26:42 +02:00
/* if the dpb needs to be extended at runtime to include items
2008-12-05 02:20:14 +01:00
in host variables , do so here ; this assumes that there is
2001-05-23 15:26:42 +02:00
always a request generated for runtime variables */
if ( request - > req_flags & REQ_extend_dpb ) {
if ( request - > req_length ) {
2005-01-19 09:59:23 +01:00
sprintf ( output_buffer , " %sMOVE %s%d to %s \n " ,
names [ COLUMN ] , names [ isc_b_pos ] , request - > req_ident , s2 ) ;
2001-05-23 15:26:42 +02:00
}
if ( db - > dbb_r_user ) {
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s%s, %s%s, BY VALUE 28, %s %s, %s%d%s \n " ,
names [ COLUMN ] ,
ISC_MODIFY_DPB ,
BY_REF , s2 ,
BY_REF , s1 ,
BY_DESC , db - > dbb_r_user ,
BY_VALUE , strlen ( db - > dbb_r_user ) - 2 , END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
if ( db - > dbb_r_password ) {
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s%s, %s%s, BY VALUE 29, %s %s, %s%d%s \n " ,
names [ COLUMN ] ,
ISC_MODIFY_DPB ,
BY_REF , s2 ,
BY_REF , s1 ,
BY_DESC , db - > dbb_r_password ,
BY_VALUE , strlen ( db - > dbb_r_password ) - 2 , END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
/*
* * = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
* * = =
* * = = Process Role Name , isc_dpb_sql_role_name / 60
* * = =
* * = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/
if ( db - > dbb_r_sql_role ) {
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s%s, %s%s, BY VALUE 60, %s %s, %s%d%s \n " ,
names [ COLUMN ] ,
ISC_MODIFY_DPB ,
BY_REF , s2 ,
BY_REF , s1 ,
BY_DESC , db - > dbb_r_sql_role ,
BY_VALUE , strlen ( db - > dbb_r_sql_role ) - 2 , END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
if ( db - > dbb_r_lc_messages ) {
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s%s, %s%s, BY VALUE 47, %s %s, %s%d%s \n " ,
names [ COLUMN ] ,
ISC_MODIFY_DPB ,
BY_REF , s2 ,
BY_REF , s1 ,
BY_REF , db - > dbb_r_lc_messages ,
BY_VALUE , strlen ( db - > dbb_r_lc_messages ) - 2 ,
END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
if ( db - > dbb_r_lc_ctype ) {
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s%s %s%s, BY VALUE 48, %s %s, %s%d%s \n " ,
names [ COLUMN ] ,
ISC_MODIFY_DPB ,
BY_REF , s2 ,
BY_REF , s1 ,
BY_REF , db - > dbb_r_lc_ctype ,
BY_VALUE , strlen ( db - > dbb_r_lc_ctype ) - 2 , END_VALUE ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
}
if ( request - > req_flags & REQ_extend_dpb ) {
sprintf ( s1Tmp , " %s%s%s " , BY_VALUE , s1 , END_VALUE ) ;
sprintf ( s2Tmp , " %s%s%s " , BY_VALUE , s2 , END_VALUE ) ;
}
else {
sprintf ( s2Tmp , " %s%s " , BY_REF , s2 ) ;
sprintf ( s1Tmp , " %s%d%s " , BY_VALUE , request - > req_length ,
END_VALUE ) ;
}
}
2004-11-28 04:43:42 +01:00
TEXT dbname [ 128 ] ;
2001-05-23 15:26:42 +02:00
if ( ! filename ) {
2003-10-15 00:22:32 +02:00
sprintf ( dbname , " %s%ddb " , names [ isc_b_pos ] , dbisc - > dbb_id ) ;
2001-05-23 15:26:42 +02:00
filename = dbname ;
namelength = strlen ( db - > dbb_filename ) ;
}
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s, %s%d%s, %s %s, %s%s, %s, %s \n " ,
names [ COLUMN ] ,
ISC_ATTACH_DATABASE ,
vector ,
BY_VALUE , namelength , END_VALUE ,
BY_REF , filename ,
BY_REF , db - > dbb_name - > sym_string ,
request ? s1Tmp : OMITTED , request ? s2Tmp : OMITTED ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// if the dpb was extended, free it here
2001-05-23 15:26:42 +02:00
if ( request & & request - > req_flags & REQ_extend_dpb ) {
if ( request - > req_length ) {
sprintf ( output_buffer ,
2005-01-19 09:59:23 +01:00
" if (%s != %s%d) " , s2 , names [ isc_b_pos ] , request - > req_ident ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
sprintf ( output_buffer ,
" %sCALL \" %s \" USING %s \n " , names [ COLUMN ] , ISC_FREE , s2Tmp ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// reset the length of the dpb
2001-05-23 15:26:42 +02:00
sprintf ( output_buffer , " %sMOVE %d to %s \n " ,
names [ COLUMN ] , request - > req_length , s1 ) ;
2003-10-29 11:53:47 +01:00
COB_print_buffer ( output_buffer , true ) ;
2001-05-23 15:26:42 +02:00
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Print a fixed string at a particular COLUMN.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static void printa ( const TEXT * column ,
2003-09-10 21:48:53 +02:00
bool call ,
2003-10-06 11:48:44 +02:00
const TEXT * string ,
2003-09-10 21:48:53 +02:00
. . . )
2001-05-23 15:26:42 +02:00
{
va_list ptr ;
TEXT s [ 256 ] ;
2004-05-24 01:28:06 +02:00
va_start ( ptr , string ) ;
2001-05-23 15:26:42 +02:00
strcpy ( s , column ) ;
strcat ( s , string ) ;
strcat ( s , " \n " ) ;
vsprintf ( output_buffer , s , ptr ) ;
2004-09-25 12:28:09 +02:00
va_end ( ptr ) ;
2001-05-23 15:26:42 +02:00
COB_print_buffer ( output_buffer , call ) ;
}
2003-04-03 10:52:45 +02:00
# ifdef NOT_USED_OR_REPLACED
2001-05-23 15:26:42 +02:00
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Print a fixed string at a particular column.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
static void printb ( const TEXT * string , . . . )
2001-05-23 15:26:42 +02:00
{
va_list ptr ;
2004-05-24 01:28:06 +02:00
va_start ( ptr , string ) ;
2004-05-24 19:13:38 +02:00
vfprintf ( gpreGlob . out_file , string , ptr ) ;
2004-09-25 12:28:09 +02:00
va_end ( ptr ) ;
2001-05-23 15:26:42 +02:00
}
2003-04-03 10:52:45 +02:00
# endif
2001-05-23 15:26:42 +02:00
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate the appropriate transaction handle.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
static const TEXT * request_trans ( const act * action , const gpre_req * request )
2001-05-23 15:26:42 +02:00
{
if ( action - > act_type = = ACT_open ) {
2004-01-28 08:50:41 +01:00
const TEXT * trname = ( ( open_cursor * ) action - > act_object ) - > opn_trans ;
2003-10-06 11:48:44 +02:00
if ( ! trname )
2003-10-15 00:22:32 +02:00
trname = names [ isc_trans_pos ] ;
2001-05-23 15:26:42 +02:00
return trname ;
}
2008-06-03 08:14:59 +02:00
return ( request ) ? request - > req_trans : names [ isc_trans_pos ] ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// generate a CALL to the appropriate SQLCODE routine.
// Note that not all COBOLs have the concept of a function.
2003-10-06 11:48:44 +02:00
static void set_sqlcode ( const act * action )
2001-05-23 15:26:42 +02:00
{
TEXT buffer [ 128 ] ;
if ( action & & action - > act_flags & ACT_sql ) {
strcpy ( buffer , SQLCODE_CALL_TEMPLATE ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , true ,
2003-10-15 00:22:32 +02:00
buffer , ISC_SQLCODE_CALL , names [ isc_status_vector_pos ] ) ;
2001-05-23 15:26:42 +02:00
}
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate the appropriate status vector parameter for a gds
// call depending on where or not the action has an error clause.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
static const TEXT * status_vector ( const act * action )
2001-05-23 15:26:42 +02:00
{
if ( action & & ( action - > act_error | | ( action - > act_flags & ACT_sql ) ) )
2003-10-15 00:22:32 +02:00
return names [ isc_status_vector_pos ] ;
2001-05-23 15:26:42 +02:00
2005-01-03 09:07:41 +01:00
return OMITTED ;
2001-05-23 15:26:42 +02:00
}
//____________________________________________________________
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
// Generate substitution text for START_TRANSACTION,
// when it's being generated automatically by a compile
// call.
2008-12-05 02:20:14 +01:00
//
2001-05-23 15:26:42 +02:00
2003-10-29 11:53:47 +01:00
static void t_start_auto ( const gpre_req * request ,
2003-10-06 11:48:44 +02:00
const TEXT * vector ,
const act * action ,
2003-09-10 21:48:53 +02:00
bool test )
2001-05-23 15:26:42 +02:00
{
2005-01-03 09:07:41 +01:00
TEXT dbname [ 80 ] , buffer [ 256 ] , temp [ MAX_CURSOR_SIZE + 10 ] ;
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
const TEXT * trname = request_trans ( action , request ) ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// find out whether we're using a status vector or not
2001-05-23 15:26:42 +02:00
2003-10-15 00:22:32 +02:00
const bool stat = ! strcmp ( vector , names [ isc_status_vector_pos ] ) ;
2001-05-23 15:26:42 +02:00
2008-12-05 02:20:14 +01:00
// this is a default transaction, make sure all databases are ready
2001-05-23 15:26:42 +02:00
2004-11-28 04:43:42 +01:00
const dbb * db ;
int count ;
2008-12-05 02:20:14 +01:00
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto ) {
2001-05-23 15:26:42 +02:00
buffer [ 0 ] = 0 ;
2004-05-24 19:13:38 +02:00
for ( count = 0 , db = gpreGlob . isc_databases ; db ; db = db - > dbb_next , count + + )
2004-11-08 04:33:26 +01:00
{
const TEXT * filename = db - > dbb_runtime ;
if ( filename | | ! ( db - > dbb_flags & DBB_sqlca ) ) {
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " %sIF %s = 0 " , names [ COLUMN ] ,
2001-05-23 15:26:42 +02:00
db - > dbb_name - > sym_string ) ;
if ( stat & & buffer [ 0 ] )
2004-05-24 19:13:38 +02:00
fprintf ( gpreGlob . out_file , " AND %s(2) = 0 " , names [ isc_status_pos ] ) ;
fprintf ( gpreGlob . out_file , " THEN \n " ) ;
2004-11-28 04:43:42 +01:00
const USHORT namelength = filename ? strlen ( filename ) : 0 ;
2001-05-23 15:26:42 +02:00
if ( filename ) {
2005-01-19 09:59:23 +01:00
sprintf ( dbname , " %s%ddb " , names [ isc_b_pos ] , db - > dbb_id ) ;
2001-05-23 15:26:42 +02:00
filename = dbname ;
}
make_ready ( db , filename , vector , 0 , namelength ) ;
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
if ( buffer [ 0 ] )
strcat ( buffer , " ) AND ( " ) ;
2005-01-03 09:07:41 +01:00
fb_utils : : snprintf ( temp , sizeof ( temp ) , " %s NOT = 0 " ,
db - > dbb_name - > sym_string ) ;
2001-05-23 15:26:42 +02:00
strcat ( buffer , temp ) ;
}
2004-11-08 04:33:26 +01:00
}
2005-01-03 09:07:41 +01:00
fb_assert ( strlen ( buffer ) < sizeof ( buffer ) ) ;
2001-05-23 15:26:42 +02:00
if ( test )
if ( buffer [ 0 ] )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF (%s) AND %s = 0 THEN " ,
2001-05-23 15:26:42 +02:00
buffer , trname ) ;
else
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF %s = 0 THEN " , trname ) ;
2001-05-23 15:26:42 +02:00
else if ( buffer [ 0 ] )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " IF (%s) THEN " , buffer ) ;
2001-05-23 15:26:42 +02:00
}
else
2004-05-24 19:13:38 +02:00
for ( count = 0 , db = gpreGlob . isc_databases ; db ; db = db - > dbb_next , count + + ) ;
2001-05-23 15:26:42 +02:00
2003-10-06 11:48:44 +02:00
const TEXT * col = ( stat ) ? names [ COLUMN_INDENT ] : names [ COLUMN ] ;
2001-05-23 15:26:42 +02:00
2003-09-10 21:48:53 +02:00
printa ( col , true , " CALL \" %s \" USING %s, %s%s, %s%d%s " ,
2001-05-23 15:26:42 +02:00
ISC_START_TRANSACTION , vector , BY_REF , trname ,
BY_VALUE , count , END_VALUE ) ;
2004-05-24 19:13:38 +02:00
for ( db = gpreGlob . isc_databases ; db ; db = db - > dbb_next )
2003-09-10 21:48:53 +02:00
printa ( names [ CONTINUE ] , true , " , %s%s, %s, %s " ,
2001-05-23 15:26:42 +02:00
BY_REF , db - > dbb_name - > sym_string , OMITTED , OMITTED ) ;
2004-05-24 19:13:38 +02:00
if ( gpreGlob . sw_auto & & ( test | | buffer [ 0 ] ) )
2003-09-10 21:48:53 +02:00
printa ( names [ COLUMN ] , false , " END-IF " ) ;
2001-05-23 15:26:42 +02:00
set_sqlcode ( action ) ;
}
2003-10-29 11:53:47 +01:00