/* * PROGRAM: Language Preprocessor * MODULE: gpre.h * DESCRIPTION: Common header modules * * 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 * * 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. * * The Original Code was created by Inprise Corporation * and its predecessors. Portions created by Inprise Corporation are * Copyright (C) Inprise Corporation. * * All Rights Reserved. * Contributor(s): ______________________________________. * $Id: gpre.h,v 1.45 2003-10-06 09:48:43 robocop Exp $ * Revision 1.3 2000/11/27 09:26:13 fsg * Fixed bugs in gpre to handle PYXIS forms * and allow edit.e and fred.e to go through * gpre without errors (and correct result). * * This is a partial fix until all * PYXIS datatypes are adjusted in frm_trn.c * * removed some compiler warnings too * * Revision 1.2 2000/11/16 15:54:29 fsg * Added new switch -verbose to gpre that will dump * parsed lines to stderr * * Fixed gpre bug in handling row names in WHERE clauses * that are reserved words now (DATE etc) * (this caused gpre to dump core when parsing tan.e) * * Fixed gpre bug in handling lower case table aliases * in WHERE clauses for sql dialect 2 and 3. * (cause a core dump in a test case from C.R. Zamana) * * 2002.02.15 Sean Leyne - Code Cleanup, removed obsolete ports: * - "IMP" and "HP9000 s300" * * 2002.10.27 Sean Leyne - Code Cleanup, removed obsolete "UNIXWARE" port * 2002.10.27 Sean Leyne - Code Cleanup, removed obsolete "Ultrix" port * * 2002.10.28 Sean Leyne - Completed removal of obsolete "DGUX" port * 2002.10.28 Sean Leyne - Completed removal of obsolete "SGI" port * 2002.10.28 Sean Leyne - Completed removal of obsolete "HP700" port * * 2002.10.30 Sean Leyne - Removed support for obsolete "PC_PLATFORM" define * */ #ifndef GPRE_GPRE_H #define GPRE_GPRE_H #include // offsetof #include "../jrd/ib_stdio.h" #include "../jrd/common.h" #include "../jrd/y_ref.h" #ifdef GPRE_FORTRAN #if defined AIX || defined AIX_PPC || defined sun #define FTN_BLK_DATA 1 #endif #endif #ifdef GPRE_ADA #if (defined hpux && defined HP10) || defined SCO_UNIX #define ALSYS_ADA 1 #endif #endif #ifdef VMS #define EITHER_CASE 1 #endif /* If the C compiler supports the ANSI const directive, we emit it before BLR string definitions */ #if (defined (SOLARIS) || defined (AIX) || defined (WIN_NT)) #define CONST_STR "const " #endif #ifndef CONST_STR #define CONST_STR "" #endif #define MAXSYMLEN 512 /* max length of symbol + terminator */ #define NAME_SIZE 32 #define SQL_DIALECT_V5 1 /* pre 6.0 dialect */ #define MAKE_ACTION(request,type) MSC_action(request,type) #define ALLOC(size) MSC_alloc (size) #define MAKE_CONTEXT(request) MSC_context (request) #define COPY(from, length, to) MSC_copy (from, length, to) #define COPY_CAT(from1, length1, from2, length2,to) MSC_copy_cat(from1, length1, from2, length2,to) #define FREE(block) MSC_free (block) #define MAKE_NODE(type, count) MSC_node (type, count) #define POP(stack) MSC_pop (stack) #define PUSH(object, stack) MSC_push (object, stack) #define REALLOC(block, size) MSC_realloc (block, size) #define MAKE_REFERENCE(link) MSC_reference (link); #define MAKE_REQUEST(type) MSC_request (type) #define MAKE_STRING(string) MSC_string (string) #define MAKE_PRIVILEGE_BLOCK() MSC_privilege_block () #define MAKE_USERNAME(string, dyn) MSC_username (string, dyn) #define IBERROR CPR_error #define RANGE_SHORT_INTEGER(X) ((X) < 32768 && (X) >= -32768) #define RANGE_POSITIVE_SHORT_INTEGER(X) ((X) < 32768 && (X) >= 0) #define QUOTED(typ) (typ == tok_sglquoted || typ == tok_dblquoted) #define STRIP_QUOTES(tkn) {int ij; \ for (ij=1; ijfld_sub_type)) /* Field block. Fields are what farms and databases are all about */ typedef struct gpre_fld { USHORT fld_dtype; /* data type of field */ FLD_LENGTH fld_length; /* field length in bytes */ SSHORT fld_scale; /* scale factor */ USHORT fld_id; /* field id in meta data */ USHORT fld_flags; /* Misc flags */ USHORT fld_seg_length; /* Segment length for blobs */ USHORT fld_position; /* Field position in relation */ USHORT fld_precision; /* Field precision */ SSHORT fld_sub_type; /* Field sub-type */ gpre_fld* fld_next; /* next field in relation */ gpre_fld* fld_array; /* array element if field is array */ gpre_rel* fld_relation; /* relation */ gpre_prc* fld_procedure; /* procedure */ sym* fld_symbol; /* symbol for field */ sym* fld_global; /* symbol for global field */ ary* fld_array_info; /* Dimension and range information about an array field */ gpre_nod* fld_default_value;/* field's default value */ txt* fld_default_source; /* source for field default value */ ind* fld_index; /* If CREATE TABLE, specifies field with the unique constraint */ cnstrt* fld_constraints; /* linked list of constraints defined during a meta operation */ intlsym* fld_character_set; /* character set for SQL declared field */ intlsym* fld_collate; /* collation clause for SQL declared field */ cmpf* fld_computed; /* computed field definition */ USHORT fld_char_length; /* field length in CHARACTERS */ SSHORT fld_charset_id; /* Field character set id for text */ SSHORT fld_collate_id; /* Field collation id for text */ SSHORT fld_ttype; /* ID of text type's implementation */ } *GPRE_FLD; #define FLD_LEN sizeof(gpre_fld) #define FLD_blob 1 #define FLD_text 2 #define FLD_stream_blob 4 #define FLD_dbkey 8 #define FLD_not_null 32 /* if CREATE TABLE specifies not null */ #define FLD_delete 64 /* if ALTER TABLE specifies delete of field */ #define FLD_meta 128 /* if true, created for a metadata operation */ #define FLD_national 256 /* uses SQL "NATIONAL" character set */ #define FLD_charset 512 /* field has a specific character set */ #define FLD_computed 1024 /* field is computed */ #define FLD_meta_cstring 2048 /* field is being defined as cstring by the user. */ typedef enum { FUN_value, FUN_reference, FUN_descriptor, FUN_blob_struct, FUN_scalar_array} FUN_T; /* Port block */ typedef struct por { USHORT por_msg_number; /* message number within request */ USHORT por_ident; /* ident in source */ int por_length; /* length of port in bytes */ ref* por_references; /* linked list of field references */ por* por_next; /* next port in request */ USHORT por_count; /* number of items in port */ } *POR; #define POR_LEN (sizeof(por)) /* Slice description block */ typedef struct slc { gpre_req* slc_parent_request; /* request for blob id */ gpre_fld* slc_field; /* database array field */ gpre_nod* slc_array; /* user defined array */ ref* slc_field_ref; /* array field reference */ USHORT slc_dimensions; /* dimensions */ USHORT slc_parameters; /* number of parameters */ struct slc_repeat { gpre_nod* slc_lower; gpre_nod* slc_upper; } slc_rpt[1]; } *SLC; #define SLC_LEN(count) (sizeof(slc) + sizeof(slc::slc_repeat) * (count - 1)) /* Request block, corresponds to a single JRD request */ enum req_t { REQ_for, REQ_store, REQ_store2, REQ_insert, REQ_cursor, REQ_select, REQ_mass_update, REQ_any, REQ_statistical, REQ_ddl, REQ_create_database, REQ_slice, REQ_ready, REQ_procedure, REQ_set_generator, REQ_LASTREQUEST /* Leave this debugging GPRE_REQ last */ }; typedef struct gpre_req { enum req_t req_type; /* request type */ USHORT req_ident; /* ident for request handle */ USHORT req_act_flag; /* activity flag ident, if used */ int req_length; /* blr length of request */ UCHAR *req_base; /* base of blr string during generation */ UCHAR *req_blr; /* raw blr string */ SCHAR *req_handle; /* request handle */ const TEXT* req_trans; /* transaction handle */ SCHAR *req_request_level; /* request level expression */ USHORT req_level; /* access level */ USHORT req_count; /* number of ports in request */ USHORT req_internal; /* next internal context number */ USHORT req_labels; /* next available label */ USHORT req_top_label; /* fortran label for top of request */ USHORT req_btm_label; /* fortran label for request exit */ gpre_nod* req_node; /* request definition tree */ dbb* req_database; /* database */ act* req_actions; /* actions within request */ gpre_ctx* req_contexts; /* contexts within request */ gpre_ctx* req_update; /* update context for mass insert */ gpre_req* req_next; /* next request in module or metadata action */ ref* req_values; /* host values required */ #ifdef SCROLLABLE_CURSORS ref* req_avalues; /* parameters to pass to asynchronous message */ #endif ref* req_eof; /* eof reference for FOR */ ref* req_index; /* index variable */ ref* req_references; /* fields referenced in context */ map* req_map; /* map for aggregates, etc */ gpre_rse* req_rse; /* record selection expression */ por* req_ports; /* linked list of ports */ por* req_primary; /* primary input or output port */ por* req_sync; /* synchronization port */ por* req_vport; /* port to send values in */ #ifdef SCROLLABLE_CURSORS por* req_aport; /* port for asynchronous message */ #endif gpre_req* req_routine; /* other requests in routine */ blb* req_blobs; /* blobs in request */ slc* req_slice; /* slice for request */ ref* req_array_references; /* array fields referenced in context */ USHORT req_scope_level; /* scope level for SQL subquery parsing */ USHORT req_in_aggregate; /* now processing value expr for aggr */ USHORT req_in_select_list; /* processing select list */ USHORT req_in_where_clause; /* processing where clause */ USHORT req_in_having_clause; /* processing having clause */ USHORT req_in_order_by_clause; /* processing order by clause */ USHORT req_in_subselect; /* processing a subselect clause */ ULONG req_flags; } *GPRE_REQ; #define REQ_exp_hand 1 #define REQ_local 2 /* defined in an included routine */ #define REQ_sql_cursor 1024 /* request is an SQL cursor */ #define REQ_extend_dpb 2048 /* we need to extend dpb at runtime */ #define REQ_sql_declare_cursor 4096 /* request is declare cursor */ #define REQ_sql_blob_open 8192 /* request is SQL open blob cursor */ #define REQ_sql_blob_create 16384 /* request is SQL create blob cursor */ #define REQ_sql_database_dyn 32768 /* request is to generate DYN to add files o database */ #ifdef SCROLLABLE_CURSORS #define REQ_scroll 65536 /* request is a scrollable cursor */ #define REQ_backwards 131072 /* request was last scrolled backwards */ #endif #define REQ_blr_version4 262144 /* request must generate blr_version4 */ #define REQ_LEN sizeof(gpre_req) /* Context block, used to define context symbols, etc. */ typedef struct gpre_ctx { USHORT ctx_internal; /* internal context number */ USHORT ctx_scope_level; /* scope level for SQL alias subquery scoping */ gpre_req* ctx_request; /* parent request */ gpre_ctx* ctx_next; /* next context in request */ sym* ctx_symbol; /* symbol for context */ gpre_rel* ctx_relation; /* relation for context */ TEXT *ctx_alias; /* holds SQL alias for passing to engine */ gpre_prc* ctx_procedure; /* procedure for context */ gpre_nod* ctx_prc_inputs; /* procedure input parameters */ gpre_rse* ctx_stream; /* stream for context */ } *GPRE_CTX; #define CTX_LEN sizeof(gpre_ctx) /* Field reference */ typedef struct ref { USHORT ref_ident; /* identifier */ USHORT ref_level; /* highest level of access */ USHORT ref_parameter; /* parameter in port */ USHORT ref_id; /* id of reference in union */ gpre_fld* ref_field; /* field in question */ gpre_ctx* ref_context; /* context for reference */ ref* ref_next; /* next reference in context */ por* ref_port; /* associated port */ ref* ref_source; /* source reference for modified field */ ref* ref_null; /* reference for null value */ ref* ref_master; /* master field for null value */ ref* ref_friend; /* value for variable */ gpre_nod* ref_expr; /* expression, if node is expression */ TEXT *ref_value; /* value string if host language value */ val* ref_values; /* linked list of values */ TEXT *ref_null_value; /* value string if host language value */ UCHAR *ref_sdl; /* Raw slice description language for an array */ UCHAR *ref_sdl_base; /* base of sdl string during generation */ int ref_sdl_length; /* sdl length for this reference */ slc* ref_slice; /* Slice, if field referenced is sliced */ USHORT ref_sdl_ident; /* identifier of sdl structure */ USHORT ref_offset; /* offset of field in port */ USHORT ref_flags; SSHORT ref_ttype; /* Character set type for literals */ } *REF; #define REF_union 1 /* Pseudo field for union */ #define REF_pseudo 2 /* Other pseudo field (probably for forms) */ #define REF_null 4 /* Only here cause of related null reference */ #define REF_fetch_array 8 /* Need to fetch full array */ #define REF_literal 16 /* Reference is to a constant */ #define REF_ttype 32 /* Reference contains character set spec */ #define REF_array_elem 64 /* Reference to an array element */ #define REF_sql_date 128 /* Reference is to a date constant */ #define REF_sql_time 256 /* Reference is to a time constant */ #define REF_timestamp 512 /* Reference is to a timestamp constant */ #define REF_LEN sizeof(ref) /**************** start of tree roots *****************/ /* Based on block. Used for based on clause */ typedef struct bas { gpre_fld* bas_field; /* database field referenced */ lls* bas_variables; /* list of variables based on above */ str* bas_db_name; /* database name if present and required */ str* bas_rel_name; /* relation name if no db statement */ str* bas_fld_name; /* field if no db statement */ USHORT bas_flags; char bas_terminator[2]; /* terminating character */ } *BAS; #define BAS_LEN (sizeof(bas)) #define BAS_segment 1 /* Based on a blob segment length */ #define BAS_ambiguous 2 /* Ambiguous reference to segment */ /* declare udf block */ typedef struct decl_udf { TEXT *decl_udf_name; TEXT *decl_udf_entry_point; TEXT *decl_udf_module_name; gpre_fld* decl_udf_arg_list; gpre_fld* decl_udf_return_type; USHORT decl_udf_return_mode; /* BY VALUE or BY REFERENCE */ SSHORT decl_udf_return_parameter; } *DECL_UDF; #define DECL_UDF_LEN sizeof(decl_udf) /* Dynamic statement block, used for dynamic SQL */ typedef struct dyn { dbb* dyn_database; /* Database involved */ sym* dyn_statement_name; /* Name of dynamic statement */ sym* dyn_cursor_name; /* Cursor name */ const TEXT* dyn_trans; /* Transaction handle */ TEXT *dyn_string; /* Dynamic string or variable name */ TEXT *dyn_sqlda; /* Name of SQLDA structure, if any */ TEXT *dyn_sqlda2; /* Name of second SQLDA structure, if any */ gpre_nod* dyn_using; /* dependent on action type */ } *DYN; #define DYN_LEN sizeof(dyn) /* Start transaction block */ typedef struct gpre_tra { gpre_tra* tra_next; /* next transaction */ TEXT *tra_handle; /* this handle */ USHORT tra_flags; /* transaction options */ tpb* tra_tpb; /* TPB's for this transaction */ int tra_db_count; /* number of db's and TPB's */ } *GPRE_TRA; #define TRA_LEN sizeof(gpre_tra) /* values for tra_flags */ #define TRA_ro 1 #define TRA_nw 2 #define TRA_con 4 #define TRA_rrl 8 #define TRA_inc 16 #define TRA_read_committed 32 #define TRA_autocommit 64 #define TRA_rec_version 128 #define TRA_no_auto_undo 256 #define MAX_TRA_OPTIONS 8 /* act_object block for SQL database commands. */ typedef struct mdbb { dbb* mdbb_database; gpre_req* mdbb_dpb_request; gpre_req* mdbb_dpb_extend_request; } *MDBB; /* Open cursor block */ typedef struct opn { sym* opn_cursor; /* Symbol block of cursor */ const TEXT* opn_trans; /* Transaction handle */ ref* opn_using; /* Using variables */ } *OPN; #define OPN_LEN (sizeof(opn)) /* Ready block */ typedef struct rdy { gpre_req* rdy_request; /* dpb message & info */ rdy* rdy_next; dbb* rdy_database; USHORT rdy_id; /* id for unique string variable- MPEXL COB */ TEXT *rdy_filename; } *RDY; #define RDY_LEN sizeof(rdy) /* Enumerated field type block */ typedef struct typ { sym* typ_symbol; /* Actual symbol */ gpre_fld* typ_field; /* Owner */ SSHORT typ_value; /* Value of type */ } *TYP; #define TYP_LEN sizeof(typ) /* User Defined Function */ typedef struct udf { dbb* udf_database; sym* udf_symbol; /* Function name or query name */ USHORT udf_args; /* Number of arguments */ USHORT udf_flags; /* UDF flags */ USHORT udf_dtype; /* Return data type */ SSHORT udf_scale; /* Return scale */ USHORT udf_length; /* Return length */ USHORT udf_sub_type; /* Return sub-type */ USHORT udf_charset_id; /* Return character set */ USHORT udf_ttype; /* Return text type */ USHORT udf_type; /* Function type */ gpre_fld* udf_inputs; /* List of udf input arguments */ TEXT udf_function[1]; /* Function name */ } *UDF; #define UDF_LEN (sizeof(udf)) #define UDF_value 0 #define UDF_boolean 1 #define UDF_scanned 1 /* Update block -- used for (at least) MODIFY */ typedef struct upd { USHORT upd_level; /* reference level */ gpre_req* upd_request; /* parent request */ ref* upd_references; /* references under modify */ gpre_ctx* upd_source; /* context being modified */ gpre_ctx* upd_update; /* update context */ por* upd_port; /* port for update */ upd* upd_outer; /* outer modify, if any */ gpre_nod* upd_assignments; /* assignments to port */ ref* upd_array_references; /* array references under modify */ } *UPD; #define UPD_LEN sizeof(upd) #include "../jrd/dsc.h" #define dtype_float dtype_real /* GPRE wide globals */ #ifdef GPRE_MAIN #define EXTERN #else #define EXTERN extern #endif /* Added sw_verbose FSG 14.Nov.2000 */ EXTERN bool sw_ansi; EXTERN bool sw_verbose; EXTERN bool sw_auto; EXTERN bool sw_sql; EXTERN bool sw_raw; EXTERN bool sw_cstring; EXTERN bool sw_dyn_using; EXTERN bool sw_standard_out; EXTERN bool sw_lines; EXTERN bool sw_ids; EXTERN bool sw_trace; EXTERN bool sw_case; EXTERN bool sw_external; EXTERN bool sw_version; EXTERN USHORT sw_window_scope; EXTERN bool sw_alsys; EXTERN bool sw_d_float; EXTERN USHORT sw_sql_dialect; EXTERN USHORT sw_know_interp; EXTERN USHORT sw_server_version; EXTERN USHORT sw_ods_version; EXTERN bool override_case; EXTERN bool dialect_specified; EXTERN SSHORT sw_interp; EXTERN USHORT compiletime_db_dialect; EXTERN TEXT ada_package[256], *ada_null_address; EXTERN DBB isc_databases; EXTERN TEXT *default_user, *default_password; EXTERN TEXT *default_lc_ctype; EXTERN TEXT *default_lc_messages; EXTERN GPRE_REQ requests; EXTERN LLS events; EXTERN IB_FILE *out_file; EXTERN LANG_T sw_language; EXTERN int line, errors, warnings, fatals; EXTERN act* global_functions; EXTERN dbd global_db_list[32]; EXTERN USHORT global_db_count; EXTERN INTLSYM text_subtypes; /* ada_flags fields definition */ #define ADA_create_database 1 /* the flag is set when there is a create database SQL statement in user program, and is used to generate additional "with" and "function" declarations */ EXTERN USHORT ada_flags; #undef EXTERN #include "../gpre/msc_proto.h" #ifndef assert #ifdef DEV_BUILD #define _assert(ex) {if (!(ex)){CPR_assert (__FILE__, __LINE__);}} #define assert(ex) _assert(ex) #else #define _assert(ex) #define assert(ex) #endif #endif #define assert_IS_REQ(x) assert(!(x) || ((x)->req_type >= 0 && (x)->req_type < REQ_LASTREQUEST)) #define assert_IS_SYM(x) assert(!(x) || ((x)->sym_type >= 0 && (x)->sym_type < SYM_LASTSYM)) #define assert_IS_NOD(x) assert(!(x) || ((x)->nod_type >= 1 && (x)->nod_type < nod_LASTNOD)) #define assert_IS_ACT(x) assert(!(x) || ((x)->act_type >= 0 && (x)->act_type < ACT_LASTACT)) #endif /* GPRE_GPRE_H */