8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-25 05:23:02 +01:00
firebird-mirror/src/dudley/ddl.h

647 lines
17 KiB
C
Raw Normal View History

2001-05-23 15:26:42 +02:00
/*
* PROGRAM: JRD Data Definition Utility
* MODULE: ddl.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): ______________________________________.
*/
#ifndef DUDLEY_DDL_H
#define DUDLEY_DDL_H
2001-05-23 15:26:42 +02:00
#include "../jrd/common.h"
#ifdef VMS
const int BLOCK_SIZE = 512;
2001-05-23 15:26:42 +02:00
#else
const int BLOCK_SIZE = 1024;
2001-05-23 15:26:42 +02:00
#endif
const int MAXSYMLEN = 257; // max length of symbol + terminator
const int MAX_PAGE_LEN = 16384; // max allowable length for a database page
2001-05-23 15:26:42 +02:00
const int DDL_MSG_FAC = 2;
2001-05-23 15:26:42 +02:00
/* Action block. Do something. */
/* Actions */
enum act_t {
act_c_database, /* create database */
act_m_database, /* modify database */
act_d_database, /* drop a database */
act_a_relation, /* add relation */
act_m_relation, /* modify existing relation */
act_d_relation, /* drop existing relations */
act_a_gfield, /* add global field */
act_m_gfield, /* modify existing global fields */
act_d_gfield, /* drop global field */
act_a_field, /* add field to relation */
act_m_field, /* modify relation specific fields */
act_d_field, /* drop field from relation */
act_a_index, /* add index */
act_m_index, /* modify index */
act_d_index, /* delete index */
act_a_security, /* add security class */
act_d_security, /* delete security class */
act_m_security, /* modify security class */
act_a_trigger, /* add new trigger */
act_m_trigger, /* modify (replace) trigger */
act_d_trigger, /* delete trigger */
act_a_file, /* add file */
act_a_function, /* add function */
act_d_function, /* drop function */
act_a_function_arg, /* add function */
act_d_function_arg, /* drop function */
act_a_trigger_msg, /* add trigger message */
act_m_trigger_msg, /* modify trigger message */
act_d_trigger_msg, /* drop trigger message */
act_a_type, /* add type for field */
act_m_type, /* modify type for field */
act_d_type, /* drop type for field */
act_a_filter, /* add filter */
act_d_filter, /* drop filter */
act_grant, /* grant user privilege */
act_revoke, /* revoke user privilege */
act_a_shadow, /* add shadow */
act_d_shadow, /* drop shadow */
act_a_generator, /* add generator */
act_s_generator /* reset generator value */
};
typedef struct act {
enum act_t act_type; // what to do
act* act_next; // next action in system
struct dbb *act_object; // object in question (dudley_rel, dudley_fld, idx, etc.)
USHORT act_line; // line the action started on
2001-05-23 15:26:42 +02:00
USHORT act_flags;
} *ACT;
const int ACT_ignore = 1; // Ignore the action
2001-05-23 15:26:42 +02:00
/* Context block */
typedef struct dudley_ctx {
2001-05-23 15:26:42 +02:00
struct sym *ctx_name;
struct dudley_rel *ctx_relation;
struct dudley_fld *ctx_field;
2001-05-23 15:26:42 +02:00
USHORT ctx_view_rse;
USHORT ctx_context_id;
} *DUDLEY_CTX;
2001-05-23 15:26:42 +02:00
/* Database Definition Block */
typedef struct dbb {
struct sym *dbb_name;
struct dudley_rel *dbb_relations;
2001-05-23 15:26:42 +02:00
struct gfl *dbb_fields;
2003-09-30 12:39:11 +02:00
dbb* dbb_next;
2001-05-23 15:26:42 +02:00
struct sym *dbb_security_class;
SLONG *dbb_handle;
SLONG *dbb_transaction;
struct txt *dbb_description;
USHORT dbb_flags;
struct sym *dbb_file_name;
struct fil *dbb_files;
USHORT dbb_page_size;
ULONG dbb_length; /* Length of database in pages, if known */
struct fil *dbb_logfiles;
struct fil *dbb_overflow;
SLONG dbb_chkptlen;
SSHORT dbb_numbufs;
SSHORT dbb_bufsize;
SLONG dbb_grp_cmt_wait;
struct fil *dbb_cache_file;
} *DBB;
enum dbb_flags_vals {
DBB_null_description = 1,
DBB_null_security_class = 2,
DBB_create_database = 4,
DBB_drop_log = 8,
DBB_log_serial = 16,
DBB_log_preallocated = 32,
DBB_log_default = 64,
DBB_cascade = 128,
DBB_drop_cache = 256
};
2001-05-23 15:26:42 +02:00
enum ods_versions {
DB_VERSION_DDL4 = 4, // ods4 db
DB_VERSION_DDL6 = 6, // ods6 db
DB_VERSION_DDL8 = 8 // ods8 db
};
2001-05-23 15:26:42 +02:00
/* Field block. Fields are what farms and databases are all about */
typedef struct dudley_fld {
2001-05-23 15:26:42 +02:00
SSHORT fld_dtype; /* data type of field */
SSHORT fld_length; /* field length in bytes */
SSHORT fld_scale; /* scale factor */
SSHORT fld_position; /* field position */
SSHORT fld_segment_length;
SSHORT fld_sub_type;
SSHORT fld_has_sub_type;
SSHORT fld_dimension; /* size of multi-dim. array */
SSHORT fld_system; /* 0 if field is user defined */
USHORT fld_flags; /* misc trash */
2003-09-30 12:39:11 +02:00
dudley_fld* fld_next; /* next field in relation */
struct dudley_rel *fld_relation; /* relation */
2001-05-23 15:26:42 +02:00
struct sym *fld_security_class;
2003-09-30 12:39:11 +02:00
dudley_ctx* fld_context; /* context for view */
dbb* fld_database; /* database for global fields */
2001-05-23 15:26:42 +02:00
struct sym *fld_name; /* field name */
struct sym *fld_source; /* name of global field */
2003-09-30 12:39:11 +02:00
dudley_fld* fld_source_field; /* global field for computed field */
2001-05-23 15:26:42 +02:00
struct sym *fld_base; /* base field for views */
struct sym *fld_query_name; /* query name */
struct dudley_nod *fld_query_header; /* query header */
2001-05-23 15:26:42 +02:00
struct sym *fld_edit_string; /* edit string */
struct dudley_nod *fld_computed; /* computed by expression */
struct dudley_nod *fld_missing; /* missing value */
struct dudley_nod *fld_default; /* default value */
struct dudley_nod *fld_validation; /* valid if value */
2001-05-23 15:26:42 +02:00
struct txt *fld_description; /* description of field */
struct txt *fld_compute_src; /* computed_by source */
struct txt *fld_valid_src; /* validation source */
SLONG *fld_ranges; /* ranges for multi-dim. array */
} *DUDLEY_FLD;
2001-05-23 15:26:42 +02:00
enum fld_flags_vals {
fld_explicit_position = 1,
fld_modify = 2,
fld_local = 4,
fld_null_description = 8,
fld_null_security_class = 16,
fld_null_validation = 32,
fld_explicit_system = 64,
fld_null_missing_value = 128,
fld_null_edit_string = 256,
fld_null_query_name = 512,
fld_null_query_header = 1024
};
2001-05-23 15:26:42 +02:00
/* File description block */
typedef struct fil {
SLONG fil_length; /* File length in pages */
SLONG fil_start; /* Starting page */
struct sym *fil_name; /* File name */
2003-09-30 12:39:11 +02:00
fil* fil_next; /* next file */
2001-05-23 15:26:42 +02:00
SSHORT fil_shadow_number; /* shadow number if part of shadow */
SSHORT fil_manual; /* flag to indicate manual shadow */
SSHORT fil_partitions; /* number of log file partitions */
SSHORT fil_raw; /* on raw device? */
SSHORT fil_conditional; /* flag to indicate conditional shadow */
} *FIL;
/* Filter block */
typedef struct filter {
struct sym *filter_name; /* symbol for filter name */
struct txt *filter_description; /* description of filter */
struct sym *filter_module_name; /* symbol for module name */
struct sym *filter_entry_point; /* symbol for entrypoint */
SSHORT filter_input_sub_type;
SSHORT filter_output_sub_type;
} *FILTER;
/* Function argument block. */
typedef struct funcarg {
struct sym *funcarg_funcname; /* symbol for function name */
SSHORT funcarg_position; /* argument position */
SSHORT funcarg_mechanism; /* argument passed by value, or by reference */
SSHORT funcarg_dtype; /* data type of argument */
SSHORT funcarg_scale; /* scale factor */
SSHORT funcarg_length; /* argument length in bytes */
SSHORT funcarg_return_arg; /* argument is the designated return arg */
SSHORT funcarg_sub_type; /* sub_type of text */
SSHORT funcarg_has_sub_type; /* null field for sub_type field */
2003-09-30 12:39:11 +02:00
funcarg* funcarg_next; /* next field in function */
2001-05-23 15:26:42 +02:00
} *FUNCARG;
enum funcarg_mechanism_vals {
FUNCARG_mechanism_value = 0,
FUNCARG_mechanism_reference,
FUNCARG_mechanism_descriptor,
FUNCARG_mechanism_blob_struc,
FUNCARG_mechanism_sc_array_desc
};
2001-05-23 15:26:42 +02:00
2003-09-30 12:39:11 +02:00
/* Function description block */
typedef struct func {
struct sym *func_name; /* symbol for function name */
struct sym *func_query_name; /* symbol for query name */
struct sym *func_module_name; /* symbol for module name */
struct sym *func_entry_point; /* symbol for entrypoint */
SSHORT func_return_arg; /* return argument position */
func* func_next; /* next function in database */
dbb* func_database; /* database for function */
struct txt *func_description; /* description of function */
funcarg* func_args; /* Known function arguments */
funcarg* func_return; /* Return argument */
} *FUNC;
2001-05-23 15:26:42 +02:00
/* Index description block */
2003-09-12 18:32:19 +02:00
enum idx_direction
{
2003-09-15 04:15:27 +02:00
IDX_type_none = 0,
IDX_type_descend = 1
2003-09-12 18:32:19 +02:00
};
2001-05-23 15:26:42 +02:00
typedef struct dudley_idx {
USHORT idx_count; /* Number of fields */
2003-09-10 19:52:12 +02:00
bool idx_unique; /* true if unique index */
bool idx_inactive; /* false if index is active */
2003-09-12 18:32:19 +02:00
idx_direction idx_type; /* true descending */
2001-05-23 15:26:42 +02:00
USHORT idx_flags; /* Indicate which attributes have changed */
struct sym *idx_name; /* Index name */
struct sym *idx_relation; /* Relation in question */
struct txt *idx_description; /* Description pointer */
struct sym *idx_field[1]; /* Fields */
} *DUDLEY_IDX;
enum idx_flags_vals {
IDX_active_flag = 1,
IDX_unique_flag = 2,
IDX_null_description = 4,
IDX_type_flag = 8,
IDX_statistics_flag = 16
};
2001-05-23 15:26:42 +02:00
static inline size_t IDX_LEN(int cnt){
return (sizeof (struct dudley_idx) + (cnt - 1) * sizeof (((DUDLEY_IDX) NULL)->idx_field[0]));
}
2001-05-23 15:26:42 +02:00
/* Linked list stack stuff */
typedef struct lls {
struct dudley_nod *lls_object; /* object on stack */
2003-09-30 12:39:11 +02:00
lls* lls_next; /* next item on stack */
2001-05-23 15:26:42 +02:00
} *LLS;
/* General Syntax node, produced by parser */
enum nod_t {
nod_field = 1, nod_literal, nod_value,
nod_and, nod_or, nod_not,
nod_eql, nod_neq, nod_geq,
nod_leq, nod_gtr, nod_lss,
nod_containing, nod_matches, nod_any,
nod_unique, nod_add, nod_multiply,
nod_divide, nod_subtract, nod_negate,
nod_msg, nod_for, nod_send,
nod_receive, nod_block, nod_select,
nod_boolean, nod_projection, nod_sort,
nod_store, nod_modify, nod_erase,
nod_if, nod_assignment, nod_rse,
nod_first, nod_context, nod_end,
nod_label, nod_leave, nod_loop,
nod_max, nod_min, nod_count,
nod_total, nod_average, nod_list,
nod_defered, nod_between, nod_missing,
nod_field_name, nod_name, nod_starts,
nod_from, nod_fid, nod_concatenate,
nod_abort, nod_null, nod_user_name,
nod_post, nod_function, nod_gen_id,
nod_uppercase, nod_sleuth, nod_over,
nod_set_generator, nod_index
};
typedef struct dudley_nod {
2001-05-23 15:26:42 +02:00
enum nod_t nod_type; /* node type */
UCHAR *nod_blr; /* symbolic blr string */
SSHORT nod_count; /* number of sub-items */
2003-09-30 12:39:11 +02:00
dudley_nod* nod_arg[1]; /* argument */
} *DUDLEY_NOD;
2001-05-23 15:26:42 +02:00
static inline size_t NOD_LEN(int cnt) {
return (sizeof(dudley_nod) + (cnt - 1) * sizeof (((DUDLEY_NOD) NULL)->nod_arg[0]));
}
2001-05-23 15:26:42 +02:00
/* Relation block, not to be confused with siblings or in-laws */
typedef struct dudley_rel {
2003-09-30 12:39:11 +02:00
dbb* rel_database; /* parent database */
2001-05-23 15:26:42 +02:00
struct sym *rel_filename; /* external filename */
2003-09-30 12:39:11 +02:00
dudley_fld* rel_fields; /* linked list of known fields */
2001-05-23 15:26:42 +02:00
struct sym *rel_name; /* symbol for relation */
struct sym *rel_security_class; /* name of security class */
2003-09-30 12:39:11 +02:00
dudley_rel* rel_next; /* next relation in database */
dudley_nod* rel_rse; /* view rse */
2001-05-23 15:26:42 +02:00
struct txt *rel_description; /* description of relation */
struct txt *rel_view_source; /* source dml for view definition */
USHORT rel_field_position; /* highest used field position */
SSHORT rel_system; /* 0 if relation is user defined */
USHORT rel_flags;
} *DUDLEY_REL;
2001-05-23 15:26:42 +02:00
enum rel_flags_values {
rel_null_description = 1,
rel_null_security_class = 2,
rel_explicit_system = 4,
rel_marked_for_delete = 8,
rel_null_ext_file = 16,
rel_marked_for_modify = 32,
rel_marked_for_creation = 64
};
2001-05-23 15:26:42 +02:00
/* Security class handling */
typedef struct scl {
struct sym *scl_name; /* name of security class */
struct txt *scl_description; /* description of security class */
struct sce *scl_entries; /* list of entries */
} *SCL;
const int SCL_write = 2;
2001-05-23 15:26:42 +02:00
/* Security entry */
typedef struct sce {
2003-09-30 12:39:11 +02:00
sce* sce_next; /* next security item in list */
2001-05-23 15:26:42 +02:00
SLONG sce_privileges; /* bitmask of privileges */
UCHAR *sce_idents[20]; /* misc identification stuff */
UCHAR sce_strings[1];
} *SCE;
/* String block for build DYN & BLR strings */
typedef struct str {
UCHAR *str_start; /* start of string buffer */
UCHAR *str_current; /* current position in string being built */
2001-05-23 15:26:42 +02:00
USHORT str_length; /* length of buffer */
} *STR;
/* Symbol block, also used for hash table */
enum sym_t {
SYM_keyword, /* unspecified */
SYM_context, /* context variable */
SYM_database, /* seems like a good idea */
SYM_relation, /* if you don't know your relations, how do you know your friends? */
SYM_global, /* Global field */
SYM_field, /* Local field */
SYM_function, /* UDF */
SYM_trigger /* any named element deserves to be hashed */
};
typedef struct sym {
TEXT *sym_string; /* address of asciz string */
SSHORT sym_length; /* length of string (exc. term.) */
enum sym_t sym_type; /* symbol type */
SSHORT sym_keyword; /* keyword number, if keyword */
2003-09-30 12:39:11 +02:00
dudley_ctx* sym_object; /* general pointer to object */
sym* sym_collision; /* collision pointer */
sym* sym_homonym; /* homonym pointer */
2001-05-23 15:26:42 +02:00
TEXT sym_name[1]; /* space for name, if necessary */
} *SYM;
const size_t SYM_LEN = sizeof(sym);
2001-05-23 15:26:42 +02:00
/* Trigger block */
/* these are the externally visible trigger types */
typedef enum {
trg_type_none = 0, /* pre store */
trg_store = 1, /* pre store */
trg_post_store = 2,
trg_modify = 3, /* pre modify */
trg_post_modify = 4,
trg_pre_erase = 5,
trg_erase = 6 /* post erase */
} TRG_T;
/* these types are used in parsing */
enum parse_trig_types {
trig_pre = 0,
trig_post = 1,
trig_sto = 2,
trig_mod = 4,
trig_era = 8, // erase defaults to post
trig_inact = 16
};
2001-05-23 15:26:42 +02:00
typedef struct dudley_trg {
2001-05-23 15:26:42 +02:00
TRG_T trg_type;
DUDLEY_REL trg_relation;
DUDLEY_NOD trg_statement; /* blr */
2003-09-30 12:39:11 +02:00
sym* trg_name; /* symbol for trigger */
2001-05-23 15:26:42 +02:00
struct txt *trg_description; /* description of relation */
struct txt *trg_source; /* source of trigger */
SSHORT trg_sequence;
SSHORT trg_inactive; /* 0 = on, 1 = off */
USHORT trg_mflag; /* modify attributes */
} *DUDLEY_TRG;
2001-05-23 15:26:42 +02:00
/* trg_modify_flag */
enum trg_modify_flag_vals {
trg_mflag_onoff = 1,
trg_mflag_type = 2,
trg_mflag_seqnum = 4,
trg_mflag_order = 8
};
2001-05-23 15:26:42 +02:00
/* Trigger message block */
typedef struct trgmsg {
2003-09-30 12:39:11 +02:00
sym* trgmsg_trg_name; /* symbol for trigger */
2001-05-23 15:26:42 +02:00
SSHORT trgmsg_number; /* abort code */
2003-09-30 12:39:11 +02:00
sym* trgmsg_text;
2001-05-23 15:26:42 +02:00
} *TRGMSG;
typedef enum {
trgmsg_none = 0,
trgmsg_add = 1,
trgmsg_modify = 2,
trgmsg_drop = 3
} TRGMSG_T;
/* Text block */
typedef struct txt {
TEXT *txt_file;
ULONG txt_position;
USHORT txt_length;
USHORT txt_start_line;
} *TXT;
/* Type block */
typedef struct typ {
2003-09-30 12:39:11 +02:00
sym* typ_field_name; /* field name */
sym* typ_name; /* type name */
2001-05-23 15:26:42 +02:00
SSHORT typ_type; /* type value */
2003-09-30 12:39:11 +02:00
txt* typ_description; /* description of relation */
2001-05-23 15:26:42 +02:00
} *TYP;
/* User privilege block */
typedef struct userpriv {
2003-09-30 12:39:11 +02:00
sym* userpriv_relation;
2001-05-23 15:26:42 +02:00
struct usre *userpriv_userlist;
struct upfe *userpriv_upflist;
USHORT userpriv_flags;
} *USERPRIV;
/* user privilege flags */
enum userpriv_flags_vals {
USERPRIV_select = 1,
USERPRIV_delete = 2,
USERPRIV_insert = 4,
USERPRIV_update = 8,
USERPRIV_grant = 16
};
2001-05-23 15:26:42 +02:00
/* rdb$user_privilege.rdb$privilege */
static const char* UPRIV_SELECT = "SELECT";
static const char* UPRIV_DELETE = "DELETE";
static const char* UPRIV_INSERT = "INSERT";
static const char* UPRIV_UPDATE = "UPDATE";
2001-05-23 15:26:42 +02:00
/* user name entry */
typedef struct usre {
2003-09-30 12:39:11 +02:00
usre* usre_next;
sym* usre_name;
2001-05-23 15:26:42 +02:00
} *USRE;
/* update field entry */
typedef struct upfe {
2003-09-30 12:39:11 +02:00
upfe* upfe_next;
sym* upfe_fldname;
2001-05-23 15:26:42 +02:00
} *UPFE;
/* Data types */
#include "../jrd/dsc.h"
/* Constant block */
typedef struct con {
2003-09-30 12:39:11 +02:00
dsc con_desc;
2001-05-23 15:26:42 +02:00
UCHAR con_data[1];
} *CON;
/* Program globals */
typedef enum lan_t {
lan_undef,
lan_pascal,
lan_fortran,
lan_cobol,
lan_ansi_cobol,
lan_c,
lan_ada,
lan_cxx
} LAN_T;
#ifdef DDL_MAIN
#define EXTERN
#else
#define EXTERN extern
#endif
EXTERN enum lan_t language;
EXTERN bool DDL_eof;
EXTERN USHORT DDL_errors;
EXTERN USHORT DDL_line;
EXTERN bool DDL_interactive;
EXTERN bool DDL_quit;
EXTERN bool DDL_dynamic;
EXTERN bool DDL_drop_database;
EXTERN bool DDL_service;
EXTERN bool DDL_replace;
EXTERN bool DDL_description;
EXTERN bool DDL_extract;
EXTERN bool DDL_trace;
EXTERN bool DDL_version;
EXTERN TEXT *DDL_file_name, DYN_file_name[256], *DB_file_name,
DDL_file_string[256], DB_file_string[256];
EXTERN TEXT *DDL_default_user, *DDL_default_password;
EXTERN ACT DDL_actions;
EXTERN DBB database;
2001-05-23 15:26:42 +02:00
#undef EXTERN
#include "../dudley/ddl_proto.h"
enum nod_val_pos {
s_rse_first = 0, // FIRST clause, if any
s_rse_boolean, // Boolean clause, if any
s_rse_sort, // Sort clause, if any
s_rse_reduced, // Reduced clause, if any
s_rse_contexts, // Relation block
s_rse_count,
s_stt_rse = 0,
s_stt_value,
s_stt_default,
s_stt_count,
s_fld_field = 0, // Field block
s_fld_context, // Context block
s_fld_name,
s_fld_subs,
s_fld_count,
s_if_boolean = 0,
s_if_true,
s_if_false,
s_for_rse = 0,
s_for_action,
s_store_rel = 0,
s_store_action,
s_mod_old_ctx = 0,
s_mod_new_ctx,
s_mod_action,
};
2001-05-23 15:26:42 +02:00
#endif // DUDLEY_DDL_H