From d4bf9ab24697e13e5f628e08ae5bf6881fe9d2c5 Mon Sep 17 00:00:00 2001 From: asfernandes Date: Sat, 24 May 2008 03:19:52 +0000 Subject: [PATCH] Split dsql_req into dsql_req and CompiledStatement. This should be my last refactoring to 2.5: - dsql_req becomes a running request; - CompiledStatement is derived from dsql_req. The compilation state previously in dsql_req comes to here; - Rename many "request" parameters to "statement" where type is changed from dsql_req to CompiledStatement. This changes makes easy the path to support compiled statement cache. --- src/dsql/DdlNodes.epp | 4 +- src/dsql/Nodes.h | 14 +- src/dsql/StmtNodes.cpp | 16 +- src/dsql/ddl.cpp | 2168 ++++++++++++++++++++-------------------- src/dsql/ddl_proto.h | 11 +- src/dsql/dsql.cpp | 185 ++-- src/dsql/dsql.h | 193 ++-- src/dsql/gen.cpp | 1434 +++++++++++++------------- src/dsql/gen_proto.h | 14 +- src/dsql/make.cpp | 104 +- src/dsql/make_proto.h | 5 +- src/dsql/metd.epp | 78 +- src/dsql/metd_proto.h | 9 +- src/dsql/pass1.cpp | 1860 +++++++++++++++++----------------- src/dsql/pass1_proto.h | 8 +- src/dsql/utld.cpp | 4 +- src/dsql/utld_proto.h | 8 +- 17 files changed, 3078 insertions(+), 3037 deletions(-) diff --git a/src/dsql/DdlNodes.epp b/src/dsql/DdlNodes.epp index fabac296a7..85c627814a 100644 --- a/src/dsql/DdlNodes.epp +++ b/src/dsql/DdlNodes.epp @@ -45,9 +45,9 @@ void AlterCharSetNode::print(Firebird::string& text, Firebird::Array& void AlterCharSetNode::execute(thread_db* tdbb, jrd_tra* transaction) { - if (dsqlRequest && dsqlRequest->req_dbb) // do not run in CREATE DATABASE + if (compiledStatement && compiledStatement->req_dbb) // do not run in CREATE DATABASE { - METD_drop_charset(dsqlRequest, charSet); + METD_drop_charset(compiledStatement, charSet); MET_dsql_cache_release(tdbb, SYM_intlsym_charset, charSet); } diff --git a/src/dsql/Nodes.h b/src/dsql/Nodes.h index d21585f806..cbc90d194d 100644 --- a/src/dsql/Nodes.h +++ b/src/dsql/Nodes.h @@ -36,7 +36,7 @@ class Node : public Firebird::PermanentStorage public: explicit Node(MemoryPool& pool) : PermanentStorage(pool), - dsqlRequest(NULL) + compiledStatement(NULL) { } @@ -45,9 +45,9 @@ public: } public: - virtual Node* dsqlPass(dsql_req* aDsqlRequest) + virtual Node* dsqlPass(CompiledStatement* aCompiledStatement) { - dsqlRequest = aDsqlRequest; + compiledStatement = aCompiledStatement; return dsqlPass(); } @@ -61,7 +61,7 @@ protected: } protected: - dsql_req* dsqlRequest; + CompiledStatement* compiledStatement; }; @@ -74,10 +74,10 @@ public: } public: - virtual Node* dsqlPass(dsql_req* aDsqlRequest) + virtual Node* dsqlPass(CompiledStatement* aCompiledStatement) { - aDsqlRequest->req_type = REQ_DDL; - return Node::dsqlPass(aDsqlRequest); + aCompiledStatement->req_type = REQ_DDL; + return Node::dsqlPass(aCompiledStatement); } public: diff --git a/src/dsql/StmtNodes.cpp b/src/dsql/StmtNodes.cpp index 4009d450a6..8e92d02323 100644 --- a/src/dsql/StmtNodes.cpp +++ b/src/dsql/StmtNodes.cpp @@ -83,15 +83,15 @@ DmlNode* InAutonomousTransactionNode::parse(thread_db* tdbb, MemoryPool& pool, InAutonomousTransactionNode* InAutonomousTransactionNode::dsqlPass() { - const bool autoTrans = dsqlRequest->req_flags & REQ_in_auto_trans_block; - dsqlRequest->req_flags |= REQ_in_auto_trans_block; + const bool autoTrans = compiledStatement->req_flags & REQ_in_auto_trans_block; + compiledStatement->req_flags |= REQ_in_auto_trans_block; InAutonomousTransactionNode* node = FB_NEW(getPool()) InAutonomousTransactionNode(getPool()); - node->dsqlRequest = dsqlRequest; - node->dsqlAction = PASS1_statement(dsqlRequest, dsqlAction); + node->compiledStatement = compiledStatement; + node->dsqlAction = PASS1_statement(compiledStatement, dsqlAction); if (!autoTrans) - dsqlRequest->req_flags &= ~REQ_in_auto_trans_block; + compiledStatement->req_flags &= ~REQ_in_auto_trans_block; return node; } @@ -107,9 +107,9 @@ void InAutonomousTransactionNode::print(Firebird::string& text, void InAutonomousTransactionNode::genBlr() { - stuff(dsqlRequest, blr_auto_trans); - stuff(dsqlRequest, 0); // to extend syntax in the future - GEN_statement(dsqlRequest, dsqlAction); + stuff(compiledStatement, blr_auto_trans); + stuff(compiledStatement, 0); // to extend syntax in the future + GEN_statement(compiledStatement, dsqlAction); } diff --git a/src/dsql/ddl.cpp b/src/dsql/ddl.cpp index 646df86f8b..79ec15c11a 100644 --- a/src/dsql/ddl.cpp +++ b/src/dsql/ddl.cpp @@ -109,91 +109,91 @@ const int BLOB_BUFFER_SIZE = 4096; // to read in blr blob for default values static void assign_field_length(dsql_fld*, USHORT); -static bool is_array_or_blob(dsql_req*, const dsql_nod*); -static void check_constraint(dsql_req*, dsql_nod*, bool); +static bool is_array_or_blob(CompiledStatement*, const dsql_nod*); +static void check_constraint(CompiledStatement*, dsql_nod*, bool); static void check_one_call(USHORT*, SSHORT, const TEXT*); -static void create_view_triggers(dsql_req*, dsql_nod*, dsql_nod*); -static void define_computed(dsql_req*, dsql_nod*, dsql_fld*, dsql_nod*); -static void define_constraint_trigger(dsql_req*, dsql_nod*); -static void define_database(dsql_req*); -static bool define_default(dsql_req*, const dsql_nod*); -static void define_del_cascade_trg(dsql_req*, const dsql_nod*, const dsql_nod*, +static void create_view_triggers(CompiledStatement*, dsql_nod*, dsql_nod*); +static void define_computed(CompiledStatement*, dsql_nod*, dsql_fld*, dsql_nod*); +static void define_constraint_trigger(CompiledStatement*, dsql_nod*); +static void define_database(CompiledStatement*); +static bool define_default(CompiledStatement*, const dsql_nod*); +static void define_del_cascade_trg(CompiledStatement*, const dsql_nod*, const dsql_nod*, const dsql_nod*, const char*, const char*); -//static void define_del_default_trg(dsql_req*, dsql_nod*, dsql_nod*, dsql_nod*, TEXT*, TEXT*); -static void define_dimensions(dsql_req*, const dsql_fld*); -static void define_domain(dsql_req*); -static void define_exception(dsql_req*, NOD_TYPE); -static void define_field(dsql_req*, dsql_nod*, SSHORT, const dsql_str*, const dsql_nod* pkcols); -static void define_filter(dsql_req*); -static SSHORT getBlobFilterSubType(dsql_req* request, const dsql_nod* node); -static void define_collation(dsql_req*); -static void define_generator(dsql_req*); -static void define_role(dsql_req*); -static void define_index(dsql_req*); +//static void define_del_default_trg(CompiledStatement*, dsql_nod*, dsql_nod*, dsql_nod*, TEXT*, TEXT*); +static void define_dimensions(CompiledStatement*, const dsql_fld*); +static void define_domain(CompiledStatement*); +static void define_exception(CompiledStatement*, NOD_TYPE); +static void define_field(CompiledStatement*, dsql_nod*, SSHORT, const dsql_str*, const dsql_nod* pkcols); +static void define_filter(CompiledStatement*); +static SSHORT getBlobFilterSubType(CompiledStatement* statement, const dsql_nod* node); +static void define_collation(CompiledStatement*); +static void define_generator(CompiledStatement*); +static void define_role(CompiledStatement*); +static void define_index(CompiledStatement*); #ifdef NOT_USED_OR_REPLACED -static dsql_nod* define_insert_action(dsql_req*); +static dsql_nod* define_insert_action(CompiledStatement*); #endif -static void define_procedure(dsql_req*, NOD_TYPE); -static void define_rel_constraint(dsql_req*, dsql_nod*); -static void define_relation(dsql_req*); -static void define_set_null_trg(dsql_req*, const dsql_nod*, const dsql_nod*, +static void define_procedure(CompiledStatement*, NOD_TYPE); +static void define_rel_constraint(CompiledStatement*, dsql_nod*); +static void define_relation(CompiledStatement*); +static void define_set_null_trg(CompiledStatement*, const dsql_nod*, const dsql_nod*, const dsql_nod*, const char*, const char*, bool); -static void define_set_default_trg(dsql_req*, const dsql_nod*, const dsql_nod*, +static void define_set_default_trg(CompiledStatement*, const dsql_nod*, const dsql_nod*, const dsql_nod*, const char*, const char*, bool); -static void define_shadow(dsql_req*); -static void define_trigger(dsql_req*, NOD_TYPE); -static void define_udf(dsql_req*); -static void define_update_action(dsql_req*, dsql_nod**, dsql_nod**, dsql_nod*); -static void define_upd_cascade_trg(dsql_req*, const dsql_nod*, const dsql_nod*, +static void define_shadow(CompiledStatement*); +static void define_trigger(CompiledStatement*, NOD_TYPE); +static void define_udf(CompiledStatement*); +static void define_update_action(CompiledStatement*, dsql_nod**, dsql_nod**, dsql_nod*); +static void define_upd_cascade_trg(CompiledStatement*, const dsql_nod*, const dsql_nod*, const dsql_nod*, const char*, const char*); -static void define_view(dsql_req*, NOD_TYPE); -static void define_view_trigger(dsql_req*, dsql_nod*, dsql_nod*, dsql_nod*); -static void delete_collation(dsql_req*); -static void delete_exception(dsql_req*, dsql_nod*, bool); -static void delete_procedure(dsql_req*, dsql_nod*, bool); -static void delete_relation_view(dsql_req*, dsql_nod*, bool); -static void delete_trigger(dsql_req*, dsql_nod*, bool); +static void define_view(CompiledStatement*, NOD_TYPE); +static void define_view_trigger(CompiledStatement*, dsql_nod*, dsql_nod*, dsql_nod*); +static void delete_collation(CompiledStatement*); +static void delete_exception(CompiledStatement*, dsql_nod*, bool); +static void delete_procedure(CompiledStatement*, dsql_nod*, bool); +static void delete_relation_view(CompiledStatement*, dsql_nod*, bool); +static void delete_trigger(CompiledStatement*, dsql_nod*, bool); static const dsql_nod* find_pk_columns(const dsql_nod* def_rel_elements); static ULONG find_start_of_body(const dsql_str* string); static void fix_default_source(dsql_str* string); -static void foreign_key(dsql_req*, dsql_nod*, const char* index_name); -static void generate_dyn(dsql_req*, dsql_nod*); -static void grant_revoke(dsql_req*); -static void make_comment(dsql_req*); -static void make_index(dsql_req*, const dsql_nod*, const dsql_nod*, +static void foreign_key(CompiledStatement*, dsql_nod*, const char* index_name); +static void generate_dyn(CompiledStatement*, dsql_nod*); +static void grant_revoke(CompiledStatement*); +static void make_comment(CompiledStatement*); +static void make_index(CompiledStatement*, const dsql_nod*, const dsql_nod*, const dsql_nod*, const char*, const char*); -static void make_index_trg_ref_int(dsql_req*, dsql_nod*, dsql_nod*, dsql_nod*, +static void make_index_trg_ref_int(CompiledStatement*, dsql_nod*, dsql_nod*, dsql_nod*, const char*, const char*); -static void modify_database(dsql_req*); -static void modify_domain(dsql_req*); -static void modify_field(dsql_req*, dsql_nod*, SSHORT, const dsql_str*); -static void modify_index(dsql_req*); -static void modify_privilege(dsql_req*, NOD_TYPE, SSHORT, const UCHAR*, +static void modify_database(CompiledStatement*); +static void modify_domain(CompiledStatement*); +static void modify_field(CompiledStatement*, dsql_nod*, SSHORT, const dsql_str*); +static void modify_index(CompiledStatement*); +static void modify_privilege(CompiledStatement*, NOD_TYPE, SSHORT, const UCHAR*, const dsql_nod*, const dsql_nod*, const dsql_str*); -static SCHAR modify_privileges(dsql_req*, NOD_TYPE, SSHORT, const dsql_nod*, +static SCHAR modify_privileges(CompiledStatement*, NOD_TYPE, SSHORT, const dsql_nod*, const dsql_nod*, const dsql_nod*); -static void modify_relation(dsql_req*); -static void modify_udf(dsql_req*); -static void modify_map(dsql_req*); +static void modify_relation(CompiledStatement*); +static void modify_udf(CompiledStatement*); +static void modify_map(CompiledStatement*); static dsql_par* parameter_reverse_order(dsql_par* parameter, dsql_par* prev); -static void process_role_nm_list(dsql_req*, SSHORT, dsql_nod*, dsql_nod*, NOD_TYPE); -static void put_descriptor(dsql_req*, const dsc*); -static void put_dtype(dsql_req*, const dsql_fld*, bool); -static void put_field(dsql_req*, dsql_fld*, bool); -static void put_local_variable(dsql_req*, dsql_var*, dsql_nod*, const dsql_str*); -static void put_local_variables(dsql_req*, dsql_nod*, SSHORT); -static void put_msg_field(dsql_req*, dsql_fld*); +static void process_role_nm_list(CompiledStatement*, SSHORT, dsql_nod*, dsql_nod*, NOD_TYPE); +static void put_descriptor(CompiledStatement*, const dsc*); +static void put_dtype(CompiledStatement*, const dsql_fld*, bool); +static void put_field(CompiledStatement*, dsql_fld*, bool); +static void put_local_variable(CompiledStatement*, dsql_var*, dsql_nod*, const dsql_str*); +static void put_local_variables(CompiledStatement*, dsql_nod*, SSHORT); +static void put_msg_field(CompiledStatement*, dsql_fld*); static dsql_nod* replace_field_names(dsql_nod*, dsql_nod*, dsql_nod*, bool, const char*); -static void reset_context_stack(dsql_req*); -static void save_field(dsql_req*, const SCHAR*); -static void save_relation(dsql_req*, const dsql_str*); -static void set_statistics(dsql_req*); -static void stuff_default_blr(dsql_req*, const UCHAR*, USHORT); -static void stuff_matching_blr(dsql_req*, const dsql_nod*, const dsql_nod*); -static void stuff_trg_firing_cond(dsql_req*, const dsql_nod*); +static void reset_context_stack(CompiledStatement*); +static void save_field(CompiledStatement*, const SCHAR*); +static void save_relation(CompiledStatement*, const dsql_str*); +static void set_statistics(CompiledStatement*); +static void stuff_default_blr(CompiledStatement*, const UCHAR*, USHORT); +static void stuff_matching_blr(CompiledStatement*, const dsql_nod*, const dsql_nod*); +static void stuff_trg_firing_cond(CompiledStatement*, const dsql_nod*); static void set_nod_value_attributes(dsql_nod*, const dsql_fld*); static void clearPermanentField (dsql_rel*, bool); -static void define_user(dsql_req*, UCHAR); +static void define_user(CompiledStatement*, UCHAR); enum trigger_type { PRE_STORE_TRIGGER = 1, @@ -260,7 +260,7 @@ static inline bool hasNewContext(const int value) // // Write out a string valued attribute. (Overload 2.) // -inline void dsql_req::append_string(UCHAR verb, const Firebird::MetaName& name) +inline void CompiledStatement::append_string(UCHAR verb, const Firebird::MetaName& name) { append_string(verb, name.c_str(), name.length()); } @@ -269,24 +269,24 @@ inline void dsql_req::append_string(UCHAR verb, const Firebird::MetaName& name) // // Write out a string valued attribute. (Overload 3.) // -inline void dsql_req::append_string(UCHAR verb, const Firebird::string& name) +inline void CompiledStatement::append_string(UCHAR verb, const Firebird::string& name) { append_string(verb, name.c_str(), name.length()); } -inline void dsql_req::append_uchar(UCHAR byte) +inline void CompiledStatement::append_uchar(UCHAR byte) { req_blr_data.add(byte); } -inline void dsql_req::append_ushort(USHORT val) +inline void CompiledStatement::append_ushort(USHORT val) { append_uchar(val); append_uchar(val >> 8); } -inline void dsql_req::append_ulong(ULONG val) +inline void CompiledStatement::append_ulong(ULONG val) { append_ushort(val); append_ushort(val >> 16); @@ -387,7 +387,7 @@ void DDL_execute(dsql_req* request) } -void DDL_generate(dsql_req* request, dsql_nod* node) +void DDL_generate(CompiledStatement* statement, dsql_nod* node) { /************************************** * @@ -402,14 +402,14 @@ void DDL_generate(dsql_req* request, dsql_nod* node) * **************************************/ - if (request->req_dbb->dbb_read_only) { + if (statement->req_dbb->dbb_read_only) { ERRD_post(isc_read_only_database, 0); return; } - request->append_uchar(isc_dyn_version_1); - generate_dyn(request, node); - request->append_uchar(isc_dyn_eoc); + statement->append_uchar(isc_dyn_version_1); + generate_dyn(statement, node); + statement->append_uchar(isc_dyn_eoc); } @@ -457,9 +457,9 @@ bool DDL_ids(const dsql_req* request) // Note that this depends on the same stuff variant // as used in gen.cpp // -void DDL_put_field_dtype(dsql_req* request, const dsql_fld* field, bool use_subtype) +void DDL_put_field_dtype(CompiledStatement* statement, const dsql_fld* field, bool use_subtype) { - put_dtype(request, field, use_subtype); + put_dtype(statement, field, use_subtype); } @@ -468,14 +468,14 @@ void DDL_put_field_dtype(dsql_req* request, const dsql_fld* field, bool use_subt // wrapper that sets the last parameter to false to indicate // we are creating a field, not modifying one. // -void DDL_resolve_intl_type(dsql_req* request, dsql_fld* field, const dsql_str* collation_name) +void DDL_resolve_intl_type(CompiledStatement* statement, dsql_fld* field, const dsql_str* collation_name) { - DDL_resolve_intl_type2 (request, field, collation_name, false); + DDL_resolve_intl_type2 (statement, field, collation_name, false); } -void DDL_resolve_intl_type2(dsql_req* request, +void DDL_resolve_intl_type2(CompiledStatement* statement, dsql_fld* field, const dsql_str* collation_name, bool modifying) @@ -507,7 +507,7 @@ void DDL_resolve_intl_type2(dsql_req* request, if (field->fld_type_of_name.hasData()) { - if (ENCODE_ODS(request->req_dbb->dbb_ods_version, request->req_dbb->dbb_minor_version) < ODS_11_1) + if (ENCODE_ODS(statement->req_dbb->dbb_ods_version, statement->req_dbb->dbb_minor_version) < ODS_11_1) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) -804, isc_arg_gds, isc_dsql_feature_not_supported_ods, @@ -519,7 +519,7 @@ void DDL_resolve_intl_type2(dsql_req* request, if (field->fld_type_of_table) { - dsql_rel* relation = METD_get_relation(request, field->fld_type_of_table); + dsql_rel* relation = METD_get_relation(statement, field->fld_type_of_table); const dsql_fld* fld = NULL; if (relation) @@ -558,7 +558,7 @@ void DDL_resolve_intl_type2(dsql_req* request, } else { - if (!METD_get_domain(request, field, field->fld_type_of_name.c_str())) + if (!METD_get_domain(statement, field, field->fld_type_of_name.c_str())) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) -607, isc_arg_gds, isc_dsql_command_err, @@ -587,7 +587,7 @@ void DDL_resolve_intl_type2(dsql_req* request, if (field->fld_sub_type_name) { SSHORT blob_sub_type; - if (!METD_get_type(request, + if (!METD_get_type(statement, reinterpret_cast(field->fld_sub_type_name), "RDB$FIELD_SUB_TYPE", &blob_sub_type)) @@ -635,7 +635,7 @@ void DDL_resolve_intl_type2(dsql_req* request, if (modifying) { - const dsql_rel* relation = request->req_relation; + const dsql_rel* relation = statement->req_relation; const dsql_fld* afield = field->fld_next; USHORT bpc = 0; while (afield) { @@ -650,7 +650,7 @@ void DDL_resolve_intl_type2(dsql_req* request, } if (afield) { field->fld_character_set_id = afield->fld_character_set_id; - bpc = METD_get_charset_bpc (request, field->fld_character_set_id); + bpc = METD_get_charset_bpc (statement, field->fld_character_set_id); field->fld_collation_id = afield->fld_collation_id; field->fld_ttype = afield->fld_ttype; @@ -673,7 +673,7 @@ void DDL_resolve_intl_type2(dsql_req* request, // Attach the database default character set, if not otherwise specified - const dsql_str* dfl_charset = METD_get_default_charset(request); + const dsql_str* dfl_charset = METD_get_default_charset(statement); if (dfl_charset) { field->fld_character_set = (dsql_nod*) dfl_charset; @@ -707,7 +707,7 @@ void DDL_resolve_intl_type2(dsql_req* request, if (charset_name) { const dsql_intlsym* resolved_charset = - METD_get_charset(request, + METD_get_charset(statement, (USHORT) strlen(charset_name), charset_name); @@ -727,7 +727,7 @@ void DDL_resolve_intl_type2(dsql_req* request, if (collation_name) { const dsql_intlsym* resolved_collation = - METD_get_collation(request, collation_name, field->fld_character_set_id); + METD_get_collation(statement, collation_name, field->fld_character_set_id); if (!resolved_collation) { @@ -736,7 +736,7 @@ void DDL_resolve_intl_type2(dsql_req* request, if (charset_name) charSetName = charset_name; else - charSetName = METD_get_charset_name(request, field->fld_character_set_id); + charSetName = METD_get_charset_name(statement, field->fld_character_set_id); // Specified collation not found ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) -204, @@ -813,7 +813,7 @@ static void assign_field_length ( } -static bool is_array_or_blob(dsql_req* request, const dsql_nod* node) +static bool is_array_or_blob(CompiledStatement* statement, const dsql_nod* node) { /************************************** * @@ -846,12 +846,12 @@ static bool is_array_or_blob(dsql_req* request, const dsql_nod* node) return false; case nod_via: - return is_array_or_blob(request, node->nod_arg[e_via_value_1]); + return is_array_or_blob(statement, node->nod_arg[e_via_value_1]); case nod_map: { const dsql_map* map = (dsql_map*) node->nod_arg[e_map_map]; - return is_array_or_blob(request, map->map_node); + return is_array_or_blob(statement, map->map_node); } case nod_agg_max: @@ -864,7 +864,7 @@ static bool is_array_or_blob(dsql_req* request, const dsql_nod* node) case nod_upcase: case nod_lowcase: case nod_negate: - return is_array_or_blob(request, node->nod_arg[0]); + return is_array_or_blob(statement, node->nod_arg[0]); case nod_cast: { @@ -872,7 +872,7 @@ static bool is_array_or_blob(dsql_req* request, const dsql_nod* node) if (fld->fld_dtype == dtype_blob || fld->fld_dtype == dtype_array) return true; } - return is_array_or_blob(request, node->nod_arg[e_cast_source]); + return is_array_or_blob(statement, node->nod_arg[e_cast_source]); case nod_add: case nod_subtract: @@ -884,13 +884,13 @@ static bool is_array_or_blob(dsql_req* request, const dsql_nod* node) case nod_multiply2: case nod_divide2: - if (is_array_or_blob(request, node->nod_arg[0])) { + if (is_array_or_blob(statement, node->nod_arg[0])) { return true; } - return is_array_or_blob(request, node->nod_arg[1]); + return is_array_or_blob(statement, node->nod_arg[1]); case nod_alias: - return is_array_or_blob(request, node->nod_arg[e_alias_value]); + return is_array_or_blob(statement, node->nod_arg[e_alias_value]); case nod_udf: { @@ -914,13 +914,13 @@ static bool is_array_or_blob(dsql_req* request, const dsql_nod* node) for (dsql_nod** p = nodeArgs->nod_arg; p < nodeArgs->nod_arg + nodeArgs->nod_count; ++p) { - MAKE_desc(request, &(*p)->nod_desc, *p, NULL); + MAKE_desc(statement, &(*p)->nod_desc, *p, NULL); args.add(&(*p)->nod_desc); } } dsc desc; - DSqlDataTypeUtil(request).makeSysFunction(&desc, name->str_data, args.getCount(), args.begin()); + DSqlDataTypeUtil(statement).makeSysFunction(&desc, name->str_data, args.getCount(), args.begin()); return DTYPE_IS_BLOB_OR_QUAD(desc.dsc_dtype); } @@ -931,7 +931,7 @@ static bool is_array_or_blob(dsql_req* request, const dsql_nod* node) const dsql_nod* const* const end = node->nod_arg + node->nod_count; for (const dsql_nod* const* ptr = node->nod_arg; ptr < end; ++ptr) { - if (is_array_or_blob(request, *ptr)) { + if (is_array_or_blob(statement, *ptr)) { return true; } } @@ -950,10 +950,10 @@ static bool is_array_or_blob(dsql_req* request, const dsql_nod* node) return false; case nod_trim: - return is_array_or_blob(request, node->nod_arg[e_trim_value]); + return is_array_or_blob(statement, node->nod_arg[e_trim_value]); case nod_derived_field: - return is_array_or_blob(request, node->nod_arg[e_derived_field_value]); + return is_array_or_blob(statement, node->nod_arg[e_derived_field_value]); default: fb_assert(false); @@ -962,7 +962,7 @@ static bool is_array_or_blob(dsql_req* request, const dsql_nod* node) } -static void check_constraint( dsql_req* request, +static void check_constraint( CompiledStatement* statement, dsql_nod* element, bool delete_trigger_required) { @@ -978,7 +978,7 @@ static void check_constraint( dsql_req* request, * **************************************/ - dsql_nod* ddl_node = request->req_ddl_node; + dsql_nod* ddl_node = statement->req_ddl_node; if (!(element->nod_arg[e_cnstr_table])) { element->nod_arg[e_cnstr_table] = ddl_node->nod_arg[e_drl_name]; @@ -997,23 +997,23 @@ static void check_constraint( dsql_req* request, element->nod_arg[e_cnstr_type] = MAKE_const_slong(PRE_STORE_TRIGGER); - define_constraint_trigger(request, element); + define_constraint_trigger(statement, element); // create the UPDATE trigger element->nod_arg[e_cnstr_type] = MAKE_const_slong(PRE_MODIFY_TRIGGER); - define_constraint_trigger(request, element); + define_constraint_trigger(statement, element); // create the DELETE trigger, if required if (delete_trigger_required) { element->nod_arg[e_cnstr_type] = MAKE_const_slong(PRE_ERASE_TRIGGER); - define_constraint_trigger(request, element); + define_constraint_trigger(statement, element); } - request->append_uchar(isc_dyn_end); // For CHECK constraint definition + statement->append_uchar(isc_dyn_end); // For CHECK constraint definition } @@ -1042,7 +1042,7 @@ static void check_one_call (USHORT* repetition_count, } -static void create_view_triggers(dsql_req* request, dsql_nod* element, +static void create_view_triggers(CompiledStatement* statement, dsql_nod* element, dsql_nod* items) { // Fields in the VIEW actually /************************************** @@ -1057,7 +1057,7 @@ static void create_view_triggers(dsql_req* request, dsql_nod* element, * **************************************/ - dsql_nod* ddl_node = request->req_ddl_node; + dsql_nod* ddl_node = statement->req_ddl_node; if (!(element->nod_arg[e_cnstr_table])) { element->nod_arg[e_cnstr_table] = ddl_node->nod_arg[e_drl_name]; @@ -1079,26 +1079,26 @@ static void create_view_triggers(dsql_req* request, dsql_nod* element, dsql_nod* base_and_node = 0; dsql_nod* base_relation = 0; - define_update_action(request, &base_and_node, &base_relation, items); + define_update_action(statement, &base_and_node, &base_relation, items); dsql_nod* rse = MAKE_node(nod_rse, e_rse_count); rse->nod_arg[e_rse_boolean] = base_and_node; dsql_nod* temp = MAKE_node(nod_list, 1); rse->nod_arg[e_rse_streams] = temp; temp->nod_arg[0] = base_relation; - define_view_trigger(request, element, rse, items); + define_view_trigger(statement, element, rse, items); // create the INSERT trigger element->nod_arg[e_cnstr_type] = MAKE_const_slong(PRE_STORE_TRIGGER); - define_view_trigger(request, element, NULL, items); + define_view_trigger(statement, element, NULL, items); - request->append_uchar(isc_dyn_end); // For triggers definition + statement->append_uchar(isc_dyn_end); // For triggers definition } -static void define_computed(dsql_req* request, +static void define_computed(CompiledStatement* statement, dsql_nod* relation_node, dsql_fld* field, dsql_nod* node) @@ -1115,13 +1115,13 @@ static void define_computed(dsql_req* request, * **************************************/ - dsql_nod* ddl_node = request->req_ddl_node; - request->req_ddl_node = node; + dsql_nod* ddl_node = statement->req_ddl_node; + statement->req_ddl_node = node; // Get the table node & set up correct context - if (request->req_context_number) { - reset_context_stack(request); + if (statement->req_context_number) { + reset_context_stack(statement); } dsc save_desc; @@ -1143,13 +1143,13 @@ static void define_computed(dsql_req* request, field->fld_sub_type = 0; } - PASS1_make_context(request, relation_node); + PASS1_make_context(statement, relation_node); - dsql_nod* input = PASS1_node(request, node->nod_arg[e_cmp_expr]); + dsql_nod* input = PASS1_node(statement, node->nod_arg[e_cmp_expr]); // check if array or blobs are used in expression - if (is_array_or_blob(request, input)) + if (is_array_or_blob(statement, input)) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) -607, isc_arg_gds, isc_dsql_no_array_computed, 0); @@ -1158,13 +1158,13 @@ static void define_computed(dsql_req* request, // try to calculate size of the computed field. The calculated size // may be ignored, but it will catch self references dsc desc; - MAKE_desc(request, &desc, input, NULL); + MAKE_desc(statement, &desc, input, NULL); // generate the blr expression - request->begin_blr(isc_dyn_fld_computed_blr); - GEN_expr(request, input); - request->end_blr(); + statement->begin_blr(isc_dyn_fld_computed_blr); + GEN_expr(statement, input); + statement->end_blr(); if (save_desc.dsc_dtype) { // restore the field size/type overrides @@ -1193,20 +1193,20 @@ static void define_computed(dsql_req* request, field->fld_sub_type = desc.dsc_sub_type; } - request->req_type = REQ_DDL; - request->req_ddl_node = ddl_node; - reset_context_stack(request); + statement->req_type = REQ_DDL; + statement->req_ddl_node = ddl_node; + reset_context_stack(statement); // generate the source text const dsql_str* source = (dsql_str*) node->nod_arg[e_cmp_text]; fb_assert(source->str_length <= MAX_USHORT); - request->append_string( isc_dyn_fld_computed_source, + statement->append_string( isc_dyn_fld_computed_source, source->str_data, (USHORT) source->str_length); } -static void define_constraint_trigger(dsql_req* request, dsql_nod* node) +static void define_constraint_trigger(CompiledStatement* statement, dsql_nod* node) { /************************************** * @@ -1220,24 +1220,24 @@ static void define_constraint_trigger(dsql_req* request, dsql_nod* node) * **************************************/ -/* make the "define trigger" node the current request ddl node so +/* make the "define trigger" node the current statement ddl node so that generating of BLR will be appropriate for trigger */ - dsql_nod* ddl_node = request->req_ddl_node; + dsql_nod* ddl_node = statement->req_ddl_node; - request->req_ddl_node = node; + statement->req_ddl_node = node; if (node->nod_type != nod_def_constraint) { return; } - request->append_string(isc_dyn_def_trigger, "", 0); + statement->append_string(isc_dyn_def_trigger, "", 0); dsql_nod* relation_node = node->nod_arg[e_cnstr_table]; const dsql_str* relation_name = (dsql_str*) relation_node->nod_arg[e_rln_name]; - request->append_string( isc_dyn_rel_name, + statement->append_string( isc_dyn_rel_name, relation_name->str_data, (USHORT) relation_name->str_length); @@ -1248,38 +1248,38 @@ static void define_constraint_trigger(dsql_req* request, dsql_nod* node) ULONG j = find_start_of_body(source); if (j < source->str_length) { - request->append_string( isc_dyn_trg_source, + statement->append_string( isc_dyn_trg_source, source->str_data + j, source->str_length - j); } } - request->append_number(isc_dyn_trg_sequence, 0); + statement->append_number(isc_dyn_trg_sequence, 0); const dsql_nod* constant = node->nod_arg[e_cnstr_type]; if (constant) { const SSHORT type = (SSHORT) constant->getSlong(); - request->append_number(isc_dyn_trg_type, type); + statement->append_number(isc_dyn_trg_type, type); } - request->append_uchar(isc_dyn_sql_object); + statement->append_uchar(isc_dyn_sql_object); // generate the trigger blr if (node->nod_arg[e_cnstr_condition] && node->nod_arg[e_cnstr_actions]) { - request->begin_blr(isc_dyn_trg_blr); - request->append_uchar(blr_begin); + statement->begin_blr(isc_dyn_trg_blr); + statement->append_uchar(blr_begin); /* create the "OLD" and "NEW" contexts for the trigger -- the new one could be a dummy place holder to avoid resolving fields to that context but prevent relations referenced in the trigger actions from referencing the predefined "1" context */ - if (request->req_context_number) + if (statement->req_context_number) { - reset_context_stack(request); + reset_context_stack(statement); } // CVC: check_constraint() is the only caller and it always receives @@ -1290,20 +1290,20 @@ static void define_constraint_trigger(dsql_req* request, dsql_nod* node) // record for fetch operation". relation_node->nod_arg[e_rln_alias] = (dsql_nod*) MAKE_cstring(OLD_CONTEXT); - dsql_ctx* oldContext = PASS1_make_context(request, relation_node); + dsql_ctx* oldContext = PASS1_make_context(statement, relation_node); oldContext->ctx_flags |= CTX_system; relation_node->nod_arg[e_rln_alias] = (dsql_nod*) MAKE_cstring(NEW_CONTEXT); - dsql_ctx* newContext = PASS1_make_context(request, relation_node); + dsql_ctx* newContext = PASS1_make_context(statement, relation_node); newContext->ctx_flags |= CTX_system; // generate the condition for firing the trigger - request->append_uchar(blr_if); + statement->append_uchar(blr_if); dsql_nod* condition = MAKE_node(nod_not, 1); condition->nod_arg[0] = node->nod_arg[e_cnstr_condition]; - GEN_expr(request, PASS1_node(request, condition)); + GEN_expr(statement, PASS1_node(statement, condition)); // generate the action statements for the trigger @@ -1312,30 +1312,30 @@ static void define_constraint_trigger(dsql_req* request, dsql_nod* node) for (const dsql_nod* const* const end = ptr + actions->nod_count; ptr < end; ptr++) { - GEN_statement(request, PASS1_statement(request, *ptr)); + GEN_statement(statement, PASS1_statement(statement, *ptr)); } - request->append_uchar(blr_end); // of if (as there's no ELSE branch) - request->append_uchar(blr_end); // of begin + statement->append_uchar(blr_end); // of if (as there's no ELSE branch) + statement->append_uchar(blr_end); // of begin - request->end_blr(); + statement->end_blr(); } - request->append_number(isc_dyn_system_flag, fb_sysflag_check_constraint); + statement->append_number(isc_dyn_system_flag, fb_sysflag_check_constraint); - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); -/* the request type may have been set incorrectly when parsing +/* the statement type may have been set incorrectly when parsing the trigger actions, so reset it to reflect the fact that this - is a data definition request; also reset the ddl node */ + is a data definition statement; also reset the ddl node */ - request->req_type = REQ_DDL; - request->req_ddl_node = ddl_node; - reset_context_stack(request); + statement->req_type = REQ_DDL; + statement->req_ddl_node = ddl_node; + reset_context_stack(statement); } -static void define_database( dsql_req* request) +static void define_database( CompiledStatement* statement) { /************************************** * @@ -1353,11 +1353,11 @@ static void define_database( dsql_req* request) **************************************/ SLONG start = 0; - const dsql_nod* ddl_node = request->req_ddl_node; + const dsql_nod* ddl_node = statement->req_ddl_node; - request->append_uchar(isc_dyn_mod_database); + statement->append_uchar(isc_dyn_mod_database); /* -request->append_number(isc_dyn_rel_sql_protection, 1); +statement->append_number(isc_dyn_rel_sql_protection, 1); */ const dsql_nod* elements = ddl_node->nod_arg[e_database_initial_desc]; @@ -1394,27 +1394,27 @@ request->append_number(isc_dyn_rel_sql_protection, 1); switch (element->nod_type) { case nod_difference_file: - request->append_cstring(isc_dyn_def_difference, + statement->append_cstring(isc_dyn_def_difference, ((dsql_str*)element->nod_arg[0])->str_data); break; case nod_file_desc: file = (dsql_fil*) element->nod_arg[0]; - request->append_cstring(isc_dyn_def_file, + statement->append_cstring(isc_dyn_def_file, file->fil_name->str_data); start = MAX(start, file->fil_start); - request->append_file_start(start); - request->append_file_length(file->fil_length); - request->append_uchar(isc_dyn_end); + statement->append_file_start(start); + statement->append_file_length(file->fil_length); + statement->append_uchar(isc_dyn_end); start += file->fil_length; break; case nod_dfl_charset: name = (dsql_str*) element->nod_arg[0]; - request->append_cstring(isc_dyn_fld_character_set_name, name->str_data); + statement->append_cstring(isc_dyn_fld_character_set_name, name->str_data); break; case nod_dfl_collate: name = (dsql_str*) element->nod_arg[0]; - request->append_cstring(isc_dyn_fld_collation, name->str_data); + statement->append_cstring(isc_dyn_fld_collation, name->str_data); break; default: @@ -1423,11 +1423,11 @@ request->append_number(isc_dyn_rel_sql_protection, 1); } } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static bool define_default(dsql_req* request, const dsql_nod* node) +static bool define_default(CompiledStatement* statement, const dsql_nod* node) { /***************************************** * @@ -1442,24 +1442,24 @@ static bool define_default(dsql_req* request, const dsql_nod* node) **************************************/ fb_assert(node && node->nod_type == nod_def_default); - dsql_nod* const value = PASS1_node(request, node->nod_arg[e_dft_default]); + dsql_nod* const value = PASS1_node(statement, node->nod_arg[e_dft_default]); fb_assert(value); - request->begin_blr(isc_dyn_fld_default_value); - GEN_expr(request, value); - request->end_blr(); + statement->begin_blr(isc_dyn_fld_default_value); + GEN_expr(statement, value); + statement->end_blr(); dsql_str* const string = (dsql_str*) node->nod_arg[e_dft_default_source]; fb_assert(string && string->str_length <= MAX_USHORT); fix_default_source(string); - request->append_string(isc_dyn_fld_default_source, string->str_data, string->str_length); + statement->append_string(isc_dyn_fld_default_source, string->str_data, string->str_length); return (value->nod_type == nod_null); } -static void define_del_cascade_trg( dsql_req* request, +static void define_del_cascade_trg( CompiledStatement* statement, const dsql_nod* element, const dsql_nod* for_columns, const dsql_nod* prim_columns, @@ -1483,45 +1483,45 @@ static void define_del_cascade_trg( dsql_req* request, } // stuff a trigger_name of size 0. So the dyn-parser will make one up. - request->append_string(isc_dyn_def_trigger, "", 0); + statement->append_string(isc_dyn_def_trigger, "", 0); - request->append_number(isc_dyn_trg_type, (SSHORT) POST_ERASE_TRIGGER); + statement->append_number(isc_dyn_trg_type, (SSHORT) POST_ERASE_TRIGGER); - request->append_uchar(isc_dyn_sql_object); - request->append_number(isc_dyn_trg_sequence, (SSHORT) 1); - request->append_number(isc_dyn_trg_inactive, (SSHORT) 0); - request->append_cstring(isc_dyn_rel_name, prim_rel_name); + statement->append_uchar(isc_dyn_sql_object); + statement->append_number(isc_dyn_trg_sequence, (SSHORT) 1); + statement->append_number(isc_dyn_trg_inactive, (SSHORT) 0); + statement->append_cstring(isc_dyn_rel_name, prim_rel_name); // the trigger blr - request->begin_blr(isc_dyn_trg_blr); - request->append_uchar(blr_for); - request->append_uchar(blr_rse); + statement->begin_blr(isc_dyn_trg_blr); + statement->append_uchar(blr_for); + statement->append_uchar(blr_rse); // the context for the prim. key relation - request->append_uchar(1); + statement->append_uchar(1); - request->append_uchar(blr_relation); - request->append_cstring(0, for_rel_name); + statement->append_uchar(blr_relation); + statement->append_cstring(0, for_rel_name); // the context for the foreign key relation - request->append_uchar(2); + statement->append_uchar(2); - stuff_matching_blr(request, for_columns, prim_columns); + stuff_matching_blr(statement, for_columns, prim_columns); - request->append_uchar(blr_erase); - request->append_uchar(2); - request->end_blr(); + statement->append_uchar(blr_erase); + statement->append_uchar(2); + statement->end_blr(); // end of the blr - request->append_number(isc_dyn_system_flag, + statement->append_number(isc_dyn_system_flag, fb_sysflag_referential_constraint); // no trg_source and no trg_description - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void define_set_default_trg( dsql_req* request, +static void define_set_default_trg( CompiledStatement* statement, const dsql_nod* element, const dsql_nod* for_columns, const dsql_nod* prim_columns, @@ -1547,7 +1547,7 @@ static void define_set_default_trg( dsql_req* request, return; } - request->generate_unnamed_trigger_beginning(on_upd_trg, + statement->generate_unnamed_trigger_beginning(on_upd_trg, prim_rel_name, prim_columns, for_rel_name, @@ -1555,13 +1555,13 @@ static void define_set_default_trg( dsql_req* request, USHORT num_fields = 0; const dsql_nod* const* for_key_flds = for_columns->nod_arg; - const dsql_nod* ddl_node = request->req_ddl_node; + const dsql_nod* ddl_node = statement->req_ddl_node; do { // for every column in the foreign key .... const dsql_str* for_key_fld_name_str = (dsql_str*) (*for_key_flds)->nod_arg[1]; - request->append_uchar(blr_assignment); + statement->append_uchar(blr_assignment); /* here stuff the default value as blr_literal .... or blr_null if this col. does not have an applicable default */ @@ -1609,7 +1609,7 @@ static void define_set_default_trg( dsql_req* request, { // case (1-a) above: there is a col. level default fb_assert(default_node->nod_type == nod_def_default); - GEN_expr(request, default_node->nod_arg[e_dft_default]); + GEN_expr(statement, default_node->nod_arg[e_dft_default]); found_default = true; search_for_default = false; } @@ -1631,19 +1631,19 @@ static void define_set_default_trg( dsql_req* request, /* case: (1-b): domain name is available. Column level default is not declared. so get the domain default */ const USHORT def_len = - METD_get_domain_default(request, domain_name, &found_default, + METD_get_domain_default(statement, domain_name, &found_default, default_val, sizeof(default_val)); search_for_default = false; if (found_default) { - stuff_default_blr(request, default_val, def_len); + stuff_default_blr(statement, default_val, def_len); } else { // neither col level nor domain level default exists - request->append_uchar(blr_null); + statement->append_uchar(blr_null); } } break; @@ -1654,48 +1654,48 @@ static void define_set_default_trg( dsql_req* request, // case 2: see if the column/domain has already been created const USHORT def_len = - METD_get_col_default(request, for_rel_name, + METD_get_col_default(statement, for_rel_name, for_key_fld_name_str->str_data, &found_default, default_val, sizeof(default_val)); if (found_default) { - stuff_default_blr(request, default_val, def_len); + stuff_default_blr(statement, default_val, def_len); } else { - request->append_uchar(blr_null); + statement->append_uchar(blr_null); } } // the context for the foreign key relation - request->append_uchar(blr_field); - request->append_uchar(2); - request->append_cstring(0, for_key_fld_name_str->str_data); + statement->append_uchar(blr_field); + statement->append_uchar(2); + statement->append_cstring(0, for_key_fld_name_str->str_data); num_fields++; for_key_flds++; } while (num_fields < for_columns->nod_count); - request->append_uchar(blr_end); + statement->append_uchar(blr_end); if (on_upd_trg) { - request->append_uchars(blr_end, 3); + statement->append_uchars(blr_end, 3); } - request->end_blr(); + statement->end_blr(); - request->append_number(isc_dyn_system_flag, + statement->append_number(isc_dyn_system_flag, fb_sysflag_referential_constraint); // no trg_source and no trg_description - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void define_dimensions( dsql_req* request, const dsql_fld* field) +static void define_dimensions( CompiledStatement* statement, const dsql_fld* field) { /***************************************** * @@ -1717,23 +1717,23 @@ static void define_dimensions( dsql_req* request, const dsql_fld* field) isc_arg_gds, isc_dsql_max_arr_dim_exceeded, 0); } - request->append_number(isc_dyn_fld_dimensions, (SSHORT) dims); + statement->append_number(isc_dyn_fld_dimensions, (SSHORT) dims); SSHORT position = 0; const dsql_nod* const* ptr = elements->nod_arg; for (const dsql_nod* const* const end = ptr + elements->nod_count; ptr < end; ++ptr, ++position) { - request->append_number(isc_dyn_def_dimension, position); + statement->append_number(isc_dyn_def_dimension, position); const dsql_nod* element = *ptr++; - request->append_uchar(isc_dyn_dim_lower); + statement->append_uchar(isc_dyn_dim_lower); const SLONG lrange = element->getSlong(); - request->append_ulong_with_length(lrange); + statement->append_ulong_with_length(lrange); element = *ptr; - request->append_uchar(isc_dyn_dim_upper); + statement->append_uchar(isc_dyn_dim_upper); const SLONG hrange = element->getSlong(); - request->append_ulong_with_length(hrange); - request->append_uchar(isc_dyn_end); + statement->append_ulong_with_length(hrange); + statement->append_uchar(isc_dyn_end); if (lrange >= hrange) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) -604, @@ -1743,7 +1743,7 @@ static void define_dimensions( dsql_req* request, const dsql_fld* field) } -static void define_domain(dsql_req* request) +static void define_domain(CompiledStatement* statement) { /************************************** * @@ -1756,7 +1756,7 @@ static void define_domain(dsql_req* request) * **************************************/ - dsql_nod* element = request->req_ddl_node; + dsql_nod* element = statement->req_ddl_node; dsql_fld* field = (dsql_fld*) element->nod_arg[e_dom_name]; if (fb_utils::implicit_domain(field->fld_name.c_str())) @@ -1766,23 +1766,23 @@ static void define_domain(dsql_req* request) isc_arg_string, field->fld_name.c_str(), 0); } - request->append_string(isc_dyn_def_global_fld, field->fld_name); + statement->append_string(isc_dyn_def_global_fld, field->fld_name); - DDL_resolve_intl_type(request, field, + DDL_resolve_intl_type(statement, field, (dsql_str*) element->nod_arg[e_dom_collate]); - put_field(request, field, false); + put_field(statement, field, false); // check for a default value dsql_nod* node = element->nod_arg[e_dom_default]; if (node) { - define_default(request, node); + define_default(statement, node); } if (field->fld_ranges) { - define_dimensions(request, field); + define_dimensions(statement, field); } bool null_flag = false; @@ -1803,7 +1803,7 @@ static void define_domain(dsql_req* request) { if (!null_flag) { - request->append_uchar(isc_dyn_fld_not_null); + statement->append_uchar(isc_dyn_fld_not_null); null_flag = true; } else @@ -1828,11 +1828,11 @@ static void define_domain(dsql_req* request) if (string) { fb_assert(string->str_length <= MAX_USHORT); - request->append_string( isc_dyn_fld_validation_source, + statement->append_string( isc_dyn_fld_validation_source, string->str_data, string->str_length); } - request->begin_blr(isc_dyn_fld_validation_blr); + statement->begin_blr(isc_dyn_fld_validation_blr); // Set any VALUE nodes to the type of the domain being defined. if (node1->nod_arg[e_cnstr_condition]) @@ -1840,7 +1840,7 @@ static void define_domain(dsql_req* request) set_nod_value_attributes(node1->nod_arg[e_cnstr_condition], field); } - /* Increment the context level for this request, so + /* Increment the context level for this statement, so that the context number for any RSE generated for a SELECT within the CHECK clause will be greater than 0. In the environment of a domain check @@ -1849,21 +1849,21 @@ static void define_domain(dsql_req* request) nod_dom_value, corresponding to an occurance of the VALUE keyword in the bod of the check constraint. -- chrisj 1999-08-20 */ - request->req_context_number++; + statement->req_context_number++; - GEN_expr(request, PASS1_node(request, node1->nod_arg[e_cnstr_condition])); + GEN_expr(statement, PASS1_node(statement, node1->nod_arg[e_cnstr_condition])); - request->end_blr(); + statement->end_blr(); } } } } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void define_exception( dsql_req* request, NOD_TYPE op) +static void define_exception( CompiledStatement* statement, NOD_TYPE op) { /************************************** * @@ -1875,27 +1875,27 @@ static void define_exception( dsql_req* request, NOD_TYPE op) * Generate ddl to create an exception code. * **************************************/ - const dsql_nod* ddl_node = request->req_ddl_node; + const dsql_nod* ddl_node = statement->req_ddl_node; const dsql_str* name = (dsql_str*) ddl_node->nod_arg[e_xcp_name]; switch (op) { case nod_replace_exception: - if (METD_get_exception(request, name)) { - define_exception(request, nod_mod_exception); + if (METD_get_exception(statement, name)) { + define_exception(statement, nod_mod_exception); } else { - define_exception(request, nod_def_exception); + define_exception(statement, nod_def_exception); } break; case nod_def_exception: case nod_redef_exception: - request->append_cstring(isc_dyn_def_exception, name->str_data); + statement->append_cstring(isc_dyn_def_exception, name->str_data); break; case nod_mod_exception: - request->append_cstring(isc_dyn_mod_exception, name->str_data); + statement->append_cstring(isc_dyn_mod_exception, name->str_data); break; default: @@ -1904,13 +1904,13 @@ static void define_exception( dsql_req* request, NOD_TYPE op) const dsql_str* text = (dsql_str*) ddl_node->nod_arg[e_xcp_text]; fb_assert(text->str_length <= MAX_USHORT); - request->append_string(isc_dyn_xcp_msg, text->str_data, text->str_length); - request->append_uchar(isc_dyn_end); + statement->append_string(isc_dyn_xcp_msg, text->str_data, text->str_length); + statement->append_uchar(isc_dyn_end); } static void define_field( - dsql_req* request, + CompiledStatement* statement, dsql_nod* element, SSHORT position, const dsql_str* relation_name, const dsql_nod* pkcols) @@ -1931,12 +1931,12 @@ static void define_field( // add the field to the relation being defined for parsing purposes bool permanent = false; - dsql_rel* relation = request->req_relation; + dsql_rel* relation = statement->req_relation; if (relation != NULL) { if (! (relation->rel_flags & REL_new_relation)) { - dsql_fld* perm_field = FB_NEW(request->req_dbb->dbb_pool) - dsql_fld(request->req_dbb->dbb_pool); + dsql_fld* perm_field = FB_NEW(statement->req_dbb->dbb_pool) + dsql_fld(statement->req_dbb->dbb_pool); *perm_field = *field; @@ -1950,14 +1950,14 @@ static void define_field( try { const dsql_nod* domain_node = element->nod_arg[e_dfl_domain]; if (domain_node) { - request->append_string(isc_dyn_def_local_fld, field->fld_name); + statement->append_string(isc_dyn_def_local_fld, field->fld_name); const dsql_nod* node1 = domain_node->nod_arg[e_dom_name]; const dsql_str* domain_name = (dsql_str*) node1->nod_arg[e_fln_name]; - request->append_cstring(isc_dyn_fld_source, domain_name->str_data); + statement->append_cstring(isc_dyn_fld_source, domain_name->str_data); // Get the domain information - if (!(METD_get_domain(request, field, domain_name->str_data))) + if (!(METD_get_domain(statement, field, domain_name->str_data))) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) -607, isc_arg_gds, isc_dsql_command_err, @@ -1967,33 +1967,33 @@ static void define_field( 0); } - DDL_resolve_intl_type( request, + DDL_resolve_intl_type( statement, field, reinterpret_cast(element->nod_arg[e_dfl_collate])); if (element->nod_arg[e_dfl_collate]) { - request->append_number(isc_dyn_fld_collation, + statement->append_number(isc_dyn_fld_collation, field->fld_collation_id); } } else { - request->append_string(isc_dyn_def_sql_fld, field->fld_name); + statement->append_string(isc_dyn_def_sql_fld, field->fld_name); if (relation_name) { - request->append_cstring(isc_dyn_rel_name, relation_name->str_data); + statement->append_cstring(isc_dyn_rel_name, relation_name->str_data); } if (element->nod_arg[e_dfl_computed]) { field->fld_flags |= FLD_computed; dsql_nod* computed_node = element->nod_arg[e_dfl_computed]; - define_computed(request, - request->req_ddl_node->nod_arg[e_drl_name], field, + define_computed(statement, + statement->req_ddl_node->nod_arg[e_drl_name], field, computed_node); } - DDL_resolve_intl_type(request, field, + DDL_resolve_intl_type(statement, field, reinterpret_cast(element->nod_arg[e_dfl_collate])); - put_field(request, field, false); + put_field(statement, field, false); } if ((relation->rel_flags & REL_external) && @@ -2011,18 +2011,18 @@ static void define_field( } if (position != -1) - request->append_number(isc_dyn_fld_position, position); + statement->append_number(isc_dyn_fld_position, position); // check for a default value bool default_null_flag = false; dsql_nod* node = element->nod_arg[e_dfl_default]; if (node) { - default_null_flag = define_default(request, node); + default_null_flag = define_default(statement, node); } if (field->fld_ranges) { - define_dimensions(request, field); + define_dimensions(statement, field); } // dimitr: store the final position of the vector to insert a not null @@ -2033,8 +2033,8 @@ static void define_field( // operations for BLR/DYN (we could store constraints in the // separate object and then merge them into req_blr_data), but // this is for another day. - const size_t end = request->req_blr_data.getCount(); - request->append_uchar(isc_dyn_end); + const size_t end = statement->req_blr_data.getCount(); + statement->append_uchar(isc_dyn_end); // check for constraints bool not_null_flag = false; @@ -2061,10 +2061,10 @@ static void define_field( } if (!not_null_flag) { - request->append_cstring(isc_dyn_rel_constraint, + statement->append_cstring(isc_dyn_rel_constraint, string && node1->nod_type == nod_null ? string->str_data : 0); - request->append_uchar(isc_dyn_fld_not_null); - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_fld_not_null); + statement->append_uchar(isc_dyn_end); not_null_flag = true; } if (node1->nod_type == nod_null) @@ -2073,7 +2073,7 @@ static void define_field( case nod_unique: { const char* constraint_name = string ? string->str_data : 0; - request->append_cstring(isc_dyn_rel_constraint, constraint_name); + statement->append_cstring(isc_dyn_rel_constraint, constraint_name); const dsql_nod* index = node1->nod_arg[e_pri_index]; fb_assert(index); @@ -2087,35 +2087,35 @@ static void define_field( if (node1->nod_type == nod_primary) { - request->append_cstring(isc_dyn_def_primary_key, index_name); + statement->append_cstring(isc_dyn_def_primary_key, index_name); } else if (node1->nod_type == nod_unique) { - request->append_cstring(isc_dyn_def_unique, index_name); + statement->append_cstring(isc_dyn_def_unique, index_name); } - request->append_number(isc_dyn_idx_unique, 1); + statement->append_number(isc_dyn_idx_unique, 1); if (index->nod_arg[e_idx_asc_dsc]) { - request->append_number(isc_dyn_idx_type, 1); + statement->append_number(isc_dyn_idx_type, 1); } - request->append_string(isc_dyn_fld_name, field->fld_name); - request->append_uchar(isc_dyn_end); + statement->append_string(isc_dyn_fld_name, field->fld_name); + statement->append_uchar(isc_dyn_end); break; } case nod_foreign: { const char* constraint_name = string ? string->str_data : 0; - request->append_cstring(isc_dyn_rel_constraint, constraint_name); - foreign_key(request, node1, constraint_name); + statement->append_cstring(isc_dyn_rel_constraint, constraint_name); + foreign_key(statement, node1, constraint_name); break; } case nod_def_constraint: - request->append_cstring(isc_dyn_rel_constraint, + statement->append_cstring(isc_dyn_rel_constraint, string ? string->str_data : 0); - check_constraint(request, node1, false); // No delete trigger + check_constraint(statement, node1, false); // No delete trigger break; } } @@ -2125,7 +2125,7 @@ static void define_field( if (not_null_flag) { // dimitr: insert a not null item right before column's isc_dyn_end - request->req_blr_data.insert(end, isc_dyn_fld_not_null); + statement->req_blr_data.insert(end, isc_dyn_fld_not_null); } else if (pkcols) { @@ -2135,7 +2135,7 @@ static void define_field( const dsql_str* pkfield_name = (dsql_str*) pkcols->nod_arg[i]->nod_arg[e_fln_name]; if (field->fld_name == pkfield_name->str_data) { - request->req_blr_data.insert(end, isc_dyn_fld_not_null); + statement->req_blr_data.insert(end, isc_dyn_fld_not_null); break; } } @@ -2152,7 +2152,7 @@ static void define_field( } -static SSHORT getBlobFilterSubType(dsql_req* request, const dsql_nod* node) +static SSHORT getBlobFilterSubType(CompiledStatement* statement, const dsql_nod* node) { /******************************************* * @@ -2178,7 +2178,7 @@ static SSHORT getBlobFilterSubType(dsql_req* request, const dsql_nod* node) // fall thru for dtype_text SSHORT blob_sub_type; - if (!METD_get_type(request, + if (!METD_get_type(statement, (const dsql_str*)(node->nod_arg[0]), "RDB$FIELD_SUB_TYPE", &blob_sub_type)) @@ -2191,7 +2191,7 @@ static SSHORT getBlobFilterSubType(dsql_req* request, const dsql_nod* node) return blob_sub_type; } -static void define_filter( dsql_req* request) +static void define_filter( CompiledStatement* statement) { /************************************** * @@ -2203,24 +2203,24 @@ static void define_filter( dsql_req* request) * define a filter to the database. * **************************************/ - const dsql_nod* filter_node = request->req_ddl_node; + const dsql_nod* filter_node = statement->req_ddl_node; const dsql_nod* const* ptr = filter_node->nod_arg; - request->append_cstring(isc_dyn_def_filter, + statement->append_cstring(isc_dyn_def_filter, ((dsql_str*) (ptr[e_filter_name]))->str_data); - request->append_number(isc_dyn_filter_in_subtype, - getBlobFilterSubType(request, ptr[e_filter_in_type])); - request->append_number(isc_dyn_filter_out_subtype, - getBlobFilterSubType(request, ptr[e_filter_out_type])); - request->append_cstring(isc_dyn_func_entry_point, + statement->append_number(isc_dyn_filter_in_subtype, + getBlobFilterSubType(statement, ptr[e_filter_in_type])); + statement->append_number(isc_dyn_filter_out_subtype, + getBlobFilterSubType(statement, ptr[e_filter_out_type])); + statement->append_cstring(isc_dyn_func_entry_point, ((dsql_str*) (ptr[e_filter_entry_pt]))->str_data); - request->append_cstring(isc_dyn_func_module_name, + statement->append_cstring(isc_dyn_func_module_name, ((dsql_str*) (ptr[e_filter_module]))->str_data); - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void define_collation( dsql_req* request) +static void define_collation( CompiledStatement* statement) { /************************************** * @@ -2233,15 +2233,15 @@ static void define_collation( dsql_req* request) * **************************************/ - const dsql_str* coll_name = (dsql_str*) request->req_ddl_node->nod_arg[e_def_coll_name]; - const dsql_str* coll_for = (dsql_str*) request->req_ddl_node->nod_arg[e_def_coll_for]; - const dsql_nod* coll_from = request->req_ddl_node->nod_arg[e_def_coll_from]; - const dsql_nod* coll_attributes = request->req_ddl_node->nod_arg[e_def_coll_attributes]; + const dsql_str* coll_name = (dsql_str*) statement->req_ddl_node->nod_arg[e_def_coll_name]; + const dsql_str* coll_for = (dsql_str*) statement->req_ddl_node->nod_arg[e_def_coll_for]; + const dsql_nod* coll_from = statement->req_ddl_node->nod_arg[e_def_coll_from]; + const dsql_nod* coll_attributes = statement->req_ddl_node->nod_arg[e_def_coll_attributes]; const dsql_nod* coll_specific_attributes = - PASS1_node(request, request->req_ddl_node->nod_arg[e_def_coll_specific_attributes]); + PASS1_node(statement, statement->req_ddl_node->nod_arg[e_def_coll_specific_attributes]); const dsql_intlsym* resolved_charset = - METD_get_charset(request, + METD_get_charset(statement, (USHORT) strlen(coll_for->str_data), coll_for->str_data); @@ -2256,15 +2256,15 @@ static void define_collation( dsql_req* request) if (coll_specific_attributes) coll_specific_attributes = coll_specific_attributes->nod_arg[0]; - request->append_cstring(isc_dyn_def_collation, coll_name->str_data); - request->append_number(isc_dyn_coll_for_charset, resolved_charset->intlsym_charset_id); + statement->append_cstring(isc_dyn_def_collation, coll_name->str_data); + statement->append_number(isc_dyn_coll_for_charset, resolved_charset->intlsym_charset_id); if (coll_from) { if (coll_from->nod_type == nod_collation_from) { const dsql_intlsym* resolved_collation = - METD_get_collation(request, (dsql_str*)coll_from->nod_arg[0], + METD_get_collation(statement, (dsql_str*)coll_from->nod_arg[0], resolved_charset->intlsym_charset_id); if (!resolved_collation) @@ -2277,13 +2277,13 @@ static void define_collation( dsql_req* request) 0); } - request->append_number(isc_dyn_coll_from, + statement->append_number(isc_dyn_coll_from, INTL_CS_COLL_TO_TTYPE(resolved_collation->intlsym_charset_id, resolved_collation->intlsym_collate_id)); } else if (coll_from->nod_type == nod_collation_from_external) { - request->append_cstring(isc_dyn_coll_from_external, + statement->append_cstring(isc_dyn_coll_from_external, ((dsql_str*)coll_from->nod_arg[0])->str_data); } else @@ -2300,7 +2300,7 @@ static void define_collation( dsql_req* request) switch (attribute->nod_type) { case nod_collation_attr: - request->append_number(isc_dyn_coll_attribute, (IPTR) attribute->nod_arg[0]); + statement->append_number(isc_dyn_coll_attribute, (IPTR) attribute->nod_arg[0]); break; default: @@ -2311,17 +2311,17 @@ static void define_collation( dsql_req* request) if (coll_specific_attributes) { - request->append_number(isc_dyn_coll_specific_attributes_charset, + statement->append_number(isc_dyn_coll_specific_attributes_charset, coll_specific_attributes->nod_desc.dsc_ttype()); - request->append_cstring(isc_dyn_coll_specific_attributes, + statement->append_cstring(isc_dyn_coll_specific_attributes, ((dsql_str*)coll_specific_attributes->nod_arg[0])->str_data); } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void define_generator( dsql_req* request) +static void define_generator( CompiledStatement* statement) { /************************************** * @@ -2334,13 +2334,13 @@ static void define_generator( dsql_req* request) * **************************************/ - const dsql_str* gen_name = (dsql_str*) request->req_ddl_node->nod_arg[e_gen_name]; - request->append_cstring(isc_dyn_def_generator, gen_name->str_data); - request->append_uchar(isc_dyn_end); + const dsql_str* gen_name = (dsql_str*) statement->req_ddl_node->nod_arg[e_gen_name]; + statement->append_cstring(isc_dyn_def_generator, gen_name->str_data); + statement->append_uchar(isc_dyn_end); } -static void define_index(dsql_req* request) +static void define_index(CompiledStatement* statement) { /************************************** * @@ -2352,16 +2352,16 @@ static void define_index(dsql_req* request) * Generate ddl to create an index. * **************************************/ - request->append_uchar(isc_dyn_begin); + statement->append_uchar(isc_dyn_begin); - const dsql_nod* ddl_node = request->req_ddl_node; + const dsql_nod* ddl_node = statement->req_ddl_node; dsql_nod* relation_node = (dsql_nod*) ddl_node->nod_arg[e_idx_table]; const dsql_str* relation_name = (dsql_str*) relation_node->nod_arg[e_rln_name]; dsql_nod* field_list = ddl_node->nod_arg[e_idx_fields]; const dsql_str* index_name = (dsql_str*) ddl_node->nod_arg[e_idx_name]; - request->append_cstring(isc_dyn_def_idx, index_name->str_data); - request->append_cstring(isc_dyn_rel_name, relation_name->str_data); + statement->append_cstring(isc_dyn_def_idx, index_name->str_data); + statement->append_cstring(isc_dyn_rel_name, relation_name->str_data); /* go through the fields list, making an index segment for each field, unless we have a computation, in which case generate an expression index */ @@ -2372,29 +2372,29 @@ static void define_index(dsql_req* request) const dsql_nod* const* const end = ptr + field_list->nod_count; for (; ptr < end; ptr++) { - request->append_cstring(isc_dyn_fld_name, + statement->append_cstring(isc_dyn_fld_name, ((dsql_str*) (*ptr)->nod_arg[1])->str_data); } } else if (field_list->nod_type == nod_def_computed) - define_computed(request, relation_node, NULL, field_list); + define_computed(statement, relation_node, NULL, field_list); // check for a unique index if (ddl_node->nod_arg[e_idx_unique]) { - request->append_number(isc_dyn_idx_unique, 1); + statement->append_number(isc_dyn_idx_unique, 1); } if (ddl_node->nod_arg[e_idx_asc_dsc]) { - request->append_number(isc_dyn_idx_type, 1); + statement->append_number(isc_dyn_idx_type, 1); } - request->append_uchar(isc_dyn_end); // of define index - request->append_uchar(isc_dyn_end); // of begin + statement->append_uchar(isc_dyn_end); // of define index + statement->append_uchar(isc_dyn_end); // of begin } -static void define_procedure(dsql_req* request, NOD_TYPE op) +static void define_procedure(CompiledStatement* statement, NOD_TYPE op) { /************************************** * @@ -2411,52 +2411,52 @@ static void define_procedure(dsql_req* request, NOD_TYPE op) SSHORT inputs = 0, defaults = 0; SSHORT outputs = 0; SSHORT locals = 0; - const dsql_nod* procedure_node = request->req_ddl_node; + const dsql_nod* procedure_node = statement->req_ddl_node; const dsql_str* procedure_name = (dsql_str*) procedure_node->nod_arg[e_prc_name]; switch (op) { case nod_replace_procedure: - if (METD_get_procedure(request, procedure_name)) - define_procedure(request, nod_mod_procedure); + if (METD_get_procedure(statement, procedure_name)) + define_procedure(statement, nod_mod_procedure); else - define_procedure(request, nod_def_procedure); + define_procedure(statement, nod_def_procedure); return; case nod_def_procedure: case nod_redef_procedure: - request->append_cstring(isc_dyn_def_procedure, + statement->append_cstring(isc_dyn_def_procedure, procedure_name->str_data); - request->append_number(isc_dyn_rel_sql_protection, 1); + statement->append_number(isc_dyn_rel_sql_protection, 1); break; default: // op == nod_mod_procedure { - request->append_cstring(isc_dyn_mod_procedure, + statement->append_cstring(isc_dyn_mod_procedure, procedure_name->str_data); - const dsql_prc* procedure = METD_get_procedure(request, procedure_name); + const dsql_prc* procedure = METD_get_procedure(statement, procedure_name); if (procedure) { const dsql_fld* field; for (field = procedure->prc_inputs; field; field = field->fld_next) { - request->append_string(isc_dyn_delete_parameter, + statement->append_string(isc_dyn_delete_parameter, field->fld_name); - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } for (field = procedure->prc_outputs; field; field = field->fld_next) { - request->append_string(isc_dyn_delete_parameter, + statement->append_string(isc_dyn_delete_parameter, field->fld_name); - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } } } } - request->begin_debug(); + statement->begin_debug(); const dsql_str* source = (dsql_str*) procedure_node->nod_arg[e_prc_source]; if (source) @@ -2465,7 +2465,7 @@ static void define_procedure(dsql_req* request, NOD_TYPE op) ULONG j = find_start_of_body(source); if (j < source->str_length) { - request->append_string( isc_dyn_prc_source, + statement->append_string( isc_dyn_prc_source, source->str_data + j, source->str_length - j); } @@ -2476,7 +2476,7 @@ static void define_procedure(dsql_req* request, NOD_TYPE op) MemoryPool& pool = *tdbb->getDefaultPool(); dsql_prc* procedure = FB_NEW(pool) dsql_prc(pool); procedure->prc_name = procedure_name->str_data; - request->req_procedure = procedure; + statement->req_procedure = procedure; // now do the input parameters @@ -2493,21 +2493,21 @@ static void define_procedure(dsql_req* request, NOD_TYPE op) dsql_nod* parameter = *ptr; dsql_fld* field = (dsql_fld*) parameter->nod_arg[e_dfl_field]; - request->append_string(isc_dyn_def_parameter, field->fld_name); - request->append_number(isc_dyn_prm_number, position); - request->append_number(isc_dyn_prm_type, 0); + statement->append_string(isc_dyn_def_parameter, field->fld_name); + statement->append_number(isc_dyn_prm_number, position); + statement->append_number(isc_dyn_prm_type, 0); - DDL_resolve_intl_type(request, field, + DDL_resolve_intl_type(statement, field, reinterpret_cast(parameter->nod_arg[e_dfl_collate])); - put_field(request, field, false); + put_field(statement, field, false); - request->put_debug_argument(fb_dbg_arg_input, position, field->fld_name.c_str()); + statement->put_debug_argument(fb_dbg_arg_input, position, field->fld_name.c_str()); // check for a parameter default value dsql_nod* node = parameter->nod_arg[e_dfl_default]; if (node) { - define_default(request, node); + define_default(statement, node); defaults++; } else if (defaults) { @@ -2527,8 +2527,8 @@ static void define_procedure(dsql_req* request, NOD_TYPE op) field_ptr = &field->fld_next; position++; - request->append_uchar(isc_dyn_end); - request->append_number(isc_dyn_prc_inputs, position); + statement->append_uchar(isc_dyn_end); + statement->append_number(isc_dyn_prc_inputs, position); } inputs = position; } @@ -2550,14 +2550,14 @@ static void define_procedure(dsql_req* request, NOD_TYPE op) { dsql_nod* parameter = *ptr; dsql_fld* field = (dsql_fld*) parameter->nod_arg[e_dfl_field]; - request->append_string(isc_dyn_def_parameter, field->fld_name); - request->append_number(isc_dyn_prm_number, position); - request->append_number(isc_dyn_prm_type, 1); - DDL_resolve_intl_type(request, field, + statement->append_string(isc_dyn_def_parameter, field->fld_name); + statement->append_number(isc_dyn_prm_number, position); + statement->append_number(isc_dyn_prm_type, 1); + DDL_resolve_intl_type(statement, field, reinterpret_cast(parameter->nod_arg[e_dfl_collate])); - put_field(request, field, false); + put_field(statement, field, false); - request->put_debug_argument(fb_dbg_arg_output, position, field->fld_name.c_str()); + statement->put_debug_argument(fb_dbg_arg_output, position, field->fld_name.c_str()); *ptr = MAKE_variable(field, field->fld_name.c_str(), VAR_output, 1, (USHORT) (2 * position), @@ -2567,8 +2567,8 @@ static void define_procedure(dsql_req* request, NOD_TYPE op) position++; locals++; - request->append_uchar(isc_dyn_end); - request->append_number(isc_dyn_prc_outputs, position); + statement->append_uchar(isc_dyn_end); + statement->append_number(isc_dyn_prc_outputs, position); } outputs = position; } @@ -2578,13 +2578,13 @@ static void define_procedure(dsql_req* request, NOD_TYPE op) procedure->prc_in_count = inputs; procedure->prc_def_count = defaults; - request->begin_blr(isc_dyn_prc_blr); - request->append_uchar(blr_begin); + statement->begin_blr(isc_dyn_prc_blr); + statement->append_uchar(blr_begin); if (inputs) { - request->append_uchar(blr_message); - request->append_uchar(0); - request->append_ushort(2 * inputs); + statement->append_uchar(blr_message); + statement->append_uchar(0); + statement->append_ushort(2 * inputs); parameters = procedure_node->nod_arg[e_prc_inputs]; dsql_nod** ptr = parameters->nod_arg; for (const dsql_nod* const* const end = ptr + parameters->nod_count; @@ -2593,12 +2593,12 @@ static void define_procedure(dsql_req* request, NOD_TYPE op) dsql_nod* parameter = *ptr; dsql_var* variable = (dsql_var*) parameter->nod_arg[e_var_variable]; dsql_fld* field = variable->var_field; - put_msg_field(request, field); + put_msg_field(statement, field); } } - request->append_uchar(blr_message); - request->append_uchar(1); - request->append_ushort(2 * outputs + 1); + statement->append_uchar(blr_message); + statement->append_uchar(1); + statement->append_ushort(2 * outputs + 1); if (outputs) { parameters = procedure_node->nod_arg[e_prc_outputs]; @@ -2609,21 +2609,21 @@ static void define_procedure(dsql_req* request, NOD_TYPE op) dsql_nod* parameter = *ptr; dsql_var* variable = (dsql_var*) parameter->nod_arg[e_var_variable]; dsql_fld* field = variable->var_field; - put_msg_field(request, field); + put_msg_field(statement, field); } } // add slot for EOS - request->append_uchar(blr_short); - request->append_uchar(0); + statement->append_uchar(blr_short); + statement->append_uchar(0); if (inputs) { - request->append_uchar(blr_receive); - request->append_uchar(0); + statement->append_uchar(blr_receive); + statement->append_uchar(0); } - request->append_uchar(blr_begin); + statement->append_uchar(blr_begin); if (inputs) { @@ -2640,12 +2640,12 @@ static void define_procedure(dsql_req* request, NOD_TYPE op) { // ASF: To validate input parameters we need only to read his value. // Assigning it to null is an easy way to do this. - request->append_uchar(blr_assignment); - request->append_uchar(blr_parameter2); - request->append_uchar(variable->var_msg_number); - request->append_ushort(variable->var_msg_item); - request->append_ushort(variable->var_msg_item + 1); - request->append_uchar(blr_null); + statement->append_uchar(blr_assignment); + statement->append_uchar(blr_parameter2); + statement->append_uchar(variable->var_msg_number); + statement->append_ushort(variable->var_msg_item); + statement->append_ushort(variable->var_msg_item + 1); + statement->append_uchar(blr_null); } } } @@ -2659,40 +2659,40 @@ static void define_procedure(dsql_req* request, NOD_TYPE op) { dsql_nod* parameter = *ptr; dsql_var* variable = (dsql_var*) parameter->nod_arg[e_var_variable]; - put_local_variable(request, variable, 0, NULL); + put_local_variable(statement, variable, 0, NULL); } } // ASF: This is here to not change the old logic (proc_flag) // of previous calls to PASS1_node and PASS1_statement. - request->setPsql(true); + statement->setPsql(true); - put_local_variables(request, procedure_node->nod_arg[e_prc_dcls], locals); + put_local_variables(statement, procedure_node->nod_arg[e_prc_dcls], locals); - request->append_uchar(blr_stall); + statement->append_uchar(blr_stall); // put a label before body of procedure, // so that any EXIT statement can get out - request->append_uchar(blr_label); - request->append_uchar(0); - request->req_loop_level = 0; - request->req_cursor_number = 0; - GEN_statement(request, PASS1_statement(request, procedure_node->nod_arg[e_prc_body])); - request->req_type = REQ_DDL; - request->append_uchar(blr_end); - GEN_return(request, procedure_node->nod_arg[e_prc_outputs], true); - request->append_uchar(blr_end); - request->end_blr(); + statement->append_uchar(blr_label); + statement->append_uchar(0); + statement->req_loop_level = 0; + statement->req_cursor_number = 0; + GEN_statement(statement, PASS1_statement(statement, procedure_node->nod_arg[e_prc_body])); + statement->req_type = REQ_DDL; + statement->append_uchar(blr_end); + GEN_return(statement, procedure_node->nod_arg[e_prc_outputs], true); + statement->append_uchar(blr_end); + statement->end_blr(); - const UCHAR prc_type = (request->req_flags & REQ_selectable) ? + const UCHAR prc_type = (statement->req_flags & REQ_selectable) ? isc_dyn_prc_t_selectable : isc_dyn_prc_t_executable; - request->append_number(isc_dyn_prc_type, prc_type); + statement->append_number(isc_dyn_prc_type, prc_type); - request->append_debug_info(); - request->append_uchar(isc_dyn_end); + statement->append_debug_info(); + statement->append_uchar(isc_dyn_end); } -void DDL_gen_block(dsql_req* request, dsql_nod* node) +void DDL_gen_block(CompiledStatement* statement, dsql_nod* node) { /************************************** * @@ -2705,8 +2705,8 @@ void DDL_gen_block(dsql_req* request, dsql_nod* node) * **************************************/ SSHORT inputs = 0, outputs = 0, locals = 0; - request->req_blk_node = node; - request->begin_debug(); + statement->req_blk_node = node; + statement->begin_debug(); dsql_nod* parameters; @@ -2723,7 +2723,7 @@ void DDL_gen_block(dsql_req* request, dsql_nod* node) dsql_fld* field = (dsql_fld*) parameter->nod_arg[e_dfl_field]; // parameter = (*ptr)->nod_arg[e_prm_val_val]; USELESS - DDL_resolve_intl_type(request, field, + DDL_resolve_intl_type(statement, field, reinterpret_cast(parameter->nod_arg[e_dfl_collate])); *ptr = MAKE_variable(field, field->fld_name.c_str(), @@ -2744,7 +2744,7 @@ void DDL_gen_block(dsql_req* request, dsql_nod* node) { dsql_fld* field = (dsql_fld*) (*ptr)->nod_arg[e_dfl_field]; - DDL_resolve_intl_type(request, field, + DDL_resolve_intl_type(statement, field, reinterpret_cast((*ptr)->nod_arg[e_dfl_collate])); *ptr = MAKE_variable(field, field->fld_name.c_str(), @@ -2755,15 +2755,15 @@ void DDL_gen_block(dsql_req* request, dsql_nod* node) outputs = position; } - request->append_uchar(blr_begin); + statement->append_uchar(blr_begin); if (inputs) { - request->req_send->msg_parameters = - parameter_reverse_order(request->req_send->msg_parameters, NULL); - GEN_port(request, request->req_send); + statement->req_send->msg_parameters = + parameter_reverse_order(statement->req_send->msg_parameters, NULL); + GEN_port(statement, statement->req_send); } else - request->req_send = NULL; + statement->req_send = NULL; if (outputs) { @@ -2774,32 +2774,32 @@ void DDL_gen_block(dsql_req* request, dsql_nod* node) for (const dsql_nod* const* const end = ptr + parameters->nod_count; ptr < end; ptr++) { - dsql_par* param = MAKE_parameter(request->req_receive, + dsql_par* param = MAKE_parameter(statement->req_receive, true, true, ++position, *ptr); param->par_node = *ptr; - MAKE_desc(request, ¶m->par_desc, *ptr, NULL); + MAKE_desc(statement, ¶m->par_desc, *ptr, NULL); param->par_desc.dsc_flags |= DSC_nullable; } } // Set up parameter to handle EOF dsql_par* param = - MAKE_parameter(request->req_receive, false, false, 0, NULL); - request->req_eof = param; + MAKE_parameter(statement->req_receive, false, false, 0, NULL); + statement->req_eof = param; param->par_desc.dsc_dtype = dtype_short; param->par_desc.dsc_scale = 0; param->par_desc.dsc_length = sizeof(SSHORT); - request->req_receive->msg_parameters = - parameter_reverse_order(request->req_receive->msg_parameters, NULL); - GEN_port(request, request->req_receive); + statement->req_receive->msg_parameters = + parameter_reverse_order(statement->req_receive->msg_parameters, NULL); + GEN_port(statement, statement->req_receive); if (inputs) { - request->append_uchar(blr_receive); - request->append_uchar(0); + statement->append_uchar(blr_receive); + statement->append_uchar(0); } - request->append_uchar(blr_begin); + statement->append_uchar(blr_begin); if (outputs) { @@ -2810,30 +2810,30 @@ void DDL_gen_block(dsql_req* request, dsql_nod* node) { dsql_nod* parameter = *ptr; dsql_var* variable = (dsql_var*) parameter->nod_arg[e_var_variable]; - put_local_variable(request, variable, 0, NULL); + put_local_variable(statement, variable, 0, NULL); } } - request->setPsql(true); + statement->setPsql(true); - put_local_variables(request, node->nod_arg[e_exe_blk_dcls], locals); + put_local_variables(statement, node->nod_arg[e_exe_blk_dcls], locals); - request->append_uchar(blr_stall); + statement->append_uchar(blr_stall); // Put a label before body of procedure, so that // any exit statement can get out - request->append_uchar(blr_label); - request->append_uchar(0); - request->req_loop_level = 0; - GEN_statement(request, PASS1_statement(request, node->nod_arg[e_exe_blk_body])); + statement->append_uchar(blr_label); + statement->append_uchar(0); + statement->req_loop_level = 0; + GEN_statement(statement, PASS1_statement(statement, node->nod_arg[e_exe_blk_body])); if (outputs) - request->req_type = REQ_SELECT_BLOCK; + statement->req_type = REQ_SELECT_BLOCK; else - request->req_type = REQ_EXEC_BLOCK; - request->append_uchar(blr_end); - GEN_return(request, node->nod_arg[e_exe_blk_outputs], true); - request->append_uchar(blr_end); + statement->req_type = REQ_EXEC_BLOCK; + statement->append_uchar(blr_end); + GEN_return(statement, node->nod_arg[e_exe_blk_outputs], true); + statement->append_uchar(blr_end); - request->end_debug(); + statement->end_debug(); } @@ -2843,25 +2843,25 @@ void DDL_gen_block(dsql_req* request, dsql_nod* node) // Define a constraint, either as part of a create // table or an alter table statement. // -static void define_rel_constraint( dsql_req* request, dsql_nod* element) +static void define_rel_constraint( CompiledStatement* statement, dsql_nod* element) { const dsql_str* string = (dsql_str*) element->nod_arg[e_rct_name]; const char* constraint_name = string ? string->str_data : 0; - request->append_cstring(isc_dyn_rel_constraint, constraint_name); + statement->append_cstring(isc_dyn_rel_constraint, constraint_name); dsql_nod* node = element->nod_arg[e_rct_type]; switch (node->nod_type) { case nod_unique: case nod_primary: - make_index(request, node, node->nod_arg[e_pri_columns], 0, 0, constraint_name); + make_index(statement, node, node->nod_arg[e_pri_columns], 0, 0, constraint_name); break; case nod_foreign: - foreign_key(request, node, constraint_name); + foreign_key(statement, node, constraint_name); break; case nod_def_constraint: - check_constraint(request, node, false); // false = No delete trigger + check_constraint(statement, node, false); // false = No delete trigger break; default: // silence compiler break; @@ -2869,7 +2869,7 @@ static void define_rel_constraint( dsql_req* request, dsql_nod* element) } -static void define_relation(dsql_req* request) +static void define_relation(CompiledStatement* statement) { /************************************** * @@ -2884,33 +2884,33 @@ static void define_relation(dsql_req* request) **************************************/ thread_db* tdbb = JRD_get_thread_data(); - dsql_nod* ddl_node = request->req_ddl_node; + dsql_nod* ddl_node = statement->req_ddl_node; const dsql_nod* relation_node = ddl_node->nod_arg[e_drl_name]; const dsql_str* relation_name = (dsql_str*) relation_node->nod_arg[e_rln_name]; - request->append_cstring(isc_dyn_def_rel, relation_name->str_data); + statement->append_cstring(isc_dyn_def_rel, relation_name->str_data); const dsql_str* external_file = (dsql_str*) ddl_node->nod_arg[e_drl_ext_file]; if (external_file) { - request->append_cstring(isc_dyn_rel_ext_file, external_file->str_data); + statement->append_cstring(isc_dyn_rel_ext_file, external_file->str_data); } - save_relation(request, relation_name); + save_relation(statement, relation_name); if (external_file) { - fb_assert(request->req_relation); - request->req_relation->rel_flags |= REL_external; + fb_assert(statement->req_relation); + statement->req_relation->rel_flags |= REL_external; } - request->append_number(isc_dyn_rel_sql_protection, 1); + statement->append_number(isc_dyn_rel_sql_protection, 1); switch(ddl_node->nod_flags) { case NOD_GLOBAL_TEMP_TABLE_PRESERVE_ROWS: - request->append_number(isc_dyn_rel_temporary, + statement->append_number(isc_dyn_rel_temporary, isc_dyn_rel_temp_global_preserve); break; case NOD_GLOBAL_TEMP_TABLE_DELETE_ROWS: - request->append_number(isc_dyn_rel_temporary, + statement->append_number(isc_dyn_rel_temporary, isc_dyn_rel_temp_global_delete); break; } @@ -2928,12 +2928,12 @@ static void define_relation(dsql_req* request) dsql_nod* element = *ptr; switch (element->nod_type) { case nod_def_field: - define_field(request, element, position, relation_name, pkcols); + define_field(statement, element, position, relation_name, pkcols); ++position; break; case nod_rel_constraint: - define_rel_constraint(request, element); + define_rel_constraint(statement, element); break; default: @@ -2941,8 +2941,8 @@ static void define_relation(dsql_req* request) } } - request->req_relation->rel_flags &= ~REL_creating; - request->append_uchar(isc_dyn_end); + statement->req_relation->rel_flags &= ~REL_creating; + statement->append_uchar(isc_dyn_end); } @@ -2951,15 +2951,15 @@ static void define_relation(dsql_req* request) // ****************************** // Create a SQL role. // -static void define_role(dsql_req* request) +static void define_role(CompiledStatement* statement) { - const dsql_str* gen_name = (dsql_str*) request->req_ddl_node->nod_arg[e_gen_name]; - request->append_cstring(isc_dyn_def_sql_role, gen_name->str_data); - request->append_uchar(isc_dyn_end); + const dsql_str* gen_name = (dsql_str*) statement->req_ddl_node->nod_arg[e_gen_name]; + statement->append_cstring(isc_dyn_def_sql_role, gen_name->str_data); + statement->append_uchar(isc_dyn_end); } -static void define_set_null_trg(dsql_req* request, +static void define_set_null_trg(CompiledStatement* statement, const dsql_nod* element, const dsql_nod* for_columns, const dsql_nod* prim_columns, @@ -2989,7 +2989,7 @@ static void define_set_null_trg(dsql_req* request, fb_assert(prim_columns->nod_count == for_columns->nod_count); fb_assert(prim_columns->nod_count != 0); - request->generate_unnamed_trigger_beginning(on_upd_trg, + statement->generate_unnamed_trigger_beginning(on_upd_trg, prim_rel_name, prim_columns, for_rel_name, @@ -3001,30 +3001,30 @@ static void define_set_null_trg(dsql_req* request, do { const dsql_str* for_key_fld_name_str = (dsql_str*) (*for_key_flds)->nod_arg[1]; - request->append_uchar(blr_assignment); - request->append_uchar(blr_null); - request->append_uchar(blr_field); - request->append_uchar(2); - request->append_cstring(0, for_key_fld_name_str->str_data); + statement->append_uchar(blr_assignment); + statement->append_uchar(blr_null); + statement->append_uchar(blr_field); + statement->append_uchar(2); + statement->append_cstring(0, for_key_fld_name_str->str_data); num_fields++; for_key_flds++; } while (num_fields < for_columns->nod_count); - request->append_uchar(blr_end); + statement->append_uchar(blr_end); if (on_upd_trg) { - request->append_uchars(blr_end, 3); + statement->append_uchars(blr_end, 3); } - request->end_blr(); + statement->end_blr(); // end of the blr - request->append_number(isc_dyn_system_flag, + statement->append_number(isc_dyn_system_flag, fb_sysflag_referential_constraint); // no trg_source and no trg_description - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } @@ -3032,9 +3032,9 @@ static void define_set_null_trg(dsql_req* request, // // create a shadow for the database // -static void define_shadow(dsql_req* request) +static void define_shadow(CompiledStatement* statement) { - const dsql_nod* shadow_node = request->req_ddl_node; + const dsql_nod* shadow_node = statement->req_ddl_node; const dsql_nod* const* ptr = shadow_node->nod_arg; if (!ptr[e_shadow_number]) @@ -3044,19 +3044,19 @@ static void define_shadow(dsql_req* request) isc_arg_gds, isc_dsql_shadow_number_err, 0); } - request->append_number(isc_dyn_def_shadow, (SSHORT)(IPTR) (ptr[e_shadow_number])); - request->append_cstring(isc_dyn_def_file, ((dsql_str*) (ptr[e_shadow_name]))->str_data); - request->append_number(isc_dyn_shadow_man_auto, + statement->append_number(isc_dyn_def_shadow, (SSHORT)(IPTR) (ptr[e_shadow_number])); + statement->append_cstring(isc_dyn_def_file, ((dsql_str*) (ptr[e_shadow_name]))->str_data); + statement->append_number(isc_dyn_shadow_man_auto, (SSHORT) ptr[e_shadow_man_auto]->getSlong()); - request->append_number(isc_dyn_shadow_conditional, + statement->append_number(isc_dyn_shadow_conditional, (SSHORT) ptr[e_shadow_conditional]->getSlong()); - request->append_file_start(0); + statement->append_file_start(0); SLONG length = (IPTR) ptr[e_shadow_length]; - request->append_file_length(length); + statement->append_file_length(length); - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); const dsql_nod* elements = ptr[e_shadow_sec_files]; if (elements) { @@ -3066,7 +3066,7 @@ static void define_shadow(dsql_req* request) { const dsql_nod* element = *ptr; const dsql_fil* file = (dsql_fil*) element->nod_arg[0]; - request->append_cstring(isc_dyn_def_file, file->fil_name->str_data); + statement->append_cstring(isc_dyn_def_file, file->fil_name->str_data); if (!length && !file->fil_start) { @@ -3079,25 +3079,25 @@ static void define_shadow(dsql_req* request) } const SLONG start = file->fil_start; - request->append_file_start(start); + statement->append_file_start(start); length = file->fil_length; - request->append_file_length(length); - request->append_uchar(isc_dyn_end); + statement->append_file_length(length); + statement->append_uchar(isc_dyn_end); } } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } // // Create the ddl to define or alter a trigger. // -static void define_trigger(dsql_req* request, NOD_TYPE op) +static void define_trigger(CompiledStatement* statement, NOD_TYPE op) { thread_db* tdbb = JRD_get_thread_data(); - dsql_nod* trigger_node = request->req_ddl_node; + dsql_nod* trigger_node = statement->req_ddl_node; const dsql_str* trigger_name = (dsql_str*) trigger_node->nod_arg[e_trg_name]; USHORT trig_type; @@ -3107,16 +3107,16 @@ static void define_trigger(dsql_req* request, NOD_TYPE op) switch (op) { case nod_replace_trigger: - if (METD_get_trigger(request, trigger_name, NULL, &trig_type)) - define_trigger(request, nod_mod_trigger); + if (METD_get_trigger(statement, trigger_name, NULL, &trig_type)) + define_trigger(statement, nod_mod_trigger); else - define_trigger(request, nod_def_trigger); + define_trigger(statement, nod_def_trigger); return; case nod_def_trigger: case nod_redef_trigger: fb_assert(trigger_name->str_length <= MAX_USHORT); - request->append_string( isc_dyn_def_trigger, + statement->append_string( isc_dyn_def_trigger, trigger_name->str_data, trigger_name->str_length); relation_node = trigger_node->nod_arg[e_trg_table]; @@ -3132,7 +3132,7 @@ static void define_trigger(dsql_req* request, NOD_TYPE op) const dsql_str* relation_name = (dsql_str*) relation_node->nod_arg[e_rln_name]; fb_assert(relation_name->str_length <= MAX_USHORT); - request->append_string( isc_dyn_rel_name, + statement->append_string( isc_dyn_rel_name, relation_name->str_data, relation_name->str_length); } @@ -3146,13 +3146,13 @@ static void define_trigger(dsql_req* request, NOD_TYPE op) } } - request->append_uchar(isc_dyn_sql_object); + statement->append_uchar(isc_dyn_sql_object); break; default: // nod_mod_trigger fb_assert(op == nod_mod_trigger); fb_assert(trigger_name->str_length <= MAX_USHORT); - request->append_string( isc_dyn_mod_trigger, + statement->append_string( isc_dyn_mod_trigger, trigger_name->str_data, trigger_name->str_length); if (trigger_node->nod_arg[e_trg_actions]) @@ -3161,7 +3161,7 @@ static void define_trigger(dsql_req* request, NOD_TYPE op) to know what relation the trigger relates to. */ dsql_str* relation_name = NULL; - bool found = METD_get_trigger(request, trigger_name, &relation_name, &trig_type); + bool found = METD_get_trigger(statement, trigger_name, &relation_name, &trig_type); if (found && relation_name) { @@ -3188,7 +3188,7 @@ static void define_trigger(dsql_req* request, NOD_TYPE op) } } - request->begin_debug(); + statement->begin_debug(); const dsql_str* source = (dsql_str*) trigger_node->nod_arg[e_trg_source]; dsql_nod* actions = (trigger_node->nod_arg[e_trg_actions]) ? @@ -3200,7 +3200,7 @@ static void define_trigger(dsql_req* request, NOD_TYPE op) ULONG j = find_start_of_body(source); if (j < source->str_length) { - request->append_string( isc_dyn_trg_source, + statement->append_string( isc_dyn_trg_source, source->str_data + j, source->str_length - j); } @@ -3208,13 +3208,13 @@ static void define_trigger(dsql_req* request, NOD_TYPE op) dsql_nod* constant = trigger_node->nod_arg[e_trg_active]; if (constant) - request->append_number(isc_dyn_trg_inactive, (SSHORT) constant->getSlong()); + statement->append_number(isc_dyn_trg_inactive, (SSHORT) constant->getSlong()); if (constant = trigger_node->nod_arg[e_trg_position]) - request->append_number(isc_dyn_trg_sequence, (SSHORT) constant->getSlong()); + statement->append_number(isc_dyn_trg_sequence, (SSHORT) constant->getSlong()); if (constant = trigger_node->nod_arg[e_trg_type]) { - request->append_number(isc_dyn_trg_type, (SSHORT) constant->getSlong()); + statement->append_number(isc_dyn_trg_type, (SSHORT) constant->getSlong()); trig_type = (USHORT) constant->getSlong(); } else { @@ -3228,8 +3228,8 @@ static void define_trigger(dsql_req* request, NOD_TYPE op) fields to that context but prevent relations referenced in the trigger actions from referencing the predefined "1" context */ - if (request->req_context_number) { - reset_context_stack(request); + if (statement->req_context_number) { + reset_context_stack(statement); } if (relation_node) @@ -3239,24 +3239,24 @@ static void define_trigger(dsql_req* request, NOD_TYPE op) { relation_node->nod_arg[e_rln_alias] = (dsql_nod*) MAKE_cstring(OLD_CONTEXT); - dsql_ctx* oldContext = PASS1_make_context(request, relation_node); + dsql_ctx* oldContext = PASS1_make_context(statement, relation_node); oldContext->ctx_flags |= CTX_system; } else { - request->req_context_number++; + statement->req_context_number++; } if (hasNewContext(trig_type)) { relation_node->nod_arg[e_rln_alias] = (dsql_nod*) MAKE_cstring(NEW_CONTEXT); - dsql_ctx* newContext = PASS1_make_context(request, relation_node); + dsql_ctx* newContext = PASS1_make_context(statement, relation_node); newContext->ctx_flags |= CTX_system; } else { - request->req_context_number++; + statement->req_context_number++; } relation_node->nod_arg[e_rln_alias] = temp; @@ -3264,15 +3264,15 @@ static void define_trigger(dsql_req* request, NOD_TYPE op) // generate the trigger blr - request->begin_blr(isc_dyn_trg_blr); - request->append_uchar(blr_begin); + statement->begin_blr(isc_dyn_trg_blr); + statement->append_uchar(blr_begin); - request->setPsql(true); + statement->setPsql(true); - put_local_variables(request, + put_local_variables(statement, trigger_node->nod_arg[e_trg_actions]->nod_arg[e_trg_act_dcls], 0); - request->req_scope_level++; + statement->req_scope_level++; // dimitr: I see no reason to deny EXIT command in triggers, // hence I've added zero label at the beginning. // My first suspicion regarding an obvious conflict @@ -3280,28 +3280,28 @@ static void define_trigger(dsql_req* request, NOD_TYPE op) // although the fact that they use the same BLR code // is still a potential danger and must be fixed. // Hopefully, system triggers are never recompiled. - request->append_uchar(blr_label); - request->append_uchar(0); - request->req_loop_level = 0; - request->req_cursor_number = 0; - GEN_statement(request, PASS1_statement(request, actions)); - request->req_scope_level--; - request->append_uchar(blr_end); - request->end_blr(); + statement->append_uchar(blr_label); + statement->append_uchar(0); + statement->req_loop_level = 0; + statement->req_cursor_number = 0; + GEN_statement(statement, PASS1_statement(statement, actions)); + statement->req_scope_level--; + statement->append_uchar(blr_end); + statement->end_blr(); - /* the request type may have been set incorrectly when parsing + /* the statement type may have been set incorrectly when parsing the trigger actions, so reset it to reflect the fact that this - is a data definition request; also reset the ddl node */ + is a data definition statement; also reset the ddl node */ - request->req_type = REQ_DDL; + statement->req_type = REQ_DDL; } - request->append_debug_info(); - request->append_uchar(isc_dyn_end); + statement->append_debug_info(); + statement->append_uchar(isc_dyn_end); } -static void define_udf( dsql_req* request) +static void define_udf( CompiledStatement* statement) { /************************************** * @@ -3315,15 +3315,15 @@ static void define_udf( dsql_req* request) **************************************/ SSHORT position, blob_position = -1; - dsql_nod* udf_node = request->req_ddl_node; + dsql_nod* udf_node = statement->req_ddl_node; dsql_nod* arguments = udf_node->nod_arg[e_udf_args]; dsql_nod** ptr = udf_node->nod_arg; const char* udf_name = ((dsql_str*) (ptr[e_udf_name]))->str_data; const dsql_str* func_entry_point_name = reinterpret_cast(ptr[e_udf_entry_pt]); const dsql_str* func_module_name = reinterpret_cast(ptr[e_udf_module]); - request->append_cstring(isc_dyn_def_function, udf_name); - request->append_cstring(isc_dyn_func_entry_point, func_entry_point_name->str_data); - request->append_cstring(isc_dyn_func_module_name, func_module_name->str_data); + statement->append_cstring(isc_dyn_def_function, udf_name); + statement->append_cstring(isc_dyn_func_entry_point, func_entry_point_name->str_data); + statement->append_cstring(isc_dyn_func_module_name, func_module_name->str_data); dsql_nod** ret_val_ptr = ptr[e_udf_return_value]->nod_arg; @@ -3363,11 +3363,11 @@ static void define_udf( dsql_req* request) 0); } - request->append_number(isc_dyn_func_return_argument, blob_position); + statement->append_number(isc_dyn_func_return_argument, blob_position); } else { - request->append_number(isc_dyn_func_return_argument, (SSHORT) 0); + statement->append_number(isc_dyn_func_return_argument, (SSHORT) 0); } position = 0; @@ -3406,7 +3406,7 @@ static void define_udf( dsql_req* request) 0); } - request->append_number(isc_dyn_func_return_argument, position); + statement->append_number(isc_dyn_func_return_argument, position); position = 1; } @@ -3419,23 +3419,23 @@ static void define_udf( dsql_req* request) /* CVC: I need to test returning blobs by descriptor before allowing the change there. For now, I ignore the return type specification. */ const bool free_it = ((SSHORT) ret_val_ptr[1]->getSlong() < 0); - request->append_number(isc_dyn_def_function_arg, blob_position); - request->append_number(isc_dyn_func_mechanism, + statement->append_number(isc_dyn_def_function_arg, blob_position); + statement->append_number(isc_dyn_func_mechanism, (SSHORT)(SLONG) ((free_it ? -1 : 1) * FUN_blob_struct)); /* if we have the free_it set then the blob has to be freed on return */ } else { - request->append_number(isc_dyn_def_function_arg, (SSHORT) 0); - request->append_number(isc_dyn_func_mechanism, + statement->append_number(isc_dyn_def_function_arg, (SSHORT) 0); + statement->append_number(isc_dyn_func_mechanism, (SSHORT) ret_val_ptr[1]->getSlong()); } - request->append_cstring(isc_dyn_function_name, udf_name); - DDL_resolve_intl_type(request, field, NULL); - put_field(request, field, true); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_function_name, udf_name); + DDL_resolve_intl_type(statement, field, NULL); + put_field(statement, field, true); + statement->append_uchar(isc_dyn_end); position = 1; } @@ -3462,34 +3462,34 @@ static void define_udf( dsql_req* request) dsql_nod** param_node = (*ptr)->nod_arg; field = (dsql_fld*) param_node[e_udf_param_field]; - request->append_number(isc_dyn_def_function_arg, position); + statement->append_number(isc_dyn_def_function_arg, position); if (param_node[e_udf_param_type]) { const SSHORT arg_mechanism = (SSHORT) param_node[e_udf_param_type]->getSlong(); - request->append_number(isc_dyn_func_mechanism, arg_mechanism); + statement->append_number(isc_dyn_func_mechanism, arg_mechanism); } else if (field->fld_dtype == dtype_blob) { - request->append_number(isc_dyn_func_mechanism, + statement->append_number(isc_dyn_func_mechanism, (SSHORT) FUN_blob_struct); } else { - request->append_number(isc_dyn_func_mechanism, + statement->append_number(isc_dyn_func_mechanism, (SSHORT) FUN_reference); } - request->append_cstring(isc_dyn_function_name, udf_name); - DDL_resolve_intl_type(request, field, NULL); - put_field(request, field, true); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_function_name, udf_name); + DDL_resolve_intl_type(statement, field, NULL); + put_field(statement, field, true); + statement->append_uchar(isc_dyn_end); } } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void define_update_action(dsql_req* request, +static void define_update_action(CompiledStatement* statement, dsql_nod** base_and_node, dsql_nod** base_relation, dsql_nod* items) { /************************************** @@ -3505,7 +3505,7 @@ static void define_update_action(dsql_req* request, * base relation. * **************************************/ - dsql_nod* ddl_node = request->req_ddl_node; + dsql_nod* ddl_node = statement->req_ddl_node; // check whether this is an updatable view definition @@ -3539,7 +3539,7 @@ static void define_update_action(dsql_req* request, { const dsql_str* rel_name = reinterpret_cast(relation_node->nod_arg[e_rln_name]); - const dsql_rel* relation = METD_get_relation(request, rel_name); + const dsql_rel* relation = METD_get_relation(statement, rel_name); DsqlNodStack field_stack; for (const dsql_fld* field = relation->rel_fields; field; field = field->fld_next) @@ -3629,7 +3629,7 @@ static void define_update_action(dsql_req* request, } -static void define_upd_cascade_trg( dsql_req* request, +static void define_upd_cascade_trg( CompiledStatement* statement, const dsql_nod* element, const dsql_nod* for_columns, const dsql_nod* prim_columns, @@ -3656,7 +3656,7 @@ static void define_upd_cascade_trg( dsql_req* request, fb_assert(prim_columns->nod_count == for_columns->nod_count); fb_assert(prim_columns->nod_count != 0); - request->generate_unnamed_trigger_beginning(true, + statement->generate_unnamed_trigger_beginning(true, prim_rel_name, prim_columns, for_rel_name, @@ -3670,13 +3670,13 @@ static void define_upd_cascade_trg( dsql_req* request, const dsql_str* for_key_fld_name_str = (dsql_str*) (*for_key_flds)->nod_arg[1]; const dsql_str* prim_key_fld_name_str = (dsql_str*) (*prim_key_flds)->nod_arg[1]; - request->append_uchar(blr_assignment); - request->append_uchar(blr_field); - request->append_uchar(1); - request->append_cstring(0, prim_key_fld_name_str->str_data); - request->append_uchar(blr_field); - request->append_uchar(2); - request->append_cstring(0, for_key_fld_name_str->str_data); + statement->append_uchar(blr_assignment); + statement->append_uchar(blr_field); + statement->append_uchar(1); + statement->append_cstring(0, prim_key_fld_name_str->str_data); + statement->append_uchar(blr_field); + statement->append_uchar(2); + statement->append_cstring(0, for_key_fld_name_str->str_data); num_fields++; prim_key_flds++; @@ -3684,20 +3684,20 @@ static void define_upd_cascade_trg( dsql_req* request, } while (num_fields < for_columns->nod_count); - request->append_uchars(blr_end, 4); - request->end_blr(); + statement->append_uchars(blr_end, 4); + statement->end_blr(); // end of the blr - request->append_number(isc_dyn_system_flag, + statement->append_number(isc_dyn_system_flag, fb_sysflag_referential_constraint); // no trg_source and no trg_description - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void define_view( dsql_req* request, NOD_TYPE op) +static void define_view( CompiledStatement* statement, NOD_TYPE op) { /************************************** * @@ -3712,30 +3712,30 @@ static void define_view( dsql_req* request, NOD_TYPE op) **************************************/ thread_db* tdbb = JRD_get_thread_data(); - dsql_nod* node = request->req_ddl_node; + dsql_nod* node = statement->req_ddl_node; const dsql_str* view_name = (dsql_str*) node->nod_arg[e_view_name]; const dsql_rel* view_relation = NULL; switch (op) { case nod_replace_view: - if (METD_get_relation(request, view_name)) - define_view(request, nod_mod_view); + if (METD_get_relation(statement, view_name)) + define_view(statement, nod_mod_view); else - define_view(request, nod_def_view); + define_view(statement, nod_def_view); return; case nod_def_view: case nod_redef_view: - request->append_cstring(isc_dyn_def_view, + statement->append_cstring(isc_dyn_def_view, view_name->str_data); - request->append_number(isc_dyn_rel_sql_protection, 1); - save_relation(request, view_name); + statement->append_number(isc_dyn_rel_sql_protection, 1); + save_relation(statement, view_name); break; default: // op == nod_mod_view - request->append_cstring(isc_dyn_mod_view, view_name->str_data); - view_relation = METD_get_relation(request, view_name); + statement->append_cstring(isc_dyn_mod_view, view_name->str_data); + view_relation = METD_get_relation(statement, view_name); if (!view_relation) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) -607, @@ -3751,17 +3751,17 @@ static void define_view( dsql_req* request, NOD_TYPE op) // at 1 (except for computed fields) -- note that calling PASS1_rse // directly rather than PASS1_statement saves the context stack - if (request->req_context_number) - reset_context_stack(request); - request->req_context_number++; + if (statement->req_context_number) + reset_context_stack(statement); + statement->req_context_number++; dsql_nod* select_expr = node->nod_arg[e_view_select]; - dsql_nod* rse = PASS1_rse(request, select_expr, NULL); + dsql_nod* rse = PASS1_rse(statement, select_expr, NULL); // store the blr and source string for the view definition - request->begin_blr(isc_dyn_view_blr); - GEN_expr(request, rse); - request->end_blr(); + statement->begin_blr(isc_dyn_view_blr); + GEN_expr(statement, rse); + statement->end_blr(); // Store source for view. gdef -e cannot cope with it. // We need to add something to rdb$views to indicate source type. @@ -3769,23 +3769,23 @@ static void define_view( dsql_req* request, NOD_TYPE op) const dsql_str* source = (dsql_str*) node->nod_arg[e_view_source]; fb_assert(source->str_length <= MAX_USHORT); - request->append_string( isc_dyn_view_source, + statement->append_string( isc_dyn_view_source, source->str_data, source->str_length); - // define the view source relations from the request contexts & union contexts + // define the view source relations from the statement contexts & union contexts - while (request->req_dt_context.hasData()) + while (statement->req_dt_context.hasData()) { - request->req_context->push(request->req_dt_context.pop()); + statement->req_context->push(statement->req_dt_context.pop()); } - while (request->req_union_context.hasData()) + while (statement->req_union_context.hasData()) { - request->req_context->push(request->req_union_context.pop()); + statement->req_context->push(statement->req_union_context.pop()); } - for (DsqlContextStack::iterator temp(*request->req_context); temp.hasData(); ++temp) + for (DsqlContextStack::iterator temp(*statement->req_context); temp.hasData(); ++temp) { const dsql_ctx* context = temp.object(); const dsql_rel* relation = context->ctx_relation; @@ -3803,13 +3803,13 @@ static void define_view( dsql_req* request, NOD_TYPE op) */ const Firebird::MetaName& name = relation ? relation->rel_name : procedure->prc_name; - request->append_string(isc_dyn_view_relation, name); - request->append_number(isc_dyn_view_context, context->ctx_context); + statement->append_string(isc_dyn_view_relation, name); + statement->append_number(isc_dyn_view_context, context->ctx_context); const char* str = context->ctx_alias ? context->ctx_alias : name.c_str(); const USHORT len = context->ctx_alias ? strlen(str) : name.length(); - request->append_string(isc_dyn_view_context_name, str, len); - request->append_uchar(isc_dyn_end); + statement->append_string(isc_dyn_view_context_name, str, len); + statement->append_uchar(isc_dyn_end); } } @@ -3925,43 +3925,43 @@ static void define_view( dsql_req* request, NOD_TYPE op) { if (rel_field) // modifying a view { - request->append_cstring(isc_dyn_mod_sql_fld, field_string); - request->append_uchar(isc_dyn_del_computed); + statement->append_cstring(isc_dyn_mod_sql_fld, field_string); + statement->append_uchar(isc_dyn_del_computed); } else - request->append_cstring(isc_dyn_def_local_fld, field_string); + statement->append_cstring(isc_dyn_def_local_fld, field_string); - request->append_string(isc_dyn_fld_base_fld, field->fld_name); + statement->append_string(isc_dyn_fld_base_fld, field->fld_name); if (field->fld_dtype <= dtype_any_text) { - request->append_number(isc_dyn_fld_collation, field->fld_collation_id); + statement->append_number(isc_dyn_fld_collation, field->fld_collation_id); } - request->append_number(isc_dyn_view_context, context->ctx_context); + statement->append_number(isc_dyn_view_context, context->ctx_context); } else { if (rel_field) // modifying a view { - request->append_cstring(isc_dyn_mod_sql_fld, field_string); - request->append_cstring(isc_dyn_fld_base_fld, ""); + statement->append_cstring(isc_dyn_mod_sql_fld, field_string); + statement->append_cstring(isc_dyn_fld_base_fld, ""); } else - request->append_cstring(isc_dyn_def_sql_fld, field_string); + statement->append_cstring(isc_dyn_def_sql_fld, field_string); - MAKE_desc(request, &field_node->nod_desc, field_node, NULL); - put_descriptor(request, &field_node->nod_desc); + MAKE_desc(statement, &field_node->nod_desc, field_node, NULL); + put_descriptor(statement, &field_node->nod_desc); - request->begin_blr(isc_dyn_fld_computed_blr); - GEN_expr(request, field_node); - request->end_blr(); + statement->begin_blr(isc_dyn_fld_computed_blr); + GEN_expr(statement, field_node); + statement->end_blr(); - request->append_number(isc_dyn_view_context, (SSHORT) 0); + statement->append_number(isc_dyn_view_context, (SSHORT) 0); } if (field_string) - save_field(request, field_string); + save_field(statement, field_string); - request->append_number(isc_dyn_fld_position, position); - request->append_uchar(isc_dyn_end); + statement->append_number(isc_dyn_fld_position, position); + statement->append_uchar(isc_dyn_end); } // CVC: This message was not catching the case when @@ -3983,8 +3983,8 @@ static void define_view( dsql_req* request, NOD_TYPE op) { if (!modified_fields.exist(rel_field)) { - request->append_string(isc_dyn_delete_local_fld, rel_field->fld_name); - request->append_uchar(isc_dyn_end); + statement->append_string(isc_dyn_delete_local_fld, rel_field->fld_name); + statement->append_uchar(isc_dyn_end); } } } @@ -4059,15 +4059,15 @@ static void define_view( dsql_req* request, NOD_TYPE op) // Define the triggers - create_view_triggers(request, check, rse->nod_arg[e_rse_items]); + create_view_triggers(statement, check, rse->nod_arg[e_rse_items]); } - request->append_uchar(isc_dyn_end); - reset_context_stack(request); + statement->append_uchar(isc_dyn_end); + reset_context_stack(statement); } -static void define_view_trigger(dsql_req* request, dsql_nod* node, dsql_nod* rse, +static void define_view_trigger(CompiledStatement* statement, dsql_nod* node, dsql_nod* rse, dsql_nod* items) { // The fields in VIEW actually /************************************** @@ -4082,26 +4082,26 @@ static void define_view_trigger(dsql_req* request, dsql_nod* node, dsql_nod* rse **************************************/ thread_db* tdbb = JRD_get_thread_data(); - dsql_nod* ddl_node = request->req_ddl_node; + dsql_nod* ddl_node = statement->req_ddl_node; dsql_nod* select_expr = ddl_node->nod_arg[e_view_select]; select_expr = select_expr->nod_arg[e_sel_query_spec]; dsql_nod* view_fields = ddl_node->nod_arg[e_view_fields]; -/* make the "define trigger" node the current request ddl node so +/* make the "define trigger" node the current statement ddl node so that generating of BLR will be appropriate for trigger */ - request->req_ddl_node = node; + statement->req_ddl_node = node; dsql_nod* relation_node = NULL; if (node->nod_type == nod_def_constraint) { - request->append_string(isc_dyn_def_trigger, "", 0); + statement->append_string(isc_dyn_def_trigger, "", 0); relation_node = node->nod_arg[e_cnstr_table]; const dsql_str* relation_name = (dsql_str*) relation_node->nod_arg[e_rln_name]; fb_assert(relation_name->str_length <= MAX_USHORT); - request->append_string( isc_dyn_rel_name, + statement->append_string( isc_dyn_rel_name, relation_name->str_data, relation_name->str_length); } @@ -4110,14 +4110,14 @@ static void define_view_trigger(dsql_req* request, dsql_nod* node, dsql_nod* rse return; } - request->append_number(isc_dyn_trg_sequence, 0); + statement->append_number(isc_dyn_trg_sequence, 0); const dsql_nod* constant = node->nod_arg[e_cnstr_type]; USHORT trig_type; if (constant) { trig_type = (USHORT) constant->getSlong(); - request->append_number(isc_dyn_trg_type, trig_type); + statement->append_number(isc_dyn_trg_type, trig_type); } else { @@ -4127,14 +4127,14 @@ static void define_view_trigger(dsql_req* request, dsql_nod* node, dsql_nod* rse trig_type = 0; } - request->append_uchar(isc_dyn_sql_object); + statement->append_uchar(isc_dyn_sql_object); // generate the trigger blr if (node->nod_arg[e_cnstr_condition] && node->nod_arg[e_cnstr_actions]) { - request->begin_blr(isc_dyn_trg_blr); - request->append_uchar(blr_begin); + statement->begin_blr(isc_dyn_trg_blr); + statement->append_uchar(blr_begin); /* create the "OLD" and "NEW" contexts for the trigger -- the new one could be a dummy place holder to avoid resolving @@ -4143,31 +4143,31 @@ static void define_view_trigger(dsql_req* request, dsql_nod* node, dsql_nod* rse dsql_ctx* sav_context = 0; dsql_ctx* context = 0; - if (request->req_context_number) { + if (statement->req_context_number) { /* If an alias is specified for the single base table involved, save and then add the context */ - context = request->req_context->object(); + context = statement->req_context->object(); if (context->ctx_alias) { MemoryPool& pool = *tdbb->getDefaultPool(); sav_context = FB_NEW(pool) dsql_ctx(pool); *sav_context = *context; } } - reset_context_stack(request); + reset_context_stack(statement); dsql_nod* temp_alias = relation_node->nod_arg[e_rln_alias]; relation_node->nod_arg[e_rln_alias] = (dsql_nod*) MAKE_cstring(OLD_CONTEXT); - dsql_ctx* oldContext = PASS1_make_context(request, relation_node); + dsql_ctx* oldContext = PASS1_make_context(statement, relation_node); oldContext->ctx_flags |= CTX_system; relation_node->nod_arg[e_rln_alias] = (dsql_nod*) MAKE_cstring(NEW_CONTEXT); - dsql_ctx* newContext = PASS1_make_context(request, relation_node); + dsql_ctx* newContext = PASS1_make_context(statement, relation_node); newContext->ctx_flags |= CTX_system; relation_node->nod_arg[e_rln_alias] = temp_alias; if (sav_context) { - sav_context->ctx_context = request->req_context_number++; - context->ctx_scope_level = request->req_scope_level; - request->req_context->push(sav_context); + sav_context->ctx_context = statement->req_context_number++; + context->ctx_scope_level = statement->req_scope_level; + statement->req_context->push(sav_context); } // generate the condition for firing the trigger @@ -4175,12 +4175,12 @@ static void define_view_trigger(dsql_req* request, dsql_nod* node, dsql_nod* rse dsql_nod* condition; if (trig_type == PRE_MODIFY_TRIGGER) { - request->append_uchar(blr_for); + statement->append_uchar(blr_for); dsql_nod* temp = rse->nod_arg[e_rse_streams]; - temp->nod_arg[0] = PASS1_node(request, temp->nod_arg[0]); + temp->nod_arg[0] = PASS1_node(statement, temp->nod_arg[0]); temp = rse->nod_arg[e_rse_boolean]; - rse->nod_arg[e_rse_boolean] = PASS1_node(request, temp); - GEN_expr(request, rse); + rse->nod_arg[e_rse_boolean] = PASS1_node(statement, temp); + GEN_expr(statement, rse); condition = replace_field_names(select_expr->nod_arg[e_qry_where], items, view_fields, false, NEW_CONTEXT); @@ -4194,10 +4194,10 @@ static void define_view_trigger(dsql_req* request, dsql_nod* node, dsql_nod* rse fb_assert(false); } - request->append_uchar(blr_if); - GEN_expr(request, PASS1_node(request, condition)); - request->append_uchar(blr_begin); - request->append_uchar(blr_end); + statement->append_uchar(blr_if); + GEN_expr(statement, PASS1_node(statement, condition)); + statement->append_uchar(blr_begin); + statement->append_uchar(blr_end); // generate the action statements for the trigger @@ -4206,27 +4206,27 @@ static void define_view_trigger(dsql_req* request, dsql_nod* node, dsql_nod* rse for (const dsql_nod* const* const end = ptr + actions->nod_count; ptr < end; ptr++) { - GEN_statement(request, PASS1_statement(request, *ptr)); + GEN_statement(statement, PASS1_statement(statement, *ptr)); } - request->append_uchar(blr_end); // of begin + statement->append_uchar(blr_end); // of begin - request->end_blr(); + statement->end_blr(); } - request->append_number(isc_dyn_system_flag, fb_sysflag_view_check); - request->append_uchar(isc_dyn_end); + statement->append_number(isc_dyn_system_flag, fb_sysflag_view_check); + statement->append_uchar(isc_dyn_end); -/* the request type may have been set incorrectly when parsing +/* the statement type may have been set incorrectly when parsing the trigger actions, so reset it to reflect the fact that this - is a data definition request; also reset the ddl node */ + is a data definition statement; also reset the ddl node */ - request->req_type = REQ_DDL; - request->req_ddl_node = ddl_node; - reset_context_stack(request); + statement->req_type = REQ_DDL; + statement->req_ddl_node = ddl_node; + reset_context_stack(statement); } -static void delete_collation(dsql_req* request) +static void delete_collation(CompiledStatement* statement) { /************************************** * @@ -4239,13 +4239,13 @@ static void delete_collation(dsql_req* request) * **************************************/ - const dsql_str* coll_name = (dsql_str*) request->req_ddl_node->nod_arg[e_del_coll_name]; - request->append_cstring(isc_dyn_del_collation, coll_name->str_data); - request->append_uchar(isc_dyn_end); + const dsql_str* coll_name = (dsql_str*) statement->req_ddl_node->nod_arg[e_del_coll_name]; + statement->append_cstring(isc_dyn_del_collation, coll_name->str_data); + statement->append_uchar(isc_dyn_end); } -static void delete_exception (dsql_req* request, +static void delete_exception (CompiledStatement* statement, dsql_nod* node, bool silent_deletion) { @@ -4263,16 +4263,16 @@ static void delete_exception (dsql_req* request, const dsql_str* string = (dsql_str*) node->nod_arg[0]; fb_assert(string); if (node->nod_type == nod_redef_exception || silent_deletion) { - if (!METD_get_exception(request, string)) { + if (!METD_get_exception(statement, string)) { return; } } - request->append_cstring(isc_dyn_del_exception, string->str_data); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_del_exception, string->str_data); + statement->append_uchar(isc_dyn_end); } -static void delete_procedure (dsql_req* request, +static void delete_procedure (CompiledStatement* statement, dsql_nod* node, bool silent_deletion) { @@ -4291,18 +4291,18 @@ static void delete_procedure (dsql_req* request, const dsql_str* string = (dsql_str*) node->nod_arg[e_prc_name]; fb_assert (string); if (node->nod_type == nod_redef_procedure || silent_deletion) { - dsql_prc* procedure = METD_get_procedure (request, string); + dsql_prc* procedure = METD_get_procedure (statement, string); if (!procedure) { return; } } - request->append_cstring(isc_dyn_delete_procedure, string->str_data); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_delete_procedure, string->str_data); + statement->append_uchar(isc_dyn_end); } static void delete_relation_view ( - dsql_req* request, + CompiledStatement* statement, dsql_nod* node, bool silent_deletion) { @@ -4333,7 +4333,7 @@ static void delete_relation_view ( fb_assert (string); - const dsql_rel* relation = METD_get_relation (request, string); + const dsql_rel* relation = METD_get_relation (statement, string); if (node->nod_type == nod_del_relation || node->nod_type == nod_redef_relation) @@ -4360,13 +4360,13 @@ static void delete_relation_view ( } } if (relation) { - request->append_cstring(isc_dyn_delete_rel, string->str_data); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_delete_rel, string->str_data); + statement->append_uchar(isc_dyn_end); } } -static void delete_trigger(dsql_req* request, +static void delete_trigger(CompiledStatement* statement, dsql_nod* node, bool silent_deletion) { @@ -4385,11 +4385,11 @@ static void delete_trigger(dsql_req* request, fb_assert(string); if (silent_deletion) { USHORT trig_type; - if (!METD_get_trigger(request, string, NULL, &trig_type)) + if (!METD_get_trigger(statement, string, NULL, &trig_type)) return; } - request->append_cstring(isc_dyn_delete_trigger, string->str_data); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_delete_trigger, string->str_data); + statement->append_uchar(isc_dyn_end); } @@ -4485,7 +4485,7 @@ static void fix_default_source(dsql_str* string) } -static void foreign_key( dsql_req* request, dsql_nod* element, const char* index_name) +static void foreign_key( CompiledStatement* statement, dsql_nod* element, const char* index_name) { /************************************** * @@ -4509,7 +4509,7 @@ static void foreign_key( dsql_req* request, dsql_nod* element, const char* index if (!columns2) { element->nod_arg[e_for_refcolumns] = - columns2 = METD_get_primary_key(request, relation2); + columns2 = METD_get_primary_key(statement, relation2); /* If there is NEITHER an explicitly referenced field name, NOR does the referenced table have a primary key to serve as the implicitly @@ -4537,14 +4537,14 @@ static void foreign_key( dsql_req* request, dsql_nod* element, const char* index /* define the foreign key index and the triggers that may be needed for referential integrity action. */ - make_index_trg_ref_int(request, element, columns1, + make_index_trg_ref_int(statement, element, columns1, element->nod_arg[e_for_refcolumns], relation2->str_data, index_name); } -static void generate_dyn(dsql_req* request, dsql_nod* node) +static void generate_dyn(CompiledStatement* statement, dsql_nod* node) { /************************************** * @@ -4559,223 +4559,223 @@ static void generate_dyn(dsql_req* request, dsql_nod* node) **************************************/ const dsql_str* string; - request->req_ddl_node = node; + statement->req_ddl_node = node; switch (node->nod_type) { case nod_def_domain: - define_domain(request); + define_domain(statement); break; case nod_mod_domain: - modify_domain(request); + modify_domain(statement); break; case nod_def_index: - define_index(request); + define_index(statement); break; case nod_def_relation: - define_relation(request); + define_relation(statement); break; case nod_redef_relation: - stuff(request, isc_dyn_begin); - delete_relation_view(request, node, true); // silent. - define_relation (request); - stuff(request, isc_dyn_end); + stuff(statement, isc_dyn_begin); + delete_relation_view(statement, node, true); // silent. + define_relation (statement); + stuff(statement, isc_dyn_end); break; case nod_mod_relation: - modify_relation(request); + modify_relation(statement); break; case nod_def_view: case nod_mod_view: case nod_replace_view: - define_view(request, node->nod_type); + define_view(statement, node->nod_type); break; case nod_redef_view: - stuff(request, isc_dyn_begin); - delete_relation_view(request, node, true); // silent. - define_view(request, node->nod_type); - stuff(request, isc_dyn_end); + stuff(statement, isc_dyn_begin); + delete_relation_view(statement, node, true); // silent. + define_view(statement, node->nod_type); + stuff(statement, isc_dyn_end); break; case nod_def_exception: case nod_mod_exception: case nod_replace_exception: - define_exception(request, node->nod_type); + define_exception(statement, node->nod_type); break; case nod_redef_exception: - stuff(request, isc_dyn_begin); - delete_exception(request, node, true); // silent - define_exception(request, node->nod_type); - stuff(request, isc_dyn_end); + stuff(statement, isc_dyn_begin); + delete_exception(statement, node, true); // silent + define_exception(statement, node->nod_type); + stuff(statement, isc_dyn_end); break; case nod_del_exception: - delete_exception(request, node, false); // no silent + delete_exception(statement, node, false); // no silent break; case nod_def_procedure: case nod_mod_procedure: case nod_replace_procedure: - define_procedure(request, node->nod_type); + define_procedure(statement, node->nod_type); break; case nod_redef_procedure: - stuff(request, isc_dyn_begin); - delete_procedure(request, node, true); // silent. - define_procedure(request, node->nod_type); - stuff(request, isc_dyn_end); + stuff(statement, isc_dyn_begin); + delete_procedure(statement, node, true); // silent. + define_procedure(statement, node->nod_type); + stuff(statement, isc_dyn_end); break; case nod_def_constraint: - define_constraint_trigger(request, node); + define_constraint_trigger(statement, node); break; case nod_def_trigger: case nod_mod_trigger: case nod_replace_trigger: - define_trigger(request, node->nod_type); + define_trigger(statement, node->nod_type); break; case nod_redef_trigger: - stuff(request, isc_dyn_begin); - delete_trigger(request, node, true); // silent - define_trigger(request, node->nod_type); - stuff(request, isc_dyn_end); + stuff(statement, isc_dyn_begin); + delete_trigger(statement, node, true); // silent + define_trigger(statement, node->nod_type); + stuff(statement, isc_dyn_end); break; case nod_del_domain: string = (dsql_str*) node->nod_arg[0]; - request->append_cstring(isc_dyn_delete_global_fld, string->str_data); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_delete_global_fld, string->str_data); + statement->append_uchar(isc_dyn_end); break; case nod_del_index: string = (dsql_str*) node->nod_arg[0]; - request->append_cstring(isc_dyn_delete_idx, string->str_data); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_delete_idx, string->str_data); + statement->append_uchar(isc_dyn_end); break; // CVC: Handling drop table and drop view properly. case nod_del_relation: case nod_del_view: - delete_relation_view (request, node, false); // no silent. + delete_relation_view (statement, node, false); // no silent. break; case nod_del_procedure: - delete_procedure(request, node, false); // no silent. + delete_procedure(statement, node, false); // no silent. break; case nod_del_trigger: - delete_trigger(request, node, false); // no silent + delete_trigger(statement, node, false); // no silent break; case nod_del_role: string = (dsql_str*) node->nod_arg[0]; - request->append_cstring(isc_dyn_del_sql_role, string->str_data); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_del_sql_role, string->str_data); + statement->append_uchar(isc_dyn_end); break; case nod_grant: case nod_revoke: - grant_revoke(request); + grant_revoke(statement); break; case nod_def_generator: - define_generator(request); + define_generator(statement); break; case nod_def_role: - define_role(request); + define_role(statement); break; case nod_def_filter: - define_filter(request); + define_filter(statement); break; case nod_del_generator: string = (dsql_str*) node->nod_arg[0]; - request->append_cstring(isc_dyn_delete_generator, string->str_data); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_delete_generator, string->str_data); + statement->append_uchar(isc_dyn_end); break; case nod_del_filter: string = (dsql_str*) node->nod_arg[0]; - request->append_cstring(isc_dyn_delete_filter, string->str_data); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_delete_filter, string->str_data); + statement->append_uchar(isc_dyn_end); break; case nod_def_udf: - define_udf(request); + define_udf(statement); break; case nod_del_udf: string = (dsql_str*) node->nod_arg[0]; - request->append_cstring(isc_dyn_delete_function, string->str_data); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_delete_function, string->str_data); + statement->append_uchar(isc_dyn_end); break; case nod_def_shadow: - define_shadow(request); + define_shadow(statement); break; case nod_del_shadow: - request->append_number(isc_dyn_delete_shadow, + statement->append_number(isc_dyn_delete_shadow, (SSHORT) (IPTR) node->nod_arg[0]); - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); break; case nod_mod_database: - modify_database(request); + modify_database(statement); break; case nod_def_database: - define_database(request); + define_database(statement); break; case nod_mod_index: - modify_index(request); + modify_index(statement); break; case nod_set_statistics: - set_statistics(request); + set_statistics(statement); break; case nod_comment: - make_comment(request); + make_comment(statement); break; case nod_mod_udf: - modify_udf(request); + modify_udf(statement); break; case nod_mod_role: - modify_map(request); + modify_map(statement); break; case nod_def_collation: - define_collation(request); + define_collation(statement); break; case nod_del_collation: - delete_collation(request); + delete_collation(statement); break; case nod_add_user: - define_user(request, isc_dyn_user_add); + define_user(statement, isc_dyn_user_add); break; case nod_mod_user: - define_user(request, isc_dyn_user_mod); + define_user(statement, isc_dyn_user_mod); break; case nod_del_user: - define_user(request, isc_dyn_user_del); + define_user(statement, isc_dyn_user_del); break; default: // CVC: Shouldn't we complain here? @@ -4784,7 +4784,7 @@ static void generate_dyn(dsql_req* request, dsql_nod* node) } -static void grant_revoke( dsql_req* request) +static void grant_revoke( CompiledStatement* statement) { /************************************** * @@ -4801,7 +4801,7 @@ static void grant_revoke( dsql_req* request) dsql_nod** uend; SSHORT option = 0; // no grant/admin option - dsql_nod* ddl_node = request->req_ddl_node; + dsql_nod* ddl_node = statement->req_ddl_node; dsql_nod* privs = ddl_node->nod_arg[e_grant_privs]; bool process_grant_role = false; @@ -4811,7 +4811,7 @@ static void grant_revoke( dsql_req* request) } } - request->append_uchar(isc_dyn_begin); + statement->append_uchar(isc_dyn_begin); if (!process_grant_role) { @@ -4824,7 +4824,7 @@ static void grant_revoke( dsql_req* request) uend = users->nod_arg + users->nod_count; for (uptr = users->nod_arg; uptr < uend; ++uptr) { - modify_privileges(request, ddl_node->nod_type, option, + modify_privileges(statement, ddl_node->nod_type, option, privs, table, *uptr); } } @@ -4842,13 +4842,13 @@ static void grant_revoke( dsql_req* request) uend = users->nod_arg + users->nod_count; for (uptr = users->nod_arg; uptr < uend; ++uptr) { - process_role_nm_list(request, option, *uptr, *role_ptr, + process_role_nm_list(statement, option, *uptr, *role_ptr, ddl_node->nod_type); } } } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } @@ -4860,9 +4860,9 @@ static void grant_revoke( dsql_req* request) // select rdb$relation_name from rdb$relation_fields where rdb$field_name = 'RDB$DESCRIPTION'; // gives the list of objects that accept descriptions. At FB2 time, the only // subobjects with descriptions are relation's fields and procedure's parameters. -static void make_comment(dsql_req* request) +static void make_comment(CompiledStatement* statement) { - const dsql_nod* node = request->req_ddl_node; + const dsql_nod* node = statement->req_ddl_node; fb_assert(node->nod_type == nod_comment); const bool have_subobj = node->nod_arg[e_comment_part] != 0; @@ -4944,27 +4944,27 @@ static void make_comment(dsql_req* request) break; } - request->append_string(dyn_verb2, field_or_param->str_data, field_or_param->str_length); + statement->append_string(dyn_verb2, field_or_param->str_data, field_or_param->str_length); } if (obj_type == ddl_database) - request->append_uchar(dyn_verb); + statement->append_uchar(dyn_verb); else { const dsql_str* obj_name = (dsql_str*) node->nod_arg[e_comment_object]; - request->append_cstring(dyn_verb, obj_name->str_data); + statement->append_cstring(dyn_verb, obj_name->str_data); } const dsql_str* obj_desc = (dsql_str*) node->nod_arg[e_comment_string]; if (obj_desc) - request->append_string(isc_dyn_description, obj_desc->str_data, obj_desc->str_length); + statement->append_string(isc_dyn_description, obj_desc->str_data, obj_desc->str_length); else - request->append_string(isc_dyn_description, NULL, 0); + statement->append_string(isc_dyn_description, NULL, 0); - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void make_index( dsql_req* request, +static void make_index( CompiledStatement* statement, const dsql_nod* element, const dsql_nod* columns, const dsql_nod* referenced_columns, // unused @@ -5002,18 +5002,18 @@ static void make_index( dsql_req* request, if (element->nod_type == nod_primary) { - request->append_cstring(isc_dyn_def_primary_key, index_name); + statement->append_cstring(isc_dyn_def_primary_key, index_name); } else if (element->nod_type == nod_unique) { - request->append_cstring(isc_dyn_def_unique, index_name); + statement->append_cstring(isc_dyn_def_unique, index_name); } - request->append_number(isc_dyn_idx_unique, 1); + statement->append_number(isc_dyn_idx_unique, 1); if (index->nod_arg[e_idx_asc_dsc]) { - request->append_number(isc_dyn_idx_type, 1); + statement->append_number(isc_dyn_idx_type, 1); } const dsql_nod* const* ptr = columns->nod_arg; @@ -5021,14 +5021,14 @@ static void make_index( dsql_req* request, ptr < end; ++ptr) { const dsql_str* field_name = (dsql_str*) (*ptr)->nod_arg[e_fln_name]; - request->append_cstring(isc_dyn_fld_name, field_name->str_data); + statement->append_cstring(isc_dyn_fld_name, field_name->str_data); } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void make_index_trg_ref_int( dsql_req* request, +static void make_index_trg_ref_int( CompiledStatement* statement, dsql_nod* element, dsql_nod* columns, dsql_nod* referenced_columns, @@ -5059,7 +5059,7 @@ static void make_index_trg_ref_int( dsql_req* request, on which the ddl operation is being done, in this case the foreign key table */ - dsql_nod* ddl_node = request->req_ddl_node; + dsql_nod* ddl_node = statement->req_ddl_node; dsql_nod* for_rel_node = ddl_node->nod_arg[e_drl_name]; const dsql_str* for_rel_name_str = (dsql_str*) for_rel_node->nod_arg[e_rln_name]; @@ -5076,11 +5076,11 @@ static void make_index_trg_ref_int( dsql_req* request, index_name = string->str_data; } - request->append_cstring(isc_dyn_def_foreign_key, index_name); + statement->append_cstring(isc_dyn_def_foreign_key, index_name); if (index->nod_arg[e_idx_asc_dsc]) { - request->append_number(isc_dyn_idx_type, 1); + statement->append_number(isc_dyn_idx_type, 1); } if (element->nod_arg[e_for_action]) @@ -5093,35 +5093,35 @@ static void make_index_trg_ref_int( dsql_req* request, { fb_assert(nod_ref_upd_action->nod_type == nod_ref_trig_action); - request->append_uchar(isc_dyn_foreign_key_update); + statement->append_uchar(isc_dyn_foreign_key_update); switch (nod_ref_upd_action->nod_flags) { case REF_ACTION_CASCADE: - request->append_uchar(isc_dyn_foreign_key_cascade); - define_upd_cascade_trg(request, element, columns, + statement->append_uchar(isc_dyn_foreign_key_cascade); + define_upd_cascade_trg(statement, element, columns, referenced_columns, relation_name, for_rel_name_str->str_data); break; case REF_ACTION_SET_DEFAULT: - request->append_uchar(isc_dyn_foreign_key_default); - define_set_default_trg(request, element, columns, + statement->append_uchar(isc_dyn_foreign_key_default); + define_set_default_trg(statement, element, columns, referenced_columns, relation_name, for_rel_name_str->str_data, true); break; case REF_ACTION_SET_NULL: - request->append_uchar(isc_dyn_foreign_key_null); - define_set_null_trg(request, element, columns, + statement->append_uchar(isc_dyn_foreign_key_null); + define_set_null_trg(statement, element, columns, referenced_columns, relation_name, for_rel_name_str->str_data, true); break; case REF_ACTION_NONE: - request->append_uchar(isc_dyn_foreign_key_none); + statement->append_uchar(isc_dyn_foreign_key_none); break; default: fb_assert(0); - request->append_uchar(isc_dyn_foreign_key_none); // just in case + statement->append_uchar(isc_dyn_foreign_key_none); // just in case break; } } @@ -5131,35 +5131,35 @@ static void make_index_trg_ref_int( dsql_req* request, { fb_assert(nod_ref_del_action->nod_type == nod_ref_trig_action); - request->append_uchar(isc_dyn_foreign_key_delete); + statement->append_uchar(isc_dyn_foreign_key_delete); switch (nod_ref_del_action->nod_flags) { case REF_ACTION_CASCADE: - request->append_uchar(isc_dyn_foreign_key_cascade); - define_del_cascade_trg(request, element, columns, + statement->append_uchar(isc_dyn_foreign_key_cascade); + define_del_cascade_trg(statement, element, columns, referenced_columns, relation_name, for_rel_name_str->str_data); break; case REF_ACTION_SET_DEFAULT: - request->append_uchar(isc_dyn_foreign_key_default); - define_set_default_trg(request, element, columns, + statement->append_uchar(isc_dyn_foreign_key_default); + define_set_default_trg(statement, element, columns, referenced_columns, relation_name, for_rel_name_str->str_data, false); break; case REF_ACTION_SET_NULL: - request->append_uchar(isc_dyn_foreign_key_null); - define_set_null_trg(request, element, columns, + statement->append_uchar(isc_dyn_foreign_key_null); + define_set_null_trg(statement, element, columns, referenced_columns, relation_name, for_rel_name_str->str_data, false); break; case REF_ACTION_NONE: - request->append_uchar(isc_dyn_foreign_key_none); + statement->append_uchar(isc_dyn_foreign_key_none); break; default: fb_assert(0); - request->append_uchar(isc_dyn_foreign_key_none); // just in case + statement->append_uchar(isc_dyn_foreign_key_none); // just in case break; // Error } @@ -5172,11 +5172,11 @@ static void make_index_trg_ref_int( dsql_req* request, ptr < end; ++ptr) { const dsql_str* field_name = (dsql_str*) (*ptr)->nod_arg[1]; - request->append_cstring(isc_dyn_fld_name, + statement->append_cstring(isc_dyn_fld_name, field_name->str_data); } - request->append_cstring(isc_dyn_idx_foreign_key, relation_name); + statement->append_cstring(isc_dyn_idx_foreign_key, relation_name); if (referenced_columns) { ptr = referenced_columns->nod_arg; @@ -5184,16 +5184,16 @@ static void make_index_trg_ref_int( dsql_req* request, ptr < end; ++ptr) { const dsql_str* field_name = (dsql_str*) (*ptr)->nod_arg[1]; - request->append_cstring(isc_dyn_idx_ref_column, + statement->append_cstring(isc_dyn_idx_ref_column, field_name->str_data); } } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void modify_database( dsql_req* request) +static void modify_database( CompiledStatement* statement) { /************************************** * @@ -5205,10 +5205,10 @@ static void modify_database( dsql_req* request) * Modify a database. * **************************************/ - const dsql_nod* ddl_node = request->req_ddl_node; + const dsql_nod* ddl_node = statement->req_ddl_node; - request->append_uchar(isc_dyn_mod_database); -// request->append_number(isc_dyn_rel_sql_protection, 1); + statement->append_uchar(isc_dyn_mod_database); +// statement->append_number(isc_dyn_rel_sql_protection, 1); bool drop_difference = false; const dsql_nod* elements = ddl_node->nod_arg[e_adb_all]; @@ -5223,7 +5223,7 @@ static void modify_database( dsql_req* request) } if (drop_difference) { - request->append_uchar(isc_dyn_drop_difference); + statement->append_uchar(isc_dyn_drop_difference); } SLONG start = 0; @@ -5238,36 +5238,36 @@ static void modify_database( dsql_req* request) switch (element->nod_type) { case nod_file_desc: file = (dsql_fil*) element->nod_arg[0]; - request->append_cstring(isc_dyn_def_file, + statement->append_cstring(isc_dyn_def_file, file->fil_name->str_data); start = MAX(start, file->fil_start); - request->append_file_start(start); + statement->append_file_start(start); - request->append_file_length(file->fil_length); - request->append_uchar(isc_dyn_end); + statement->append_file_length(file->fil_length); + statement->append_uchar(isc_dyn_end); start += file->fil_length; break; case nod_difference_file: - request->append_cstring(isc_dyn_def_difference, + statement->append_cstring(isc_dyn_def_difference, ((dsql_str*)element->nod_arg[0])->str_data); break; case nod_begin_backup: - request->append_uchar(isc_dyn_begin_backup); + statement->append_uchar(isc_dyn_begin_backup); break; case nod_end_backup: - request->append_uchar(isc_dyn_end_backup); + statement->append_uchar(isc_dyn_end_backup); break; default: break; } } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void modify_domain( dsql_req* request) +static void modify_domain( CompiledStatement* statement) { /************************************** * @@ -5281,18 +5281,18 @@ static void modify_domain( dsql_req* request) **************************************/ dsql_str* string; dsql_fld* field; - dsql_fld local_field(request->req_pool); + dsql_fld local_field(statement->req_pool); /* CVC: This array used with check_one_call to ensure each modification option is called only once. Enlarge it if the switch() below gets more cases. */ USHORT repetition_count[6]; - dsql_nod* ddl_node = request->req_ddl_node; + dsql_nod* ddl_node = statement->req_ddl_node; dsql_nod* domain_node = ddl_node->nod_arg[e_alt_dom_name]; const dsql_str* domain_name = (dsql_str*) domain_node->nod_arg[e_fln_name]; - request->append_cstring(isc_dyn_mod_global_fld, + statement->append_cstring(isc_dyn_mod_global_fld, domain_name->str_data); @@ -5314,18 +5314,18 @@ static void modify_domain( dsql_req* request) { case nod_def_default: check_one_call(repetition_count, 0, "DOMAIN DEFAULT"); - define_default(request, element); + define_default(statement, element); break; case nod_def_constraint: check_one_call(repetition_count, 1, "DOMAIN CONSTRAINT"); - request->append_uchar(isc_dyn_single_validation); - request->begin_blr(isc_dyn_fld_validation_blr); + statement->append_uchar(isc_dyn_single_validation); + statement->begin_blr(isc_dyn_fld_validation_blr); /* Get the attributes of the domain, and set any occurances of nod_dom_value (corresponding to the keyword VALUE) to the correct type, length, scale, etc. */ - if (!METD_get_domain(request, &local_field, domain_name->str_data)) + if (!METD_get_domain(statement, &local_field, domain_name->str_data)) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) -607, isc_arg_gds, isc_dsql_command_err, @@ -5340,7 +5340,7 @@ static void modify_domain( dsql_req* request) &local_field); } - /* Increment the context level for this request, so that + /* Increment the context level for this statement, so that the context number for any RSE generated for a SELECT within the CHECK clause will be greater than 0. In the environment of a domain check constraint, context @@ -5348,14 +5348,14 @@ static void modify_domain( dsql_req* request) is emitted for a nod_dom_value, corresponding to an occurance of the VALUE keyword in the body of the check constraint. -- chrisj 1999-08-20 */ - request->req_context_number++; + statement->req_context_number++; - GEN_expr(request, PASS1_node(request, element->nod_arg[e_cnstr_condition])); + GEN_expr(statement, PASS1_node(statement, element->nod_arg[e_cnstr_condition])); - request->end_blr(); + statement->end_blr(); if ((string = (dsql_str*) element->nod_arg[e_cnstr_source]) != NULL) { fb_assert(string->str_length <= MAX_USHORT); - request->append_string( isc_dyn_fld_validation_source, + statement->append_string(isc_dyn_fld_validation_source, string->str_data, string->str_length); } @@ -5363,8 +5363,8 @@ static void modify_domain( dsql_req* request) case nod_mod_domain_type: field = (dsql_fld*) element->nod_arg[e_mod_dom_new_dom_type]; - DDL_resolve_intl_type(request, field, NULL); - put_field(request, field, false); + DDL_resolve_intl_type(statement, field, NULL); + put_field(statement, field, false); break; case nod_field_name: @@ -5372,19 +5372,19 @@ static void modify_domain( dsql_req* request) check_one_call(repetition_count, 3, "DOMAIN NAME"); const dsql_str* new_dom_name = (dsql_str*) element->nod_arg[e_fln_name]; - request->append_cstring(isc_dyn_fld_name, + statement->append_cstring(isc_dyn_fld_name, new_dom_name->str_data); break; } case nod_delete_rel_constraint: check_one_call(repetition_count, 4, "DOMAIN DROP CONSTRAINT"); - request->append_uchar(isc_dyn_del_validation); + statement->append_uchar(isc_dyn_del_validation); break; case nod_del_default: check_one_call(repetition_count, 5, "DOMAIN DROP DEFAULT"); - request->append_uchar(isc_dyn_del_default); + statement->append_uchar(isc_dyn_del_default); break; default: @@ -5392,11 +5392,11 @@ static void modify_domain( dsql_req* request) } } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void modify_index( dsql_req* request) +static void modify_index( CompiledStatement* statement) { /************************************** * @@ -5408,25 +5408,25 @@ static void modify_index( dsql_req* request) * Alter an index (only active or inactive for now) * **************************************/ - dsql_nod* ddl_node = request->req_ddl_node; + dsql_nod* ddl_node = statement->req_ddl_node; dsql_nod* index_node = ddl_node->nod_arg[e_alt_index]; const dsql_str* index_name = (dsql_str*) index_node->nod_arg[e_alt_idx_name]; - request->append_cstring(isc_dyn_mod_idx, index_name->str_data); + statement->append_cstring(isc_dyn_mod_idx, index_name->str_data); if (index_node->nod_type == nod_idx_active) { - request->append_number(isc_dyn_idx_inactive, 0); + statement->append_number(isc_dyn_idx_inactive, 0); } else if (index_node->nod_type == nod_idx_inactive) { - request->append_number(isc_dyn_idx_inactive, 1); + statement->append_number(isc_dyn_idx_inactive, 1); } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void modify_privilege( dsql_req* request, +static void modify_privilege( CompiledStatement* statement, NOD_TYPE type, SSHORT option, const UCHAR* privs, @@ -5446,22 +5446,22 @@ static void modify_privilege( dsql_req* request, **************************************/ if (type == nod_grant) { - request->append_uchar(isc_dyn_grant); + statement->append_uchar(isc_dyn_grant); } else { - request->append_uchar(isc_dyn_revoke); + statement->append_uchar(isc_dyn_revoke); } // stuff the privileges string SSHORT priv_count = 0; - request->append_ushort(0); + statement->append_ushort(0); for (; *privs; privs++) { priv_count++; - request->append_uchar(*privs); + statement->append_uchar(*privs); } - UCHAR* dynsave = request->req_blr_data.end(); + UCHAR* dynsave = statement->req_blr_data.end(); for (SSHORT i = priv_count + 2; i; i--) { --dynsave; } @@ -5471,41 +5471,41 @@ static void modify_privilege( dsql_req* request, const dsql_str* name = (dsql_str*) table->nod_arg[0]; if (table->nod_type == nod_procedure_name) { - request->append_cstring(isc_dyn_prc_name, name->str_data); + statement->append_cstring(isc_dyn_prc_name, name->str_data); } else { - request->append_cstring(isc_dyn_rel_name, name->str_data); + statement->append_cstring(isc_dyn_rel_name, name->str_data); } name = (dsql_str*) user->nod_arg[0]; switch (user->nod_type) { case nod_user_group: // GRANT priv ON tbl TO GROUP unix_group - request->append_cstring(isc_dyn_grant_user_group, name->str_data); + statement->append_cstring(isc_dyn_grant_user_group, name->str_data); break; case nod_user_name: if (user->nod_count == 2) { - request->append_cstring(isc_dyn_grant_user_explicit, name->str_data); + statement->append_cstring(isc_dyn_grant_user_explicit, name->str_data); } else { - request->append_cstring(isc_dyn_grant_user, name->str_data); + statement->append_cstring(isc_dyn_grant_user, name->str_data); } break; case nod_proc_obj: - request->append_cstring(isc_dyn_grant_proc, name->str_data); + statement->append_cstring(isc_dyn_grant_proc, name->str_data); break; case nod_trig_obj: - request->append_cstring(isc_dyn_grant_trig, name->str_data); + statement->append_cstring(isc_dyn_grant_trig, name->str_data); break; case nod_view_obj: - request->append_cstring(isc_dyn_grant_view, name->str_data); + statement->append_cstring(isc_dyn_grant_view, name->str_data); break; case nod_role_name: - request->append_cstring(isc_dyn_grant_role, name->str_data); + statement->append_cstring(isc_dyn_grant_role, name->str_data); break; default: @@ -5516,20 +5516,20 @@ static void modify_privilege( dsql_req* request, } if (field_name) { - request->append_cstring(isc_dyn_fld_name, field_name->str_data); + statement->append_cstring(isc_dyn_fld_name, field_name->str_data); } if (option) { - request->append_number(isc_dyn_grant_options, option); + statement->append_number(isc_dyn_grant_options, option); } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static SCHAR modify_privileges(dsql_req* request, +static SCHAR modify_privileges(CompiledStatement* statement, NOD_TYPE type, SSHORT option, const dsql_nod* privs, @@ -5579,7 +5579,7 @@ static SCHAR modify_privileges(dsql_req* request, for (ptr = fields->nod_arg, end = ptr + fields->nod_count; ptr < end; ptr++) { - modify_privilege(request, type, option, + modify_privilege(statement, type, option, reinterpret_cast(p), table, user, reinterpret_cast((*ptr)->nod_arg[1])); } @@ -5593,7 +5593,7 @@ static SCHAR modify_privileges(dsql_req* request, for (ptr = privs->nod_arg, end = ptr + privs->nod_count; ptr < end; ptr++) { - *q = modify_privileges(request, type, option, *ptr, table, + *q = modify_privileges(statement, type, option, *ptr, table, user); if (*q) { q++; @@ -5607,7 +5607,7 @@ static SCHAR modify_privileges(dsql_req* request, } if (*p) { - modify_privilege( request, + modify_privilege( statement, type, option, reinterpret_cast(p), @@ -5620,7 +5620,7 @@ static SCHAR modify_privileges(dsql_req* request, } -static void modify_relation(dsql_req* request) +static void modify_relation(CompiledStatement* statement) { /************************************** * @@ -5635,15 +5635,15 @@ static void modify_relation(dsql_req* request) **************************************/ thread_db* tdbb = JRD_get_thread_data(); - dsql_nod* ddl_node = request->req_ddl_node; + dsql_nod* ddl_node = statement->req_ddl_node; dsql_nod* relation_node = ddl_node->nod_arg[e_alt_name]; const dsql_str* relation_name = (dsql_str*) relation_node->nod_arg[e_rln_name]; - request->append_cstring(isc_dyn_mod_rel, relation_name->str_data); - save_relation(request, relation_name); + statement->append_cstring(isc_dyn_mod_rel, relation_name->str_data); + save_relation(statement, relation_name); - if (!request->req_relation) + if (!statement->req_relation) { TEXT linecol[64]; sprintf (linecol, "At line %d, column %d.", @@ -5673,16 +5673,16 @@ static void modify_relation(dsql_req* request) { const dsql_nod* old_field = element->nod_arg[e_mod_fld_name_orig_name]; const dsql_str* old_field_name = (dsql_str*) old_field->nod_arg[e_fln_name]; - request->append_cstring(isc_dyn_mod_local_fld, + statement->append_cstring(isc_dyn_mod_local_fld, old_field_name->str_data); dsql_nod* new_field = element->nod_arg[e_mod_fld_name_new_name]; const dsql_str* new_field_name = (dsql_str*) new_field->nod_arg[e_fln_name]; - request->append_cstring(isc_dyn_rel_name, + statement->append_cstring(isc_dyn_rel_name, relation_name->str_data); - request->append_cstring(isc_dyn_new_fld_name, + statement->append_cstring(isc_dyn_new_fld_name, new_field_name->str_data); - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); break; } @@ -5690,26 +5690,26 @@ static void modify_relation(dsql_req* request) { field_node = element->nod_arg[e_mod_fld_pos_orig_name]; field_name = (dsql_str*) field_node->nod_arg[e_fln_name]; - request->append_cstring(isc_dyn_mod_local_fld, field_name->str_data); + statement->append_cstring(isc_dyn_mod_local_fld, field_name->str_data); const dsql_nod* const_node = element->nod_arg[e_mod_fld_pos_new_position]; // CVC: Since now the parser accepts pos=1..N, let's subtract one here. const SSHORT constant = (SSHORT) const_node->getSlong() - 1; - request->append_cstring(isc_dyn_rel_name, + statement->append_cstring(isc_dyn_rel_name, relation_name->str_data); - request->append_number(isc_dyn_fld_position, constant); - request->append_uchar(isc_dyn_end); + statement->append_number(isc_dyn_fld_position, constant); + statement->append_uchar(isc_dyn_end); break; } case nod_mod_field_type: - modify_field(request, element, (SSHORT) -1, relation_name); + modify_field(statement, element, (SSHORT) -1, relation_name); break; case nod_def_field: - define_field(request, element, (SSHORT) -1, relation_name, 0); + define_field(statement, element, (SSHORT) -1, relation_name, 0); break; case nod_del_field: @@ -5737,17 +5737,17 @@ static void modify_relation(dsql_req* request) } fb_assert((element->nod_arg[1])->nod_type == nod_restrict); - request->append_cstring(isc_dyn_delete_local_fld, field_name->str_data); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_delete_local_fld, field_name->str_data); + statement->append_uchar(isc_dyn_end); break; case nod_delete_rel_constraint: field_name = (dsql_str*) element->nod_arg[0]; - request->append_cstring(isc_dyn_delete_rel_constraint, field_name->str_data); + statement->append_cstring(isc_dyn_delete_rel_constraint, field_name->str_data); break; case nod_rel_constraint: - define_rel_constraint(request, element); + define_rel_constraint(statement, element); break; default: @@ -5755,13 +5755,13 @@ static void modify_relation(dsql_req* request) } } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } // try catch (const Firebird::Exception&) { - METD_drop_relation(request, relation_name); - request->req_relation = 0; + METD_drop_relation(statement, relation_name); + statement->req_relation = 0; throw; } } @@ -5772,9 +5772,9 @@ static void modify_relation(dsql_req* request) // ******************* // Allow the user to change the entry point or module name. // Useful when there are dependencies on the udf, so it cannot be dropped. -static void modify_udf(dsql_req* request) +static void modify_udf(CompiledStatement* statement) { - const dsql_nod* node = request->req_ddl_node; + const dsql_nod* node = statement->req_ddl_node; fb_assert(node->nod_type == nod_mod_udf); const dsql_str* obj_name = (dsql_str*) node->nod_arg[e_mod_udf_name]; @@ -5786,16 +5786,16 @@ static void modify_udf(dsql_req* request) (SLONG) node->nod_column + obj_name->str_length, // + strlen("FUNCTION"), 0); - request->append_cstring(isc_dyn_mod_function, obj_name->str_data); + statement->append_cstring(isc_dyn_mod_function, obj_name->str_data); const dsql_str* entry_point_name = (dsql_str*) node->nod_arg[e_mod_udf_entry_pt]; if (entry_point_name) - request->append_cstring(isc_dyn_func_entry_point, entry_point_name->str_data); + statement->append_cstring(isc_dyn_func_entry_point, entry_point_name->str_data); const dsql_str* module_name = (dsql_str*) node->nod_arg[e_mod_udf_module]; if (module_name) - request->append_cstring(isc_dyn_func_module_name, module_name->str_data); + statement->append_cstring(isc_dyn_func_module_name, module_name->str_data); - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } @@ -5803,22 +5803,22 @@ static void modify_udf(dsql_req* request) // m o d i f y _ m a p // ******************* // Allow the user to establish/drop the mapping between OS security object and the role -static void modify_map(dsql_req* request) +static void modify_map(CompiledStatement* statement) { - const dsql_nod* node = request->req_ddl_node; + const dsql_nod* node = statement->req_ddl_node; fb_assert(node->nod_type == nod_mod_role); const dsql_str* ds = (dsql_str*) node->nod_arg[e_mod_role_os_name]; fb_assert(ds || node->nod_arg[e_mod_role_action]->getSlong() == isc_dyn_automap_role || node->nod_arg[e_mod_role_action]->getSlong() == isc_dyn_autounmap_role); - request->append_cstring(isc_dyn_mapping, ds ? ds->str_data : ""); + statement->append_cstring(isc_dyn_mapping, ds ? ds->str_data : ""); ds = (dsql_str*) node->nod_arg[e_mod_role_db_name]; fb_assert(ds); - request->append_cstring(node->nod_arg[e_mod_role_action]->getSlong(), ds->str_data); + statement->append_cstring(node->nod_arg[e_mod_role_action]->getSlong(), ds->str_data); - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } @@ -5826,11 +5826,11 @@ static void modify_map(dsql_req* request) // d e f i n e _ u s e r // ********************* // Support SQL operator create/alter/drop user -static void define_user(dsql_req* request, UCHAR op) +static void define_user(CompiledStatement* statement, UCHAR op) { - request->append_uchar(isc_dyn_user); + statement->append_uchar(isc_dyn_user); - const dsql_nod* node = request->req_ddl_node; + const dsql_nod* node = statement->req_ddl_node; int argCount = 0; for (int i = 0; i < node->nod_count; ++i) @@ -5855,19 +5855,19 @@ static void define_user(dsql_req* request, UCHAR op) switch(i) { case e_user_name: - request->append_cstring(op, ds->str_data); + statement->append_cstring(op, ds->str_data); break; case e_user_passwd: - request->append_cstring(isc_dyn_user_passwd, ds->str_data); + statement->append_cstring(isc_dyn_user_passwd, ds->str_data); break; case e_user_first: - request->append_cstring(isc_dyn_user_first, ds->str_data); + statement->append_cstring(isc_dyn_user_first, ds->str_data); break; case e_user_middle: - request->append_cstring(isc_dyn_user_middle, ds->str_data); + statement->append_cstring(isc_dyn_user_middle, ds->str_data); break; case e_user_last: - request->append_cstring(isc_dyn_user_last, ds->str_data); + statement->append_cstring(isc_dyn_user_last, ds->str_data); break; } } @@ -5881,8 +5881,8 @@ static void define_user(dsql_req* request, UCHAR op) 0); } - request->append_uchar(isc_user_end); - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_user_end); + statement->append_uchar(isc_dyn_end); } @@ -5910,7 +5910,7 @@ static dsql_par* parameter_reverse_order(dsql_par* parameter, dsql_par* prev) } -static void process_role_nm_list( dsql_req* request, +static void process_role_nm_list( CompiledStatement* statement, SSHORT option, dsql_nod* user_ptr, dsql_nod* role_ptr, @@ -5927,30 +5927,30 @@ static void process_role_nm_list( dsql_req* request, * **************************************/ if (type == nod_grant) { - request->append_uchar(isc_dyn_grant); + statement->append_uchar(isc_dyn_grant); } else { - request->append_uchar(isc_dyn_revoke); + statement->append_uchar(isc_dyn_revoke); } - request->append_ushort(1); - request->append_uchar('M'); + statement->append_ushort(1); + statement->append_uchar('M'); const dsql_str* role_nm = (dsql_str*) role_ptr->nod_arg[0]; - request->append_cstring(isc_dyn_sql_role_name, role_nm->str_data); + statement->append_cstring(isc_dyn_sql_role_name, role_nm->str_data); const dsql_str* user_nm = (dsql_str*) user_ptr->nod_arg[0]; - request->append_cstring(isc_dyn_grant_user, user_nm->str_data); + statement->append_cstring(isc_dyn_grant_user, user_nm->str_data); if (option) { - request->append_number(isc_dyn_grant_admin_options, option); + statement->append_number(isc_dyn_grant_admin_options, option); } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } -static void put_descriptor(dsql_req* request, const dsc* desc) +static void put_descriptor(CompiledStatement* statement, const dsc* desc) { /************************************** * @@ -5964,28 +5964,28 @@ static void put_descriptor(dsql_req* request, const dsc* desc) * **************************************/ - request->append_number(isc_dyn_fld_type, blr_dtypes[desc->dsc_dtype]); + statement->append_number(isc_dyn_fld_type, blr_dtypes[desc->dsc_dtype]); if (desc->dsc_dtype == dtype_varying) { - request->append_number(isc_dyn_fld_length, + statement->append_number(isc_dyn_fld_length, (SSHORT) (desc->dsc_length - sizeof(USHORT))); } else { - request->append_number(isc_dyn_fld_length, desc->dsc_length); + statement->append_number(isc_dyn_fld_length, desc->dsc_length); } if (desc->dsc_dtype <= dtype_any_text) { - request->append_number(isc_dyn_fld_character_set, DSC_GET_CHARSET(desc)); - request->append_number(isc_dyn_fld_collation, DSC_GET_COLLATE(desc)); + statement->append_number(isc_dyn_fld_character_set, DSC_GET_CHARSET(desc)); + statement->append_number(isc_dyn_fld_collation, DSC_GET_COLLATE(desc)); } else if (desc->dsc_dtype == dtype_blob) { - request->append_number(isc_dyn_fld_sub_type, desc->dsc_sub_type); + statement->append_number(isc_dyn_fld_sub_type, desc->dsc_sub_type); if (desc->dsc_sub_type == isc_blob_text) { - request->append_number(isc_dyn_fld_character_set, desc->dsc_scale); - request->append_number(isc_dyn_fld_collation, desc->dsc_flags >> 8); // BLOB collation + statement->append_number(isc_dyn_fld_character_set, desc->dsc_scale); + statement->append_number(isc_dyn_fld_collation, desc->dsc_flags >> 8); // BLOB collation } } else { - request->append_number(isc_dyn_fld_sub_type, desc->dsc_sub_type); - request->append_number(isc_dyn_fld_scale, desc->dsc_scale); + statement->append_number(isc_dyn_fld_sub_type, desc->dsc_sub_type); + statement->append_number(isc_dyn_fld_scale, desc->dsc_scale); } } @@ -5994,7 +5994,7 @@ static void put_descriptor(dsql_req* request, const dsc* desc) // Write out field data type // Taking special care to declare international text. // -static void put_dtype(dsql_req* request, const dsql_fld* field, bool use_subtype) +static void put_dtype(CompiledStatement* statement, const dsql_fld* field, bool use_subtype) { #ifdef DEV_BUILD // Check if the field describes a known datatype @@ -6010,7 +6010,7 @@ static void put_dtype(dsql_req* request, const dsql_fld* field, bool use_subtype #endif if (field->fld_not_nullable) - request->append_uchar(blr_not_nullable); + statement->append_uchar(blr_not_nullable); if (field->fld_type_of_name.hasData()) { @@ -6018,34 +6018,34 @@ static void put_dtype(dsql_req* request, const dsql_fld* field, bool use_subtype { if (field->fld_explicit_collation) { - request->append_uchar(blr_column_name2); - request->append_uchar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); - request->append_meta_string(field->fld_type_of_table->str_data); - request->append_meta_string(field->fld_type_of_name.c_str()); - request->append_ushort(field->fld_ttype); + statement->append_uchar(blr_column_name2); + statement->append_uchar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); + statement->append_meta_string(field->fld_type_of_table->str_data); + statement->append_meta_string(field->fld_type_of_name.c_str()); + statement->append_ushort(field->fld_ttype); } else { - request->append_uchar(blr_column_name); - request->append_uchar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); - request->append_meta_string(field->fld_type_of_table->str_data); - request->append_meta_string(field->fld_type_of_name.c_str()); + statement->append_uchar(blr_column_name); + statement->append_uchar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); + statement->append_meta_string(field->fld_type_of_table->str_data); + statement->append_meta_string(field->fld_type_of_name.c_str()); } } else { if (field->fld_explicit_collation) { - request->append_uchar(blr_domain_name2); - request->append_uchar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); - request->append_meta_string(field->fld_type_of_name.c_str()); - request->append_ushort(field->fld_ttype); + statement->append_uchar(blr_domain_name2); + statement->append_uchar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); + statement->append_meta_string(field->fld_type_of_name.c_str()); + statement->append_ushort(field->fld_ttype); } else { - request->append_uchar(blr_domain_name); - request->append_uchar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); - request->append_meta_string(field->fld_type_of_name.c_str()); + statement->append_uchar(blr_domain_name); + statement->append_uchar(field->fld_full_domain ? blr_domain_full : blr_domain_type_of); + statement->append_meta_string(field->fld_type_of_name.c_str()); } } @@ -6059,46 +6059,46 @@ static void put_dtype(dsql_req* request, const dsql_fld* field, bool use_subtype case dtype_varying: case dtype_blob: if (!use_subtype) { - request->append_uchar(blr_dtypes[field->fld_dtype]); + statement->append_uchar(blr_dtypes[field->fld_dtype]); } else if (field->fld_dtype == dtype_varying) { - request->append_uchar(blr_varying2); - request->append_ushort(field->fld_ttype); + statement->append_uchar(blr_varying2); + statement->append_ushort(field->fld_ttype); } else if (field->fld_dtype == dtype_cstring) { - request->append_uchar(blr_cstring2); - request->append_ushort(field->fld_ttype); + statement->append_uchar(blr_cstring2); + statement->append_ushort(field->fld_ttype); } else if (field->fld_dtype == dtype_blob) { - request->append_uchar(blr_blob2); - request->append_ushort(field->fld_sub_type); - request->append_ushort(field->fld_ttype); + statement->append_uchar(blr_blob2); + statement->append_ushort(field->fld_sub_type); + statement->append_ushort(field->fld_ttype); } else { - request->append_uchar(blr_text2); - request->append_ushort(field->fld_ttype); + statement->append_uchar(blr_text2); + statement->append_ushort(field->fld_ttype); } if (field->fld_dtype == dtype_varying) { - request->append_ushort(field->fld_length - sizeof(USHORT)); + statement->append_ushort(field->fld_length - sizeof(USHORT)); } else if (field->fld_dtype != dtype_blob) { - request->append_ushort(field->fld_length); + statement->append_ushort(field->fld_length); } break; default: - request->append_uchar(blr_dtypes[field->fld_dtype]); + statement->append_uchar(blr_dtypes[field->fld_dtype]); if (DTYPE_IS_EXACT(field->fld_dtype) || (dtype_quad == field->fld_dtype)) { - request->append_uchar(field->fld_scale); + statement->append_uchar(field->fld_scale); } } } -static void put_field( dsql_req* request, dsql_fld* field, bool udf_flag) +static void put_field( CompiledStatement* statement, dsql_fld* field, bool udf_flag) { /************************************** * @@ -6114,84 +6114,84 @@ static void put_field( dsql_req* request, dsql_fld* field, bool udf_flag) **************************************/ if (field->fld_not_nullable) - request->append_uchar(isc_dyn_fld_not_null); + statement->append_uchar(isc_dyn_fld_not_null); if (field->fld_type_of_name.hasData()) { if (field->fld_source.hasData()) { - request->append_string(isc_dyn_fld_source, field->fld_source); - request->append_string(isc_dyn_fld_name, field->fld_type_of_name); - request->append_cstring(isc_dyn_rel_name, field->fld_type_of_table->str_data); + statement->append_string(isc_dyn_fld_source, field->fld_source); + statement->append_string(isc_dyn_fld_name, field->fld_type_of_name); + statement->append_cstring(isc_dyn_rel_name, field->fld_type_of_table->str_data); } else - request->append_string(isc_dyn_fld_source, field->fld_type_of_name); + statement->append_string(isc_dyn_fld_source, field->fld_type_of_name); if (field->fld_explicit_collation) - request->append_number(isc_dyn_fld_collation, field->fld_collation_id); + statement->append_number(isc_dyn_fld_collation, field->fld_collation_id); if (!field->fld_full_domain) - request->append_number(isc_dyn_prm_mechanism, prm_mech_type_of); + statement->append_number(isc_dyn_prm_mechanism, prm_mech_type_of); return; } - request->append_number(isc_dyn_fld_type, blr_dtypes[field->fld_dtype]); + statement->append_number(isc_dyn_fld_type, blr_dtypes[field->fld_dtype]); if (field->fld_dtype == dtype_blob) { - request->append_number(isc_dyn_fld_sub_type, field->fld_sub_type); - request->append_number(isc_dyn_fld_scale, 0); + statement->append_number(isc_dyn_fld_sub_type, field->fld_sub_type); + statement->append_number(isc_dyn_fld_scale, 0); if (!udf_flag) { if (!field->fld_seg_length) { field->fld_seg_length = DEFAULT_BLOB_SEGMENT_SIZE; } - request->append_number(isc_dyn_fld_segment_length, + statement->append_number(isc_dyn_fld_segment_length, field->fld_seg_length); } if (field->fld_sub_type == isc_blob_text) { - request->append_number(isc_dyn_fld_character_set, + statement->append_number(isc_dyn_fld_character_set, field->fld_character_set_id); - request->append_number(isc_dyn_fld_collation, + statement->append_number(isc_dyn_fld_collation, field->fld_collation_id); } } else if (field->fld_dtype <= dtype_any_text) { - request->append_number(isc_dyn_fld_sub_type, field->fld_sub_type); - request->append_number(isc_dyn_fld_scale, 0); + statement->append_number(isc_dyn_fld_sub_type, field->fld_sub_type); + statement->append_number(isc_dyn_fld_scale, 0); if (field->fld_dtype == dtype_varying) { // CVC: Fix the assertion fb_assert((field->fld_length) <= MAX_SSHORT); - request->append_number(isc_dyn_fld_length, + statement->append_number(isc_dyn_fld_length, (SSHORT) (field->fld_length - sizeof(USHORT))); } else { - request->append_number(isc_dyn_fld_length, field->fld_length); + statement->append_number(isc_dyn_fld_length, field->fld_length); } - request->append_number(isc_dyn_fld_char_length, + statement->append_number(isc_dyn_fld_char_length, field->fld_character_length); - request->append_number(isc_dyn_fld_character_set, + statement->append_number(isc_dyn_fld_character_set, field->fld_character_set_id); if (!udf_flag) - request->append_number(isc_dyn_fld_collation, + statement->append_number(isc_dyn_fld_collation, field->fld_collation_id); } else { - request->append_number(isc_dyn_fld_scale, field->fld_scale); - request->append_number(isc_dyn_fld_length, field->fld_length); + statement->append_number(isc_dyn_fld_scale, field->fld_scale); + statement->append_number(isc_dyn_fld_length, field->fld_length); if (DTYPE_IS_EXACT(field->fld_dtype)) { - request->append_number(isc_dyn_fld_precision, field->fld_precision); - request->append_number(isc_dyn_fld_sub_type, field->fld_sub_type); + statement->append_number(isc_dyn_fld_precision, field->fld_precision); + statement->append_number(isc_dyn_fld_sub_type, field->fld_sub_type); } } } -static void put_local_variable( dsql_req* request, dsql_var* variable, +static void put_local_variable( CompiledStatement* statement, dsql_var* variable, dsql_nod* host_param, const dsql_str* collation_name) { /************************************** @@ -6207,13 +6207,13 @@ static void put_local_variable( dsql_req* request, dsql_var* variable, dsql_fld* field = variable->var_field; - request->append_uchar(blr_dcl_variable); - request->append_ushort(variable->var_variable_number); - DDL_resolve_intl_type(request, field, collation_name); + statement->append_uchar(blr_dcl_variable); + statement->append_ushort(variable->var_variable_number); + DDL_resolve_intl_type(statement, field, collation_name); const USHORT dtype = field->fld_dtype; - put_dtype(request, field, true); + put_dtype(statement, field, true); field->fld_dtype = dtype; // Check for a default value, borrowed from define_domain @@ -6221,35 +6221,35 @@ static void put_local_variable( dsql_req* request, dsql_var* variable, if (node || (!field->fld_full_domain && !field->fld_not_nullable)) { - request->append_uchar(blr_assignment); + statement->append_uchar(blr_assignment); if (node) { fb_assert(node->nod_type == nod_def_default); - PsqlChanger psqlChanger(request, false); - node = PASS1_node(request, node->nod_arg[e_dft_default]); - GEN_expr(request, node); + PsqlChanger psqlChanger(statement, false); + node = PASS1_node(statement, node->nod_arg[e_dft_default]); + GEN_expr(statement, node); } else { // Initialize variable to NULL - request->append_uchar(blr_null); + statement->append_uchar(blr_null); } - request->append_uchar(blr_variable); - request->append_ushort(variable->var_variable_number); + statement->append_uchar(blr_variable); + statement->append_ushort(variable->var_variable_number); } else { - request->append_uchar(blr_init_variable); - request->append_ushort(variable->var_variable_number); + statement->append_uchar(blr_init_variable); + statement->append_ushort(variable->var_variable_number); } - request->put_debug_variable(variable->var_variable_number, + statement->put_debug_variable(variable->var_variable_number, variable->var_name); } -static void put_local_variables(dsql_req* request, dsql_nod* parameters, SSHORT locals) +static void put_local_variables(CompiledStatement* statement, dsql_nod* parameters, SSHORT locals) { /************************************** * @@ -6271,7 +6271,7 @@ static void put_local_variables(dsql_req* request, dsql_nod* parameters, SSHORT { dsql_nod* parameter = *ptr; - request->put_debug_src_info(parameter->nod_line, parameter->nod_column); + statement->put_debug_src_info(parameter->nod_line, parameter->nod_column); if (parameter->nod_type == nod_def_field) { @@ -6295,7 +6295,7 @@ static void put_local_variables(dsql_req* request, dsql_nod* parameters, SSHORT *ptr = var_node; dsql_var* variable = (dsql_var*) var_node->nod_arg[e_var_variable]; - put_local_variable(request, variable, parameter, + put_local_variable(statement, variable, parameter, reinterpret_cast(parameter->nod_arg[e_dfl_collate])); // Some field attributes are calculated inside @@ -6307,15 +6307,15 @@ static void put_local_variables(dsql_req* request, dsql_nod* parameters, SSHORT } else if (parameter->nod_type == nod_cursor) { - PASS1_statement(request, parameter); - GEN_statement(request, parameter); + PASS1_statement(statement, parameter); + GEN_statement(statement, parameter); } } } } -static void put_msg_field( dsql_req* request, dsql_fld* field) +static void put_msg_field( CompiledStatement* statement, dsql_fld* field) { /************************************** * @@ -6330,12 +6330,12 @@ static void put_msg_field( dsql_req* request, dsql_fld* field) const USHORT dtype = field->fld_dtype; - put_dtype(request, field, true); + put_dtype(statement, field, true); field->fld_dtype = dtype; // add slot for null flag (parameter2) - request->append_uchar(blr_short); - request->append_uchar(0); + statement->append_uchar(blr_short); + statement->append_uchar(0); } @@ -6431,7 +6431,7 @@ static dsql_nod* replace_field_names(dsql_nod* input, } -static void reset_context_stack( dsql_req* request) +static void reset_context_stack( CompiledStatement* statement) { /************************************** * @@ -6445,12 +6445,12 @@ static void reset_context_stack( dsql_req* request) * **************************************/ - request->req_context->clear(); - request->req_context_number = 0; + statement->req_context->clear(); + statement->req_context_number = 0; } -static void save_field(dsql_req* request, const TEXT* field_name) +static void save_field(CompiledStatement* statement, const TEXT* field_name) { /************************************** * @@ -6462,18 +6462,18 @@ static void save_field(dsql_req* request, const TEXT* field_name) * Save the name of a field in the relation or view currently * being defined. This is done to support definition * of triggers which will depend on the metadata created - * in this request. + * in this statement. * **************************************/ thread_db* tdbb = JRD_get_thread_data(); - dsql_rel* relation = request->req_relation; + dsql_rel* relation = statement->req_relation; if (!relation) { return; } MemoryPool& p = relation->rel_flags & REL_new_relation ? - *tdbb->getDefaultPool() : request->req_dbb->dbb_pool; + *tdbb->getDefaultPool() : statement->req_dbb->dbb_pool; dsql_fld* field = FB_NEW(p) dsql_fld(p); field->fld_name = field_name; field->fld_next = relation->rel_fields; @@ -6481,7 +6481,7 @@ static void save_field(dsql_req* request, const TEXT* field_name) } -static void save_relation(dsql_req* request, const dsql_str* relation_name) +static void save_relation(CompiledStatement* statement, const dsql_str* relation_name) { /************************************** * @@ -6493,23 +6493,23 @@ static void save_relation(dsql_req* request, const dsql_str* relation_name) * Save the name of the relation or view currently * being defined. This is done to support definition * of triggers which will depend on the metadata created - * in this request. + * in this statement. * **************************************/ thread_db* tdbb = JRD_get_thread_data(); - if (request->req_flags & REQ_save_metadata) { + if (statement->req_flags & REQ_save_metadata) { return; } - request->req_flags |= REQ_save_metadata; + statement->req_flags |= REQ_save_metadata; - const dsql_nod* ddl_node = request->req_ddl_node; + const dsql_nod* ddl_node = statement->req_ddl_node; dsql_rel* relation; if (ddl_node->nod_type == nod_mod_relation) { - relation = METD_get_relation(request, relation_name); + relation = METD_get_relation(statement, relation_name); } else { @@ -6519,11 +6519,11 @@ static void save_relation(dsql_req* request, const dsql_str* relation_name) if (ddl_node->nod_type == nod_def_relation || ddl_node->nod_type == nod_redef_relation) relation->rel_flags = REL_creating; } - request->req_relation = relation; + statement->req_relation = relation; } -static void set_statistics( dsql_req* request) +static void set_statistics( CompiledStatement* statement) { /************************************** * @@ -6535,15 +6535,15 @@ static void set_statistics( dsql_req* request) * Alter an index/.. statistics * **************************************/ - dsql_nod* ddl_node = request->req_ddl_node; + dsql_nod* ddl_node = statement->req_ddl_node; const dsql_str* index_name = (dsql_str*) ddl_node->nod_arg[e_stat_name]; - request->append_cstring(isc_dyn_mod_idx, index_name->str_data); - request->append_uchar(isc_dyn_idx_statistic); - request->append_uchar(isc_dyn_end); + statement->append_cstring(isc_dyn_mod_idx, index_name->str_data); + statement->append_uchar(isc_dyn_idx_statistic); + statement->append_uchar(isc_dyn_end); } -static void stuff_default_blr( dsql_req* request, +static void stuff_default_blr( CompiledStatement* statement, const UCHAR* default_buff, USHORT buff_size) { @@ -6556,7 +6556,7 @@ static void stuff_default_blr( dsql_req* request, * The default_blr is passed in default_buffer. It is of the form: * blr_version4 blr_literal ..... blr_eoc. * strip the blr_version4 and blr_eoc verbs and stuff the remaining - * blr in the blr stream in the request. + * blr in the blr stream in the statement. * *********************************************/ fb_assert((*default_buff == blr_version4) || (*default_buff == blr_version5)); @@ -6565,14 +6565,14 @@ static void stuff_default_blr( dsql_req* request, for (i = 1; i < buff_size - 1; ++i) { - request->append_uchar(default_buff[i]); + statement->append_uchar(default_buff[i]); } fb_assert(default_buff[i] == blr_eoc); } -static void stuff_matching_blr(dsql_req* request, const dsql_nod* for_columns, +static void stuff_matching_blr(CompiledStatement* statement, const dsql_nod* for_columns, const dsql_nod* prim_columns) { /******************************************** @@ -6592,9 +6592,9 @@ static void stuff_matching_blr(dsql_req* request, const dsql_nod* for_columns, fb_assert(prim_columns->nod_count == for_columns->nod_count); fb_assert(prim_columns->nod_count != 0); - request->append_uchar(blr_boolean); + statement->append_uchar(blr_boolean); if (prim_columns->nod_count > 1) { - request->append_uchar(blr_and); + statement->append_uchar(blr_and); } USHORT num_fields = 0; @@ -6602,22 +6602,22 @@ static void stuff_matching_blr(dsql_req* request, const dsql_nod* for_columns, const dsql_nod* const* prim_key_flds = prim_columns->nod_arg; do { - request->append_uchar(blr_eql); + statement->append_uchar(blr_eql); const dsql_str* for_key_fld_name_str = (dsql_str*) (*for_key_flds)->nod_arg[1]; const dsql_str* prim_key_fld_name_str = (dsql_str*) (*prim_key_flds)->nod_arg[1]; - request->append_uchar(blr_field); - request->append_uchar(2); - request->append_cstring(0, for_key_fld_name_str->str_data); - request->append_uchar(blr_field); - request->append_uchar(0); - request->append_cstring(0, prim_key_fld_name_str->str_data); + statement->append_uchar(blr_field); + statement->append_uchar(2); + statement->append_cstring(0, for_key_fld_name_str->str_data); + statement->append_uchar(blr_field); + statement->append_uchar(0); + statement->append_cstring(0, prim_key_fld_name_str->str_data); num_fields++; if (prim_columns->nod_count - num_fields >= 2) { - request->append_uchar(blr_and); + statement->append_uchar(blr_and); } for_key_flds++; @@ -6625,11 +6625,11 @@ static void stuff_matching_blr(dsql_req* request, const dsql_nod* for_columns, } while (num_fields < for_columns->nod_count); - request->append_uchar(blr_end); + statement->append_uchar(blr_end); } -static void stuff_trg_firing_cond(dsql_req* request, +static void stuff_trg_firing_cond(CompiledStatement* statement, const dsql_nod* prim_columns) { /******************************************** @@ -6644,31 +6644,31 @@ static void stuff_trg_firing_cond(dsql_req* request, * **************************************/ - request->append_uchar(blr_if); + statement->append_uchar(blr_if); if (prim_columns->nod_count > 1) { - request->append_uchar(blr_or); + statement->append_uchar(blr_or); } USHORT num_fields = 0; const dsql_nod* const* prim_key_flds = prim_columns->nod_arg; do { - request->append_uchar(blr_neq); + statement->append_uchar(blr_neq); const dsql_str* prim_key_fld_name_str = (dsql_str*) (*prim_key_flds)->nod_arg[1]; - request->append_uchar(blr_field); - request->append_uchar(0); - request->append_cstring(0, prim_key_fld_name_str->str_data); - request->append_uchar(blr_field); - request->append_uchar(1); - request->append_cstring(0, prim_key_fld_name_str->str_data); + statement->append_uchar(blr_field); + statement->append_uchar(0); + statement->append_cstring(0, prim_key_fld_name_str->str_data); + statement->append_uchar(blr_field); + statement->append_uchar(1); + statement->append_cstring(0, prim_key_fld_name_str->str_data); num_fields++; if (prim_columns->nod_count - num_fields >= 2) - request->append_uchar(blr_or); + statement->append_uchar(blr_or); prim_key_flds++; @@ -6676,7 +6676,7 @@ static void stuff_trg_firing_cond(dsql_req* request, } -static void modify_field(dsql_req* request, +static void modify_field(CompiledStatement* statement, dsql_nod* element, SSHORT position, const dsql_str* relation_name) @@ -6693,18 +6693,18 @@ static void modify_field(dsql_req* request, * **************************************/ dsql_fld* field = (dsql_fld*) element->nod_arg[e_mod_fld_type_field]; - request->append_string(isc_dyn_mod_sql_fld, field->fld_name); + statement->append_string(isc_dyn_mod_sql_fld, field->fld_name); // add the field to the relation being defined for parsing purposes bool permanent = false; - dsql_rel* relation = request->req_relation; + dsql_rel* relation = statement->req_relation; if (relation != NULL) { if (! (relation->rel_flags & REL_new_relation)) { - dsql_fld* perm_field = FB_NEW(request->req_dbb->dbb_pool) - dsql_fld(request->req_dbb->dbb_pool); + dsql_fld* perm_field = FB_NEW(statement->req_dbb->dbb_pool) + dsql_fld(statement->req_dbb->dbb_pool); *perm_field = *field; field = perm_field; @@ -6720,31 +6720,31 @@ static void modify_field(dsql_req* request, dsql_nod* computedNod = element->nod_arg[e_mod_fld_type_computed]; if (computedNod) { - if (request->req_context_number) - reset_context_stack(request); + if (statement->req_context_number) + reset_context_stack(statement); - PASS1_make_context(request, request->req_ddl_node->nod_arg[e_alt_name]); + PASS1_make_context(statement, statement->req_ddl_node->nod_arg[e_alt_name]); dsql_str* computedSrc = (dsql_str*) computedNod->nod_arg[e_cmp_text]; fb_assert(computedSrc->str_length <= MAX_USHORT); - computedNod = PASS1_node(request, computedNod->nod_arg[e_cmp_expr]); + computedNod = PASS1_node(statement, computedNod->nod_arg[e_cmp_expr]); - if (is_array_or_blob(request, computedNod)) + if (is_array_or_blob(statement, computedNod)) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) -607, isc_arg_gds, isc_dsql_no_array_computed, 0); } - request->begin_blr(isc_dyn_fld_computed_blr); - GEN_expr(request, computedNod); - request->end_blr(); + statement->begin_blr(isc_dyn_fld_computed_blr); + GEN_expr(statement, computedNod); + statement->end_blr(); - request->append_string(isc_dyn_fld_computed_source, + statement->append_string(isc_dyn_fld_computed_source, computedSrc->str_data, (USHORT) computedSrc->str_length); - reset_context_stack(request); + reset_context_stack(statement); } const dsql_nod* defNod = element->nod_arg[e_mod_fld_type_default]; @@ -6752,9 +6752,9 @@ static void modify_field(dsql_req* request, { // We have the default or want to get rid of it. if (defNod->nod_type == nod_def_default) - define_default(request, defNod); + define_default(statement, defNod); else if (defNod->nod_type == nod_del_default) - request->append_uchar(isc_dyn_del_default); + statement->append_uchar(isc_dyn_del_default); else { fb_assert(false); @@ -6768,10 +6768,10 @@ static void modify_field(dsql_req* request, { dsql_nod* node1 = domain_node->nod_arg[e_dom_name]; const dsql_str* domain_name = (dsql_str*) node1->nod_arg[e_fln_name]; - request->append_cstring(isc_dyn_fld_source, domain_name->str_data); + statement->append_cstring(isc_dyn_fld_source, domain_name->str_data); // Get the domain information - if (!METD_get_domain(request, field, domain_name->str_data)) + if (!METD_get_domain(statement, field, domain_name->str_data)) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) -607, isc_arg_gds, isc_dsql_command_err, @@ -6780,12 +6780,12 @@ static void modify_field(dsql_req* request, isc_arg_string, domain_name->str_data, 0); } - DDL_resolve_intl_type(request, field, NULL); + DDL_resolve_intl_type(statement, field, NULL); } else { if (relation_name) { - request->append_cstring(isc_dyn_rel_name, relation_name->str_data); + statement->append_cstring(isc_dyn_rel_name, relation_name->str_data); } // If COMPUTED was specified but the type wasn't, we use the type of @@ -6793,7 +6793,7 @@ static void modify_field(dsql_req* request, if (computedNod && field->fld_dtype == dtype_unknown) { dsc desc; - MAKE_desc(request, &desc, computedNod, NULL); + MAKE_desc(statement, &desc, computedNod, NULL); field->fld_dtype = desc.dsc_dtype; field->fld_length = desc.dsc_length; @@ -6807,13 +6807,13 @@ static void modify_field(dsql_req* request, field->fld_sub_type = desc.dsc_sub_type; } else - DDL_resolve_intl_type2(request, field, NULL, true); + DDL_resolve_intl_type2(statement, field, NULL, true); - put_field(request, field, false); + put_field(statement, field, false); } } - request->append_uchar(isc_dyn_end); + statement->append_uchar(isc_dyn_end); } // try catch (const Firebird::Exception&) { @@ -6875,7 +6875,7 @@ static void set_nod_value_attributes( dsql_nod* node, const dsql_fld* field) // Write out a string of blr as part of a ddl string, // as in a view or computed field definition. // -void dsql_req::begin_blr(UCHAR verb) +void CompiledStatement::begin_blr(UCHAR verb) { if (verb) { append_uchar(verb); @@ -6892,7 +6892,7 @@ void dsql_req::begin_blr(UCHAR verb) // Complete the stuffing of a piece of // blr by going back and inserting the length. // -void dsql_req::end_blr() +void CompiledStatement::end_blr() { append_uchar(blr_eoc); @@ -6912,7 +6912,7 @@ void dsql_req::end_blr() } -void dsql_req::append_number(UCHAR verb, SSHORT number) +void CompiledStatement::append_number(UCHAR verb, SSHORT number) { /************************************** * @@ -6936,7 +6936,7 @@ void dsql_req::append_number(UCHAR verb, SSHORT number) // // Write out a string valued attribute. // -void dsql_req::append_cstring(UCHAR verb, const char* string) +void CompiledStatement::append_cstring(UCHAR verb, const char* string) { const USHORT length = string ? strlen(string) : 0; append_string(verb, string, length); @@ -6946,7 +6946,7 @@ void dsql_req::append_cstring(UCHAR verb, const char* string) // // Write out a string in metadata charset with one byte of length. // -void dsql_req::append_meta_string(const char* string) +void CompiledStatement::append_meta_string(const char* string) { thread_db* tdbb = JRD_get_thread_data(); @@ -6964,7 +6964,7 @@ void dsql_req::append_meta_string(const char* string) // // Write out a string valued attribute. (Overload 1.) // -void dsql_req::append_string(UCHAR verb, const char* string, USHORT length) +void CompiledStatement::append_string(UCHAR verb, const char* string, USHORT length) { // TMN: Doesn't this look pretty awkward? If we are given // a verb, the length is a ushort, else it's uchar. @@ -6984,34 +6984,34 @@ void dsql_req::append_string(UCHAR verb, const char* string, USHORT length) } } -void dsql_req::append_uchars(UCHAR byte, UCHAR count) +void CompiledStatement::append_uchars(UCHAR byte, UCHAR count) { for (int i = 0; i < count; ++i) { append_uchar(byte); } } -void dsql_req::append_ushort_with_length(USHORT val) +void CompiledStatement::append_ushort_with_length(USHORT val) { // append an USHORT value, prepended with the USHORT length of an USHORT append_ushort(2); append_ushort(val); } -void dsql_req::append_ulong_with_length(ULONG val) +void CompiledStatement::append_ulong_with_length(ULONG val) { // append an ULONG value, prepended with the USHORT length of an ULONG append_ushort(4); append_ulong(val); } -void dsql_req::append_file_length(ULONG length) +void CompiledStatement::append_file_length(ULONG length) { append_uchar(isc_dyn_file_length); append_ulong_with_length(length); } -void dsql_req::append_file_start(ULONG start) +void CompiledStatement::append_file_start(ULONG start) { append_uchar(isc_dyn_file_start); append_ulong_with_length(start); @@ -7020,7 +7020,7 @@ void dsql_req::append_file_start(ULONG start) // // common code factored out // -void dsql_req::generate_unnamed_trigger_beginning( bool on_update_trigger, +void CompiledStatement::generate_unnamed_trigger_beginning( bool on_update_trigger, const char* prim_rel_name, const dsql_nod* prim_columns, const char* for_rel_name, @@ -7069,7 +7069,7 @@ void dsql_req::generate_unnamed_trigger_beginning( bool on_update_trigger, append_uchar(blr_begin); } -void dsql_req::begin_debug() +void CompiledStatement::begin_debug() { fb_assert(!req_debug_data.getCount()); @@ -7077,12 +7077,12 @@ void dsql_req::begin_debug() req_debug_data.add(1); } -void dsql_req::end_debug() +void CompiledStatement::end_debug() { req_debug_data.add(fb_dbg_end); } -void dsql_req::put_debug_src_info(USHORT line, USHORT col) +void CompiledStatement::put_debug_src_info(USHORT line, USHORT col) { req_debug_data.add(fb_dbg_map_src2blr); @@ -7094,7 +7094,7 @@ void dsql_req::put_debug_src_info(USHORT line, USHORT col) ULONG offset = (req_blr_data.getCount() - req_base_offset); - // for DDL requests we store BLR's length at the first 2 bytes + // for DDL statements we store BLR's length at the first 2 bytes if (req_type == REQ_DDL || req_ddl_node) { offset -= 2; } @@ -7102,7 +7102,7 @@ void dsql_req::put_debug_src_info(USHORT line, USHORT col) req_debug_data.add(offset >> 8); } -void dsql_req::put_debug_variable(USHORT number, const TEXT* name) +void CompiledStatement::put_debug_variable(USHORT number, const TEXT* name) { fb_assert(name); @@ -7120,7 +7120,7 @@ void dsql_req::put_debug_variable(USHORT number, const TEXT* name) req_debug_data.add(*name++); } -void dsql_req::put_debug_argument(UCHAR type, USHORT number, const TEXT* name) +void CompiledStatement::put_debug_argument(UCHAR type, USHORT number, const TEXT* name) { fb_assert(name); @@ -7139,7 +7139,7 @@ void dsql_req::put_debug_argument(UCHAR type, USHORT number, const TEXT* name) req_debug_data.add(*name++); } -void dsql_req::append_debug_info() +void CompiledStatement::append_debug_info() { end_debug(); diff --git a/src/dsql/ddl_proto.h b/src/dsql/ddl_proto.h index 71a89a5b3a..dc2de8c739 100644 --- a/src/dsql/ddl_proto.h +++ b/src/dsql/ddl_proto.h @@ -32,18 +32,19 @@ namespace Jrd { class dsql_req; + class CompiledStatement; class dsql_fld; class dsql_nod; class dsql_str; }; void DDL_execute(Jrd::dsql_req*); -void DDL_generate(Jrd::dsql_req*, Jrd::dsql_nod*); +void DDL_generate(Jrd::CompiledStatement*, Jrd::dsql_nod*); bool DDL_ids(const Jrd::dsql_req*); -void DDL_put_field_dtype(Jrd::dsql_req*, const Jrd::dsql_fld*, bool); -void DDL_resolve_intl_type(Jrd::dsql_req*, Jrd::dsql_fld*, const Jrd::dsql_str*); -void DDL_resolve_intl_type2(Jrd::dsql_req*, Jrd::dsql_fld*, const Jrd::dsql_str*, bool); -void DDL_gen_block(Jrd::dsql_req*, Jrd::dsql_nod*); +void DDL_put_field_dtype(Jrd::CompiledStatement*, const Jrd::dsql_fld*, bool); +void DDL_resolve_intl_type(Jrd::CompiledStatement*, Jrd::dsql_fld*, const Jrd::dsql_str*); +void DDL_resolve_intl_type2(Jrd::CompiledStatement*, Jrd::dsql_fld*, const Jrd::dsql_str*, bool); +void DDL_gen_block(Jrd::CompiledStatement*, Jrd::dsql_nod*); #endif // DSQL_DDL_PROTO_H diff --git a/src/dsql/dsql.cpp b/src/dsql/dsql.cpp index 7fbfcf6cda..8eac275dee 100644 --- a/src/dsql/dsql.cpp +++ b/src/dsql/dsql.cpp @@ -92,7 +92,7 @@ static bool get_rsb_item(SSHORT*, const SCHAR**, SSHORT*, SCHAR**, USHORT*, static dsql_dbb* init(Attachment*); static void map_in_out(dsql_req*, dsql_msg*, USHORT, const UCHAR*, USHORT, UCHAR*, const UCHAR* = 0); static USHORT parse_blr(USHORT, const UCHAR*, const USHORT, dsql_par*); -static dsql_req* prepare(thread_db*, dsql_req*, USHORT, const TEXT*, USHORT, USHORT); +static dsql_req* prepare(thread_db*, dsql_dbb*, jrd_tra*, USHORT, const TEXT*, USHORT, USHORT); static UCHAR* put_item(UCHAR, USHORT, const UCHAR*, UCHAR*, const UCHAR* const); static void release_request(thread_db*, dsql_req*, bool); static void sql_info(thread_db*, dsql_req*, USHORT, const UCHAR*, USHORT, UCHAR*); @@ -669,8 +669,6 @@ void DSQL_prepare(thread_db* tdbb, 0); } - Jrd::ContextPoolHolder context(tdbb, database->createPool()); - // check to see if old request has an open cursor if (old_request && (old_request->req_flags & REQ_cursor_open)) { @@ -686,10 +684,7 @@ void DSQL_prepare(thread_db* tdbb, /* Because that's the client's allocated statement handle and we don't want to trash the context in it -- 2001-Oct-27 Ann Harrison */ - MemoryPool& pool = *tdbb->getDefaultPool(); - dsql_req* request = FB_NEW(pool) dsql_req(pool); - request->req_dbb = database; - request->req_transaction = transaction; + dsql_req* request = NULL; try { @@ -737,9 +732,7 @@ void DSQL_prepare(thread_db* tdbb, dialect /= 10; } - request->req_client_dialect = dialect; - - request = prepare(tdbb, request, length, string, dialect, parser_version); + request = prepare(tdbb, database, transaction, length, string, dialect, parser_version); // Can not prepare a CREATE DATABASE/SCHEMA statement @@ -754,16 +747,22 @@ void DSQL_prepare(thread_db* tdbb, // Now that we know that the new request exists, zap the old one. { - Jrd::ContextPoolHolder another_context(tdbb, &old_request->req_pool); + Jrd::ContextPoolHolder context(tdbb, &old_request->req_pool); release_request(tdbb, old_request, true); } *req_handle = request; + Jrd::ContextPoolHolder context(tdbb, &request->req_pool); sql_info(tdbb, request, item_length, items, buffer_length, buffer); } - catch (const Firebird::Exception&) { - release_request(tdbb, request, true); + catch (const Firebird::Exception&) + { + if (request) + { + Jrd::ContextPoolHolder context(tdbb, &request->req_pool); + release_request(tdbb, request, true); + } throw; } } @@ -1093,14 +1092,8 @@ static void execute_immediate(thread_db* tdbb, SET_TDBB(tdbb); dsql_dbb* const database = init(attachment); - Jrd::ContextPoolHolder context(tdbb, database->createPool()); - // allocate the request block, then prepare the request - - MemoryPool& pool = *tdbb->getDefaultPool(); - dsql_req* request = FB_NEW(pool) dsql_req(pool); - request->req_dbb = database; - request->req_transaction = *tra_handle; + dsql_req* request = NULL; try { @@ -1140,9 +1133,9 @@ static void execute_immediate(thread_db* tdbb, dialect /= 10; } - request->req_client_dialect = dialect; + request = prepare(tdbb, database, *tra_handle, length, string, dialect, parser_version); - request = prepare(tdbb, request, length, string, dialect, parser_version); + Jrd::ContextPoolHolder context(tdbb, &request->req_pool); execute_request(tdbb, request, tra_handle, in_blr_length, in_blr, in_msg_length, in_msg, out_blr_length, out_blr, @@ -1150,8 +1143,13 @@ static void execute_immediate(thread_db* tdbb, release_request(tdbb, request, true); } - catch (const Firebird::Exception&) { - release_request(tdbb, request, true); + catch (const Firebird::Exception&) + { + if (request) + { + Jrd::ContextPoolHolder context(tdbb, &request->req_pool); + release_request(tdbb, request, true); + } throw; } } @@ -2485,8 +2483,7 @@ static USHORT parse_blr( @param parser_version **/ -static dsql_req* prepare(thread_db* tdbb, - dsql_req* request, +static dsql_req* prepare(thread_db* tdbb, dsql_dbb* database, jrd_tra* transaction, USHORT string_length, const TEXT* string, USHORT client_dialect, USHORT parser_version) @@ -2514,9 +2511,21 @@ static dsql_req* prepare(thread_db* tdbb, } } + // allocate the statement block, then prepare the statement + + Jrd::ContextPoolHolder context(tdbb, database->createPool()); + + MemoryPool& pool = *tdbb->getDefaultPool(); + CompiledStatement* statement = FB_NEW(pool) CompiledStatement(pool); + statement->req_dbb = database; + statement->req_transaction = transaction; + statement->req_client_dialect = client_dialect; + + try { + // Parse the SQL statement. If it croaks, return - Parser parser(*tdbb->getDefaultPool(), client_dialect, request->req_dbb->dbb_db_SQL_dialect, + Parser parser(*tdbb->getDefaultPool(), client_dialect, statement->req_dbb->dbb_db_SQL_dialect, parser_version, string, string_length, tdbb->getAttachment()->att_charset); dsql_nod* node = parser.parse(); @@ -2531,95 +2540,94 @@ static dsql_req* prepare(thread_db* tdbb, 0); } -// allocate the send and receive messages + // allocate the send and receive messages - MemoryPool& pool = *tdbb->getDefaultPool(); - request->req_send = FB_NEW(pool) dsql_msg; + statement->req_send = FB_NEW(pool) dsql_msg; dsql_msg* message = FB_NEW(pool) dsql_msg; - request->req_receive = message; + statement->req_receive = message; message->msg_number = 1; #ifdef SCROLLABLE_CURSORS - if (request->req_dbb->dbb_base_level >= 5) { + if (statement->req_dbb->dbb_base_level >= 5) { /* allocate a message in which to send scrolling information outside of the normal send/receive protocol */ - request->req_async = message = FB_NEW(*tdsql->getDefaultPool()) dsql_msg; + statement->req_async = message = FB_NEW(*tdsql->getDefaultPool()) dsql_msg; message->msg_number = 2; } #endif - request->req_type = REQ_SELECT; - request->req_flags &= ~REQ_cursor_open; + statement->req_type = REQ_SELECT; + statement->req_flags &= ~REQ_cursor_open; -/* - * No work is done during pass1 for set transaction - like - * checking for valid table names. This is because that will - * require a valid transaction handle. - * Error will be caught at execute time. - */ + /* + * No work is done during pass1 for set transaction - like + * checking for valid table names. This is because that will + * require a valid transaction handle. + * Error will be caught at execute time. + */ - node = PASS1_statement(request, node); + node = PASS1_statement(statement, node); if (!node) - return request; + return statement; -// stop here for requests not requiring code generation + // stop here for statements not requiring code generation - if (request->req_type == REQ_DDL && parser.isStmtAmbiguous() && - request->req_dbb->dbb_db_SQL_dialect != client_dialect) + if (statement->req_type == REQ_DDL && parser.isStmtAmbiguous() && + statement->req_dbb->dbb_db_SQL_dialect != client_dialect) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 817, isc_arg_gds, isc_ddl_not_allowed_by_db_sql_dial, isc_arg_number, - (SLONG) request->req_dbb->dbb_db_SQL_dialect, 0); + (SLONG) statement->req_dbb->dbb_db_SQL_dialect, 0); } - if (request->req_type == REQ_COMMIT || - request->req_type == REQ_COMMIT_RETAIN || - request->req_type == REQ_ROLLBACK || - request->req_type == REQ_ROLLBACK_RETAIN) + if (statement->req_type == REQ_COMMIT || + statement->req_type == REQ_COMMIT_RETAIN || + statement->req_type == REQ_ROLLBACK || + statement->req_type == REQ_ROLLBACK_RETAIN) { - return request; + return statement; } -// Work on blob segment requests + // Work on blob segment statements - if (request->req_type == REQ_GET_SEGMENT || - request->req_type == REQ_PUT_SEGMENT) + if (statement->req_type == REQ_GET_SEGMENT || + statement->req_type == REQ_PUT_SEGMENT) { - GEN_port(request, request->req_blob->blb_open_in_msg); - GEN_port(request, request->req_blob->blb_open_out_msg); - GEN_port(request, request->req_blob->blb_segment_msg); - return request; + GEN_port(statement, statement->req_blob->blb_open_in_msg); + GEN_port(statement, statement->req_blob->blb_open_out_msg); + GEN_port(statement, statement->req_blob->blb_segment_msg); + return statement; } -// Generate BLR, DDL or TPB for request + // Generate BLR, DDL or TPB for statement -// Start transactions takes parameters via a parameter block. -// The request blr string is used for that + // Start transactions takes parameters via a parameter block. + // The statement blr string is used for that - if (request->req_type == REQ_START_TRANS) { - GEN_start_transaction(request, node); - return request; + if (statement->req_type == REQ_START_TRANS) { + GEN_start_transaction(statement, node); + return statement; } if (client_dialect > SQL_DIALECT_V5) - request->req_flags |= REQ_blr_version5; + statement->req_flags |= REQ_blr_version5; else - request->req_flags |= REQ_blr_version4; + statement->req_flags |= REQ_blr_version4; - GEN_request(request, node); - const USHORT length = request->req_blr_data.getCount(); + GEN_request(statement, node); + const USHORT length = statement->req_blr_data.getCount(); -// stop here for ddl requests + // stop here for ddl statements - if (request->req_type == REQ_CREATE_DB || - request->req_type == REQ_DDL) + if (statement->req_type == REQ_CREATE_DB || + statement->req_type == REQ_DDL) { - return request; + return statement; } -// have the access method compile the request + // have the access method compile the statement #ifdef DSQL_DEBUG if (DSQL_debug & 64) { @@ -2627,12 +2635,12 @@ static dsql_req* prepare(thread_db* tdbb, gds__trace_raw("Statement:\n"); gds__trace_raw(string, string_length); gds__trace_raw("\nBLR:\n"); - gds__print_blr(request->req_blr_data.begin(), + gds__print_blr(statement->req_blr_data.begin(), gds__trace_printer, 0, 0); } #endif -// check for warnings + // check for warnings if (tdbb->tdbb_status_vector[2] == isc_arg_warning) { // save a status vector memcpy(local_status, tdbb->tdbb_status_vector, sizeof(ISC_STATUS_ARRAY)); @@ -2643,21 +2651,21 @@ static dsql_req* prepare(thread_db* tdbb, try { JRD_compile(tdbb, - request->req_dbb->dbb_attachment, - &request->req_request, + statement->req_dbb->dbb_attachment, + &statement->req_request, length, - request->req_blr_data.begin(), + statement->req_blr_data.begin(), string_length, string, - request->req_debug_data.getCount(), - request->req_debug_data.begin()); + statement->req_debug_data.getCount(), + statement->req_debug_data.begin()); } catch (const Firebird::Exception&) { status = tdbb->tdbb_status_vector[1]; } -// restore warnings (if there are any) + // restore warnings (if there are any) if (local_status[2] == isc_arg_warning) { int indx, len, warning; @@ -2675,13 +2683,20 @@ static dsql_req* prepare(thread_db* tdbb, memcpy(&tdbb->tdbb_status_vector[indx], &local_status[2], sizeof(ISC_STATUS) * len); } -// free blr memory - request->req_blr_data.free(); + // free blr memory + statement->req_blr_data.free(); if (status) Firebird::status_exception::raise(tdbb->tdbb_status_vector); - return request; + return statement; + + } + catch (const Firebird::Exception&) + { + release_request(tdbb, statement, true); + throw; + } } diff --git a/src/dsql/dsql.h b/src/dsql/dsql.h index 531cd68cf0..cca017cabc 100644 --- a/src/dsql/dsql.h +++ b/src/dsql/dsql.h @@ -366,8 +366,83 @@ enum REQ_TYPE REQ_EXEC_BLOCK, REQ_SELECT_BLOCK }; + class dsql_req : public pool_alloc { +public: + explicit dsql_req(MemoryPool& p) + : req_pool(p), + req_blr_data(p) + { + } + + dsql_req* req_parent; //!< Source request, if cursor update + dsql_req* req_sibling; //!< Next sibling request, if cursor update + dsql_req* req_offspring; //!< Cursor update requests + MemoryPool& req_pool; + + dsql_sym* req_name; //!< Name of request + dsql_sym* req_cursor; //!< Cursor symbol, if any + dsql_dbb* req_dbb; //!< DSQL attachment + jrd_tra* req_transaction; //!< JRD transaction + dsql_nod* req_ddl_node; //!< Store metadata request + class dsql_blb* req_blob; //!< Blob info for blob requests + jrd_req* req_request; //!< JRD request + //dsql_str* req_blr_string; //!< String block during BLR generation + Firebird::HalfStaticArray req_blr_data; + class dsql_msg* req_send; //!< Message to be sent to start request + class dsql_msg* req_receive; //!< Per record message to be received + class dsql_msg* req_async; //!< Message for sending scrolling information + dsql_par* req_eof; //!< End of file parameter + dsql_par* req_dbkey; //!< Database key for current of + dsql_par* req_rec_version; //!< Record Version for current of + dsql_par* req_parent_rec_version; //!< parent record version + dsql_par* req_parent_dbkey; //!< Parent database key for current of + //BLOB_PTR* req_blr; //!< Running blr address + //BLOB_PTR* req_blr_yellow; //!< Threshold for upping blr buffer size + ULONG req_inserts; //!< records processed in request + ULONG req_deletes; + ULONG req_updates; + ULONG req_selects; + REQ_TYPE req_type; //!< Type of request + ULONG req_flags; //!< generic flag + +protected: + // Request should never be destroyed using delete. + // It dies together with it's pool in release_request(). + ~dsql_req() + { + } + + // To avoid posix warning about missing public destructor declare + // MemoryPool as friend class. In fact IT releases request memory! + friend class MemoryPool; +}; + + +class CompiledStatement : public dsql_req +{ +public: + explicit CompiledStatement(MemoryPool& p) + : dsql_req(p), + req_debug_data(p), + req_main_context(p), + req_context(&req_main_context), + req_union_context(p), + req_dt_context(p), + req_labels(p), + req_cursors(p), + req_curr_ctes(p), + req_ctes(p), + req_cte_aliases(p) + { + } + +protected: + // Request should never be destroyed using delete. + // It dies together with it's pool in release_request(). + ~CompiledStatement(); + public: // begin - member functions that should be private void append_uchar(UCHAR byte); @@ -400,77 +475,6 @@ public: void append_debug_info(); // end - member functions that should be private - explicit dsql_req(MemoryPool& p) - : req_pool(p), - req_main_context(p), - req_context(&req_main_context), - req_union_context(p), - req_dt_context(p), - req_blr_data(p), - req_labels(p), - req_cursors(p), - req_debug_data(p), - req_curr_ctes(p), - req_ctes(p), - req_cte_aliases(p) { } - - dsql_req* req_parent; //!< Source request, if cursor update - dsql_req* req_sibling; //!< Next sibling request, if cursor update - dsql_req* req_offspring; //!< Cursor update requests - MemoryPool& req_pool; - DsqlContextStack req_main_context; - DsqlContextStack* req_context; - DsqlContextStack req_union_context; //!< Save contexts for views of unions - DsqlContextStack req_dt_context; //!< Save contexts for views of derived tables - dsql_sym* req_name; //!< Name of request - dsql_sym* req_cursor; //!< Cursor symbol, if any - dsql_dbb* req_dbb; //!< DSQL attachment - jrd_tra* req_transaction; //!< JRD transaction - dsql_nod* req_ddl_node; //!< Store metadata request - dsql_nod* req_blk_node; //!< exec_block node - class dsql_blb* req_blob; //!< Blob info for blob requests - jrd_req* req_request; //!< JRD request - //dsql_str* req_blr_string; //!< String block during BLR generation - Firebird::HalfStaticArray req_blr_data; - class dsql_msg* req_send; //!< Message to be sent to start request - class dsql_msg* req_receive; //!< Per record message to be received - class dsql_msg* req_async; //!< Message for sending scrolling information - dsql_par* req_eof; //!< End of file parameter - dsql_par* req_dbkey; //!< Database key for current of - dsql_par* req_rec_version; //!< Record Version for current of - dsql_par* req_parent_rec_version; //!< parent record version - dsql_par* req_parent_dbkey; //!< Parent database key for current of - dsql_rel* req_relation; //!< relation created by this request (for DDL) - dsql_prc* req_procedure; //!< procedure created by this request (for DDL) - class dsql_ctx* req_outer_agg_context; //!< agg context for outer ref - //BLOB_PTR* req_blr; //!< Running blr address - //BLOB_PTR* req_blr_yellow; //!< Threshold for upping blr buffer size - ULONG req_inserts; //!< records processed in request - ULONG req_deletes; - ULONG req_updates; - ULONG req_selects; - REQ_TYPE req_type; //!< Type of request - ULONG req_base_offset; //!< place to go back and stuff in blr length - USHORT req_context_number; //!< Next available context number - USHORT req_scope_level; //!< Scope level for parsing aliases in subqueries - //USHORT req_message_number; //!< Next available message number - USHORT req_loop_level; //!< Loop level - DsqlStrStack req_labels; //!< Loop labels - USHORT req_cursor_number; //!< Cursor number - DsqlNodStack req_cursors; //!< Cursors - USHORT req_in_select_list; //!< now processing "select list" - USHORT req_in_where_clause; //!< processing "where clause" - USHORT req_in_group_by_clause; //!< processing "group by clause" - USHORT req_in_having_clause; //!< processing "having clause" - USHORT req_in_order_by_clause; //!< processing "order by clause" - USHORT req_error_handlers; //!< count of active error handlers - ULONG req_flags; //!< generic flag - USHORT req_client_dialect; //!< dialect passed into the API call - USHORT req_in_outer_join; //!< processing inside outer-join part - dsql_str* req_alias_relation_prefix; //!< prefix for every relation-alias. - - Firebird::HalfStaticArray req_debug_data; - void addCTEs(dsql_nod* list); dsql_nod* findCTE(const dsql_str* name); void clearCTEs(); @@ -505,40 +509,59 @@ public: psql = value; } + dsql_nod* req_blk_node; //!< exec_block node + dsql_rel* req_relation; //!< relation created by this request (for DDL) + dsql_prc* req_procedure; //!< procedure created by this request (for DDL) + Firebird::HalfStaticArray req_debug_data; + DsqlContextStack req_main_context; + DsqlContextStack* req_context; + DsqlContextStack req_union_context; //!< Save contexts for views of unions + DsqlContextStack req_dt_context; //!< Save contexts for views of derived tables + class dsql_ctx* req_outer_agg_context; //!< agg context for outer ref + ULONG req_base_offset; //!< place to go back and stuff in blr length + USHORT req_context_number; //!< Next available context number + USHORT req_scope_level; //!< Scope level for parsing aliases in subqueries + //USHORT req_message_number; //!< Next available message number + USHORT req_loop_level; //!< Loop level + DsqlStrStack req_labels; //!< Loop labels + USHORT req_cursor_number; //!< Cursor number + DsqlNodStack req_cursors; //!< Cursors + USHORT req_in_select_list; //!< now processing "select list" + USHORT req_in_where_clause; //!< processing "where clause" + USHORT req_in_group_by_clause; //!< processing "group by clause" + USHORT req_in_having_clause; //!< processing "having clause" + USHORT req_in_order_by_clause; //!< processing "order by clause" + USHORT req_error_handlers; //!< count of active error handlers + USHORT req_client_dialect; //!< dialect passed into the API call + USHORT req_in_outer_join; //!< processing inside outer-join part + dsql_str* req_alias_relation_prefix; //!< prefix for every relation-alias. + DsqlNodStack req_curr_ctes; // current processing CTE's class dsql_ctx* req_recursive_ctx; // context of recursive CTE USHORT req_recursive_ctx_id; // id of recursive union stream context private: - // Request should never be destroyed using delete. - // It dies together with it's pool in release_request(). - ~dsql_req(); - Firebird::HalfStaticArray req_ctes; // common table expressions Firebird::HalfStaticArray req_cte_aliases; // CTE aliases in recursive members const dsql_str* const* req_curr_cte_alias; bool psql; - - // To avoid posix warning about missing public destructor declare - // MemoryPool as friend class. In fact IT releases request memory! - friend class MemoryPool; }; class PsqlChanger { public: - PsqlChanger(dsql_req* aRequest, bool value) - : request(aRequest) + PsqlChanger(CompiledStatement* aStatement, bool value) + : statement(aStatement) { - oldValue = request->isPsql(); - request->setPsql(value); + oldValue = statement->isPsql(); + statement->setPsql(value); } ~PsqlChanger() { - request->setPsql(oldValue); + statement->setPsql(oldValue); } private: @@ -546,7 +569,7 @@ private: PsqlChanger(const PsqlChanger&); PsqlChanger& operator =(const PsqlChanger&); - dsql_req* request; + CompiledStatement* statement; bool oldValue; }; diff --git a/src/dsql/gen.cpp b/src/dsql/gen.cpp index c67410c91d..5433805926 100644 --- a/src/dsql/gen.cpp +++ b/src/dsql/gen.cpp @@ -60,37 +60,37 @@ using namespace Jrd; using namespace Dsql; -static void gen_aggregate(dsql_req*, const dsql_nod*); -static void gen_cast(dsql_req*, const dsql_nod*); -static void gen_coalesce(dsql_req*, const dsql_nod*); -static void gen_constant(dsql_req*, const dsc*, bool); -static void gen_constant(dsql_req*, dsql_nod*, bool); -static void gen_descriptor(dsql_req*, const dsc*, bool); -static void gen_error_condition(dsql_req*, const dsql_nod*); -static void gen_field(dsql_req*, const dsql_ctx*, const dsql_fld*, dsql_nod*); -static void gen_for_select(dsql_req*, const dsql_nod*); -static void gen_gen_id(dsql_req*, const dsql_nod*); -static void gen_join_rse(dsql_req*, const dsql_nod*); -static void gen_map(dsql_req*, dsql_map*); -static void gen_parameter(dsql_req*, const dsql_par*); -static void gen_plan(dsql_req*, const dsql_nod*); -static void gen_relation(dsql_req*, dsql_ctx*); -static void gen_rse(dsql_req*, const dsql_nod*); -static void gen_searched_case(dsql_req*, const dsql_nod*); -static void gen_select(dsql_req*, dsql_nod*); -static void gen_simple_case(dsql_req*, const dsql_nod*); -static void gen_sort(dsql_req*, dsql_nod*); -static void gen_statement(dsql_req*, const dsql_nod*); -static void gen_sys_function(dsql_req*, const dsql_nod*); -static void gen_table_lock(dsql_req*, const dsql_nod*, USHORT); -static void gen_udf(dsql_req*, const dsql_nod*); -static void gen_union(dsql_req*, const dsql_nod*); -static void stuff_context(dsql_req*, const dsql_ctx*); -static void stuff_cstring(dsql_req*, const char*); -static void stuff_meta_string(dsql_req*, const char*); -static void stuff_string(dsql_req*, const char*, int); -static void stuff_string(dsql_req* request, const Firebird::MetaName& name); -static void stuff_word(dsql_req*, USHORT); +static void gen_aggregate(CompiledStatement*, const dsql_nod*); +static void gen_cast(CompiledStatement*, const dsql_nod*); +static void gen_coalesce(CompiledStatement*, const dsql_nod*); +static void gen_constant(CompiledStatement*, const dsc*, bool); +static void gen_constant(CompiledStatement*, dsql_nod*, bool); +static void gen_descriptor(CompiledStatement*, const dsc*, bool); +static void gen_error_condition(CompiledStatement*, const dsql_nod*); +static void gen_field(CompiledStatement*, const dsql_ctx*, const dsql_fld*, dsql_nod*); +static void gen_for_select(CompiledStatement*, const dsql_nod*); +static void gen_gen_id(CompiledStatement*, const dsql_nod*); +static void gen_join_rse(CompiledStatement*, const dsql_nod*); +static void gen_map(CompiledStatement*, dsql_map*); +static void gen_parameter(CompiledStatement*, const dsql_par*); +static void gen_plan(CompiledStatement*, const dsql_nod*); +static void gen_relation(CompiledStatement*, dsql_ctx*); +static void gen_rse(CompiledStatement*, const dsql_nod*); +static void gen_searched_case(CompiledStatement*, const dsql_nod*); +static void gen_select(CompiledStatement*, dsql_nod*); +static void gen_simple_case(CompiledStatement*, const dsql_nod*); +static void gen_sort(CompiledStatement*, dsql_nod*); +static void gen_statement(CompiledStatement*, const dsql_nod*); +static void gen_sys_function(CompiledStatement*, const dsql_nod*); +static void gen_table_lock(CompiledStatement*, const dsql_nod*, USHORT); +static void gen_udf(CompiledStatement*, const dsql_nod*); +static void gen_union(CompiledStatement*, const dsql_nod*); +static void stuff_context(CompiledStatement*, const dsql_ctx*); +static void stuff_cstring(CompiledStatement*, const char*); +static void stuff_meta_string(CompiledStatement*, const char*); +static void stuff_string(CompiledStatement*, const char*, int); +static void stuff_string(CompiledStatement* statement, const Firebird::MetaName& name); +static void stuff_word(CompiledStatement*, USHORT); // STUFF is defined in dsql.h for use in common with ddl.c @@ -106,11 +106,11 @@ const bool USE_VALUE = false; @brief Generate blr for an arbitrary expression. - @param request + @param statement @param node **/ -void GEN_expr( dsql_req* request, dsql_nod* node) +void GEN_expr( CompiledStatement* statement, dsql_nod* node) { UCHAR blr_operator; dsql_ctx* context; @@ -119,62 +119,62 @@ void GEN_expr( dsql_req* request, dsql_nod* node) switch (node->nod_type) { case nod_alias: - GEN_expr(request, node->nod_arg[e_alias_value]); + GEN_expr(statement, node->nod_arg[e_alias_value]); return; case nod_aggregate: - gen_aggregate(request, node); + gen_aggregate(statement, node); return; case nod_constant: - gen_constant(request, node, USE_VALUE); + gen_constant(statement, node, USE_VALUE); return; case nod_derived_field: - GEN_expr(request, node->nod_arg[e_derived_field_value]); + GEN_expr(statement, node->nod_arg[e_derived_field_value]); return; case nod_extract: - stuff(request, blr_extract); - stuff(request, node->nod_arg[e_extract_part]->getSlong()); - GEN_expr(request, node->nod_arg[e_extract_value]); + stuff(statement, blr_extract); + stuff(statement, node->nod_arg[e_extract_part]->getSlong()); + GEN_expr(statement, node->nod_arg[e_extract_value]); return; case nod_strlen: - stuff(request, blr_strlen); - stuff(request, node->nod_arg[e_strlen_type]->getSlong()); - GEN_expr(request, node->nod_arg[e_strlen_value]); + stuff(statement, blr_strlen); + stuff(statement, node->nod_arg[e_strlen_type]->getSlong()); + GEN_expr(statement, node->nod_arg[e_strlen_value]); return; case nod_dbkey: node = node->nod_arg[0]; context = (dsql_ctx*) node->nod_arg[e_rel_context]; - stuff(request, blr_dbkey); - stuff_context(request, context); + stuff(statement, blr_dbkey); + stuff_context(statement, context); return; case nod_rec_version: node = node->nod_arg[0]; context = (dsql_ctx*) node->nod_arg[e_rel_context]; - stuff(request, blr_record_version); - stuff_context(request, context); + stuff(statement, blr_record_version); + stuff_context(statement, context); return; case nod_dom_value: - stuff(request, blr_fid); - stuff(request, 0); // Context - stuff_word(request, 0); // Field id + stuff(statement, blr_fid); + stuff(statement, 0); // Context + stuff_word(statement, 0); // Field id return; case nod_field: - gen_field(request, + gen_field(statement, (dsql_ctx*) node->nod_arg[e_fld_context], (dsql_fld*) node->nod_arg[e_fld_field], node->nod_arg[e_fld_indices]); return; case nod_user_name: - stuff(request, blr_user_name); + stuff(statement, blr_user_name); return; case nod_current_time: @@ -182,11 +182,11 @@ void GEN_expr( dsql_req* request, dsql_nod* node) const dsql_nod* const_node = node->nod_arg[0]; fb_assert(const_node->nod_type == nod_constant); const int precision = (int) const_node->getSlong(); - stuff(request, blr_current_time2); - stuff(request, precision); + stuff(statement, blr_current_time2); + stuff(statement, precision); } else { - stuff(request, blr_current_time); + stuff(statement, blr_current_time); } return; @@ -195,80 +195,80 @@ void GEN_expr( dsql_req* request, dsql_nod* node) const dsql_nod* const_node = node->nod_arg[0]; fb_assert(const_node->nod_type == nod_constant); const int precision = (int) const_node->getSlong(); - stuff(request, blr_current_timestamp2); - stuff(request, precision); + stuff(statement, blr_current_timestamp2); + stuff(statement, precision); } else { - stuff(request, blr_current_timestamp); + stuff(statement, blr_current_timestamp); } return; case nod_current_date: - stuff(request, blr_current_date); + stuff(statement, blr_current_date); return; case nod_current_role: - stuff(request, blr_current_role); + stuff(statement, blr_current_role); return; case nod_udf: - gen_udf(request, node); + gen_udf(statement, node); return; case nod_sys_function: - gen_sys_function(request, node); + gen_sys_function(statement, node); return; case nod_variable: variable = (dsql_var*) node->nod_arg[e_var_variable]; if (variable->var_type == VAR_input) { - stuff(request, blr_parameter2); - stuff(request, variable->var_msg_number); - stuff_word(request, variable->var_msg_item); - stuff_word(request, variable->var_msg_item + 1); + stuff(statement, blr_parameter2); + stuff(statement, variable->var_msg_number); + stuff_word(statement, variable->var_msg_item); + stuff_word(statement, variable->var_msg_item + 1); } else { - stuff(request, blr_variable); - stuff_word(request, variable->var_variable_number); + stuff(statement, blr_variable); + stuff_word(statement, variable->var_variable_number); } return; case nod_join: - gen_join_rse(request, node); + gen_join_rse(statement, node); return; case nod_map: map = (dsql_map*) node->nod_arg[e_map_map]; context = (dsql_ctx*) node->nod_arg[e_map_context]; - stuff(request, blr_fid); - stuff_context(request, context); - stuff_word(request, map->map_position); + stuff(statement, blr_fid); + stuff_context(statement, context); + stuff_word(statement, map->map_position); return; case nod_parameter: - gen_parameter(request, (dsql_par*) node->nod_arg[e_par_parameter]); + gen_parameter(statement, (dsql_par*) node->nod_arg[e_par_parameter]); return; case nod_relation: - gen_relation(request, (dsql_ctx*) node->nod_arg[e_rel_context]); + gen_relation(statement, (dsql_ctx*) node->nod_arg[e_rel_context]); return; case nod_rse: - gen_rse(request, node); + gen_rse(statement, node); return; case nod_derived_table: - gen_rse(request, node->nod_arg[e_derived_table_rse]); + gen_rse(statement, node->nod_arg[e_derived_table_rse]); return; case nod_exists: - stuff(request, blr_any); - gen_rse(request, node->nod_arg[0]); + stuff(statement, blr_any); + gen_rse(statement, node->nod_arg[0]); return; case nod_singular: - stuff(request, blr_unique); - gen_rse(request, node->nod_arg[0]); + stuff(statement, blr_unique); + gen_rse(statement, node->nod_arg[0]); return; case nod_agg_count: @@ -360,17 +360,17 @@ void GEN_expr( dsql_req* request, dsql_nod* node) blr_operator = blr_containing; break; case nod_similar: - stuff(request, blr_similar); - GEN_expr(request, node->nod_arg[e_similar_value]); - GEN_expr(request, node->nod_arg[e_similar_pattern]); + stuff(statement, blr_similar); + GEN_expr(statement, node->nod_arg[e_similar_value]); + GEN_expr(statement, node->nod_arg[e_similar_pattern]); if (node->nod_arg[e_similar_escape]) { - stuff(request, 1); - GEN_expr(request, node->nod_arg[e_similar_escape]); + stuff(statement, 1); + GEN_expr(statement, node->nod_arg[e_similar_escape]); } else - stuff(request, 0); + stuff(statement, 0); return; @@ -401,7 +401,7 @@ void GEN_expr( dsql_req* request, dsql_nod* node) if (child->nod_type == nod_constant && DTYPE_IS_NUMERIC(child->nod_desc.dsc_dtype)) { - gen_constant(request, child, NEGATE_VALUE); + gen_constant(statement, child, NEGATE_VALUE); return; } } @@ -455,20 +455,20 @@ void GEN_expr( dsql_req* request, dsql_nod* node) blr_operator = blr_substring; break; case nod_cast: - gen_cast(request, node); + gen_cast(statement, node); return; case nod_gen_id: case nod_gen_id2: - gen_gen_id(request, node); + gen_gen_id(statement, node); return; case nod_coalesce: - gen_coalesce(request, node); + gen_coalesce(statement, node); return; case nod_simple_case: - gen_simple_case(request, node); + gen_simple_case(statement, node); return; case nod_searched_case: - gen_searched_case(request, node); + gen_searched_case(statement, node); return; case nod_average: //case nod_count: @@ -503,25 +503,25 @@ void GEN_expr( dsql_req* request, dsql_nod* node) break; } - stuff(request, blr_operator); - gen_rse(request, node->nod_arg[0]); + stuff(statement, blr_operator); + gen_rse(statement, node->nod_arg[0]); if (blr_operator != blr_count) - GEN_expr(request, node->nod_arg[0]->nod_arg[e_rse_items]); + GEN_expr(statement, node->nod_arg[0]->nod_arg[e_rse_items]); return; case nod_trim: - stuff(request, blr_trim); - stuff(request, node->nod_arg[e_trim_specification]->getSlong()); + stuff(statement, blr_trim); + stuff(statement, node->nod_arg[e_trim_specification]->getSlong()); if (node->nod_arg[e_trim_characters]) { - stuff(request, blr_trim_characters); - GEN_expr(request, node->nod_arg[e_trim_characters]); + stuff(statement, blr_trim_characters); + GEN_expr(statement, node->nod_arg[e_trim_characters]); } else - stuff(request, blr_trim_spaces); + stuff(statement, blr_trim_spaces); - GEN_expr(request, node->nod_arg[e_trim_value]); + GEN_expr(statement, node->nod_arg[e_trim_value]); return; default: @@ -532,13 +532,13 @@ void GEN_expr( dsql_req* request, dsql_nod* node) 0); } - stuff(request, blr_operator); + stuff(statement, blr_operator); dsql_nod* const* ptr = node->nod_arg; for (const dsql_nod* const* const end = ptr + node->nod_count; ptr < end; ptr++) { - GEN_expr(request, *ptr); + GEN_expr(statement, *ptr); } /* Check whether the node we just processed is for a dialect 3 @@ -557,9 +557,9 @@ void GEN_expr( dsql_req* request, dsql_nod* node) const char* s = 0; char message_buf[8]; - MAKE_desc(request, &desc, node, NULL); + MAKE_desc(statement, &desc, node, NULL); if ((node->nod_flags & NOD_COMP_DIALECT) && - (request->req_client_dialect == SQL_DIALECT_V6_TRANSITION)) + (statement->req_client_dialect == SQL_DIALECT_V6_TRANSITION)) { switch (node->nod_type) { case nod_add2: @@ -599,19 +599,19 @@ void GEN_expr( dsql_req* request, dsql_nod* node) order of parameters. - @param request + @param statement @param message **/ -void GEN_port(dsql_req* request, dsql_msg* message) +void GEN_port(CompiledStatement* statement, dsql_msg* message) { thread_db* tdbb = JRD_get_thread_data(); Attachment* att = tdbb->getAttachment(); -// if (request->req_blr_string) { - stuff(request, blr_message); - stuff(request, message->msg_number); - stuff_word(request, message->msg_parameter); +// if (statement->req_blr_string) { + stuff(statement, blr_message); + stuff(statement, message->msg_number); + stuff_word(statement, message->msg_parameter); // } dsql_par* parameter; @@ -638,8 +638,8 @@ void GEN_port(dsql_req* request, dsql_msg* message) parameter->par_desc.dsc_length -= adjust; - USHORT fromCharSetBPC = METD_get_charset_bpc(request, fromCharSet); - USHORT toCharSetBPC = METD_get_charset_bpc(request, toCharSet); + USHORT fromCharSetBPC = METD_get_charset_bpc(statement, fromCharSet); + USHORT toCharSetBPC = METD_get_charset_bpc(statement, toCharSet); INTL_ASSIGN_TTYPE(¶meter->par_desc, INTL_CS_COLL_TO_TTYPE(toCharSet, (fromCharSet == toCharSet ? INTL_GET_COLLATE(¶meter->par_desc) : 0))); @@ -649,8 +649,8 @@ void GEN_port(dsql_req* request, dsql_msg* message) parameter->par_desc.dsc_length += adjust; } - else if (ENCODE_ODS(request->req_dbb->dbb_ods_version, - request->req_dbb->dbb_minor_version) >= ODS_11_1 && + else if (ENCODE_ODS(statement->req_dbb->dbb_ods_version, + statement->req_dbb->dbb_minor_version) >= ODS_11_1 && parameter->par_desc.dsc_dtype == dtype_blob && parameter->par_desc.dsc_sub_type == isc_blob_text && att->att_charset != CS_NONE && @@ -662,7 +662,7 @@ void GEN_port(dsql_req* request, dsql_msg* message) /* For older clients - generate an error should they try and access data types which did not exist in the older dialect */ - if (request->req_client_dialect <= SQL_DIALECT_V5) + if (statement->req_client_dialect <= SQL_DIALECT_V5) switch (parameter->par_desc.dsc_dtype) { /* In V6.0 - older clients, which we distinguish by @@ -674,7 +674,7 @@ void GEN_port(dsql_req* request, dsql_msg* message) ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 804, isc_arg_gds, isc_dsql_datatype_err, isc_arg_gds, isc_sql_dialect_datatype_unsupport, - isc_arg_number, (SLONG) request->req_client_dialect, + isc_arg_number, (SLONG) statement->req_client_dialect, isc_arg_string, DSC_dtype_tostring(parameter->par_desc.dsc_dtype), 0); @@ -688,8 +688,8 @@ void GEN_port(dsql_req* request, dsql_msg* message) offset = FB_ALIGN(offset, align); parameter->par_desc.dsc_address = (UCHAR*)(IPTR) offset; offset += parameter->par_desc.dsc_length; -// if (request->req_blr_string) - gen_descriptor(request, ¶meter->par_desc, false); +// if (statement->req_blr_string) + gen_descriptor(statement, ¶meter->par_desc, false); } if (offset > MAX_FORMAT_SIZE) { @@ -721,72 +721,72 @@ void GEN_port(dsql_req* request, dsql_msg* message) GEN_request - @brief Generate complete blr for a request. + @brief Generate complete blr for a statement. - @param request + @param statement @param node **/ -void GEN_request( dsql_req* request, dsql_nod* node) +void GEN_request( CompiledStatement* statement, dsql_nod* node) { - if (request->req_type == REQ_CREATE_DB || - request->req_type == REQ_DDL) + if (statement->req_type == REQ_CREATE_DB || + statement->req_type == REQ_DDL) { - DDL_generate(request, node); + DDL_generate(statement, node); return; } - if (request->req_flags & REQ_blr_version4) - stuff(request, blr_version4); + if (statement->req_flags & REQ_blr_version4) + stuff(statement, blr_version4); else - stuff(request, blr_version5); + stuff(statement, blr_version5); - if (request->req_type == REQ_SAVEPOINT) + if (statement->req_type == REQ_SAVEPOINT) { // Do not generate BEGIN..END block around savepoint statement // to avoid breaking of savepoint logic - request->req_send = NULL; - request->req_receive = NULL; - GEN_statement(request, node); + statement->req_send = NULL; + statement->req_receive = NULL; + GEN_statement(statement, node); } else { - stuff(request, blr_begin); + stuff(statement, blr_begin); - switch (request->req_type) + switch (statement->req_type) { case REQ_SELECT: case REQ_SELECT_UPD: case REQ_EMBED_SELECT: - gen_select(request, node); + gen_select(statement, node); break; case REQ_EXEC_BLOCK: case REQ_SELECT_BLOCK: - GEN_statement(request, node); + GEN_statement(statement, node); break; default: { - dsql_msg* message = request->req_send; + dsql_msg* message = statement->req_send; if (!message->msg_parameter) - request->req_send = NULL; + statement->req_send = NULL; else { - GEN_port(request, message); - stuff(request, blr_receive); - stuff(request, message->msg_number); + GEN_port(statement, message); + stuff(statement, blr_receive); + stuff(statement, message->msg_number); } - message = request->req_receive; + message = statement->req_receive; if (!message->msg_parameter) - request->req_receive = NULL; + statement->req_receive = NULL; else - GEN_port(request, message); - GEN_statement(request, node); + GEN_port(statement, message); + GEN_statement(statement, node); } } - stuff(request, blr_end); + stuff(statement, blr_end); } - stuff(request, blr_eoc); + stuff(statement, blr_eoc); } @@ -794,17 +794,17 @@ void GEN_request( dsql_req* request, dsql_nod* node) GEN_start_transaction - @brief Generate tpb for set transaction. Use blr string of request. + @brief Generate tpb for set transaction. Use blr string of statement. If a value is not specified, default is not STUFF'ed, let the engine handle it. Do not allow an option to be specified more than once. - @param request + @param statement @param tran_node **/ -void GEN_start_transaction( dsql_req* request, const dsql_nod* tran_node) +void GEN_start_transaction( CompiledStatement* statement, const dsql_nod* tran_node) { SSHORT count = tran_node->nod_count; @@ -840,7 +840,7 @@ void GEN_start_transaction( dsql_req* request, const dsql_nod* tran_node) // Stuff some version info. if (count = node->nod_count) - stuff(request, isc_tpb_version1); + stuff(statement, isc_tpb_version1); while (count--) { @@ -857,9 +857,9 @@ void GEN_start_transaction( dsql_req* request, const dsql_nod* tran_node) sw_access = true; if (ptr->nod_flags & NOD_READ_ONLY) - stuff(request, isc_tpb_read); + stuff(statement, isc_tpb_read); else - stuff(request, isc_tpb_write); + stuff(statement, isc_tpb_write); break; case nod_wait: @@ -869,9 +869,9 @@ void GEN_start_transaction( dsql_req* request, const dsql_nod* tran_node) sw_wait = true; if (ptr->nod_flags & NOD_NO_WAIT) - stuff(request, isc_tpb_nowait); + stuff(statement, isc_tpb_nowait); else - stuff(request, isc_tpb_wait); + stuff(statement, isc_tpb_wait); break; case nod_isolation: @@ -882,22 +882,22 @@ void GEN_start_transaction( dsql_req* request, const dsql_nod* tran_node) sw_isolation = true; if (ptr->nod_flags & NOD_CONCURRENCY) - stuff(request, isc_tpb_concurrency); + stuff(statement, isc_tpb_concurrency); else if (ptr->nod_flags & NOD_CONSISTENCY) - stuff(request, isc_tpb_consistency); + stuff(statement, isc_tpb_consistency); else { - stuff(request, isc_tpb_read_committed); + stuff(statement, isc_tpb_read_committed); if ((ptr->nod_count) && (ptr->nod_arg[0]) && (ptr->nod_arg[0]->nod_type == nod_version)) { if (ptr->nod_arg[0]->nod_flags & NOD_VERSION) - stuff(request, isc_tpb_rec_version); + stuff(statement, isc_tpb_rec_version); else - stuff(request, isc_tpb_no_rec_version); + stuff(statement, isc_tpb_no_rec_version); } else - stuff(request, isc_tpb_no_rec_version); + stuff(statement, isc_tpb_no_rec_version); } break; @@ -916,7 +916,7 @@ void GEN_start_transaction( dsql_req* request, const dsql_nod* tran_node) for (const dsql_nod* const* end = temp + reserve->nod_count; temp < end; temp++) { - gen_table_lock(request, *temp, lock_level); + gen_table_lock(statement, *temp, lock_level); } } break; @@ -929,11 +929,11 @@ void GEN_start_transaction( dsql_req* request, const dsql_nod* tran_node) misc_flags |= ptr->nod_flags; if (ptr->nod_flags & NOD_NO_AUTO_UNDO) - stuff(request, isc_tpb_no_auto_undo); + stuff(statement, isc_tpb_no_auto_undo); else if (ptr->nod_flags & NOD_IGNORE_LIMBO) - stuff(request, isc_tpb_ignore_limbo); + stuff(statement, isc_tpb_ignore_limbo); else if (ptr->nod_flags & NOD_RESTART_REQUESTS) - stuff(request, isc_tpb_restart_requests); + stuff(statement, isc_tpb_restart_requests); break; case nod_lock_timeout: @@ -945,9 +945,9 @@ void GEN_start_transaction( dsql_req* request, const dsql_nod* tran_node) if (ptr->nod_count == 1 && ptr->nod_arg[0]->nod_type == nod_constant) { const int lck_timeout = (int) ptr->nod_arg[0]->getSlong(); - stuff(request, isc_tpb_lock_timeout); - stuff(request, 2); - stuff_word(request, lck_timeout); + stuff(statement, isc_tpb_lock_timeout); + stuff(statement, 2); + stuff_word(statement, lck_timeout); } break; @@ -966,11 +966,11 @@ void GEN_start_transaction( dsql_req* request, const dsql_nod* tran_node) @brief Generate blr for an arbitrary expression. - @param request + @param statement @param node **/ -void GEN_statement( dsql_req* request, dsql_nod* node) +void GEN_statement( CompiledStatement* statement, dsql_nod* node) { dsql_nod* temp; dsql_nod** ptr; @@ -980,27 +980,27 @@ void GEN_statement( dsql_req* request, dsql_nod* node) switch (node->nod_type) { case nod_assign: - stuff(request, blr_assignment); - GEN_expr(request, node->nod_arg[0]); - GEN_expr(request, node->nod_arg[1]); + stuff(statement, blr_assignment); + GEN_expr(statement, node->nod_arg[0]); + GEN_expr(statement, node->nod_arg[1]); return; case nod_block: - stuff(request, blr_block); - GEN_statement(request, node->nod_arg[e_blk_action]); + stuff(statement, blr_block); + GEN_statement(statement, node->nod_arg[e_blk_action]); if (node->nod_count > 1) { temp = node->nod_arg[e_blk_errs]; for (ptr = temp->nod_arg, end = ptr + temp->nod_count; ptr < end; ptr++) { - GEN_statement(request, *ptr); + GEN_statement(statement, *ptr); } } - stuff(request, blr_end); + stuff(statement, blr_end); return; case nod_exec_block: - DDL_gen_block(request, node); + DDL_gen_block(statement, node); return; case nod_class_node: @@ -1008,35 +1008,35 @@ void GEN_statement( dsql_req* request, dsql_nod* node) return; case nod_for_select: - gen_for_select(request, node); + gen_for_select(statement, node); return; case nod_set_generator: case nod_set_generator2: - stuff(request, blr_set_generator); + stuff(statement, blr_set_generator); string = (dsql_str*) node->nod_arg[e_gen_id_name]; - stuff_cstring(request, string->str_data); - GEN_expr(request, node->nod_arg[e_gen_id_value]); + stuff_cstring(statement, string->str_data); + GEN_expr(statement, node->nod_arg[e_gen_id_value]); return; case nod_if: - stuff(request, blr_if); - GEN_expr(request, node->nod_arg[e_if_condition]); - GEN_statement(request, node->nod_arg[e_if_true]); + stuff(statement, blr_if); + GEN_expr(statement, node->nod_arg[e_if_condition]); + GEN_statement(statement, node->nod_arg[e_if_true]); if (node->nod_arg[e_if_false]) - GEN_statement(request, node->nod_arg[e_if_false]); + GEN_statement(statement, node->nod_arg[e_if_false]); else - stuff(request, blr_end); + stuff(statement, blr_end); return; case nod_list: - stuff(request, blr_begin); + stuff(statement, blr_begin); for (ptr = node->nod_arg, end = ptr + node->nod_count; ptr < end; ptr++) { - GEN_statement(request, *ptr); + GEN_statement(statement, *ptr); } - stuff(request, blr_end); + stuff(statement, blr_end); return; case nod_erase: @@ -1045,57 +1045,57 @@ void GEN_statement( dsql_req* request, dsql_nod* node) case nod_modify_current: case nod_store: case nod_exec_procedure: - gen_statement(request, node); + gen_statement(statement, node); return; case nod_on_error: - stuff(request, blr_error_handler); + stuff(statement, blr_error_handler); temp = node->nod_arg[e_err_errs]; - stuff_word(request, temp->nod_count); + stuff_word(statement, temp->nod_count); for (ptr = temp->nod_arg, end = ptr + temp->nod_count; ptr < end; ptr++) { - gen_error_condition(request, *ptr); + gen_error_condition(statement, *ptr); } - GEN_statement(request, node->nod_arg[e_err_action]); + GEN_statement(statement, node->nod_arg[e_err_action]); return; case nod_post: if ( (temp = node->nod_arg[e_pst_argument]) ) { - stuff(request, blr_post_arg); - GEN_expr(request, node->nod_arg[e_pst_event]); - GEN_expr(request, temp); + stuff(statement, blr_post_arg); + GEN_expr(statement, node->nod_arg[e_pst_event]); + GEN_expr(statement, temp); } else { - stuff(request, blr_post); - GEN_expr(request, node->nod_arg[e_pst_event]); + stuff(statement, blr_post); + GEN_expr(statement, node->nod_arg[e_pst_event]); } return; case nod_exec_sql: - stuff(request, blr_exec_sql); - GEN_expr(request, node->nod_arg[e_exec_sql_stmnt]); + stuff(statement, blr_exec_sql); + GEN_expr(statement, node->nod_arg[e_exec_sql_stmnt]); return; case nod_exec_into: if (node->nod_arg[e_exec_into_block]) { - stuff(request, blr_label); - stuff(request, (int) (IPTR) node->nod_arg[e_exec_into_label]->nod_arg[e_label_number]); + stuff(statement, blr_label); + stuff(statement, (int) (IPTR) node->nod_arg[e_exec_into_label]->nod_arg[e_label_number]); } - stuff(request, blr_exec_into); + stuff(statement, blr_exec_into); temp = node->nod_arg[e_exec_into_list]; - stuff_word(request, temp->nod_count); - GEN_expr(request, node->nod_arg[e_exec_into_stmnt]); + stuff_word(statement, temp->nod_count); + GEN_expr(statement, node->nod_arg[e_exec_into_stmnt]); if (node->nod_arg[e_exec_into_block]) { - stuff(request, 0); // Non-singleton - GEN_statement(request, node->nod_arg[e_exec_into_block]); + stuff(statement, 0); // Non-singleton + GEN_statement(statement, node->nod_arg[e_exec_into_block]); } else - stuff(request, 1); // Singleton + stuff(statement, 1); // Singleton for (ptr = temp->nod_arg, end = ptr + temp->nod_count; ptr < end; ptr++) { - GEN_expr(request, *ptr); + GEN_expr(statement, *ptr); } return; @@ -1111,56 +1111,56 @@ void GEN_statement( dsql_req* request, dsql_nod* node) const bool old_exec_into = old_syntax && node->nod_arg[e_exec_stmt_outputs]; if (node->nod_arg[e_exec_stmt_proc_block]) { - stuff(request, blr_label); - stuff(request, (int)(IPTR) node->nod_arg[e_exec_stmt_label]->nod_arg[e_label_number]); + stuff(statement, blr_label); + stuff(statement, (int)(IPTR) node->nod_arg[e_exec_stmt_label]->nod_arg[e_label_number]); } if (old_syntax) { if (old_exec_into) { - stuff(request, blr_exec_into); + stuff(statement, blr_exec_into); } else { - stuff(request, blr_exec_sql); + stuff(statement, blr_exec_sql); } } else { - stuff(request, blr_exec_stmt); + stuff(statement, blr_exec_stmt); } // counts of input and output parameters if (!old_syntax) { temp = node->nod_arg[e_exec_stmt_inputs]; - stuff_word(request, temp ? temp->nod_count : 0); + stuff_word(statement, temp ? temp->nod_count : 0); } if (!old_syntax || old_exec_into) { temp = node->nod_arg[e_exec_stmt_outputs]; - stuff_word(request, temp ? temp->nod_count : 0); + stuff_word(statement, temp ? temp->nod_count : 0); } // query expression - GEN_expr(request, node->nod_arg[e_exec_stmt_sql]); + GEN_expr(statement, node->nod_arg[e_exec_stmt_sql]); if (!old_syntax) { // external data source, user and password - GEN_expr(request, node->nod_arg[e_exec_stmt_data_src]); - GEN_expr(request, node->nod_arg[e_exec_stmt_user]); - GEN_expr(request, node->nod_arg[e_exec_stmt_pwd]); + GEN_expr(statement, node->nod_arg[e_exec_stmt_data_src]); + GEN_expr(statement, node->nod_arg[e_exec_stmt_user]); + GEN_expr(statement, node->nod_arg[e_exec_stmt_pwd]); // statement's transaction behavior - stuff(request, (UCHAR) node->nod_arg[e_exec_stmt_tran]->nod_flags); - stuff(request, 0); // transaction parameters equal to current transaction + stuff(statement, (UCHAR) node->nod_arg[e_exec_stmt_tran]->nod_flags); + stuff(statement, 0); // transaction parameters equal to current transaction } // singleton flag and proc block body if (node->nod_arg[e_exec_stmt_proc_block]) { - stuff(request, 0); // non-singleton - GEN_statement(request, node->nod_arg[e_exec_stmt_proc_block]); + stuff(statement, 0); // non-singleton + GEN_statement(statement, node->nod_arg[e_exec_stmt_proc_block]); } else if (!old_syntax || old_exec_into) { - stuff(request, 1); // singleton + stuff(statement, 1); // singleton } // inputs @@ -1170,18 +1170,18 @@ void GEN_statement( dsql_req* request, dsql_nod* node) ptr = temp->nod_arg; const bool haveNames = ((*ptr)->nod_arg[e_named_param_name] != 0); if (haveNames) - stuff(request, 1); + stuff(statement, 1); else - stuff(request, 0); + stuff(statement, 0); for (end = ptr + temp->nod_count; ptr < end; ptr++) { if (haveNames) { dsql_str* name = (dsql_str*) (*ptr)->nod_arg[e_named_param_name]; - stuff_cstring(request, name->str_data); + stuff_cstring(statement, name->str_data); } - GEN_expr(request, (*ptr)->nod_arg[e_named_param_expr]); + GEN_expr(statement, (*ptr)->nod_arg[e_named_param_expr]); } } @@ -1189,7 +1189,7 @@ void GEN_statement( dsql_req* request, dsql_nod* node) temp = node->nod_arg[e_exec_stmt_outputs]; if (temp) { for (ptr = temp->nod_arg, end = ptr + temp->nod_count; ptr < end; ptr++) { - GEN_expr(request, *ptr); + GEN_expr(statement, *ptr); } } } // scope of case nod_exec_stmt @@ -1199,60 +1199,60 @@ void GEN_statement( dsql_req* request, dsql_nod* node) if ( (temp = node->nod_arg[e_rtn_procedure]) ) { if (temp->nod_type == nod_exec_block) - GEN_return(request, temp->nod_arg[e_exe_blk_outputs], false); + GEN_return(statement, temp->nod_arg[e_exe_blk_outputs], false); else - GEN_return(request, temp->nod_arg[e_prc_outputs], false); + GEN_return(statement, temp->nod_arg[e_prc_outputs], false); } return; case nod_exit: - stuff(request, blr_leave); - stuff(request, 0); + stuff(statement, blr_leave); + stuff(statement, 0); return; case nod_breakleave: - stuff(request, blr_leave); - stuff(request, (int) (IPTR) node->nod_arg[e_breakleave_label]->nod_arg[e_label_number]); + stuff(statement, blr_leave); + stuff(statement, (int) (IPTR) node->nod_arg[e_breakleave_label]->nod_arg[e_label_number]); return; case nod_abort: - stuff(request, blr_leave); - stuff(request, (int) (IPTR) node->nod_arg[e_abrt_number]); + stuff(statement, blr_leave); + stuff(statement, (int) (IPTR) node->nod_arg[e_abrt_number]); return; case nod_start_savepoint: - stuff(request, blr_start_savepoint); + stuff(statement, blr_start_savepoint); return; case nod_end_savepoint: - stuff(request, blr_end_savepoint); + stuff(statement, blr_end_savepoint); return; case nod_user_savepoint: - stuff(request, blr_user_savepoint); - stuff(request, blr_savepoint_set); - stuff_cstring(request, ((dsql_str*)node->nod_arg[e_sav_name])->str_data); + stuff(statement, blr_user_savepoint); + stuff(statement, blr_savepoint_set); + stuff_cstring(statement, ((dsql_str*)node->nod_arg[e_sav_name])->str_data); return; case nod_release_savepoint: - stuff(request, blr_user_savepoint); + stuff(statement, blr_user_savepoint); if (node->nod_arg[1]) { - stuff(request, blr_savepoint_release_single); + stuff(statement, blr_savepoint_release_single); } else { - stuff(request, blr_savepoint_release); + stuff(statement, blr_savepoint_release); } - stuff_cstring(request, ((dsql_str*)node->nod_arg[e_sav_name])->str_data); + stuff_cstring(statement, ((dsql_str*)node->nod_arg[e_sav_name])->str_data); return; case nod_undo_savepoint: - stuff(request, blr_user_savepoint); - stuff(request, blr_savepoint_undo); - stuff_cstring(request, ((dsql_str*)node->nod_arg[e_sav_name])->str_data); + stuff(statement, blr_user_savepoint); + stuff(statement, blr_savepoint_undo); + stuff_cstring(statement, ((dsql_str*)node->nod_arg[e_sav_name])->str_data); return; case nod_exception_stmt: - stuff(request, blr_abort); + stuff(statement, blr_abort); string = (dsql_str*) node->nod_arg[e_xcps_name]; temp = node->nod_arg[e_xcps_msg]; /* if exception name is undefined, @@ -1260,7 +1260,7 @@ void GEN_statement( dsql_req* request, dsql_nod* node) so blr_raise verb should be generated */ if (!string) { - stuff(request, blr_raise); + stuff(statement, blr_raise); return; } /* if exception value is defined, @@ -1268,13 +1268,13 @@ void GEN_statement( dsql_req* request, dsql_nod* node) so blr_exception_msg verb should be generated */ if (temp) { - stuff(request, blr_exception_msg); + stuff(statement, blr_exception_msg); } /* otherwise go usual way, i.e. generate blr_exception */ else { - stuff(request, blr_exception); + stuff(statement, blr_exception); } if (!(string->str_flags & STR_delimited_id)) { @@ -1286,44 +1286,44 @@ void GEN_statement( dsql_req* request, dsql_nod* node) *p++; } } - stuff_cstring(request, string->str_data); + stuff_cstring(statement, string->str_data); /* if exception value is defined, generate appropriate BLR verbs */ if (temp) { - GEN_expr(request, temp); + GEN_expr(statement, temp); } return; case nod_while: - stuff(request, blr_label); - stuff(request, (int) (IPTR) node->nod_arg[e_while_label]->nod_arg[e_label_number]); - stuff(request, blr_loop); - stuff(request, blr_begin); - stuff(request, blr_if); - GEN_expr(request, node->nod_arg[e_while_cond]); - GEN_statement(request, node->nod_arg[e_while_action]); - stuff(request, blr_leave); - stuff(request, (int) (IPTR) node->nod_arg[e_while_label]->nod_arg[e_label_number]); - stuff(request, blr_end); + stuff(statement, blr_label); + stuff(statement, (int) (IPTR) node->nod_arg[e_while_label]->nod_arg[e_label_number]); + stuff(statement, blr_loop); + stuff(statement, blr_begin); + stuff(statement, blr_if); + GEN_expr(statement, node->nod_arg[e_while_cond]); + GEN_statement(statement, node->nod_arg[e_while_action]); + stuff(statement, blr_leave); + stuff(statement, (int) (IPTR) node->nod_arg[e_while_label]->nod_arg[e_label_number]); + stuff(statement, blr_end); return; case nod_sqlcode: case nod_gdscode: - stuff(request, blr_abort); - gen_error_condition(request, node); + stuff(statement, blr_abort); + gen_error_condition(statement, node); return; case nod_cursor: - stuff(request, blr_dcl_cursor); - stuff_word(request, (int) (IPTR) node->nod_arg[e_cur_number]); - GEN_expr(request, node->nod_arg[e_cur_rse]); + stuff(statement, blr_dcl_cursor); + stuff_word(statement, (int) (IPTR) node->nod_arg[e_cur_number]); + GEN_expr(statement, node->nod_arg[e_cur_rse]); temp = node->nod_arg[e_cur_rse]->nod_arg[e_rse_items]; - stuff_word(request, temp->nod_count); + stuff_word(statement, temp->nod_count); ptr = temp->nod_arg; end = ptr + temp->nod_count; while (ptr < end) { - GEN_expr(request, *ptr++); + GEN_expr(statement, *ptr++); } return; @@ -1332,22 +1332,22 @@ void GEN_statement( dsql_req* request, dsql_nod* node) case nod_cursor_fetch: { // op-code - stuff(request, blr_cursor_stmt); + stuff(statement, blr_cursor_stmt); if (node->nod_type == nod_cursor_open) - stuff(request, blr_cursor_open); + stuff(statement, blr_cursor_open); else if (node->nod_type == nod_cursor_close) - stuff(request, blr_cursor_close); + stuff(statement, blr_cursor_close); else - stuff(request, blr_cursor_fetch); + stuff(statement, blr_cursor_fetch); // cursor reference dsql_nod* cursor = node->nod_arg[e_cur_stmt_id]; - stuff_word(request, (int) (IPTR) cursor->nod_arg[e_cur_number]); + stuff_word(statement, (int) (IPTR) cursor->nod_arg[e_cur_number]); // preliminary navigation dsql_nod* seek = node->nod_arg[e_cur_stmt_seek]; if (seek) { - stuff(request, blr_seek); - GEN_expr(request, seek->nod_arg[0]); - GEN_expr(request, seek->nod_arg[1]); + stuff(statement, blr_seek); + GEN_expr(statement, seek->nod_arg[0]); + GEN_expr(statement, seek->nod_arg[1]); } // assignment dsql_nod* list_into = node->nod_arg[e_cur_stmt_into]; @@ -1356,23 +1356,23 @@ void GEN_statement( dsql_req* request, dsql_nod* node) if (list->nod_count != list_into->nod_count) ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 313, isc_arg_gds, isc_dsql_count_mismatch, 0); - stuff(request, blr_begin); + stuff(statement, blr_begin); ptr = list->nod_arg; end = ptr + list->nod_count; dsql_nod** ptr_to = list_into->nod_arg; while (ptr < end) { - stuff(request, blr_assignment); - GEN_expr(request, *ptr++); - GEN_expr(request, *ptr_to++); + stuff(statement, blr_assignment); + GEN_expr(statement, *ptr++); + GEN_expr(statement, *ptr_to++); } - stuff(request, blr_end); + stuff(statement, blr_end); } } return; case nod_src_info: - request->put_debug_src_info(node->nod_line, node->nod_column); - GEN_statement(request, node->nod_arg[e_src_info_stmt]); + statement->put_debug_src_info(node->nod_line, node->nod_column); + GEN_statement(statement, node->nod_arg[e_src_info_stmt]); return; default: @@ -1395,33 +1395,33 @@ void GEN_statement( dsql_req* request, dsql_nod* node) @param **/ -static void gen_aggregate( dsql_req* request, const dsql_nod* node) +static void gen_aggregate( CompiledStatement* statement, const dsql_nod* node) { const dsql_ctx* context = (dsql_ctx*) node->nod_arg[e_agg_context]; - stuff(request, blr_aggregate); - stuff_context(request, context); - gen_rse(request, node->nod_arg[e_agg_rse]); + stuff(statement, blr_aggregate); + stuff_context(statement, context); + gen_rse(statement, node->nod_arg[e_agg_rse]); // Handle GROUP BY clause - stuff(request, blr_group_by); + stuff(statement, blr_group_by); dsql_nod* list = node->nod_arg[e_agg_group]; if (list != NULL) { - stuff(request, list->nod_count); + stuff(statement, list->nod_count); dsql_nod** ptr = list->nod_arg; for (const dsql_nod* const* end = ptr + list->nod_count; ptr < end; ptr++) { - GEN_expr(request, *ptr); + GEN_expr(statement, *ptr); } } else - stuff(request, 0); + stuff(statement, 0); // Generate value map - gen_map(request, context->ctx_map); + gen_map(statement, context->ctx_map); } @@ -1432,16 +1432,16 @@ static void gen_aggregate( dsql_req* request, const dsql_nod* node) @brief Generate BLR for a data-type cast operation - @param request + @param statement @param node **/ -static void gen_cast( dsql_req* request, const dsql_nod* node) +static void gen_cast( CompiledStatement* statement, const dsql_nod* node) { - stuff(request, blr_cast); + stuff(statement, blr_cast); const dsql_fld* field = (dsql_fld*) node->nod_arg[e_cast_target]; - DDL_put_field_dtype(request, field, true); - GEN_expr(request, node->nod_arg[e_cast_source]); + DDL_put_field_dtype(statement, field, true); + GEN_expr(statement, node->nod_arg[e_cast_source]); } @@ -1462,24 +1462,24 @@ static void gen_cast( dsql_req* request, const dsql_nod* node) expression n blr for expression n-1 - @param request + @param statement @param node **/ -static void gen_coalesce( dsql_req* request, const dsql_nod* node) +static void gen_coalesce( CompiledStatement* statement, const dsql_nod* node) { // blr_value_if is used for building the coalesce function dsql_nod* list = node->nod_arg[0]; - stuff(request, blr_cast); - gen_descriptor(request, &node->nod_desc, true); + stuff(statement, blr_cast); + gen_descriptor(statement, &node->nod_desc, true); dsql_nod* const* ptr = list->nod_arg; for (const dsql_nod* const* const end = ptr + (list->nod_count - 1); ptr < end; ptr++) { // IF (expression IS NULL) THEN - stuff(request, blr_value_if); - stuff(request, blr_missing); - GEN_expr(request, *ptr); + stuff(statement, blr_value_if); + stuff(statement, blr_missing); + GEN_expr(statement, *ptr); } // Return values list = node->nod_arg[1]; @@ -1488,7 +1488,7 @@ static void gen_coalesce( dsql_req* request, const dsql_nod* node) // if all expressions are NULL return NULL for (ptr--; ptr >= begin; ptr--) { - GEN_expr(request, *ptr); + GEN_expr(statement, *ptr); } } @@ -1500,68 +1500,68 @@ static void gen_coalesce( dsql_req* request, const dsql_nod* node) @brief Generate BLR for a constant. - @param request + @param statement @param desc @param negate_value **/ -static void gen_constant( dsql_req* request, const dsc* desc, bool negate_value) +static void gen_constant( CompiledStatement* statement, const dsc* desc, bool negate_value) { SLONG value; SINT64 i64value; DSC tmp_desc; - stuff(request, blr_literal); + stuff(statement, blr_literal); USHORT l = 0; //= desc->dsc_length; const UCHAR* p = desc->dsc_address; switch (desc->dsc_dtype) { case dtype_short: - gen_descriptor(request, desc, true); + gen_descriptor(statement, desc, true); value = *(SSHORT *) p; if (negate_value) value = -value; - stuff_word(request, value); + stuff_word(statement, value); break; case dtype_long: - gen_descriptor(request, desc, true); + gen_descriptor(statement, desc, true); value = *(SLONG *) p; if (negate_value) value = -value; //printf("gen.cpp = %p %d\n", *((void**)p), value); - stuff_word(request, value); - stuff_word(request, value >> 16); + stuff_word(statement, value); + stuff_word(statement, value >> 16); break; case dtype_sql_time: case dtype_sql_date: - gen_descriptor(request, desc, true); + gen_descriptor(statement, desc, true); value = *(SLONG *) p; - stuff_word(request, value); - stuff_word(request, value >> 16); + stuff_word(statement, value); + stuff_word(statement, value >> 16); break; case dtype_double: /* this is used for approximate/large numeric literal which is transmitted to the engine as a string. */ - gen_descriptor(request, desc, true); + gen_descriptor(statement, desc, true); // Length of string literal, cast because it could be > 127 bytes. l = (USHORT) (UCHAR) desc->dsc_scale; if (negate_value) { - stuff_word(request, l + 1); - stuff(request, '-'); + stuff_word(statement, l + 1); + stuff(statement, '-'); } else { - stuff_word(request, l); + stuff_word(statement, l); } if (l) do { - stuff(request, *p++); + stuff(statement, *p++); } while (--l); break; @@ -1595,19 +1595,19 @@ static void gen_constant( dsql_req* request, const dsc* desc, bool negate_value) if ((i64value >= (SINT64) MIN_SLONG) && (i64value <= (SINT64) MAX_SLONG)) { - stuff(request, blr_long); - stuff(request, desc->dsc_scale); - stuff_word(request, i64value); - stuff_word(request, i64value >> 16); + stuff(statement, blr_long); + stuff(statement, desc->dsc_scale); + stuff_word(statement, i64value); + stuff_word(statement, i64value >> 16); break; } else { - stuff(request, blr_int64); - stuff(request, desc->dsc_scale); - stuff_word(request, i64value); - stuff_word(request, i64value >> 16); - stuff_word(request, i64value >> 32); - stuff_word(request, i64value >> 48); + stuff(statement, blr_int64); + stuff(statement, desc->dsc_scale); + stuff_word(statement, i64value); + stuff_word(statement, i64value >> 16); + stuff_word(statement, i64value >> 32); + stuff_word(statement, i64value >> 48); } break; @@ -1615,23 +1615,23 @@ static void gen_constant( dsql_req* request, const dsc* desc, bool negate_value) case dtype_blob: case dtype_array: case dtype_timestamp: - gen_descriptor(request, desc, true); + gen_descriptor(statement, desc, true); value = *(SLONG *) p; - stuff_word(request, value); - stuff_word(request, value >> 16); + stuff_word(statement, value); + stuff_word(statement, value >> 16); value = *(SLONG *) (p + 4); - stuff_word(request, value); - stuff_word(request, value >> 16); + stuff_word(statement, value); + stuff_word(statement, value >> 16); break; case dtype_text: { USHORT length = desc->dsc_length; - gen_descriptor(request, desc, true); + gen_descriptor(statement, desc, true); if (length) do { - stuff(request, *p++); + stuff(statement, *p++); } while (--length); break; } @@ -1651,17 +1651,17 @@ static void gen_constant( dsql_req* request, const dsc* desc, bool negate_value) @brief Generate BLR for a constant. - @param request + @param statement @param node @param negate_value **/ -static void gen_constant( dsql_req* request, dsql_nod* node, bool negate_value) +static void gen_constant( CompiledStatement* statement, dsql_nod* node, bool negate_value) { if (node->nod_desc.dsc_dtype == dtype_text) node->nod_desc.dsc_length = ((dsql_str*) node->nod_arg[0])->str_length; - gen_constant(request, &node->nod_desc, negate_value); + gen_constant(statement, &node->nod_desc, negate_value); } @@ -1672,88 +1672,88 @@ static void gen_constant( dsql_req* request, dsql_nod* node, bool negate_value) @brief Generate a blr descriptor from an internal descriptor. - @param request + @param statement @param desc @param texttype **/ -static void gen_descriptor( dsql_req* request, const dsc* desc, bool texttype) +static void gen_descriptor( CompiledStatement* statement, const dsc* desc, bool texttype) { switch (desc->dsc_dtype) { case dtype_text: if (texttype || desc->dsc_ttype() == ttype_binary || desc->dsc_ttype() == ttype_none) { - stuff(request, blr_text2); - stuff_word(request, desc->dsc_ttype()); + stuff(statement, blr_text2); + stuff_word(statement, desc->dsc_ttype()); } else { - stuff(request, blr_text2); // automatic transliteration - stuff_word(request, ttype_dynamic); + stuff(statement, blr_text2); // automatic transliteration + stuff_word(statement, ttype_dynamic); } - stuff_word(request, desc->dsc_length); + stuff_word(statement, desc->dsc_length); break; case dtype_varying: if (texttype || desc->dsc_ttype() == ttype_binary || desc->dsc_ttype() == ttype_none) { - stuff(request, blr_varying2); - stuff_word(request, desc->dsc_ttype()); + stuff(statement, blr_varying2); + stuff_word(statement, desc->dsc_ttype()); } else { - stuff(request, blr_varying2); // automatic transliteration - stuff_word(request, ttype_dynamic); + stuff(statement, blr_varying2); // automatic transliteration + stuff_word(statement, ttype_dynamic); } - stuff_word(request, desc->dsc_length - sizeof(USHORT)); + stuff_word(statement, desc->dsc_length - sizeof(USHORT)); break; case dtype_short: - stuff(request, blr_short); - stuff(request, desc->dsc_scale); + stuff(statement, blr_short); + stuff(statement, desc->dsc_scale); break; case dtype_long: - stuff(request, blr_long); - stuff(request, desc->dsc_scale); + stuff(statement, blr_long); + stuff(statement, desc->dsc_scale); break; case dtype_quad: - stuff(request, blr_quad); - stuff(request, desc->dsc_scale); + stuff(statement, blr_quad); + stuff(statement, desc->dsc_scale); break; case dtype_int64: - stuff(request, blr_int64); - stuff(request, desc->dsc_scale); + stuff(statement, blr_int64); + stuff(statement, desc->dsc_scale); break; case dtype_real: - stuff(request, blr_float); + stuff(statement, blr_float); break; case dtype_double: - stuff(request, blr_double); + stuff(statement, blr_double); break; case dtype_sql_date: - stuff(request, blr_sql_date); + stuff(statement, blr_sql_date); break; case dtype_sql_time: - stuff(request, blr_sql_time); + stuff(statement, blr_sql_time); break; case dtype_timestamp: - stuff(request, blr_timestamp); + stuff(statement, blr_timestamp); break; case dtype_array: - stuff(request, blr_quad); - stuff(request, 0); + stuff(statement, blr_quad); + stuff(statement, 0); break; case dtype_blob: - stuff(request, blr_blob2); - stuff_word(request, desc->dsc_sub_type); - stuff_word(request, desc->getTextType()); + stuff(statement, blr_blob2); + stuff_word(statement, desc->dsc_sub_type); + stuff_word(statement, desc->getTextType()); break; default: @@ -1771,34 +1771,34 @@ static void gen_descriptor( dsql_req* request, const dsc* desc, bool texttype) @brief Generate blr for an error condtion - @param request + @param statement @param node **/ -static void gen_error_condition( dsql_req* request, const dsql_nod* node) +static void gen_error_condition( CompiledStatement* statement, const dsql_nod* node) { const dsql_str* string; switch (node->nod_type) { case nod_sqlcode: - stuff(request, blr_sql_code); - stuff_word(request, (USHORT)(IPTR) node->nod_arg[0]); + stuff(statement, blr_sql_code); + stuff_word(statement, (USHORT)(IPTR) node->nod_arg[0]); return; case nod_gdscode: - stuff(request, blr_gds_code); + stuff(statement, blr_gds_code); string = (dsql_str*) node->nod_arg[0]; - stuff_cstring(request, string->str_data); + stuff_cstring(statement, string->str_data); return; case nod_exception: - stuff(request, blr_exception); + stuff(statement, blr_exception); string = (dsql_str*) node->nod_arg[0]; - stuff_cstring(request, string->str_data); + stuff_cstring(statement, string->str_data); return; case nod_default: - stuff(request, blr_default_code); + stuff(statement, blr_default_code); return; default: @@ -1816,18 +1816,18 @@ static void gen_error_condition( dsql_req* request, const dsql_nod* node) are preferred but not for trigger or view blr. - @param request + @param statement @param context @param field @param indices **/ -static void gen_field( dsql_req* request, const dsql_ctx* context, +static void gen_field( CompiledStatement* statement, const dsql_ctx* context, const dsql_fld* field, dsql_nod* indices) { /* For older clients - generate an error should they try and * access data types which did not exist in the older dialect */ - if (request->req_client_dialect <= SQL_DIALECT_V5) { + if (statement->req_client_dialect <= SQL_DIALECT_V5) { switch (field->fld_dtype) { case dtype_sql_date: case dtype_sql_time: @@ -1835,7 +1835,7 @@ static void gen_field( dsql_req* request, const dsql_ctx* context, ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 804, isc_arg_gds, isc_dsql_datatype_err, isc_arg_gds, isc_sql_dialect_datatype_unsupport, - isc_arg_number, (SLONG) request->req_client_dialect, + isc_arg_number, (SLONG) statement->req_client_dialect, isc_arg_string, DSC_dtype_tostring(static_cast < UCHAR > (field->fld_dtype)), 0); @@ -1847,26 +1847,26 @@ static void gen_field( dsql_req* request, const dsql_ctx* context, } if (indices) - stuff(request, blr_index); + stuff(statement, blr_index); - if (DDL_ids(request)) { - stuff(request, blr_fid); - stuff_context(request, context); - stuff_word(request, field->fld_id); + if (DDL_ids(statement)) { + stuff(statement, blr_fid); + stuff_context(statement, context); + stuff_word(statement, field->fld_id); } else { - stuff(request, blr_field); - stuff_context(request, context); - stuff_string(request, field->fld_name); + stuff(statement, blr_field); + stuff_context(statement, context); + stuff_string(statement, field->fld_name); } if (indices) { - stuff(request, indices->nod_count); + stuff(statement, indices->nod_count); dsql_nod** ptr = indices->nod_arg; for (const dsql_nod* const* end = ptr + indices->nod_count; ptr < end; ptr++) { - GEN_expr(request, *ptr); + GEN_expr(statement, *ptr); } } } @@ -1879,31 +1879,31 @@ static void gen_field( dsql_req* request, const dsql_ctx* context, @brief Generate BLR for a SELECT statement. - @param request + @param statement @param for_select **/ -static void gen_for_select( dsql_req* request, const dsql_nod* for_select) +static void gen_for_select( CompiledStatement* statement, const dsql_nod* for_select) { dsql_nod* rse = for_select->nod_arg[e_flp_select]; // CVC: Only put a label if this is not singular; otherwise, // what loop is the user trying to abandon? if (for_select->nod_arg[e_flp_action]) { - stuff(request, blr_label); - stuff(request, (int) (IPTR) for_select->nod_arg[e_flp_label]->nod_arg[e_label_number]); + stuff(statement, blr_label); + stuff(statement, (int) (IPTR) for_select->nod_arg[e_flp_label]->nod_arg[e_label_number]); } // Generate FOR loop - stuff(request, blr_for); + stuff(statement, blr_for); if (!for_select->nod_arg[e_flp_action]) { - stuff(request, blr_singular); + stuff(statement, blr_singular); } - gen_rse(request, rse); - stuff(request, blr_begin); + gen_rse(statement, rse); + stuff(statement, blr_begin); // Build body of FOR loop @@ -1930,15 +1930,15 @@ static void gen_for_select( dsql_req* request, const dsql_nod* for_select) for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++, ptr_to++) { - stuff(request, blr_assignment); - GEN_expr(request, *ptr); - GEN_expr(request, *ptr_to); + stuff(statement, blr_assignment); + GEN_expr(statement, *ptr); + GEN_expr(statement, *ptr_to); } } if (for_select->nod_arg[e_flp_action]) - GEN_statement(request, for_select->nod_arg[e_flp_action]); - stuff(request, blr_end); + GEN_statement(statement, for_select->nod_arg[e_flp_action]); + stuff(statement, blr_end); } @@ -1949,16 +1949,16 @@ static void gen_for_select( dsql_req* request, const dsql_nod* for_select) @brief Generate BLR for gen_id - @param request + @param statement @param node **/ -static void gen_gen_id( dsql_req* request, const dsql_nod* node) +static void gen_gen_id( CompiledStatement* statement, const dsql_nod* node) { - stuff(request, blr_gen_id); + stuff(statement, blr_gen_id); const dsql_str* string = (dsql_str*) node->nod_arg[e_gen_id_name]; - stuff_cstring(request, string->str_data); - GEN_expr(request, node->nod_arg[e_gen_id_value]); + stuff_cstring(statement, string->str_data); + GEN_expr(statement, node->nod_arg[e_gen_id_value]); } @@ -1970,36 +1970,36 @@ static void gen_gen_id( dsql_req* request, const dsql_nod* node) with an explicit join type. - @param request + @param statement @param rse **/ -static void gen_join_rse( dsql_req* request, const dsql_nod* rse) +static void gen_join_rse( CompiledStatement* statement, const dsql_nod* rse) { - stuff(request, blr_rs_stream); - stuff(request, 2); + stuff(statement, blr_rs_stream); + stuff(statement, 2); - GEN_expr(request, rse->nod_arg[e_join_left_rel]); - GEN_expr(request, rse->nod_arg[e_join_rght_rel]); + GEN_expr(statement, rse->nod_arg[e_join_left_rel]); + GEN_expr(statement, rse->nod_arg[e_join_rght_rel]); const dsql_nod* node = rse->nod_arg[e_join_type]; if (node->nod_type != nod_join_inner) { - stuff(request, blr_join_type); + stuff(statement, blr_join_type); if (node->nod_type == nod_join_left) - stuff(request, blr_left); + stuff(statement, blr_left); else if (node->nod_type == nod_join_right) - stuff(request, blr_right); + stuff(statement, blr_right); else - stuff(request, blr_full); + stuff(statement, blr_full); } if (rse->nod_arg[e_join_boolean]) { - stuff(request, blr_boolean); - GEN_expr(request, rse->nod_arg[e_join_boolean]); + stuff(statement, blr_boolean); + GEN_expr(statement, rse->nod_arg[e_join_boolean]); } - stuff(request, blr_end); + stuff(statement, blr_end); } @@ -2010,23 +2010,23 @@ static void gen_join_rse( dsql_req* request, const dsql_nod* rse) @brief Generate a value map for a record selection expression. - @param request + @param statement @param map **/ -static void gen_map( dsql_req* request, dsql_map* map) +static void gen_map( CompiledStatement* statement, dsql_map* map) { USHORT count = 0; dsql_map* temp; for (temp = map; temp; temp = temp->map_next) temp->map_position = count++; - stuff(request, blr_map); - stuff_word(request, count); + stuff(statement, blr_map); + stuff_word(statement, count); for (temp = map; temp; temp = temp->map_next) { - stuff_word(request, temp->map_position); - GEN_expr(request, temp->map_node); + stuff_word(statement, temp->map_position); + GEN_expr(statement, temp->map_node); } } @@ -2038,26 +2038,26 @@ static void gen_map( dsql_req* request, dsql_map* map) @brief Generate a parameter reference. - @param request + @param statement @param parameter **/ -static void gen_parameter( dsql_req* request, const dsql_par* parameter) +static void gen_parameter( CompiledStatement* statement, const dsql_par* parameter) { const dsql_msg* message = parameter->par_message; const dsql_par* null = parameter->par_null; if (null != NULL) { - stuff(request, blr_parameter2); - stuff(request, message->msg_number); - stuff_word(request, parameter->par_parameter); - stuff_word(request, null->par_parameter); + stuff(statement, blr_parameter2); + stuff(statement, message->msg_number); + stuff_word(statement, parameter->par_parameter); + stuff_word(statement, null->par_parameter); return; } - stuff(request, blr_parameter); - stuff(request, message->msg_number); - stuff_word(request, parameter->par_parameter); + stuff(statement, blr_parameter); + stuff(statement, message->msg_number); + stuff_word(statement, parameter->par_parameter); } @@ -2069,21 +2069,21 @@ static void gen_parameter( dsql_req* request, const dsql_par* parameter) @brief Generate blr for an access plan expression. - @param request + @param statement @param plan_expression **/ -static void gen_plan( dsql_req* request, const dsql_nod* plan_expression) +static void gen_plan( CompiledStatement* statement, const dsql_nod* plan_expression) { // stuff the join type const dsql_nod* list = plan_expression->nod_arg[1]; if (list->nod_count > 1) { if (plan_expression->nod_arg[0]) - stuff(request, blr_merge); + stuff(statement, blr_merge); else - stuff(request, blr_join); - stuff(request, list->nod_count); + stuff(statement, blr_join); + stuff(statement, list->nod_count); } // stuff one or more plan items @@ -2094,19 +2094,19 @@ static void gen_plan( dsql_req* request, const dsql_nod* plan_expression) { const dsql_nod* node = *ptr; if (node->nod_type == nod_plan_expr) { - gen_plan(request, node); + gen_plan(statement, node); continue; } // if we're here, it must be a nod_plan_item - stuff(request, blr_retrieve); + stuff(statement, blr_retrieve); /* stuff the relation--the relation id itself is redundant except when there is a need to differentiate the base tables of views */ const dsql_nod* arg = node->nod_arg[0]; - gen_relation(request, (dsql_ctx*) arg->nod_arg[e_rel_context]); + gen_relation(statement, (dsql_ctx*) arg->nod_arg[e_rel_context]); // now stuff the access method for this stream const dsql_str* index_string; @@ -2114,29 +2114,29 @@ static void gen_plan( dsql_req* request, const dsql_nod* plan_expression) arg = node->nod_arg[1]; switch (arg->nod_type) { case nod_natural: - stuff(request, blr_sequential); + stuff(statement, blr_sequential); break; case nod_index_order: - stuff(request, blr_navigational); + stuff(statement, blr_navigational); index_string = (dsql_str*) arg->nod_arg[0]; - stuff_cstring(request, index_string->str_data); + stuff_cstring(statement, index_string->str_data); if (!arg->nod_arg[1]) break; // dimitr: FALL INTO, if the plan item is ORDER ... INDEX (...) case nod_index: { - stuff(request, blr_indices); + stuff(statement, blr_indices); arg = (arg->nod_type == nod_index) ? arg->nod_arg[0] : arg->nod_arg[1]; - stuff(request, arg->nod_count); + stuff(statement, arg->nod_count); const dsql_nod* const* ptr2 = arg->nod_arg; for (const dsql_nod* const* const end2 = ptr2 + arg->nod_count; ptr2 < end2; ptr2++) { index_string = (dsql_str*) * ptr2; - stuff_cstring(request, index_string->str_data); + stuff_cstring(statement, index_string->str_data); } break; } @@ -2158,61 +2158,61 @@ static void gen_plan( dsql_req* request, const dsql_nod* plan_expression) @brief Generate blr for a relation reference. - @param request + @param statement @param context **/ -static void gen_relation( dsql_req* request, dsql_ctx* context) +static void gen_relation( CompiledStatement* statement, dsql_ctx* context) { const dsql_rel* relation = context->ctx_relation; const dsql_prc* procedure = context->ctx_procedure; // if this is a trigger or procedure, don't want relation id used if (relation) { - if (DDL_ids(request)) { + if (DDL_ids(statement)) { if (context->ctx_alias) - stuff(request, blr_rid2); + stuff(statement, blr_rid2); else - stuff(request, blr_rid); - stuff_word(request, relation->rel_id); + stuff(statement, blr_rid); + stuff_word(statement, relation->rel_id); } else { if (context->ctx_alias) - stuff(request, blr_relation2); + stuff(statement, blr_relation2); else - stuff(request, blr_relation); - stuff_meta_string(request, relation->rel_name.c_str()); + stuff(statement, blr_relation); + stuff_meta_string(statement, relation->rel_name.c_str()); } if (context->ctx_alias) - stuff_meta_string(request, context->ctx_alias); + stuff_meta_string(statement, context->ctx_alias); - stuff_context(request, context); + stuff_context(statement, context); } else if (procedure) { - if (DDL_ids(request)) { - stuff(request, blr_pid); - stuff_word(request, procedure->prc_id); + if (DDL_ids(statement)) { + stuff(statement, blr_pid); + stuff_word(statement, procedure->prc_id); } else { - stuff(request, blr_procedure); - stuff_meta_string(request, procedure->prc_name.c_str()); + stuff(statement, blr_procedure); + stuff_meta_string(statement, procedure->prc_name.c_str()); } - stuff_context(request, context); + stuff_context(statement, context); dsql_nod* inputs = context->ctx_proc_inputs; if (inputs) { - stuff_word(request, inputs->nod_count); + stuff_word(statement, inputs->nod_count); dsql_nod* const* ptr = inputs->nod_arg; for (const dsql_nod* const* const end = ptr + inputs->nod_count; ptr < end; ptr++) { - GEN_expr(request, *ptr); + GEN_expr(statement, *ptr); } } else - stuff_word(request, 0); + stuff_word(statement, 0); } } @@ -2224,18 +2224,18 @@ static void gen_relation( dsql_req* request, dsql_ctx* context) @brief Generate blr for a procedure return. - @param request + @param statement @param procedure @param eos_flag **/ -void GEN_return( dsql_req* request, const dsql_nod* parameters, bool eos_flag) +void GEN_return( CompiledStatement* statement, const dsql_nod* parameters, bool eos_flag) { if (!eos_flag) - stuff(request, blr_begin); - stuff(request, blr_send); - stuff(request, 1); - stuff(request, blr_begin); + stuff(statement, blr_begin); + stuff(statement, blr_send); + stuff(statement, 1); + stuff(statement, blr_begin); USHORT outputs = 0; if (parameters) { @@ -2246,30 +2246,30 @@ void GEN_return( dsql_req* request, const dsql_nod* parameters, bool eos_flag) outputs++; const dsql_nod* parameter = *ptr; const dsql_var* variable = (dsql_var*) parameter->nod_arg[e_var_variable]; - stuff(request, blr_assignment); - stuff(request, blr_variable); - stuff_word(request, variable->var_variable_number); - stuff(request, blr_parameter2); - stuff(request, variable->var_msg_number); - stuff_word(request, variable->var_msg_item); - stuff_word(request, variable->var_msg_item + 1); + stuff(statement, blr_assignment); + stuff(statement, blr_variable); + stuff_word(statement, variable->var_variable_number); + stuff(statement, blr_parameter2); + stuff(statement, variable->var_msg_number); + stuff_word(statement, variable->var_msg_item); + stuff_word(statement, variable->var_msg_item + 1); } } - stuff(request, blr_assignment); - stuff(request, blr_literal); - stuff(request, blr_short); - stuff(request, 0); + stuff(statement, blr_assignment); + stuff(statement, blr_literal); + stuff(statement, blr_short); + stuff(statement, 0); if (eos_flag) - stuff_word(request, 0); + stuff_word(statement, 0); else - stuff_word(request, 1); - stuff(request, blr_parameter); - stuff(request, 1); - stuff_word(request, 2 * outputs); - stuff(request, blr_end); + stuff_word(statement, 1); + stuff(statement, blr_parameter); + stuff(statement, 1); + stuff_word(statement, 2 * outputs); + stuff(statement, blr_end); if (!eos_flag) { - stuff(request, blr_stall); - stuff(request, blr_end); + stuff(statement, blr_stall); + stuff(statement, blr_end); } } @@ -2281,29 +2281,29 @@ void GEN_return( dsql_req* request, const dsql_nod* parameters, bool eos_flag) @brief Generate a record selection expression. - @param request + @param statement @param rse **/ -static void gen_rse( dsql_req* request, const dsql_nod* rse) +static void gen_rse( CompiledStatement* statement, const dsql_nod* rse) { if (rse->nod_flags & NOD_SELECT_EXPR_SINGLETON) { - stuff(request, blr_singular); + stuff(statement, blr_singular); } - stuff(request, blr_rse); + stuff(statement, blr_rse); dsql_nod* list = rse->nod_arg[e_rse_streams]; // Handle source streams if (list->nod_type == nod_union) { - stuff(request, 1); - gen_union(request, rse); + stuff(statement, 1); + gen_union(statement, rse); } else if (list->nod_type == nod_list) { - stuff(request, list->nod_count); + stuff(statement, list->nod_count); dsql_nod* const* ptr = list->nod_arg; for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++) @@ -2313,57 +2313,57 @@ static void gen_rse( dsql_req* request, const dsql_nod* rse) node->nod_type == nod_aggregate || node->nod_type == nod_join) { - GEN_expr(request, node); + GEN_expr(statement, node); } else if (node->nod_type == nod_derived_table) { - GEN_expr(request, node->nod_arg[e_derived_table_rse]); + GEN_expr(statement, node->nod_arg[e_derived_table_rse]); } } } else { - stuff(request, 1); - GEN_expr(request, list); + stuff(statement, 1); + GEN_expr(statement, list); } if (rse->nod_arg[e_rse_lock]) - stuff(request, blr_writelock); + stuff(statement, blr_writelock); dsql_nod* node; if ((node = rse->nod_arg[e_rse_first]) != NULL) { - stuff(request, blr_first); - GEN_expr(request, node); + stuff(statement, blr_first); + GEN_expr(statement, node); } if ((node = rse->nod_arg[e_rse_skip]) != NULL) { - stuff(request, blr_skip); - GEN_expr (request, node); + stuff(statement, blr_skip); + GEN_expr (statement, node); } if ((node = rse->nod_arg[e_rse_boolean]) != NULL) { - stuff(request, blr_boolean); - GEN_expr(request, node); + stuff(statement, blr_boolean); + GEN_expr(statement, node); } if ((list = rse->nod_arg[e_rse_sort]) != NULL) - gen_sort(request, list); + gen_sort(statement, list); if ((list = rse->nod_arg[e_rse_reduced]) != NULL) { - stuff(request, blr_project); - stuff(request, list->nod_count); + stuff(statement, blr_project); + stuff(statement, list->nod_count); dsql_nod** ptr = list->nod_arg; for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++) { - GEN_expr(request, *ptr); + GEN_expr(statement, *ptr); } } // if the user specified an access plan to use, add it here if ((node = rse->nod_arg[e_rse_plan]) != NULL) { - stuff(request, blr_plan); - gen_plan(request, node); + stuff(statement, blr_plan); + gen_plan(statement, node); } #ifdef SCROLLABLE_CURSORS @@ -2373,19 +2373,19 @@ static void gen_rse( dsql_req* request, const dsql_nod* rse) and offset to scroll; note that we do this only on a SELECT type statement and only when talking to a 4.1 engine or greater */ - if (request->req_type == REQ_SELECT && - request->req_dbb->dbb_base_level >= 5) + if (statement->req_type == REQ_SELECT && + statement->req_dbb->dbb_base_level >= 5) { - stuff(request, blr_receive); - stuff(request, request->req_async->msg_number); - stuff(request, blr_seek); - const dsql_par* parameter = request->req_async->msg_parameters; - gen_parameter(request, parameter->par_next); - gen_parameter(request, parameter); + stuff(statement, blr_receive); + stuff(statement, statement->req_async->msg_number); + stuff(statement, blr_seek); + const dsql_par* parameter = statement->req_async->msg_parameters; + gen_parameter(statement, parameter->par_next); + gen_parameter(statement, parameter); } #endif - stuff(request, blr_end); + stuff(statement, blr_end); } @@ -2396,16 +2396,16 @@ static void gen_rse( dsql_req* request, const dsql_nod* rse) @brief Generate BLR for CASE function (searched) - @param request + @param statement @param node **/ -static void gen_searched_case( dsql_req* request, const dsql_nod* node) +static void gen_searched_case( CompiledStatement* statement, const dsql_nod* node) { // blr_value_if is used for building the case expression - stuff(request, blr_cast); - gen_descriptor(request, &node->nod_desc, true); + stuff(statement, blr_cast); + gen_descriptor(statement, &node->nod_desc, true); const SSHORT count = node->nod_arg[e_searched_case_search_conditions]->nod_count; dsql_nod* boolean_list = node->nod_arg[e_searched_case_search_conditions]; @@ -2415,12 +2415,12 @@ static void gen_searched_case( dsql_req* request, const dsql_nod* node) for (const dsql_nod* const* const end = bptr + count; bptr < end; bptr++, rptr++) { - stuff(request, blr_value_if); - GEN_expr(request, *bptr); - GEN_expr(request, *rptr); + stuff(statement, blr_value_if); + GEN_expr(statement, *bptr); + GEN_expr(statement, *rptr); } // else_result - GEN_expr(request, node->nod_arg[e_searched_case_results]->nod_arg[count]); + GEN_expr(statement, node->nod_arg[e_searched_case_results]->nod_arg[count]); } @@ -2431,11 +2431,11 @@ static void gen_searched_case( dsql_req* request, const dsql_nod* node) @brief Generate BLR for a SELECT statement. - @param request + @param statement @param rse **/ -static void gen_select( dsql_req* request, dsql_nod* rse) +static void gen_select( CompiledStatement* statement, dsql_nod* rse) { const dsql_rel* relation; dsql_ctx* context; @@ -2449,16 +2449,16 @@ static void gen_select( dsql_req* request, dsql_nod* rse) ptr++) { dsql_par* parameter = - MAKE_parameter(request->req_receive, true, true, 0, *ptr); + MAKE_parameter(statement->req_receive, true, true, 0, *ptr); parameter->par_node = *ptr; - MAKE_desc(request, ¶meter->par_desc, *ptr, NULL); + MAKE_desc(statement, ¶meter->par_desc, *ptr, NULL); } // Set up parameter to handle EOF dsql_par* parameter_eof = - MAKE_parameter(request->req_receive, false, false, 0, NULL); - request->req_eof = parameter_eof; + MAKE_parameter(statement->req_receive, false, false, 0, NULL); + statement->req_eof = parameter_eof; parameter_eof->par_desc.dsc_dtype = dtype_short; parameter_eof->par_desc.dsc_scale = 0; parameter_eof->par_desc.dsc_length = sizeof(SSHORT); @@ -2478,7 +2478,7 @@ static void gen_select( dsql_req* request, dsql_nod* rse) if (relation = context->ctx_relation) { // Set up dbkey dsql_par* parameter = - MAKE_parameter(request->req_receive, + MAKE_parameter(statement->req_receive, false, false, 0, NULL); parameter->par_dbkey_ctx = context; parameter->par_desc.dsc_dtype = dtype_text; @@ -2489,7 +2489,7 @@ static void gen_select( dsql_req* request, dsql_nod* rse) // Set up record version - for post v33 databases parameter = - MAKE_parameter(request->req_receive, false, + MAKE_parameter(statement->req_receive, false, false, 0, NULL); parameter->par_rec_version_ctx = context; parameter->par_desc.dsc_dtype = dtype_text; @@ -2503,13 +2503,13 @@ static void gen_select( dsql_req* request, dsql_nod* rse) #ifdef SCROLLABLE_CURSORS /* define the parameters for the scrolling message--offset and direction, - in that order to make it easier to generate the request */ + in that order to make it easier to generate the statement */ - if (request->req_type == REQ_SELECT && - request->req_dbb->dbb_base_level >= 5) + if (statement->req_type == REQ_SELECT && + statement->req_dbb->dbb_base_level >= 5) { dsql_par* parameter = - MAKE_parameter(request->req_async, false, false, 0, NULL); + MAKE_parameter(statement->req_async, false, false, 0, NULL); parameter->par_desc.dsc_dtype = dtype_short; parameter->par_desc.dsc_length = sizeof(USHORT); parameter->par_desc.dsc_scale = 0; @@ -2517,7 +2517,7 @@ static void gen_select( dsql_req* request, dsql_nod* rse) parameter->par_desc.dsc_sub_type = 0; parameter = - MAKE_parameter(request->req_async, false, false, 0, NULL); + MAKE_parameter(statement->req_async, false, false, 0, NULL); parameter->par_desc.dsc_dtype = dtype_long; parameter->par_desc.dsc_length = sizeof(ULONG); parameter->par_desc.dsc_scale = 0; @@ -2528,36 +2528,36 @@ static void gen_select( dsql_req* request, dsql_nod* rse) // Generate definitions for the messages - GEN_port(request, request->req_receive); - dsql_msg* message = request->req_send; + GEN_port(statement, statement->req_receive); + dsql_msg* message = statement->req_send; if (message->msg_parameter) - GEN_port(request, message); + GEN_port(statement, message); else - request->req_send = NULL; + statement->req_send = NULL; #ifdef SCROLLABLE_CURSORS - if (request->req_type == REQ_SELECT && - request->req_dbb->dbb_base_level >= 5) - GEN_port(request, request->req_async); + if (statement->req_type == REQ_SELECT && + statement->req_dbb->dbb_base_level >= 5) + GEN_port(statement, statement->req_async); #endif // If there is a send message, build a RECEIVE - if ((message = request->req_send) != NULL) { - stuff(request, blr_receive); - stuff(request, message->msg_number); + if ((message = statement->req_send) != NULL) { + stuff(statement, blr_receive); + stuff(statement, message->msg_number); } // Generate FOR loop - message = request->req_receive; + message = statement->req_receive; - stuff(request, blr_for); - stuff(request, blr_stall); - gen_rse(request, rse); + stuff(statement, blr_for); + stuff(statement, blr_stall); + gen_rse(statement, rse); - stuff(request, blr_send); - stuff(request, message->msg_number); - stuff(request, blr_begin); + stuff(statement, blr_send); + stuff(statement, message->msg_number); + stuff(statement, blr_begin); // Build body of FOR loop @@ -2572,40 +2572,40 @@ static void gen_select( dsql_req* request, dsql_nod* rse) // Add invalid usage here - stuff(request, blr_assignment); + stuff(statement, blr_assignment); constant = 1; - gen_constant(request, &constant_desc, USE_VALUE); - gen_parameter(request, request->req_eof); + gen_constant(statement, &constant_desc, USE_VALUE); + gen_parameter(statement, statement->req_eof); for (dsql_par* parameter = message->msg_parameters; parameter; parameter = parameter->par_next) { if (parameter->par_node) { - stuff(request, blr_assignment); - GEN_expr(request, parameter->par_node); - gen_parameter(request, parameter); + stuff(statement, blr_assignment); + GEN_expr(statement, parameter->par_node); + gen_parameter(statement, parameter); } if (context = parameter->par_dbkey_ctx) { - stuff(request, blr_assignment); - stuff(request, blr_dbkey); - stuff_context(request, context); - gen_parameter(request, parameter); + stuff(statement, blr_assignment); + stuff(statement, blr_dbkey); + stuff_context(statement, context); + gen_parameter(statement, parameter); } if (context = parameter->par_rec_version_ctx) { - stuff(request, blr_assignment); - stuff(request, blr_record_version); - stuff_context(request, context); - gen_parameter(request, parameter); + stuff(statement, blr_assignment); + stuff(statement, blr_record_version); + stuff_context(statement, context); + gen_parameter(statement, parameter); } } - stuff(request, blr_end); - stuff(request, blr_send); - stuff(request, message->msg_number); - stuff(request, blr_assignment); + stuff(statement, blr_end); + stuff(statement, blr_send); + stuff(statement, message->msg_number); + stuff(statement, blr_assignment); constant = 0; - gen_constant(request, &constant_desc, USE_VALUE); - gen_parameter(request, request->req_eof); + gen_constant(statement, &constant_desc, USE_VALUE); + gen_parameter(statement, statement->req_eof); } @@ -2616,16 +2616,16 @@ static void gen_select( dsql_req* request, dsql_nod* rse) @brief Generate BLR for CASE function (simple) - @param request + @param statement @param node **/ -static void gen_simple_case( dsql_req* request, const dsql_nod* node) +static void gen_simple_case( CompiledStatement* statement, const dsql_nod* node) { // blr_value_if is used for building the case expression - stuff(request, blr_cast); - gen_descriptor(request, &node->nod_desc, true); + stuff(statement, blr_cast); + gen_descriptor(statement, &node->nod_desc, true); SSHORT count = node->nod_arg[e_simple_case_when_operands]->nod_count; dsql_nod* when_list = node->nod_arg[e_simple_case_when_operands]; dsql_nod* results_list = node->nod_arg[e_simple_case_results]; @@ -2635,14 +2635,14 @@ static void gen_simple_case( dsql_req* request, const dsql_nod* node) for (const dsql_nod* const* const end = wptr + count; wptr < end; wptr++, rptr++) { - stuff(request, blr_value_if); - stuff(request, blr_eql); - GEN_expr(request, node->nod_arg[e_simple_case_case_operand]); - GEN_expr(request, *wptr); - GEN_expr(request, *rptr); + stuff(statement, blr_value_if); + stuff(statement, blr_eql); + GEN_expr(statement, node->nod_arg[e_simple_case_case_operand]); + GEN_expr(statement, *wptr); + GEN_expr(statement, *rptr); } // else_result - GEN_expr(request, node->nod_arg[e_simple_case_results]->nod_arg[count]); + GEN_expr(statement, node->nod_arg[e_simple_case_results]->nod_arg[count]); } @@ -2653,14 +2653,14 @@ static void gen_simple_case( dsql_req* request, const dsql_nod* node) @brief Generate a sort clause. - @param request + @param statement @param list **/ -static void gen_sort( dsql_req* request, dsql_nod* list) +static void gen_sort( CompiledStatement* statement, dsql_nod* list) { - stuff(request, blr_sort); - stuff(request, list->nod_count); + stuff(statement, blr_sort); + stuff(statement, list->nod_count); dsql_nod* const* ptr = list->nod_arg; for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; @@ -2670,18 +2670,18 @@ static void gen_sort( dsql_req* request, dsql_nod* list) if (nulls_placement) { switch (nulls_placement->getSlong()) { case NOD_NULLS_FIRST: - stuff(request, blr_nullsfirst); + stuff(statement, blr_nullsfirst); break; case NOD_NULLS_LAST: - stuff(request, blr_nullslast); + stuff(statement, blr_nullslast); break; } } if ((*ptr)->nod_arg[e_order_flag]) - stuff(request, blr_descending); + stuff(statement, blr_descending); else - stuff(request, blr_ascending); - GEN_expr(request, (*ptr)->nod_arg[e_order_field]); + stuff(statement, blr_ascending); + GEN_expr(statement, (*ptr)->nod_arg[e_order_field]); } } @@ -2693,15 +2693,15 @@ static void gen_sort( dsql_req* request, dsql_nod* list) @brief Generate BLR for DML statements. - @param request + @param statement @param node **/ -static void gen_statement(dsql_req* request, const dsql_nod* node) +static void gen_statement(CompiledStatement* statement, const dsql_nod* node) { dsql_nod* rse = NULL; const dsql_msg* message = NULL; - bool send_before_for = !(request->req_flags & REQ_dsql_upd_or_ins); + bool send_before_for = !(statement->req_flags & REQ_dsql_upd_or_ins); switch (node->nod_type) { case nod_store: @@ -2718,30 +2718,30 @@ static void gen_statement(dsql_req* request, const dsql_nod* node) break; } - if (request->req_type == REQ_EXEC_PROCEDURE && send_before_for) + if (statement->req_type == REQ_EXEC_PROCEDURE && send_before_for) { - if ((message = request->req_receive)) + if ((message = statement->req_receive)) { - stuff(request, blr_send); - stuff(request, message->msg_number); + stuff(statement, blr_send); + stuff(statement, message->msg_number); } } if (rse) { - stuff(request, blr_for); - GEN_expr(request, rse); + stuff(statement, blr_for); + GEN_expr(statement, rse); } - if (request->req_type == REQ_EXEC_PROCEDURE) + if (statement->req_type == REQ_EXEC_PROCEDURE) { - if ((message = request->req_receive)) + if ((message = statement->req_receive)) { - stuff(request, blr_begin); + stuff(statement, blr_begin); if (!send_before_for) { - stuff(request, blr_send); - stuff(request, message->msg_number); + stuff(statement, blr_send); + stuff(statement, message->msg_number); } } } @@ -2752,38 +2752,38 @@ static void gen_statement(dsql_req* request, const dsql_nod* node) switch (node->nod_type) { case nod_store: - stuff(request, node->nod_arg[e_sto_return] ? blr_store2 : blr_store); - GEN_expr(request, node->nod_arg[e_sto_relation]); - GEN_statement(request, node->nod_arg[e_sto_statement]); + stuff(statement, node->nod_arg[e_sto_return] ? blr_store2 : blr_store); + GEN_expr(statement, node->nod_arg[e_sto_relation]); + GEN_statement(statement, node->nod_arg[e_sto_statement]); if (node->nod_arg[e_sto_return]) { - GEN_statement(request, node->nod_arg[e_sto_return]); + GEN_statement(statement, node->nod_arg[e_sto_return]); } break; case nod_modify: - stuff(request, node->nod_arg[e_mod_return] ? blr_modify2 : blr_modify); + stuff(statement, node->nod_arg[e_mod_return] ? blr_modify2 : blr_modify); temp = node->nod_arg[e_mod_source]; context = (dsql_ctx*) temp->nod_arg[e_rel_context]; - stuff_context(request, context); + stuff_context(statement, context); temp = node->nod_arg[e_mod_update]; context = (dsql_ctx*) temp->nod_arg[e_rel_context]; - stuff_context(request, context); - GEN_statement(request, node->nod_arg[e_mod_statement]); + stuff_context(statement, context); + GEN_statement(statement, node->nod_arg[e_mod_statement]); if (node->nod_arg[e_mod_return]) { - GEN_statement(request, node->nod_arg[e_mod_return]); + GEN_statement(statement, node->nod_arg[e_mod_return]); } break; case nod_modify_current: - stuff(request, node->nod_arg[e_mdc_return] ? blr_modify2 : blr_modify); + stuff(statement, node->nod_arg[e_mdc_return] ? blr_modify2 : blr_modify); context = (dsql_ctx*) node->nod_arg[e_mdc_context]; - stuff_context(request, context); + stuff_context(statement, context); temp = node->nod_arg[e_mdc_update]; context = (dsql_ctx*) temp->nod_arg[e_rel_context]; - stuff_context(request, context); - GEN_statement(request, node->nod_arg[e_mdc_statement]); + stuff_context(statement, context); + GEN_statement(statement, node->nod_arg[e_mdc_statement]); if (node->nod_arg[e_mdc_return]) { - GEN_statement(request, node->nod_arg[e_mdc_return]); + GEN_statement(statement, node->nod_arg[e_mdc_return]); } break; @@ -2791,63 +2791,63 @@ static void gen_statement(dsql_req* request, const dsql_nod* node) temp = node->nod_arg[e_era_relation]; context = (dsql_ctx*) temp->nod_arg[e_rel_context]; if (node->nod_arg[e_era_return]) { - stuff(request, blr_begin); - GEN_statement(request, node->nod_arg[e_era_return]); - stuff(request, blr_erase); - stuff_context(request, context); - stuff(request, blr_end); + stuff(statement, blr_begin); + GEN_statement(statement, node->nod_arg[e_era_return]); + stuff(statement, blr_erase); + stuff_context(statement, context); + stuff(statement, blr_end); } else { - stuff(request, blr_erase); - stuff_context(request, context); + stuff(statement, blr_erase); + stuff_context(statement, context); } break; case nod_erase_current: context = (dsql_ctx*) node->nod_arg[e_erc_context]; if (node->nod_arg[e_erc_return]) { - stuff(request, blr_begin); - GEN_statement(request, node->nod_arg[e_erc_return]); - stuff(request, blr_erase); - stuff_context(request, context); - stuff(request, blr_end); + stuff(statement, blr_begin); + GEN_statement(statement, node->nod_arg[e_erc_return]); + stuff(statement, blr_erase); + stuff_context(statement, context); + stuff(statement, blr_end); } else { - stuff(request, blr_erase); - stuff_context(request, context); + stuff(statement, blr_erase); + stuff_context(statement, context); } break; case nod_exec_procedure: - stuff(request, blr_exec_proc); + stuff(statement, blr_exec_proc); name = (dsql_str*) node->nod_arg[e_exe_procedure]; - stuff_meta_string(request, name->str_data); + stuff_meta_string(statement, name->str_data); // Input parameters if ( (temp = node->nod_arg[e_exe_inputs]) ) { - stuff_word(request, temp->nod_count); + stuff_word(statement, temp->nod_count); dsql_nod** ptr = temp->nod_arg; const dsql_nod* const* end = ptr + temp->nod_count; while (ptr < end) { - GEN_expr(request, *ptr++); + GEN_expr(statement, *ptr++); } } else { - stuff_word(request, 0); + stuff_word(statement, 0); } // Output parameters if ( ( temp = node->nod_arg[e_exe_outputs]) ) { - stuff_word(request, temp->nod_count); + stuff_word(statement, temp->nod_count); dsql_nod** ptr = temp->nod_arg; const dsql_nod* const* end = ptr + temp->nod_count; while (ptr < end) { - GEN_expr(request, *ptr++); + GEN_expr(statement, *ptr++); } } else { - stuff_word(request, 0); + stuff_word(statement, 0); } break; @@ -2856,7 +2856,7 @@ static void gen_statement(dsql_req* request, const dsql_nod* node) } if (message) { - stuff(request, blr_end); + stuff(statement, blr_end); } } @@ -2868,28 +2868,28 @@ static void gen_statement(dsql_req* request, const dsql_nod* node) @brief Generate a system defined function. - @param request + @param statement @param node **/ -static void gen_sys_function(dsql_req* request, const dsql_nod* node) +static void gen_sys_function(CompiledStatement* statement, const dsql_nod* node) { - stuff(request, blr_sys_function); - stuff_cstring(request, ((dsql_str*) node->nod_arg[e_sysfunc_name])->str_data); + stuff(statement, blr_sys_function); + stuff_cstring(statement, ((dsql_str*) node->nod_arg[e_sysfunc_name])->str_data); const dsql_nod* list; if ((node->nod_count == e_sysfunc_args + 1) && (list = node->nod_arg[e_sysfunc_args])) { - stuff(request, list->nod_count); + stuff(statement, list->nod_count); dsql_nod* const* ptr = list->nod_arg; for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++) { - GEN_expr(request, *ptr); + GEN_expr(statement, *ptr); } } else - stuff(request, 0); + stuff(statement, 0); } @@ -2901,12 +2901,12 @@ static void gen_sys_function(dsql_req* request, const dsql_nod* node) If lock level is specified, it overrrides the transaction lock level. - @param request + @param statement @param tbl_lock @param lock_level **/ -static void gen_table_lock( dsql_req* request, const dsql_nod* tbl_lock, +static void gen_table_lock( CompiledStatement* statement, const dsql_nod* tbl_lock, USHORT lock_level) { if ((!tbl_lock) || (tbl_lock->nod_type != nod_table_lock)) @@ -2933,13 +2933,13 @@ static void gen_table_lock( dsql_req* request, const dsql_nod* tbl_lock, if ((*ptr)->nod_type != nod_relation_name) continue; - stuff(request, lock_mode); + stuff(statement, lock_mode); // stuff table name const dsql_str* temp = (dsql_str*) ((*ptr)->nod_arg[e_rln_name]); - stuff_cstring(request, reinterpret_cast(temp->str_data)); + stuff_cstring(statement, reinterpret_cast(temp->str_data)); - stuff(request, lock_level); + stuff(statement, lock_level); } } @@ -2951,28 +2951,28 @@ static void gen_table_lock( dsql_req* request, const dsql_nod* tbl_lock, @brief Generate a user defined function. - @param request + @param statement @param node **/ -static void gen_udf( dsql_req* request, const dsql_nod* node) +static void gen_udf( CompiledStatement* statement, const dsql_nod* node) { const dsql_udf* userFunc = (dsql_udf*) node->nod_arg[0]; - stuff(request, blr_function); - stuff_string(request, userFunc->udf_name); + stuff(statement, blr_function); + stuff_string(statement, userFunc->udf_name); const dsql_nod* list; if ((node->nod_count == 2) && (list = node->nod_arg[1])) { - stuff(request, list->nod_count); + stuff(statement, list->nod_count); dsql_nod* const* ptr = list->nod_arg; for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++) { - GEN_expr(request, *ptr); + GEN_expr(statement, *ptr); } } else - stuff(request, 0); + stuff(statement, 0); } @@ -2983,17 +2983,17 @@ static void gen_udf( dsql_req* request, const dsql_nod* node) @brief Generate a union of substreams. - @param request + @param statement @param union_node **/ -static void gen_union( dsql_req* request, const dsql_nod* union_node) +static void gen_union( CompiledStatement* statement, const dsql_nod* union_node) { if (union_node->nod_arg[0]->nod_flags & NOD_UNION_RECURSIVE) { - stuff(request, blr_recurse); + stuff(statement, blr_recurse); } else { - stuff(request, blr_union); + stuff(statement, blr_union); } // Obtain the context for UNION from the first dsql_map* node @@ -3004,29 +3004,29 @@ static void gen_union( dsql_req* request, const dsql_nod* union_node) map_item = map_item->nod_arg[e_alias_value]; } dsql_ctx* union_context = (dsql_ctx*) map_item->nod_arg[e_map_context]; - stuff_context(request, union_context); + stuff_context(statement, union_context); // secondary context number must be present once in generated blr union_context->ctx_flags &= ~CTX_recursive; dsql_nod* streams = union_node->nod_arg[e_rse_streams]; - stuff(request, streams->nod_count); // number of substreams + stuff(statement, streams->nod_count); // number of substreams dsql_nod** ptr = streams->nod_arg; for (const dsql_nod* const* const end = ptr + streams->nod_count; ptr < end; ptr++) { dsql_nod* sub_rse = *ptr; - gen_rse(request, sub_rse); + gen_rse(statement, sub_rse); items = sub_rse->nod_arg[e_rse_items]; - stuff(request, blr_map); - stuff_word(request, items->nod_count); + stuff(statement, blr_map); + stuff_word(statement, items->nod_count); USHORT count = 0; dsql_nod** iptr = items->nod_arg; for (const dsql_nod* const* const iend = iptr + items->nod_count; iptr < iend; iptr++) { - stuff_word(request, count); - GEN_expr(request, *iptr); + stuff_word(statement, count); + GEN_expr(statement, *iptr); count++; } } @@ -3041,23 +3041,23 @@ static void gen_union( dsql_req* request, const dsql_nod* union_node) Check for possible overflow. - @param request + @param statement @param context **/ -static void stuff_context(dsql_req* request, const dsql_ctx* context) +static void stuff_context(CompiledStatement* statement, const dsql_ctx* context) { if (context->ctx_context > MAX_UCHAR) { ERRD_post(isc_too_many_contexts, 0); } - stuff(request, context->ctx_context); + stuff(statement, context->ctx_context); if (context->ctx_flags & CTX_recursive) { if (context->ctx_recursive > MAX_UCHAR) { ERRD_post(isc_too_many_contexts, 0); } - stuff(request, context->ctx_recursive); + stuff(statement, context->ctx_recursive); } } @@ -3069,13 +3069,13 @@ static void stuff_context(dsql_req* request, const dsql_ctx* context) @brief Write out a string with one byte of length. - @param request + @param statement @param string **/ -static void stuff_cstring(dsql_req* request, const char* string) +static void stuff_cstring(CompiledStatement* statement, const char* string) { - stuff_string(request, string, strlen(string)); + stuff_string(statement, string, strlen(string)); } @@ -3086,13 +3086,13 @@ static void stuff_cstring(dsql_req* request, const char* string) @brief Write out a string in metadata charset with one byte of length. - @param request + @param statement @param string **/ -static void stuff_meta_string(dsql_req* request, const char* string) +static void stuff_meta_string(CompiledStatement* statement, const char* string) { - request->append_meta_string(string); + statement->append_meta_string(string); } @@ -3103,24 +3103,24 @@ static void stuff_meta_string(dsql_req* request, const char* string) @brief Write out a string with one byte of length. - @param request + @param statement @param string **/ -static void stuff_string(dsql_req* request, const char* string, int len) +static void stuff_string(CompiledStatement* statement, const char* string, int len) { fb_assert(len >= 0 && len <= 255); - stuff(request, len); + stuff(statement, len); while (len--) - stuff(request, *string++); + stuff(statement, *string++); } -static void stuff_string(dsql_req* request, const Firebird::MetaName& name) +static void stuff_string(CompiledStatement* statement, const Firebird::MetaName& name) { - stuff_string(request, name.c_str(), name.length()); + stuff_string(statement, name.c_str(), name.length()); } @@ -3132,13 +3132,13 @@ static void stuff_string(dsql_req* request, const Firebird::MetaName& name) ready to overflow, expand it. - @param request + @param statement @param word **/ -static void stuff_word( dsql_req* request, USHORT word) +static void stuff_word( CompiledStatement* statement, USHORT word) { - stuff(request, word); - stuff(request, word >> 8); + stuff(statement, word); + stuff(statement, word >> 8); } diff --git a/src/dsql/gen_proto.h b/src/dsql/gen_proto.h index a831da8efe..a1fc1ac931 100644 --- a/src/dsql/gen_proto.h +++ b/src/dsql/gen_proto.h @@ -24,15 +24,15 @@ #ifndef DSQL_GEN_PROTO_H #define DSQL_GEN_PROTO_H -void GEN_expr(Jrd::dsql_req*, Jrd::dsql_nod*); -void GEN_port(Jrd::dsql_req*, Jrd::dsql_msg*); -void GEN_request(Jrd::dsql_req*, Jrd::dsql_nod*); -void GEN_return(Jrd::dsql_req*, const Jrd::dsql_nod*, bool); -void GEN_start_transaction(Jrd::dsql_req*, const Jrd::dsql_nod*); -void GEN_statement(Jrd::dsql_req*, Jrd::dsql_nod*); +void GEN_expr(Jrd::CompiledStatement*, Jrd::dsql_nod*); +void GEN_port(Jrd::CompiledStatement*, Jrd::dsql_msg*); +void GEN_request(Jrd::CompiledStatement*, Jrd::dsql_nod*); +void GEN_return(Jrd::CompiledStatement*, const Jrd::dsql_nod*, bool); +void GEN_start_transaction(Jrd::CompiledStatement*, const Jrd::dsql_nod*); +void GEN_statement(Jrd::CompiledStatement*, Jrd::dsql_nod*); // CVC: I think this can be replaced by request->append_uchar(byte) in the calling code. -inline void stuff(Jrd::dsql_req* request, const UCHAR byte) +inline void stuff(Jrd::CompiledStatement* request, const UCHAR byte) { request->req_blr_data.add(byte); } diff --git a/src/dsql/make.cpp b/src/dsql/make.cpp index a1091b19f0..13f309b3d8 100644 --- a/src/dsql/make.cpp +++ b/src/dsql/make.cpp @@ -388,7 +388,7 @@ dsql_str* MAKE_cstring(const char* str) @param null_replacement **/ -void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_replacement) +void MAKE_desc(CompiledStatement* statement, dsc* desc, dsql_nod* node, dsql_nod* null_replacement) { dsc desc1, desc2, desc3; USHORT dtype, dtype1, dtype2; @@ -436,17 +436,17 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl case nod_map: map = (dsql_map*) node->nod_arg[e_map_map]; - MAKE_desc(request, desc, map->map_node, null_replacement); + MAKE_desc(statement, desc, map->map_node, null_replacement); return; case nod_agg_min: case nod_agg_max: - MAKE_desc(request, desc, node->nod_arg[0], null_replacement); + MAKE_desc(statement, desc, node->nod_arg[0], null_replacement); desc->dsc_flags = DSC_nullable; return; case nod_agg_average: - MAKE_desc(request, desc, node->nod_arg[0], null_replacement); + MAKE_desc(statement, desc, node->nod_arg[0], null_replacement); desc->dsc_flags = DSC_nullable; if (!DTYPE_IS_NUMERIC(desc->dsc_dtype) && !DTYPE_IS_TEXT(desc->dsc_dtype)) @@ -460,7 +460,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_agg_average2: - MAKE_desc(request, desc, node->nod_arg[0], null_replacement); + MAKE_desc(statement, desc, node->nod_arg[0], null_replacement); desc->dsc_flags = DSC_nullable; dtype = desc->dsc_dtype; if (!DTYPE_IS_NUMERIC(dtype)) { @@ -478,7 +478,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_agg_total: - MAKE_desc(request, desc, node->nod_arg[0], null_replacement); + MAKE_desc(statement, desc, node->nod_arg[0], null_replacement); if (!DTYPE_IS_NUMERIC(desc->dsc_dtype) && !DTYPE_IS_TEXT(desc->dsc_dtype)) { @@ -500,7 +500,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_agg_total2: - MAKE_desc(request, desc, node->nod_arg[0], null_replacement); + MAKE_desc(statement, desc, node->nod_arg[0], null_replacement); dtype = desc->dsc_dtype; if (!DTYPE_IS_NUMERIC(dtype)) { ERRD_post(isc_expression_eval_err, 0); @@ -518,24 +518,24 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_agg_list: - MAKE_desc(request, desc, node->nod_arg[0], null_replacement); + MAKE_desc(statement, desc, node->nod_arg[0], null_replacement); desc->makeBlob(desc->getBlobSubType(), desc->getTextType()); desc->setNullable(true); return; case nod_concatenate: - MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]); - MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]); - DSqlDataTypeUtil(request).makeConcatenate(desc, &desc1, &desc2); + MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]); + MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]); + DSqlDataTypeUtil(statement).makeConcatenate(desc, &desc1, &desc2); return; case nod_derived_field: - MAKE_desc(request, desc, node->nod_arg[e_derived_field_value], null_replacement); + MAKE_desc(statement, desc, node->nod_arg[e_derived_field_value], null_replacement); return; case nod_upcase: case nod_lowcase: - MAKE_desc(request, &desc1, node->nod_arg[0], null_replacement); + MAKE_desc(statement, &desc1, node->nod_arg[0], null_replacement); if (desc1.dsc_dtype <= dtype_any_text || desc1.dsc_dtype == dtype_blob) { *desc = desc1; @@ -550,16 +550,16 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_substr: - MAKE_desc(request, &desc1, node->nod_arg[0], null_replacement); - MAKE_desc(request, &desc2, node->nod_arg[1], null_replacement); - MAKE_desc(request, &desc3, node->nod_arg[2], null_replacement); - DSqlDataTypeUtil(request).makeSubstr(desc, &desc1, &desc2, &desc3); + MAKE_desc(statement, &desc1, node->nod_arg[0], null_replacement); + MAKE_desc(statement, &desc2, node->nod_arg[1], null_replacement); + MAKE_desc(statement, &desc3, node->nod_arg[2], null_replacement); + DSqlDataTypeUtil(statement).makeSubstr(desc, &desc1, &desc2, &desc3); return; case nod_trim: - MAKE_desc(request, &desc1, node->nod_arg[e_trim_value], null_replacement); + MAKE_desc(statement, &desc1, node->nod_arg[e_trim_value], null_replacement); if (node->nod_arg[e_trim_characters]) - MAKE_desc(request, &desc2, node->nod_arg[e_trim_characters], null_replacement); + MAKE_desc(statement, &desc2, node->nod_arg[e_trim_characters], null_replacement); else desc2.dsc_flags = 0; @@ -589,24 +589,24 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl case nod_cast: field = (dsql_fld*) node->nod_arg[e_cast_target]; MAKE_desc_from_field(desc, field); - MAKE_desc(request, &desc1, node->nod_arg[e_cast_source], NULL); + MAKE_desc(statement, &desc1, node->nod_arg[e_cast_source], NULL); desc->dsc_flags = desc1.dsc_flags & DSC_nullable; return; case nod_simple_case: - MAKE_desc_from_list(request, &desc1, node->nod_arg[e_simple_case_results], + MAKE_desc_from_list(statement, &desc1, node->nod_arg[e_simple_case_results], null_replacement, "CASE"); *desc = desc1; return; case nod_searched_case: - MAKE_desc_from_list(request, &desc1, node->nod_arg[e_searched_case_results], + MAKE_desc_from_list(statement, &desc1, node->nod_arg[e_searched_case_results], null_replacement, "CASE"); *desc = desc1; return; case nod_coalesce: - MAKE_desc_from_list(request, &desc1, node->nod_arg[0], + MAKE_desc_from_list(statement, &desc1, node->nod_arg[0], null_replacement, "COALESCE"); *desc = desc1; return; @@ -619,8 +619,8 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl case nod_add: case nod_subtract: - MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]); - MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]); + MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]); + MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]); if (node->nod_arg[0]->nod_type == nod_null && node->nod_arg[1]->nod_type == nod_null) @@ -764,8 +764,8 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl case nod_add2: case nod_subtract2: - MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]); - MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]); + MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]); + MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]); if (node->nod_arg[0]->nod_type == nod_null && node->nod_arg[1]->nod_type == nod_null) @@ -939,8 +939,8 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_multiply: - MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]); - MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]); + MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]); + MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]); if (node->nod_arg[0]->nod_type == nod_null && node->nod_arg[1]->nod_type == nod_null) @@ -980,8 +980,8 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_multiply2: - MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]); - MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]); + MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]); + MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]); if (node->nod_arg[0]->nod_type == nod_null && node->nod_arg[1]->nod_type == nod_null) @@ -1039,8 +1039,8 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl */ case nod_divide: - MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]); - MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]); + MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]); + MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]); if (node->nod_arg[0]->nod_type == nod_null && node->nod_arg[1]->nod_type == nod_null) @@ -1077,8 +1077,8 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_divide2: - MAKE_desc(request, &desc1, node->nod_arg[0], node->nod_arg[1]); - MAKE_desc(request, &desc2, node->nod_arg[1], node->nod_arg[0]); + MAKE_desc(statement, &desc1, node->nod_arg[0], node->nod_arg[1]); + MAKE_desc(statement, &desc2, node->nod_arg[1], node->nod_arg[0]); if (node->nod_arg[0]->nod_type == nod_null && node->nod_arg[1]->nod_type == nod_null) @@ -1124,7 +1124,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_negate: - MAKE_desc(request, desc, node->nod_arg[0], null_replacement); + MAKE_desc(statement, desc, node->nod_arg[0], null_replacement); if (node->nod_arg[0]->nod_type == nod_null) { @@ -1136,7 +1136,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl // In Dialect 2 or 3, a string can never partipate in negation // (use a specific cast instead) if (DTYPE_IS_TEXT(desc->dsc_dtype)) { - if (request->req_client_dialect >= SQL_DIALECT_V6_TRANSITION) { + if (statement->req_client_dialect >= SQL_DIALECT_V6_TRANSITION) { ERRD_post(isc_expression_eval_err, 0); } desc->dsc_dtype = dtype_double; @@ -1155,7 +1155,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_alias: - MAKE_desc(request, desc, node->nod_arg[e_alias_value], null_replacement); + MAKE_desc(statement, desc, node->nod_arg[e_alias_value], null_replacement); return; case nod_dbkey: @@ -1209,19 +1209,19 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl for (dsql_nod** p = nodeArgs->nod_arg; p < nodeArgs->nod_arg + nodeArgs->nod_count; ++p) { - MAKE_desc(request, &(*p)->nod_desc, *p, NULL); + MAKE_desc(statement, &(*p)->nod_desc, *p, NULL); args.add(&(*p)->nod_desc); } } const dsql_str* name = (dsql_str*) node->nod_arg[e_sysfunc_name]; - DSqlDataTypeUtil(request).makeSysFunction(desc, name->str_data, args.getCount(), args.begin()); + DSqlDataTypeUtil(statement).makeSysFunction(desc, name->str_data, args.getCount(), args.begin()); return; } case nod_gen_id: - MAKE_desc(request, &desc1, node->nod_arg[e_gen_id_value], NULL); + MAKE_desc(statement, &desc1, node->nod_arg[e_gen_id_value], NULL); desc->dsc_dtype = dtype_long; desc->dsc_sub_type = 0; desc->dsc_scale = 0; @@ -1230,7 +1230,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_gen_id2: - MAKE_desc(request, &desc1, node->nod_arg[e_gen_id_value], NULL); + MAKE_desc(statement, &desc1, node->nod_arg[e_gen_id_value], NULL); desc->dsc_dtype = dtype_int64; desc->dsc_sub_type = 0; desc->dsc_scale = 0; @@ -1241,7 +1241,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl case nod_limit: case nod_rows: - if (request->req_client_dialect <= SQL_DIALECT_V5) { + if (statement->req_client_dialect <= SQL_DIALECT_V5) { desc->dsc_dtype = dtype_long; desc->dsc_length = sizeof (SLONG); } @@ -1273,7 +1273,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl desc->dsc_flags = 0; desc->dsc_ttype() = ttype_metadata; desc->dsc_length = - USERNAME_LENGTH * METD_get_charset_bpc(request, ttype_metadata) + + USERNAME_LENGTH * METD_get_charset_bpc(statement, ttype_metadata) + sizeof(USHORT); return; @@ -1309,7 +1309,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_extract: - MAKE_desc(request, &desc1, node->nod_arg[e_extract_value], NULL); + MAKE_desc(statement, &desc1, node->nod_arg[e_extract_value], NULL); switch (*(ULONG *) node->nod_arg[e_extract_part]->nod_desc.dsc_address) { @@ -1331,7 +1331,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_strlen: - MAKE_desc(request, &desc1, node->nod_arg[e_strlen_value], NULL); + MAKE_desc(statement, &desc1, node->nod_arg[e_strlen_value], NULL); desc->dsc_sub_type = 0; desc->dsc_scale = 0; desc->dsc_flags = (desc1.dsc_flags & DSC_nullable); @@ -1367,7 +1367,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl */ if (null_replacement) { - MAKE_desc(request, desc, null_replacement, NULL); + MAKE_desc(statement, desc, null_replacement, NULL); desc->dsc_flags |= (DSC_nullable | DSC_null); } else @@ -1377,7 +1377,7 @@ void MAKE_desc(dsql_req* request, dsc* desc, dsql_nod* node, dsql_nod* null_repl return; case nod_via: - MAKE_desc(request, desc, node->nod_arg[e_via_value_1], null_replacement); + MAKE_desc(statement, desc, node->nod_arg[e_via_value_1], null_replacement); /** Set the descriptor flag as nullable. The select expression may or may not return @@ -1451,7 +1451,7 @@ void MAKE_desc_from_field(dsc* desc, const dsql_fld* field) @param expression_name **/ -void MAKE_desc_from_list(dsql_req* request, dsc* desc, dsql_nod* node, +void MAKE_desc_from_list(CompiledStatement* statement, dsc* desc, dsql_nod* node, dsql_nod* null_replacement, const TEXT* expression_name) { @@ -1461,17 +1461,17 @@ void MAKE_desc_from_list(dsql_req* request, dsc* desc, dsql_nod* node, for (dsql_nod** p = node->nod_arg; p < node->nod_arg + node->nod_count; ++p) { - MAKE_desc(request, &(*p)->nod_desc, *p, NULL); + MAKE_desc(statement, &(*p)->nod_desc, *p, NULL); args.add(&(*p)->nod_desc); } - DSqlDataTypeUtil(request).makeFromList(desc, expression_name, args.getCount(), args.begin()); + DSqlDataTypeUtil(statement).makeFromList(desc, expression_name, args.getCount(), args.begin()); // If we have literal NULLs only, let the result be either // CHAR(1) CHARACTER SET NONE or the context-provided datatype if (desc->isNull() && null_replacement) { - MAKE_desc(request, desc, null_replacement, NULL); + MAKE_desc(statement, desc, null_replacement, NULL); desc->dsc_flags |= DSC_null | DSC_nullable; return; } diff --git a/src/dsql/make_proto.h b/src/dsql/make_proto.h index 63121b29ab..1964a49c87 100644 --- a/src/dsql/make_proto.h +++ b/src/dsql/make_proto.h @@ -33,6 +33,7 @@ namespace Jrd { class dsql_nod; class dsql_fld; class dsql_req; + class CompiledStatement; // Parameters to MAKE_constant enum dsql_constant_type { @@ -59,9 +60,9 @@ Jrd::dsql_nod* MAKE_const_slong(SLONG); Jrd::dsql_nod* MAKE_constant(Jrd::dsql_str*, Jrd::dsql_constant_type); Jrd::dsql_nod* MAKE_str_constant(Jrd::dsql_str*, SSHORT); Jrd::dsql_str* MAKE_cstring(const char*); -void MAKE_desc(Jrd::dsql_req*, dsc*, Jrd::dsql_nod*, Jrd::dsql_nod*); +void MAKE_desc(Jrd::CompiledStatement*, dsc*, Jrd::dsql_nod*, Jrd::dsql_nod*); void MAKE_desc_from_field(dsc*, const Jrd::dsql_fld*); -void MAKE_desc_from_list(Jrd::dsql_req*, dsc*, Jrd::dsql_nod*, Jrd::dsql_nod*, const TEXT*); +void MAKE_desc_from_list(Jrd::CompiledStatement*, dsc*, Jrd::dsql_nod*, Jrd::dsql_nod*, const TEXT*); Jrd::dsql_nod* MAKE_field(Jrd::dsql_ctx*, Jrd::dsql_fld*, Jrd::dsql_nod*); Jrd::dsql_nod* MAKE_field_name(const char*); Jrd::dsql_nod* MAKE_list(Jrd::DsqlNodStack&); diff --git a/src/dsql/metd.epp b/src/dsql/metd.epp index c7cc77303e..b07f6ae253 100644 --- a/src/dsql/metd.epp +++ b/src/dsql/metd.epp @@ -1141,7 +1141,7 @@ dsql_nod* METD_get_primary_key(dsql_req* request, const dsql_str* relation_name) } -dsql_prc* METD_get_procedure(dsql_req* request, const dsql_str* name) +dsql_prc* METD_get_procedure(CompiledStatement* statement, const dsql_str* name) { /************************************** * @@ -1157,37 +1157,37 @@ dsql_prc* METD_get_procedure(dsql_req* request, const dsql_str* name) **************************************/ thread_db* tdbb = JRD_get_thread_data(); - dsql_dbb* dbb = request->req_dbb; + dsql_dbb* dbb = statement->req_dbb; dsql_fld* parameter; dsql_fld** ptr; dsql_prc* temp; SSHORT type, count, defaults; - // see if the procedure is the one currently being defined in this request + // see if the procedure is the one currently being defined in this statement - if (((temp = request->req_procedure) != NULL) && + if (((temp = statement->req_procedure) != NULL) && temp->prc_name == name->str_data) { return temp; } - MutexHolder holder(request); + MutexHolder holder(statement); // Start by seeing if symbol is already defined - dsql_sym* symbol = lookup_symbol(request->req_dbb, name, SYM_procedure); + dsql_sym* symbol = lookup_symbol(statement->req_dbb, name, SYM_procedure); if (symbol) return (dsql_prc*) symbol->sym_object; // now see if it is in the database - validateTransaction(request); + validateTransaction(statement); dsql_prc* procedure = NULL; jrd_req* handle1 = CMP_find_request(tdbb, irq_procedure, IRQ_REQUESTS); - FOR(REQUEST_HANDLE handle1 TRANSACTION_HANDLE request->req_transaction) + FOR(REQUEST_HANDLE handle1 TRANSACTION_HANDLE statement->req_transaction) X IN RDB$PROCEDURES WITH X.RDB$PROCEDURE_NAME EQ name->str_data @@ -1224,7 +1224,7 @@ dsql_prc* METD_get_procedure(dsql_req* request, const dsql_str* name) jrd_req* handle2 = CMP_find_request(tdbb, irq_parameters, IRQ_REQUESTS); - FOR(REQUEST_HANDLE handle2 TRANSACTION_HANDLE request->req_transaction) + FOR(REQUEST_HANDLE handle2 TRANSACTION_HANDLE statement->req_transaction) PR IN RDB$PROCEDURE_PARAMETERS CROSS FLD IN RDB$FIELDS WITH FLD.RDB$FIELD_NAME EQ PR.RDB$FIELD_SOURCE @@ -1246,7 +1246,7 @@ dsql_prc* METD_get_procedure(dsql_req* request, const dsql_str* name) { jrd_req* handle3 = CMP_find_request(tdbb, irq_parameters2, IRQ_REQUESTS); - FOR(REQUEST_HANDLE handle3 TRANSACTION_HANDLE request->req_transaction) + FOR(REQUEST_HANDLE handle3 TRANSACTION_HANDLE statement->req_transaction) PR2 IN RDB$PROCEDURE_PARAMETERS WITH PR2.RDB$PROCEDURE_NAME EQ PR.RDB$PROCEDURE_NAME AND PR2.RDB$PARAMETER_NAME EQ PR.RDB$PARAMETER_NAME @@ -1337,7 +1337,7 @@ dsql_prc* METD_get_procedure(dsql_req* request, const dsql_str* name) // Since we could give up control due to the THREAD_EXIT and THEAD_ENTER // calls, another thread may have added the same procedure in the mean time - if ((symbol = lookup_symbol(request->req_dbb, name, SYM_procedure))) + if ((symbol = lookup_symbol(statement->req_dbb, name, SYM_procedure))) { // Get rid of all the stuff we just read in. Use existing one free_procedure(procedure); @@ -1359,14 +1359,14 @@ dsql_prc* METD_get_procedure(dsql_req* request, const dsql_str* name) symbol->sym_length = procedure->prc_name.length(); symbol->sym_type = SYM_procedure; symbol->sym_dbb = dbb; - insert_symbol(request->req_dbb, symbol); + insert_symbol(statement->req_dbb, symbol); } return procedure; } -dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name) +dsql_rel* METD_get_relation(CompiledStatement* statement, const dsql_str* name) { /************************************** * @@ -1381,38 +1381,38 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name) **************************************/ thread_db* tdbb = JRD_get_thread_data(); - dsql_dbb* dbb = request->req_dbb; + dsql_dbb* dbb = statement->req_dbb; dsql_fld* field; dsql_fld** ptr; dsql_rel* temp; - // See if the relation is the one currently being defined in this request + // See if the relation is the one currently being defined in this statement - if (((temp = request->req_relation) != NULL) && + if (((temp = statement->req_relation) != NULL) && temp->rel_name == name->str_data) { return temp; } - MutexHolder holder(request); + MutexHolder holder(statement); // Start by seeing if symbol is already defined - dsql_sym* symbol = lookup_symbol(request->req_dbb, name, SYM_relation); + dsql_sym* symbol = lookup_symbol(statement->req_dbb, name, SYM_relation); if (symbol) return (dsql_rel*) symbol->sym_object; // If the relation id or any of the field ids have not yet been assigned, - // and this is a type of request which does not use ids, prepare a + // and this is a type of statement which does not use ids, prepare a // temporary relation block to provide information without caching it - validateTransaction(request); + validateTransaction(statement); bool permanent = true; jrd_req* handle1 = CMP_find_request(tdbb, irq_rel_ids, IRQ_REQUESTS); - FOR(REQUEST_HANDLE handle1 TRANSACTION_HANDLE request->req_transaction) + FOR(REQUEST_HANDLE handle1 TRANSACTION_HANDLE statement->req_transaction) REL IN RDB$RELATIONS CROSS RFR IN RDB$RELATION_FIELDS OVER RDB$RELATION_NAME WITH REL.RDB$RELATION_NAME EQ name->str_data @@ -1436,7 +1436,7 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name) jrd_req* handle2 = CMP_find_request(tdbb, irq_relation, IRQ_REQUESTS); - FOR(REQUEST_HANDLE handle2 TRANSACTION_HANDLE request->req_transaction) + FOR(REQUEST_HANDLE handle2 TRANSACTION_HANDLE statement->req_transaction) X IN RDB$RELATIONS WITH X.RDB$RELATION_NAME EQ name->str_data if (!DSQL_REQUEST(irq_relation)) @@ -1450,7 +1450,7 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name) relation = FB_NEW(pool) dsql_rel(pool); relation->rel_id = X.RDB$RELATION_ID; } - else if (!DDL_ids(request)) { + else if (!DDL_ids(statement)) { relation = FB_NEW(pool) dsql_rel(pool); } @@ -1485,7 +1485,7 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name) jrd_req* handle3 = CMP_find_request(tdbb, irq_fields, IRQ_REQUESTS); - FOR(REQUEST_HANDLE handle3 TRANSACTION_HANDLE request->req_transaction) + FOR(REQUEST_HANDLE handle3 TRANSACTION_HANDLE statement->req_transaction) FLX IN RDB$FIELDS CROSS RFR IN RDB$RELATION_FIELDS WITH FLX.RDB$FIELD_NAME EQ RFR.RDB$FIELD_SOURCE @@ -1509,7 +1509,7 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name) field = FB_NEW(pool) dsql_fld(pool); field->fld_id = RFR.RDB$FIELD_ID; } - else if (!DDL_ids(request)) + else if (!DDL_ids(statement)) field = FB_NEW(pool) dsql_fld(pool); if (field) { @@ -1566,7 +1566,7 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name) if (!DSQL_REQUEST(irq_fields)) DSQL_REQUEST(irq_fields) = handle3; - if ((symbol = lookup_symbol(request->req_dbb, name, SYM_relation))) + if ((symbol = lookup_symbol(statement->req_dbb, name, SYM_relation))) { free_relation(relation); return (dsql_rel*) symbol->sym_object; @@ -1586,7 +1586,7 @@ dsql_rel* METD_get_relation(dsql_req* request, const dsql_str* name) symbol->sym_length = relation->rel_name.length(); symbol->sym_type = SYM_relation; symbol->sym_dbb = dbb; - insert_symbol(request->req_dbb, symbol); + insert_symbol(statement->req_dbb, symbol); } else { relation->rel_flags |= REL_new_relation; @@ -1688,7 +1688,7 @@ bool METD_get_type(dsql_req* request, const dsql_str* name, char* field, SSHORT* } -dsql_rel* METD_get_view_base(dsql_req* request, +dsql_rel* METD_get_view_base(CompiledStatement* statement, const char* view_name, // UTF-8 MetaNamePairMap& fields) { @@ -1709,11 +1709,11 @@ dsql_rel* METD_get_view_base(dsql_req* request, **************************************/ thread_db* tdbb = JRD_get_thread_data(); - validateTransaction(request); + validateTransaction(statement); dsql_rel* relation = NULL; - dsql_dbb* dbb = request->req_dbb; + dsql_dbb* dbb = statement->req_dbb; bool first = true; bool cont = true; MetaNamePairMap previousAux; @@ -1724,7 +1724,7 @@ dsql_rel* METD_get_view_base(dsql_req* request, { jrd_req* handle1 = CMP_find_request(tdbb, irq_view_base, IRQ_REQUESTS); - FOR(REQUEST_HANDLE handle1 TRANSACTION_HANDLE request->req_transaction) + FOR(REQUEST_HANDLE handle1 TRANSACTION_HANDLE statement->req_transaction) X IN RDB$VIEW_RELATIONS WITH X.RDB$VIEW_NAME EQ view_name @@ -1744,7 +1744,7 @@ dsql_rel* METD_get_view_base(dsql_req* request, dsql_str* relation_name = MAKE_string(X.RDB$RELATION_NAME, strlen(X.RDB$RELATION_NAME)); - relation = METD_get_relation(request, relation_name); + relation = METD_get_relation(statement, relation_name); delete relation_name; Firebird::Array ambiguities; @@ -1758,7 +1758,7 @@ dsql_rel* METD_get_view_base(dsql_req* request, jrd_req* handle2 = CMP_find_request(tdbb, irq_view_base_flds, IRQ_REQUESTS); - FOR(REQUEST_HANDLE handle2 TRANSACTION_HANDLE request->req_transaction) + FOR(REQUEST_HANDLE handle2 TRANSACTION_HANDLE statement->req_transaction) RFL IN RDB$RELATION_FIELDS WITH RFL.RDB$RELATION_NAME EQ X.RDB$VIEW_NAME @@ -1832,7 +1832,7 @@ dsql_rel* METD_get_view_base(dsql_req* request, } -dsql_rel* METD_get_view_relation(dsql_req* request, +dsql_rel* METD_get_view_relation(CompiledStatement* statement, const char* view_name, // UTF-8 const char* relation_or_alias) // UTF-8 { @@ -1850,15 +1850,15 @@ dsql_rel* METD_get_view_relation(dsql_req* request, **************************************/ thread_db* tdbb = JRD_get_thread_data(); - validateTransaction(request); + validateTransaction(statement); dsql_rel* relation = NULL; - dsql_dbb* dbb = request->req_dbb; + dsql_dbb* dbb = statement->req_dbb; jrd_req* handle = CMP_find_request(tdbb, irq_view, IRQ_REQUESTS); - FOR(REQUEST_HANDLE handle TRANSACTION_HANDLE request->req_transaction) + FOR(REQUEST_HANDLE handle TRANSACTION_HANDLE statement->req_transaction) X IN RDB$VIEW_RELATIONS WITH X.RDB$VIEW_NAME EQ view_name if (!DSQL_REQUEST(irq_view)) @@ -1872,13 +1872,13 @@ dsql_rel* METD_get_view_relation(dsql_req* request, { dsql_str* relation_name = MAKE_string(X.RDB$RELATION_NAME, strlen(X.RDB$RELATION_NAME)); - relation = METD_get_relation(request, relation_name); + relation = METD_get_relation(statement, relation_name); delete relation_name; return relation; } relation = - METD_get_view_relation(request, X.RDB$RELATION_NAME, relation_or_alias); + METD_get_view_relation(statement, X.RDB$RELATION_NAME, relation_or_alias); if (relation) { return relation; } diff --git a/src/dsql/metd_proto.h b/src/dsql/metd_proto.h index ab6f3cbdfb..8854bddea5 100644 --- a/src/dsql/metd_proto.h +++ b/src/dsql/metd_proto.h @@ -37,6 +37,7 @@ typedef Firebird::GenericMap MetaNamePairMap; namespace Jrd { class dsql_req; class dsql_str; + class CompiledStatement; }; void METD_drop_charset(Jrd::dsql_req*, const Firebird::MetaName&); @@ -56,14 +57,14 @@ USHORT METD_get_domain_default(Jrd::dsql_req*, const TEXT*, bool*, UCHAR*, USH bool METD_get_exception(Jrd::dsql_req*, const Jrd::dsql_str*); Jrd::dsql_udf* METD_get_function(Jrd::dsql_req*, const Jrd::dsql_str*); Jrd::dsql_nod* METD_get_primary_key(Jrd::dsql_req*, const Jrd::dsql_str*); -Jrd::dsql_prc* METD_get_procedure(Jrd::dsql_req*, const Jrd::dsql_str*); -Jrd::dsql_rel* METD_get_relation(Jrd::dsql_req*, const Jrd::dsql_str*); +Jrd::dsql_prc* METD_get_procedure(Jrd::CompiledStatement*, const Jrd::dsql_str*); +Jrd::dsql_rel* METD_get_relation(Jrd::CompiledStatement*, const Jrd::dsql_str*); bool METD_get_trigger(Jrd::dsql_req*, const Jrd::dsql_str*, Jrd::dsql_str**, USHORT*); bool METD_get_type(Jrd::dsql_req*, const Jrd::dsql_str*, char*, SSHORT*); -Jrd::dsql_rel* METD_get_view_base(Jrd::dsql_req* request, +Jrd::dsql_rel* METD_get_view_base(Jrd::CompiledStatement* request, const char* view_name, // UTF-8 MetaNamePairMap& fields); -Jrd::dsql_rel* METD_get_view_relation(Jrd::dsql_req* request, +Jrd::dsql_rel* METD_get_view_relation(Jrd::CompiledStatement* request, const char* view_name, // UTF-8 const char* relation_or_alias); // UTF-8 diff --git a/src/dsql/pass1.cpp b/src/dsql/pass1.cpp index f36ba01e39..5f808d8ca7 100644 --- a/src/dsql/pass1.cpp +++ b/src/dsql/pass1.cpp @@ -1,7 +1,7 @@ /* * PROGRAM: Dynamic SQL runtime support * MODULE: pass1.cpp - * DESCRIPTION: First-pass compiler for request trees. + * DESCRIPTION: First-pass compiler for statement trees. * * The contents of this file are subject to the Interbase Public * License Version 1.0 (the "License"); you may not use this file @@ -193,21 +193,21 @@ typedef Firebird::SortedArraynod_type == nod_rel_proc_name) && relation_node->nod_arg[e_rpn_inputs]) { - procedure = METD_get_procedure(request, relation_name); + procedure = METD_get_procedure(statement, relation_name); if (!procedure) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 204, @@ -372,16 +372,16 @@ dsql_ctx* PASS1_make_context(dsql_req* request, const dsql_nod* relation_node) 0); } } - else if ((cte = request->findCTE(relation_name))) + else if ((cte = statement->findCTE(relation_name))) { relation_node = cte; } else { - relation = METD_get_relation(request, relation_name); + relation = METD_get_relation(statement, relation_name); if (!relation && (relation_node->nod_type == nod_rel_proc_name)) { - procedure = METD_get_procedure(request, relation_name); + procedure = METD_get_procedure(statement, relation_name); } if (!relation && !procedure) { @@ -410,11 +410,11 @@ dsql_ctx* PASS1_make_context(dsql_req* request, const dsql_nod* relation_node) dsql_ctx(*tdbb->getDefaultPool()); context->ctx_relation = relation; context->ctx_procedure = procedure; - context->ctx_request = request; - context->ctx_context = request->req_context_number++; - context->ctx_scope_level = request->req_scope_level; + context->ctx_request = statement; + context->ctx_context = statement->req_context_number++; + context->ctx_scope_level = statement->req_scope_level; // When we're in a outer-join part mark context for it. - if (request->req_in_outer_join) { + if (statement->req_in_outer_join) { context->ctx_flags |= CTX_outer_join; } @@ -437,13 +437,13 @@ dsql_ctx* PASS1_make_context(dsql_req* request, const dsql_nod* relation_node) } DEV_BLKCHK(string, dsql_type_str); - if (request->req_alias_relation_prefix && !(relation_node->nod_type == nod_derived_table)) + if (statement->req_alias_relation_prefix && !(relation_node->nod_type == nod_derived_table)) { if (string) { - string = pass1_alias_concat(request->req_alias_relation_prefix, string); + string = pass1_alias_concat(statement->req_alias_relation_prefix, string); } else { - string = pass1_alias_concat(request->req_alias_relation_prefix, relation_name); + string = pass1_alias_concat(statement->req_alias_relation_prefix, relation_name); } } @@ -452,8 +452,8 @@ dsql_ctx* PASS1_make_context(dsql_req* request, const dsql_nod* relation_node) // check to make sure the context is not already used at this same // query level (if there are no subqueries, this checks that the - // alias is not used twice in the request). - for (DsqlContextStack::iterator stack(*request->req_context); + // alias is not used twice in the statement). + for (DsqlContextStack::iterator stack(*statement->req_context); stack.hasData(); ++stack) { const dsql_ctx* conflict = stack.object(); @@ -497,11 +497,11 @@ dsql_ctx* PASS1_make_context(dsql_req* request, const dsql_nod* relation_node) if (relation_node->nod_arg[e_rpn_inputs]) { context->ctx_proc_inputs = - pass1_node_psql(request, relation_node->nod_arg[e_rpn_inputs], false); + pass1_node_psql(statement, relation_node->nod_arg[e_rpn_inputs], false); count = context->ctx_proc_inputs->nod_count; } - if (!(request->req_flags & REQ_procedure)) + if (!(statement->req_flags & REQ_procedure)) { if (count > procedure->prc_in_count || count < procedure->prc_in_count - procedure->prc_def_count) @@ -522,17 +522,17 @@ dsql_ctx* PASS1_make_context(dsql_req* request, const dsql_nod* relation_node) DEV_BLKCHK(field, dsql_type_fld); DEV_BLKCHK(*input, dsql_type_nod); MAKE_desc_from_field(&desc_node->nod_desc, field); - // set_parameter_type(request, *input, &desc_node, false); - set_parameter_type(request, *input, desc_node, false); + // set_parameter_type(statement, *input, &desc_node, false); + set_parameter_type(statement, *input, desc_node, false); } } } } - // push the context onto the request context stack + // push the context onto the statement context stack // for matching fields against - request->req_context->push(context); + statement->req_context->push(context); return context; } @@ -542,16 +542,16 @@ dsql_ctx* PASS1_make_context(dsql_req* request, const dsql_nod* relation_node) PASS1_node - @brief Compile a parsed request into something more interesting. + @brief Compile a parsed statement into something more interesting. - @param request + @param statement @param input **/ -dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) +dsql_nod* PASS1_node(CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); if (input == NULL) { @@ -569,7 +569,7 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) case nod_alias: node = MAKE_node(input->nod_type, e_alias_count); node->nod_arg[e_alias_value] = sub1 = - PASS1_node(request, input->nod_arg[e_alias_value]); + PASS1_node(statement, input->nod_arg[e_alias_value]); node->nod_arg[e_alias_alias] = input->nod_arg[e_alias_alias]; node->nod_desc = sub1->nod_desc; return node; @@ -577,45 +577,45 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) case nod_cast: node = MAKE_node(input->nod_type, e_cast_count); node->nod_arg[e_cast_source] = sub1 = - PASS1_node(request, input->nod_arg[e_cast_source]); + PASS1_node(statement, input->nod_arg[e_cast_source]); node->nod_arg[e_cast_target] = input->nod_arg[e_cast_target]; field = (dsql_fld*) node->nod_arg[e_cast_target]; DEV_BLKCHK(field, dsql_type_fld); - DDL_resolve_intl_type(request, field, NULL); + DDL_resolve_intl_type(statement, field, NULL); MAKE_desc_from_field(&node->nod_desc, field); - set_parameter_type(request, node, NULL, false); + set_parameter_type(statement, node, NULL, false); // If the source is nullable, so is the target - MAKE_desc(request, &sub1->nod_desc, sub1, NULL); + MAKE_desc(statement, &sub1->nod_desc, sub1, NULL); if (sub1->nod_desc.dsc_flags & DSC_nullable) node->nod_desc.dsc_flags |= DSC_nullable; return node; case nod_coalesce: - return pass1_coalesce(request, input); + return pass1_coalesce(statement, input); case nod_derived_field: return input; case nod_simple_case: - return pass1_simple_case(request, input); + return pass1_simple_case(statement, input); case nod_searched_case: - return pass1_searched_case(request, input); + return pass1_searched_case(statement, input); case nod_gen_id: case nod_gen_id2: node = MAKE_node(input->nod_type, e_gen_id_count); node->nod_arg[e_gen_id_value] = - PASS1_node(request, input->nod_arg[e_gen_id_value]); + PASS1_node(statement, input->nod_arg[e_gen_id_value]); node->nod_arg[e_gen_id_name] = input->nod_arg[e_gen_id_name]; return node; case nod_collate: global_temp_collation_name = (dsql_str*) input->nod_arg[e_coll_target]; - sub1 = PASS1_node(request, input->nod_arg[e_coll_source]); + sub1 = PASS1_node(statement, input->nod_arg[e_coll_source]); global_temp_collation_name = NULL; node = - pass1_collate(request, sub1, (dsql_str*) input->nod_arg[e_coll_target]); + pass1_collate(statement, sub1, (dsql_str*) input->nod_arg[e_coll_target]); return node; case nod_extract: @@ -623,8 +623,8 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) // Figure out the data type of the sub parameter, and make // sure the requested type of information can be extracted - sub1 = PASS1_node(request, input->nod_arg[e_extract_value]); - MAKE_desc(request, &sub1->nod_desc, sub1, NULL); + sub1 = PASS1_node(statement, input->nod_arg[e_extract_value]); + MAKE_desc(statement, &sub1->nod_desc, sub1, NULL); switch (input->nod_arg[e_extract_part]->getSlong()) { @@ -670,7 +670,7 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) node = MAKE_node(input->nod_type, e_strlen_count); node->nod_arg[e_strlen_type] = input->nod_arg[e_strlen_type]; node->nod_arg[e_strlen_value] = - PASS1_node(request, input->nod_arg[e_strlen_value]); + PASS1_node(statement, input->nod_arg[e_strlen_value]); if (node->nod_arg[e_strlen_value]->nod_desc.dsc_flags & DSC_nullable) node->nod_desc.dsc_flags |= DSC_nullable; return node; @@ -686,46 +686,46 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) isc_arg_gds, isc_dsql_command_err, 0); case nod_derived_table: - return pass1_derived_table(request, input, NULL); + return pass1_derived_table(statement, input, NULL); case nod_select_expr: { - if (request->isPsql()) + if (statement->isPsql()) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 206, isc_arg_gds, isc_dsql_subselect_err, 0); } - const DsqlContextStack::iterator base(*request->req_context); + const DsqlContextStack::iterator base(*statement->req_context); node = MAKE_node(nod_via, e_via_count); - dsql_nod* rse = PASS1_rse(request, input, NULL); + dsql_nod* rse = PASS1_rse(statement, input, NULL); node->nod_arg[e_via_rse] = rse; node->nod_arg[e_via_value_1] = rse->nod_arg[e_rse_items]->nod_arg[0]; node->nod_arg[e_via_value_2] = MAKE_node(nod_null, (int) 0); // Finish off by cleaning up contexts - request->req_context->clear(base); + statement->req_context->clear(base); return node; } case nod_exists: case nod_singular: { - const DsqlContextStack::iterator base(*request->req_context); + const DsqlContextStack::iterator base(*statement->req_context); node = MAKE_node(input->nod_type, 1); input = input->nod_arg[0]; - node->nod_arg[0] = PASS1_rse(request, input, NULL); + node->nod_arg[0] = PASS1_rse(statement, input, NULL); // Finish off by cleaning up contexts - request->req_context->clear(base); + statement->req_context->clear(base); return node; } case nod_field_name: - if (request->isPsql()) - return pass1_variable(request, input); + if (statement->isPsql()) + return pass1_variable(statement, input); else - return pass1_field(request, input, false, NULL); + return pass1_field(statement, input, false, NULL); case nod_field: // AB: nod_field is an already passed node. @@ -733,13 +733,13 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) return input; case nod_array: - if (request->isPsql()) + if (statement->isPsql()) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_dsql_invalid_array, 0); } else - return pass1_field(request, input, false, NULL); + return pass1_field(statement, input, false, NULL); case nod_variable: node = MAKE_node (input->nod_type, e_var_count); @@ -748,10 +748,10 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) return node; case nod_var_name: - return pass1_variable(request, input); + return pass1_variable(statement, input); case nod_dbkey: - return pass1_dbkey(request, input); + return pass1_dbkey(statement, input); case nod_relation_name: case nod_rel_proc_name: @@ -772,14 +772,14 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) rel_alias = rel_name; } - dsql_nod* cte = request->findCTE(rel_name); + dsql_nod* cte = statement->findCTE(rel_name); if (cte) { cte->nod_flags |= NOD_DT_CTE_USED; - if ((request->req_flags & REQ_CTE_recursive) && - request->req_curr_ctes.hasData() && - (request->req_curr_ctes.object() == cte)) + if ((statement->req_flags & REQ_CTE_recursive) && + statement->req_curr_ctes.hasData() && + (statement->req_curr_ctes.object() == cte)) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_dsql_cte_wrong_reference, // Recursive CTE member (%s) can refer itself only in FROM clause @@ -787,7 +787,7 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) 0); } - for (DsqlNodStack::const_iterator stack(request->req_curr_ctes); stack.hasData(); ++stack) + for (DsqlNodStack::const_iterator stack(statement->req_curr_ctes); stack.hasData(); ++stack) { dsql_nod* cte1 = stack.object(); if (cte1 == cte) { @@ -808,26 +808,26 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) cte->nod_arg[e_derived_table_alias] = (dsql_nod*) rel_alias; } - request->req_curr_ctes.push(cte); + statement->req_curr_ctes.push(cte); - dsql_nod* derived_node = pass1_derived_table(request, cte, (isRecursive ? rel_alias : NULL)); + dsql_nod* derived_node = pass1_derived_table(statement, cte, (isRecursive ? rel_alias : NULL)); if (!isRecursive) { cte->nod_arg[e_derived_table_alias] = (dsql_nod*) cte_name; } - request->req_curr_ctes.pop(); + statement->req_curr_ctes.pop(); return derived_node; } - return pass1_relation(request, input); + return pass1_relation(statement, input); } case nod_constant: - return pass1_constant(request, input); + return pass1_constant(statement, input); case nod_parameter: - if (request->isPsql()) + if (statement->isPsql()) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_dsql_command_err, 0); @@ -839,7 +839,7 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) MAKE_parameter( (input->nod_arg[e_par_parameter] ? (dsql_msg*) ((dsql_par*) input->nod_arg[e_par_parameter])->par_message : - request->req_send), + statement->req_send), true, true, (USHORT)(IPTR) input->nod_arg[e_par_index], NULL); @@ -849,10 +849,10 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) case nod_param_val: node = MAKE_node(input->nod_type, e_prm_val_count); node->nod_arg[e_prm_val_fld] = input->nod_arg[e_prm_val_fld]; - node->nod_arg[e_prm_val_val] = PASS1_node(request, input->nod_arg[e_prm_val_val]); + node->nod_arg[e_prm_val_val] = PASS1_node(statement, input->nod_arg[e_prm_val_val]); field = (dsql_fld*) node->nod_arg[e_prm_val_fld]->nod_arg[e_dfl_field]; - DDL_resolve_intl_type(request, field, NULL); + DDL_resolve_intl_type(statement, field, NULL); { // scope dsql_nod *temp = node->nod_arg[e_prm_val_val]; @@ -864,16 +864,16 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) field->fld_flags |= FLD_nullable; MAKE_desc_from_field(&(desc_node->nod_desc), field); - set_parameter_type(request, temp, desc_node, false); + set_parameter_type(statement, temp, desc_node, false); } // end scope return node; case nod_udf: - return pass1_udf(request, input); + return pass1_udf(statement, input); case nod_sys_function: - return pass1_sys_function(request, input); + return pass1_sys_function(statement, input); case nod_equiv: case nod_eql: @@ -920,23 +920,23 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) 0); } - return PASS1_node(request, node); + return PASS1_node(statement, node); } if (sub2->nod_type == nod_select_expr) { - if (request->isPsql()) + if (statement->isPsql()) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 206, isc_arg_gds, isc_dsql_subselect_err, 0); } if (sub2->nod_flags & NOD_SELECT_EXPR_SINGLETON) { - const DsqlContextStack::iterator base(*request->req_context); + const DsqlContextStack::iterator base(*statement->req_context); node = MAKE_node(input->nod_type, 2); - node->nod_arg[0] = pass1_node_psql(request, input->nod_arg[0], false); + node->nod_arg[0] = pass1_node_psql(statement, input->nod_arg[0], false); dsql_nod* temp = MAKE_node(nod_via, e_via_count); node->nod_arg[1] = temp; - dsql_nod* rse = PASS1_rse(request, sub2, NULL); + dsql_nod* rse = PASS1_rse(statement, sub2, NULL); temp->nod_arg[e_via_rse] = rse; temp->nod_arg[e_via_value_1] = rse->nod_arg[e_rse_items]->nod_arg[0]; @@ -945,10 +945,10 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) // Try to force sub1 to be same type as sub2 eg: ? = (select ...) case sub1 = node->nod_arg[0]; sub2 = node->nod_arg[1]; - set_parameter_type(request, sub1, sub2, false); + set_parameter_type(statement, sub1, sub2, false); // Finish off by cleaning up contexts - request->req_context->clear(base); + statement->req_context->clear(base); return node; } @@ -962,7 +962,7 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) case nod_geq: case nod_lss: case nod_leq: - return pass1_any(request, input, nod_any); + return pass1_any(statement, input, nod_any); case nod_eql_any: case nod_neq_any: @@ -970,7 +970,7 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) case nod_geq_any: case nod_lss_any: case nod_leq_any: - return pass1_any(request, input, nod_ansi_any); + return pass1_any(statement, input, nod_ansi_any); case nod_eql_all: case nod_neq_all: @@ -978,7 +978,7 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) case nod_geq_all: case nod_lss_all: case nod_leq_all: - return pass1_any(request, input, nod_ansi_all); + return pass1_any(statement, input, nod_ansi_all); default: // make compiler happy break; } @@ -995,14 +995,14 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) case nod_agg_average2: case nod_agg_total2: case nod_agg_list: - if (request->isPsql()) + if (statement->isPsql()) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_dsql_command_err, 0); } - if (!(request->req_in_select_list || request->req_in_where_clause || - request->req_in_group_by_clause || request->req_in_having_clause || - request->req_in_order_by_clause)) + if (!(statement->req_in_select_list || statement->req_in_where_clause || + statement->req_in_group_by_clause || statement->req_in_having_clause || + statement->req_in_order_by_clause)) { /* not part of a select list, where clause, group by clause, having clause, or order by clause */ @@ -1014,20 +1014,20 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) node->nod_flags = input->nod_flags; if (input->nod_count) { for (int i = 0; i < input->nod_count; i++) { - node->nod_arg[i] = PASS1_node(request, input->nod_arg[i]); + node->nod_arg[i] = PASS1_node(statement, input->nod_arg[i]); Firebird::AutoPtr desc_node(FB_NEW_RPT(*getDefaultMemoryPool(), 0) dsql_nod); desc_node->nod_desc.dsc_dtype = dtype_text; desc_node->nod_desc.dsc_length = 1; desc_node->nod_desc.dsc_sub_type = 0; desc_node->nod_desc.dsc_scale = 0; - set_parameter_type(request, node->nod_arg[i], desc_node, false); + set_parameter_type(statement, node->nod_arg[i], desc_node, false); } } else { // Scope level is needed to determine to which context COUNT(*) belongs. node->nod_arg[e_agg_function_scope_level] = - (dsql_nod*)(IPTR) request->req_scope_level; + (dsql_nod*)(IPTR) statement->req_scope_level; } return node; @@ -1037,8 +1037,8 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) node = MAKE_node(input->nod_type, 2); node->nod_arg[0] = sub1 = MAKE_node(nod_relation, e_rel_count); sub1->nod_arg[e_rel_context] = - pass1_alias_list(request, input->nod_arg[0]); - node->nod_arg[1] = PASS1_node(request, input->nod_arg[1]); + pass1_alias_list(statement, input->nod_arg[0]); + node->nod_arg[1] = PASS1_node(statement, input->nod_arg[1]); return node; case nod_index: @@ -1055,7 +1055,7 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) case nod_dom_value: { const dsql_nod* const ddl_node = - (request->req_type == REQ_DDL) ? request->req_ddl_node : NULL; + (statement->req_type == REQ_DDL) ? statement->req_ddl_node : NULL; if (!ddl_node || !(ddl_node->nod_type == nod_def_domain || ddl_node->nod_type == nod_mod_domain)) @@ -1073,7 +1073,7 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) const internal_info_id id = *reinterpret_cast(input->nod_arg[0]->nod_desc.dsc_address); USHORT req_mask = InternalInfo::getMask(id); - if (req_mask && !(request->req_flags & req_mask)) + if (req_mask && !(statement->req_flags & req_mask)) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_token_err, // Token unknown @@ -1099,13 +1099,13 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) break; case nod_join: - return pass1_join(request, input); + return pass1_join(statement, input); case nod_returning: - return pass1_returning(request, input); + return pass1_returning(statement, input); case nod_not: - return pass1_not(request, input, true); + return pass1_not(statement, input, true); case nod_tran_params: return input; @@ -1114,7 +1114,7 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) node = MAKE_node(input->nod_type, input->nod_count); node->nod_arg[e_named_param_name] = input->nod_arg[e_named_param_name]; node->nod_arg[e_named_param_expr] = - PASS1_node(request, input->nod_arg[e_named_param_expr]); + PASS1_node(statement, input->nod_arg[e_named_param_expr]); return node; default: @@ -1131,7 +1131,7 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) ptr < end; ptr++) { DEV_BLKCHK(*ptr, dsql_type_nod); - *ptr2++ = PASS1_node(request, *ptr); + *ptr2++ = PASS1_node(statement, *ptr); DEV_BLKCHK(*(ptr2 - 1), dsql_type_nod); } @@ -1168,18 +1168,18 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) sub2 = node->nod_arg[1]; // Try to force sub1 to be same type as sub2 eg: ? = FIELD case - set_parameter_type(request, sub1, sub2, false); + set_parameter_type(statement, sub1, sub2, false); // Try to force sub2 to be same type as sub1 eg: FIELD = ? case // Try even when the above call succeeded, because "sub2" may // have sub-expressions that should be resolved. - set_parameter_type(request, sub2, sub1, false); + set_parameter_type(statement, sub2, sub1, false); // X BETWEEN Y AND ? case - if (!set_parameter_type(request, sub3, sub1, false)) + if (!set_parameter_type(statement, sub3, sub1, false)) { // ? BETWEEN Y AND ? case - set_parameter_type(request, sub3, sub2, false); + set_parameter_type(statement, sub3, sub2, false); } break; @@ -1195,19 +1195,19 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) sub2 = node->nod_arg[1]; // Try to force sub1 to be same type as sub2 eg: ? LIKE FIELD case - set_parameter_type(request, sub1, sub2, true); + set_parameter_type(statement, sub1, sub2, true); // Try to force sub2 same type as sub 1 eg: FIELD LIKE ? case // Try even when the above call succeeded, because "sub2" may // have sub-expressions that should be resolved. - set_parameter_type(request, sub2, sub1, true); + set_parameter_type(statement, sub2, sub1, true); // X LIKE Y ESCAPE ? case - set_parameter_type(request, sub3, sub2, true); + set_parameter_type(statement, sub3, sub2, true); break; case nod_missing: - set_parameter_type(request, node, NULL, false); + set_parameter_type(statement, node, NULL, false); break; case nod_trim: @@ -1215,7 +1215,7 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) sub2 = node->nod_arg[e_trim_value]; // Try to force sub1 to be same type as sub2 eg: TRIM(? FROM FIELD) case - set_parameter_type(request, sub1, sub2, false); + set_parameter_type(statement, sub1, sub2, false); break; default: @@ -1231,27 +1231,27 @@ dsql_nod* PASS1_node(dsql_req* request, dsql_nod* input) PASS1_rse @brief Compile a record selection expression, - bumping up the request scope level + bumping up the statement scope level everytime an rse is seen. The scope level controls parsing of aliases. - @param request + @param statement @param input @param update_lock **/ -dsql_nod* PASS1_rse(dsql_req* request, dsql_nod* input, dsql_nod* update_lock) +dsql_nod* PASS1_rse(CompiledStatement* statement, dsql_nod* input, dsql_nod* update_lock) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); DEV_BLKCHK(update_lock, dsql_type_nod); fb_assert(input->nod_type == nod_select_expr); - request->req_scope_level++; - dsql_nod* node = pass1_rse(request, input, NULL, NULL, update_lock, 0); - request->req_scope_level--; + statement->req_scope_level++; + dsql_nod* node = pass1_rse(statement, input, NULL, NULL, update_lock, 0); + statement->req_scope_level--; return node; } @@ -1261,16 +1261,16 @@ dsql_nod* PASS1_rse(dsql_req* request, dsql_nod* input, dsql_nod* update_lock) PASS1_statement - @brief Compile a parsed request into something more interesting. + @brief Compile a parsed statement into something more interesting. - @param request + @param statement @param input **/ -dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) +dsql_nod* PASS1_statement(CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); #ifdef DSQL_DEBUG @@ -1281,14 +1281,14 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) #endif dsql_nod* node = NULL; - const DsqlContextStack::iterator base(*request->req_context); + const DsqlContextStack::iterator base(*statement->req_context); // Dispatch on node type. Fall thru on easy ones switch (input->nod_type) { case nod_def_database: - request->req_type = REQ_CREATE_DB; + statement->req_type = REQ_CREATE_DB; return input; case nod_def_relation: @@ -1334,12 +1334,12 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) case nod_del_user: case nod_def_collation: case nod_del_collation: - request->req_type = REQ_DDL; + statement->req_type = REQ_DDL; return input; case nod_class_node: node = reinterpret_cast( - reinterpret_cast(input->nod_arg[0])->dsqlPass(request)); + reinterpret_cast(input->nod_arg[0])->dsqlPass(statement)); if (node != input->nod_arg[0]) { input = MAKE_node(input->nod_type, input->nod_count); @@ -1352,13 +1352,13 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) case nod_mod_trigger: case nod_replace_trigger: case nod_del_trigger: - request->req_type = REQ_DDL; - request->req_flags |= (REQ_block | REQ_procedure | REQ_trigger); + statement->req_type = REQ_DDL; + statement->req_flags |= (REQ_block | REQ_procedure | REQ_trigger); return input; case nod_del_procedure: - request->req_type = REQ_DDL; - request->req_flags |= (REQ_block | REQ_procedure); + statement->req_type = REQ_DDL; + statement->req_flags |= (REQ_block | REQ_procedure); return input; case nod_def_procedure: @@ -1366,8 +1366,8 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) case nod_mod_procedure: case nod_replace_procedure: { - request->req_type = REQ_DDL; - request->req_flags |= (REQ_block | REQ_procedure); + statement->req_type = REQ_DDL; + statement->req_flags |= (REQ_block | REQ_procedure); const dsql_nod* variables = input->nod_arg[e_prc_dcls]; if (variables) { @@ -1432,39 +1432,39 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) case nod_assign: node = MAKE_node(input->nod_type, input->nod_count); - node->nod_arg[e_asgn_value] = PASS1_node(request, input->nod_arg[e_asgn_value]); - node->nod_arg[e_asgn_field] = PASS1_node(request, input->nod_arg[e_asgn_field]); + node->nod_arg[e_asgn_value] = PASS1_node(statement, input->nod_arg[e_asgn_value]); + node->nod_arg[e_asgn_field] = PASS1_node(statement, input->nod_arg[e_asgn_field]); break; case nod_commit: if ((input->nod_arg[e_commit_retain]) && (input->nod_arg[e_commit_retain]->nod_type == nod_retain)) { - request->req_type = REQ_COMMIT_RETAIN; + statement->req_type = REQ_COMMIT_RETAIN; } else - request->req_type = REQ_COMMIT; + statement->req_type = REQ_COMMIT; return input; case nod_rollback: if ((input->nod_arg[e_rollback_retain]) && (input->nod_arg[e_rollback_retain]->nod_type == nod_retain)) { - request->req_type = REQ_ROLLBACK_RETAIN; + statement->req_type = REQ_ROLLBACK_RETAIN; } else - request->req_type = REQ_ROLLBACK; + statement->req_type = REQ_ROLLBACK; return input; case nod_delete: - node = pass1_savepoint(request, pass1_delete(request, input)); + node = pass1_savepoint(statement, pass1_delete(statement, input)); break; case nod_exec_procedure: { const dsql_str* name = (dsql_str*) input->nod_arg[e_exe_procedure]; DEV_BLKCHK(name, dsql_type_str); - dsql_prc* procedure = METD_get_procedure(request, name); + dsql_prc* procedure = METD_get_procedure(statement, name); if (!procedure) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 204, isc_arg_gds, isc_dsql_procedure_err, @@ -1472,10 +1472,10 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) isc_arg_string, name->str_data, 0); } - if (!request->isPsql()) + if (!statement->isPsql()) { - request->req_procedure = procedure; - request->req_type = REQ_EXEC_PROCEDURE; + statement->req_procedure = procedure; + statement->req_type = REQ_EXEC_PROCEDURE; } node = MAKE_node(input->nod_type, input->nod_count); @@ -1491,7 +1491,7 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) ERRD_post(isc_prcmismat, isc_arg_string, name->str_data, 0); } - node->nod_arg[e_exe_inputs] = PASS1_node(request, input->nod_arg[e_exe_inputs]); + node->nod_arg[e_exe_inputs] = PASS1_node(statement, input->nod_arg[e_exe_inputs]); if (count) { // Initialize this stack variable, and make it look like a node @@ -1505,14 +1505,14 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) DEV_BLKCHK(*ptr, dsql_type_nod); MAKE_desc_from_field(&desc_node->nod_desc, field); // set_parameter_type(*ptr, &desc_node, false); - set_parameter_type(request, *ptr, desc_node, false); + set_parameter_type(statement, *ptr, desc_node, false); } } // handle output parameters dsql_nod* temp = input->nod_arg[e_exe_outputs]; - if (request->isPsql()) + if (statement->isPsql()) { count = temp ? temp->nod_count : 0; if (count != procedure->prc_out_count) @@ -1521,7 +1521,7 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) isc_arg_string, name->str_data, 0); } - node->nod_arg[e_exe_outputs] = PASS1_node(request, temp); + node->nod_arg[e_exe_outputs] = PASS1_node(statement, temp); } else { if (temp) { @@ -1530,7 +1530,7 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) isc_arg_gds, isc_random, isc_arg_string, "RETURNING_VALUES", 0); } node->nod_arg[e_exe_outputs] = - explode_outputs(request, request->req_procedure); + explode_outputs(statement, statement->req_procedure); } } break; @@ -1539,15 +1539,15 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) if (input->nod_arg[e_exe_blk_outputs] && input->nod_arg[e_exe_blk_outputs]->nod_count) { - request->req_type = REQ_SELECT_BLOCK; + statement->req_type = REQ_SELECT_BLOCK; } else - request->req_type = REQ_EXEC_BLOCK; - request->req_flags |= REQ_block; + statement->req_type = REQ_EXEC_BLOCK; + statement->req_flags |= REQ_block; node = MAKE_node(input->nod_type, input->nod_count); node->nod_arg[e_exe_blk_inputs] = - pass1_node_psql(request, input->nod_arg[e_exe_blk_inputs], false); + pass1_node_psql(statement, input->nod_arg[e_exe_blk_inputs], false); node->nod_arg[e_exe_blk_outputs] = input->nod_arg[e_exe_blk_outputs]; @@ -1580,15 +1580,15 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) node->nod_flags = input->nod_flags; dsql_nod* cursor = node->nod_arg[e_flp_cursor] = input->nod_arg[e_flp_cursor]; - node->nod_arg[e_flp_select] = PASS1_statement(request, input->nod_arg[e_flp_select]); + node->nod_arg[e_flp_select] = PASS1_statement(statement, input->nod_arg[e_flp_select]); if (cursor) { fb_assert(cursor->nod_flags > 0); - pass1_cursor_name(request, (dsql_str*) cursor->nod_arg[e_cur_name], + pass1_cursor_name(statement, (dsql_str*) cursor->nod_arg[e_cur_name], NOD_CURSOR_ALL, false); cursor->nod_arg[e_cur_rse] = node->nod_arg[e_flp_select]; - cursor->nod_arg[e_cur_number] = (dsql_nod*) (IPTR) request->req_cursor_number++; - request->req_cursors.push(cursor); + cursor->nod_arg[e_cur_number] = (dsql_nod*) (IPTR) statement->req_cursor_number++; + statement->req_cursors.push(cursor); } dsql_nod* into_in = input->nod_arg[e_flp_into]; @@ -1603,7 +1603,7 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) ptr < end; ptr++) { DEV_BLKCHK(*ptr, dsql_type_nod); - *ptr2++ = PASS1_node(request, *ptr); + *ptr2++ = PASS1_node(statement, *ptr); DEV_BLKCHK(*(ptr2 - 1), dsql_type_nod); } } @@ -1612,34 +1612,34 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) { // CVC: Let's add the ability to BREAK the for_select same as the while, // but only if the command is FOR SELECT, otherwise we have singular SELECT - request->req_loop_level++; - node->nod_arg[e_flp_label] = pass1_label(request, input); + statement->req_loop_level++; + node->nod_arg[e_flp_label] = pass1_label(statement, input); node->nod_arg[e_flp_action] = - PASS1_statement(request, input->nod_arg[e_flp_action]); - request->req_loop_level--; - request->req_labels.pop(); + PASS1_statement(statement, input->nod_arg[e_flp_action]); + statement->req_loop_level--; + statement->req_labels.pop(); } if (cursor) { - request->req_cursor_number--; - request->req_cursors.pop(); + statement->req_cursor_number--; + statement->req_cursors.pop(); } } break; case nod_get_segment: case nod_put_segment: - pass1_blob(request, input); + pass1_blob(statement, input); return input; case nod_if: node = MAKE_node(input->nod_type, input->nod_count); node->nod_arg[e_if_condition] = - PASS1_node(request, input->nod_arg[e_if_condition]); + PASS1_node(statement, input->nod_arg[e_if_condition]); node->nod_arg[e_if_true] = - PASS1_statement(request, input->nod_arg[e_if_true]); + PASS1_statement(statement, input->nod_arg[e_if_true]); if (input->nod_arg[e_if_false]) - node->nod_arg[e_if_false] = PASS1_statement(request, input->nod_arg[e_if_false]); + node->nod_arg[e_if_false] = PASS1_statement(statement, input->nod_arg[e_if_false]); else node->nod_arg[e_if_false] = NULL; break; @@ -1650,28 +1650,28 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) if (input->nod_arg[e_xcps_msg]) { node->nod_arg[e_xcps_msg] = - PASS1_node(request, input->nod_arg[e_xcps_msg]); + PASS1_node(statement, input->nod_arg[e_xcps_msg]); } else { node->nod_arg[e_xcps_msg] = 0; } - return pass1_savepoint(request, node); + return pass1_savepoint(statement, node); case nod_insert: - node = pass1_savepoint(request, pass1_insert(request, input, false)); + node = pass1_savepoint(statement, pass1_insert(statement, input, false)); break; case nod_merge: - node = pass1_savepoint(request, pass1_merge(request, input)); + node = pass1_savepoint(statement, pass1_merge(statement, input)); break; case nod_block: if (input->nod_arg[e_blk_errs]) - request->req_error_handlers++; + statement->req_error_handlers++; else if (input->nod_arg[e_blk_action]) { input->nod_count = 1; - if (!request->req_error_handlers) + if (!statement->req_error_handlers) input->nod_type = nod_list; } else { @@ -1689,13 +1689,13 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) { DEV_BLKCHK(*ptr, dsql_type_nod); if ((*ptr)->nod_type == nod_assign) - *ptr2++ = PASS1_node(request, *ptr); + *ptr2++ = PASS1_node(statement, *ptr); else - *ptr2++ = PASS1_statement(request, *ptr); + *ptr2++ = PASS1_statement(statement, *ptr); DEV_BLKCHK(*(ptr2 - 1), dsql_type_nod); } if (input->nod_type == nod_block && input->nod_arg[e_blk_errs]) - request->req_error_handlers--; + statement->req_error_handlers--; return node; } @@ -1703,47 +1703,47 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) node = MAKE_node(input->nod_type, input->nod_count); node->nod_arg[e_err_errs] = input->nod_arg[e_err_errs]; node->nod_arg[e_err_action] = - PASS1_statement(request, input->nod_arg[e_err_action]); + PASS1_statement(statement, input->nod_arg[e_err_action]); return node; case nod_post: node = MAKE_node(input->nod_type, input->nod_count); node->nod_arg[e_pst_event] = - PASS1_node(request, input->nod_arg[e_pst_event]); + PASS1_node(statement, input->nod_arg[e_pst_event]); node->nod_arg[e_pst_argument] = - PASS1_node(request, input->nod_arg[e_pst_argument]); + PASS1_node(statement, input->nod_arg[e_pst_argument]); return node; case nod_exec_sql: node = MAKE_node(input->nod_type, input->nod_count); node->nod_arg[e_exec_sql_stmnt] = - PASS1_node(request, input->nod_arg[e_exec_sql_stmnt]); - return pass1_savepoint(request, node); + PASS1_node(statement, input->nod_arg[e_exec_sql_stmnt]); + return pass1_savepoint(statement, node); // CVC: This node seems obsolete. case nod_exec_into: node = MAKE_node(input->nod_type, input->nod_count); node->nod_arg[e_exec_into_stmnt] = - PASS1_node(request, input->nod_arg[e_exec_into_stmnt]); + PASS1_node(statement, input->nod_arg[e_exec_into_stmnt]); if (input->nod_arg[e_exec_into_block]) { - request->req_loop_level++; - node->nod_arg[e_exec_into_label] = pass1_label(request, input); + statement->req_loop_level++; + node->nod_arg[e_exec_into_label] = pass1_label(statement, input); node->nod_arg[e_exec_into_block] = - PASS1_statement(request, input->nod_arg[e_exec_into_block]); - request->req_loop_level--; - request->req_labels.pop(); + PASS1_statement(statement, input->nod_arg[e_exec_into_block]); + statement->req_loop_level--; + statement->req_labels.pop(); } node->nod_arg[e_exec_into_list] = - PASS1_node(request, input->nod_arg[e_exec_into_list]); - return pass1_savepoint(request, node); + PASS1_node(statement, input->nod_arg[e_exec_into_list]); + return pass1_savepoint(statement, node); case nod_exec_stmt: node = MAKE_node(input->nod_type, input->nod_count); node->nod_arg[e_exec_stmt_sql] = - PASS1_node(request, input->nod_arg[e_exec_stmt_sql]); + PASS1_node(statement, input->nod_arg[e_exec_stmt_sql]); node->nod_arg[e_exec_stmt_inputs] = - PASS1_node(request, input->nod_arg[e_exec_stmt_inputs]); + PASS1_node(statement, input->nod_arg[e_exec_stmt_inputs]); // check params names uniqueness, if present if (node->nod_arg[e_exec_stmt_inputs]) @@ -1768,52 +1768,52 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) } node->nod_arg[e_exec_stmt_outputs] = - PASS1_node(request, input->nod_arg[e_exec_stmt_outputs]); + PASS1_node(statement, input->nod_arg[e_exec_stmt_outputs]); if (input->nod_arg[e_exec_stmt_proc_block]) { - request->req_loop_level++; - node->nod_arg[e_exec_stmt_label] = pass1_label(request, input); + statement->req_loop_level++; + node->nod_arg[e_exec_stmt_label] = pass1_label(statement, input); node->nod_arg[e_exec_stmt_proc_block] = - PASS1_statement(request, input->nod_arg[e_exec_stmt_proc_block]); - request->req_loop_level--; - request->req_labels.pop(); + PASS1_statement(statement, input->nod_arg[e_exec_stmt_proc_block]); + statement->req_loop_level--; + statement->req_labels.pop(); } node->nod_arg[e_exec_stmt_data_src] = - PASS1_node(request, input->nod_arg[e_exec_stmt_data_src]); + PASS1_node(statement, input->nod_arg[e_exec_stmt_data_src]); node->nod_arg[e_exec_stmt_user] = - PASS1_node(request, input->nod_arg[e_exec_stmt_user]); + PASS1_node(statement, input->nod_arg[e_exec_stmt_user]); node->nod_arg[e_exec_stmt_pwd] = - PASS1_node(request, input->nod_arg[e_exec_stmt_pwd]); + PASS1_node(statement, input->nod_arg[e_exec_stmt_pwd]); node->nod_arg[e_exec_stmt_tran] = - PASS1_node(request, input->nod_arg[e_exec_stmt_tran]); + PASS1_node(statement, input->nod_arg[e_exec_stmt_tran]); - return pass1_savepoint(request, node); + return pass1_savepoint(statement, node); case nod_exit: return input; case nod_breakleave: - if (!request->req_loop_level) + if (!statement->req_loop_level) ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_token_err, // Token unknown isc_arg_gds, isc_random, isc_arg_string, "BREAK/LEAVE", 0); - input->nod_arg[e_breakleave_label] = pass1_label(request, input); + input->nod_arg[e_breakleave_label] = pass1_label(statement, input); return input; case nod_return: - if (request->req_flags & REQ_trigger) // triggers only + if (statement->req_flags & REQ_trigger) // triggers only { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_token_err, // Token unknown isc_arg_gds, isc_random, isc_arg_string, "SUSPEND", 0); } - if (request->req_flags & REQ_in_auto_trans_block) // autonomous transaction + if (statement->req_flags & REQ_in_auto_trans_block) // autonomous transaction { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 901, isc_arg_gds, isc_dsql_unsupported_in_auto_trans, @@ -1821,20 +1821,20 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) 0); } - request->req_flags |= REQ_selectable; + statement->req_flags |= REQ_selectable; input->nod_arg[e_rtn_procedure] = - request->req_ddl_node ? request->req_ddl_node : request->req_blk_node; + statement->req_ddl_node ? statement->req_ddl_node : statement->req_blk_node; return input; case nod_select: { - node = PASS1_rse(request, input->nod_arg[e_select_expr], + node = PASS1_rse(statement, input->nod_arg[e_select_expr], input->nod_arg[e_select_lock]); if (input->nod_arg[e_select_update]) { - request->req_type = REQ_SELECT_UPD; - request->req_flags |= REQ_no_batch; + statement->req_type = REQ_SELECT_UPD; + statement->req_flags |= REQ_no_batch; break; } /* @@ -1845,34 +1845,34 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) */ if (node->nod_arg[e_rse_sort] || node->nod_arg[e_rse_reduced]) { - request->req_flags &= ~REQ_no_batch; + statement->req_flags &= ~REQ_no_batch; } } break; case nod_trans: - request->req_type = REQ_START_TRANS; + statement->req_type = REQ_START_TRANS; return input; case nod_update: - node = pass1_savepoint(request, pass1_update(request, input, false)); + node = pass1_savepoint(statement, pass1_update(statement, input, false)); break; case nod_while: { node = MAKE_node(input->nod_type, input->nod_count); node->nod_arg[e_while_cond] = - PASS1_node(request, input->nod_arg[e_while_cond]); + PASS1_node(statement, input->nod_arg[e_while_cond]); // CVC: loop numbers should be incremented before analyzing the body // to preserve nesting <==> increasing level number - request->req_loop_level++; - node->nod_arg[e_while_label] = pass1_label(request, input); + statement->req_loop_level++; + node->nod_arg[e_while_label] = pass1_label(statement, input); node->nod_arg[e_while_action] = - PASS1_statement(request, input->nod_arg[e_while_action]); - request->req_loop_level--; - request->req_labels.pop(); + PASS1_statement(statement, input->nod_arg[e_while_action]); + statement->req_loop_level--; + statement->req_labels.pop(); } break; @@ -1883,27 +1883,27 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) return input; case nod_user_savepoint: - if (request->req_flags & REQ_block) // blocks, procedures and triggers + if (statement->req_flags & REQ_block) // blocks, procedures and triggers ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_token_err, // Token unknown isc_arg_gds, isc_random, isc_arg_string, "SAVEPOINT", 0); - request->req_type = REQ_SAVEPOINT; + statement->req_type = REQ_SAVEPOINT; return input; case nod_release_savepoint: - if (request->req_flags & REQ_block) // blocks, procedures and triggers + if (statement->req_flags & REQ_block) // blocks, procedures and triggers ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_token_err, // Token unknown isc_arg_gds, isc_random, isc_arg_string, "RELEASE", 0); - request->req_type = REQ_SAVEPOINT; + statement->req_type = REQ_SAVEPOINT; return input; case nod_undo_savepoint: - if (request->req_flags & REQ_block) // blocks, procedures and triggers + if (statement->req_flags & REQ_block) // blocks, procedures and triggers ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_token_err, // Token unknown isc_arg_gds, isc_random, isc_arg_string, "ROLLBACK", 0); - request->req_type = REQ_SAVEPOINT; + statement->req_type = REQ_SAVEPOINT; return input; case nod_null: @@ -1912,17 +1912,17 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) case nod_set_generator: node = MAKE_node(input->nod_type, e_gen_id_count); node->nod_arg[e_gen_id_value] = - PASS1_node(request, input->nod_arg[e_gen_id_value]); + PASS1_node(statement, input->nod_arg[e_gen_id_value]); node->nod_arg[e_gen_id_name] = input->nod_arg[e_gen_id_name]; - request->req_type = REQ_SET_GENERATOR; + statement->req_type = REQ_SET_GENERATOR; break; case nod_set_generator2: node = MAKE_node(input->nod_type, e_gen_id_count); node->nod_arg[e_gen_id_value] = - PASS1_node(request, input->nod_arg[e_gen_id_value]); + PASS1_node(statement, input->nod_arg[e_gen_id_value]); node->nod_arg[e_gen_id_name] = input->nod_arg[e_gen_id_name]; - request->req_type = REQ_SET_GENERATOR; + statement->req_type = REQ_SET_GENERATOR; break; case nod_union: @@ -1936,28 +1936,28 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) { fb_assert(input->nod_flags > 0); // make sure the cursor doesn't exist - pass1_cursor_name(request, (dsql_str*) input->nod_arg[e_cur_name], + pass1_cursor_name(statement, (dsql_str*) input->nod_arg[e_cur_name], NOD_CURSOR_ALL, false); // temporarily hide unnecessary contexts and process our RSE - DsqlContextStack* const base_context = request->req_context; + DsqlContextStack* const base_context = statement->req_context; DsqlContextStack temp; - request->req_context = &temp; + statement->req_context = &temp; const dsql_nod* select = input->nod_arg[e_cur_rse]; input->nod_arg[e_cur_rse] = - PASS1_rse(request, select->nod_arg[e_select_expr], + PASS1_rse(statement, select->nod_arg[e_select_expr], select->nod_arg[e_select_lock]); - request->req_context->clear(); - request->req_context = base_context; - // assign number and store in the request stack - input->nod_arg[e_cur_number] = (dsql_nod*) (IPTR) request->req_cursor_number++; - request->req_cursors.push(input); + statement->req_context->clear(); + statement->req_context = base_context; + // assign number and store in the statement stack + input->nod_arg[e_cur_number] = (dsql_nod*) (IPTR) statement->req_cursor_number++; + statement->req_cursors.push(input); } return input; case nod_cursor_open: case nod_cursor_close: case nod_cursor_fetch: - if (request->req_flags & REQ_in_auto_trans_block) // autonomous transaction + if (statement->req_flags & REQ_in_auto_trans_block) // autonomous transaction { const char* stmt = NULL; @@ -1982,17 +1982,17 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) // resolve the cursor input->nod_arg[e_cur_stmt_id] = - pass1_cursor_name(request, (dsql_str*) input->nod_arg[e_cur_stmt_id], + pass1_cursor_name(statement, (dsql_str*) input->nod_arg[e_cur_stmt_id], NOD_CURSOR_EXPLICIT, true); // process a seek node, if exists if (input->nod_arg[e_cur_stmt_seek]) { input->nod_arg[e_cur_stmt_seek] = - PASS1_node(request, input->nod_arg[e_cur_stmt_seek]); + PASS1_node(statement, input->nod_arg[e_cur_stmt_seek]); } // process an assignment node, if exists if (input->nod_arg[e_cur_stmt_into]) { input->nod_arg[e_cur_stmt_into] = - PASS1_node(request, input->nod_arg[e_cur_stmt_into]); + PASS1_node(statement, input->nod_arg[e_cur_stmt_into]); } return input; @@ -2000,12 +2000,12 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) { input->nod_line = (USHORT) (IPTR) input->nod_arg[e_src_info_line]; input->nod_column = (USHORT) (IPTR) input->nod_arg[e_src_info_column]; - input->nod_arg[e_src_info_stmt] = PASS1_statement(request, input->nod_arg[e_src_info_stmt]); + input->nod_arg[e_src_info_stmt] = PASS1_statement(statement, input->nod_arg[e_src_info_stmt]); return input; } case nod_update_or_insert: - node = pass1_savepoint(request, pass1_update_or_insert(request, input)); + node = pass1_savepoint(statement, pass1_update_or_insert(statement, input)); break; default: @@ -2017,7 +2017,7 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) } // Finish off by cleaning up contexts - request->req_context->clear(base); + statement->req_context->clear(base); #ifdef DSQL_DEBUG if (DSQL_debug & 1) { @@ -2039,19 +2039,19 @@ dsql_nod* PASS1_statement(dsql_req* request, dsql_nod* input) an expression tree. - @param request + @param statement @param node **/ -static bool aggregate_found( const dsql_req* request, const dsql_nod* node) +static bool aggregate_found( const CompiledStatement* statement, const dsql_nod* node) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(node, dsql_type_nod); - USHORT current_level = request->req_scope_level; + USHORT current_level = statement->req_scope_level; USHORT deepest_level = 0; - return aggregate_found2(request, node, ¤t_level, &deepest_level, false); + return aggregate_found2(statement, node, ¤t_level, &deepest_level, false); } @@ -2069,18 +2069,18 @@ static bool aggregate_found( const dsql_req* request, const dsql_nod* node) field is true if a non-aggregate field reference is seen. - @param request + @param statement @param node @param current_level @param deepest_level @param ignore_sub_selects **/ -static bool aggregate_found2(const dsql_req* request, const dsql_nod* node, +static bool aggregate_found2(const CompiledStatement* statement, const dsql_nod* node, USHORT* current_level, USHORT* deepest_level, bool ignore_sub_selects) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(node, dsql_type_nod); if (!node) @@ -2107,7 +2107,7 @@ static bool aggregate_found2(const dsql_req* request, const dsql_nod* node, // If we are already in a aggregate function don't search inside // sub-selects and other aggregate-functions for the deepest field // used else we would have a wrong deepest_level value. - aggregate_found2(request, node->nod_arg[e_agg_function_expression], + aggregate_found2(statement, node->nod_arg[e_agg_function_expression], current_level, &ldeepest_level, true); if (ldeepest_level == 0) { *deepest_level = *current_level; @@ -2117,18 +2117,18 @@ static bool aggregate_found2(const dsql_req* request, const dsql_nod* node, } // If the deepest_value is the same as the current scope_level // this an aggregate that belongs to the current context. - if (*deepest_level == request->req_scope_level) { + if (*deepest_level == statement->req_scope_level) { aggregate = true; } else { // Check also for a nested aggregate that could belong to this context - aggregate |= aggregate_found2(request, node->nod_arg[e_agg_function_expression], + aggregate |= aggregate_found2(statement, node->nod_arg[e_agg_function_expression], current_level, &ldeepest_level, false); } } else { // we have Count(*) - if (request->req_scope_level == (USHORT)(U_IPTR)node->nod_arg[e_agg_function_scope_level]) { + if (statement->req_scope_level == (USHORT)(U_IPTR)node->nod_arg[e_agg_function_scope_level]) { aggregate = true; } } @@ -2146,7 +2146,7 @@ static bool aggregate_found2(const dsql_req* request, const dsql_nod* node, } case nod_alias: - aggregate = aggregate_found2(request, node->nod_arg[e_alias_value], + aggregate = aggregate_found2(statement, node->nod_arg[e_alias_value], current_level, deepest_level, ignore_sub_selects); return aggregate; @@ -2164,12 +2164,12 @@ static bool aggregate_found2(const dsql_req* request, const dsql_nod* node, case nod_map: { const dsql_ctx* lcontext = reinterpret_cast(node->nod_arg[e_map_context]); - if (lcontext->ctx_scope_level == request->req_scope_level) { + if (lcontext->ctx_scope_level == statement->req_scope_level) { return true; } else { const dsql_map* lmap = reinterpret_cast(node->nod_arg[e_map_map]); - aggregate = aggregate_found2(request, lmap->map_node, current_level, + aggregate = aggregate_found2(statement, lmap->map_node, current_level, deepest_level, ignore_sub_selects); return aggregate; } @@ -2180,7 +2180,7 @@ static bool aggregate_found2(const dsql_req* request, const dsql_nod* node, case nod_via: if (!ignore_sub_selects) { - aggregate = aggregate_found2(request, node->nod_arg[e_via_rse], current_level, + aggregate = aggregate_found2(statement, node->nod_arg[e_via_rse], current_level, deepest_level, ignore_sub_selects); } return aggregate; @@ -2188,31 +2188,31 @@ static bool aggregate_found2(const dsql_req* request, const dsql_nod* node, case nod_exists: case nod_singular: if (!ignore_sub_selects) { - aggregate = aggregate_found2(request, node->nod_arg[0], current_level, + aggregate = aggregate_found2(statement, node->nod_arg[0], current_level, deepest_level, ignore_sub_selects); } return aggregate; case nod_aggregate: if (!ignore_sub_selects) { - aggregate = aggregate_found2(request, node->nod_arg[e_agg_rse], current_level, + aggregate = aggregate_found2(statement, node->nod_arg[e_agg_rse], current_level, deepest_level, ignore_sub_selects); } return aggregate; case nod_rse: ++*current_level; - aggregate |= aggregate_found2(request, node->nod_arg[e_rse_streams], current_level, + aggregate |= aggregate_found2(statement, node->nod_arg[e_rse_streams], current_level, deepest_level, ignore_sub_selects); - aggregate |= aggregate_found2(request, node->nod_arg[e_rse_boolean], + aggregate |= aggregate_found2(statement, node->nod_arg[e_rse_boolean], current_level, deepest_level, ignore_sub_selects); - aggregate |= aggregate_found2(request, node->nod_arg[e_rse_items], + aggregate |= aggregate_found2(statement, node->nod_arg[e_rse_items], current_level, deepest_level, ignore_sub_selects); --*current_level; return aggregate; case nod_order: - aggregate = aggregate_found2(request, node->nod_arg[e_order_field], current_level, + aggregate = aggregate_found2(statement, node->nod_arg[e_order_field], current_level, deepest_level, ignore_sub_selects); return aggregate; @@ -2274,7 +2274,7 @@ static bool aggregate_found2(const dsql_req* request, const dsql_nod* node, for (const dsql_nod* const* const end = ptr + node->nod_count; ptr < end; ++ptr) { - aggregate |= aggregate_found2(request, *ptr, current_level, + aggregate |= aggregate_found2(statement, *ptr, current_level, deepest_level, ignore_sub_selects); } return aggregate; @@ -2286,7 +2286,7 @@ static bool aggregate_found2(const dsql_req* request, const dsql_nod* node, case nod_udf: case nod_sys_function: if (node->nod_count == 2) { - return (aggregate_found2(request, node->nod_arg[1], current_level, + return (aggregate_found2(statement, node->nod_arg[1], current_level, deepest_level, ignore_sub_selects)); } return false; @@ -2300,7 +2300,7 @@ static bool aggregate_found2(const dsql_req* request, const dsql_nod* node, // Check if relation is a procedure if (lrelation_context->ctx_procedure) { // Check if a aggregate is buried inside the input parameters - aggregate |= aggregate_found2(request, lrelation_context->ctx_proc_inputs, + aggregate |= aggregate_found2(statement, lrelation_context->ctx_proc_inputs, current_level, deepest_level, ignore_sub_selects); } return aggregate; @@ -2322,13 +2322,13 @@ static bool aggregate_found2(const dsql_req* request, const dsql_nod* node, message is build from it. - @param request + @param statement @param node @param name @param ambiguous_contexts **/ -static dsql_nod* ambiguity_check(dsql_req* request, dsql_nod* node, +static dsql_nod* ambiguity_check(CompiledStatement* statement, dsql_nod* node, const dsql_str* name, const DsqlContextStack& ambiguous_contexts) { // If there are no relations or only 1 there's no ambiguity, thus return. @@ -2388,7 +2388,7 @@ static dsql_nod* ambiguity_check(dsql_req* request, dsql_nod* node, *--p = 0; } - if (request->req_client_dialect >= SQL_DIALECT_V6) { + if (statement->req_client_dialect >= SQL_DIALECT_V6) { if (node) { delete node; } @@ -2574,13 +2574,13 @@ static dsql_nod* explode_fields(dsql_rel* relation) @brief Generate a parameter list to correspond to procedure outputs. - @param request + @param statement @param procedure **/ -static dsql_nod* explode_outputs( dsql_req* request, const dsql_prc* procedure) +static dsql_nod* explode_outputs( CompiledStatement* statement, const dsql_prc* procedure) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(procedure, dsql_type_prc); const SSHORT count = procedure->prc_out_count; @@ -2595,7 +2595,7 @@ static dsql_nod* explode_outputs( dsql_req* request, const dsql_prc* procedure) *ptr = p_node; p_node->nod_count = 0; dsql_par* parameter = - MAKE_parameter(request->req_receive, true, true, 0, NULL); + MAKE_parameter(statement->req_receive, true, true, 0, NULL); p_node->nod_arg[e_par_index] = (dsql_nod*) (IPTR) parameter->par_index; p_node->nod_arg[e_par_parameter] = (dsql_nod*) parameter; MAKE_desc_from_field(¶meter->par_desc, field); @@ -2760,19 +2760,19 @@ static void field_unknown(const TEXT* qualifier_name, const TEXT* field_name, find_dbkey - @brief Find dbkey for named relation in request's saved dbkeys. + @brief Find dbkey for named relation in statement's saved dbkeys. - @param request + @param statement @param relation_name **/ -static dsql_par* find_dbkey(const dsql_req* request, const dsql_nod* relation_name) +static dsql_par* find_dbkey(const CompiledStatement* statement, const dsql_nod* relation_name) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(relation_name, dsql_type_nod); - dsql_msg* message = request->req_receive; + dsql_msg* message = statement->req_receive; dsql_par* candidate = NULL; const dsql_str* rel_name = (dsql_str*) relation_name->nod_arg[e_rln_name]; DEV_BLKCHK(rel_name, dsql_type_str); @@ -2801,19 +2801,19 @@ static dsql_par* find_dbkey(const dsql_req* request, const dsql_nod* relation_na find_record_version - @brief Find record version for relation in request's saved record version + @brief Find record version for relation in statement's saved record version - @param request + @param statement @param relation_name **/ -static dsql_par* find_record_version(const dsql_req* request, const dsql_nod* relation_name) +static dsql_par* find_record_version(const CompiledStatement* statement, const dsql_nod* relation_name) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(relation_name, dsql_type_nod); - dsql_msg* message = request->req_receive; + dsql_msg* message = statement->req_receive; dsql_par* candidate = NULL; const dsql_str* rel_name = (dsql_str*) relation_name->nod_arg[e_rln_name]; DEV_BLKCHK(rel_name, dsql_type_str); @@ -2994,7 +2994,7 @@ static bool invalid_reference(const dsql_ctx* context, const dsql_nod* node, // If we come here then this Field is used inside a // aggregate-function. The ctx_scope_level gives the - // info how deep the context is inside the request. + // info how deep the context is inside the statement. // If the context-scope-level from this field is // lower or the same as the scope-level from the @@ -3447,7 +3447,7 @@ static bool node_match(const dsql_nod* node1, const dsql_nod* node2, @param input **/ -static dsql_nod* nullify_returning(dsql_req* request, dsql_nod* input) +static dsql_nod* nullify_returning(CompiledStatement* statement, dsql_nod* input) { DEV_BLKCHK(input, dsql_type_nod); @@ -3468,7 +3468,7 @@ static dsql_nod* nullify_returning(dsql_req* request, dsql_nod* input) fb_assert(false); } - if (request->isPsql() || !returning) + if (statement->isPsql() || !returning) return input; // If this is a RETURNING in DSQL, we need to initialize the output @@ -3507,17 +3507,17 @@ static dsql_nod* nullify_returning(dsql_req* request, dsql_nod* input) pass1_any - @brief Compile a parsed request into something more interesting. + @brief Compile a parsed statement into something more interesting. - @param request + @param statement @param input @param ntype **/ -static dsql_nod* pass1_any( dsql_req* request, dsql_nod* input, NOD_TYPE ntype) +static dsql_nod* pass1_any( CompiledStatement* statement, dsql_nod* input, NOD_TYPE ntype) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); // create a derived table representing our subquery @@ -3532,15 +3532,15 @@ static dsql_nod* pass1_any( dsql_req* request, dsql_nod* input, NOD_TYPE ntype) dsql_nod* select_expr = MAKE_node(nod_select_expr, e_sel_count); select_expr->nod_arg[e_sel_query_spec] = query_spec; - const DsqlContextStack::iterator base(*request->req_context); - const DsqlContextStack::iterator baseDT(request->req_dt_context); - const DsqlContextStack::iterator baseUnion(request->req_union_context); + const DsqlContextStack::iterator base(*statement->req_context); + const DsqlContextStack::iterator baseDT(statement->req_dt_context); + const DsqlContextStack::iterator baseUnion(statement->req_union_context); - dsql_nod* rse = PASS1_rse(request, select_expr, NULL); + dsql_nod* rse = PASS1_rse(statement, select_expr, NULL); // create a conjunct to be injected dsql_nod* temp = MAKE_node(input->nod_type, 2); - temp->nod_arg[0] = pass1_node_psql(request, input->nod_arg[0], false); + temp->nod_arg[0] = pass1_node_psql(statement, input->nod_arg[0], false); temp->nod_arg[1] = rse->nod_arg[e_rse_items]->nod_arg[0]; rse->nod_arg[e_rse_boolean] = temp; @@ -3550,9 +3550,9 @@ static dsql_nod* pass1_any( dsql_req* request, dsql_nod* input, NOD_TYPE ntype) node->nod_arg[0] = rse; // Finish off by cleaning up contexts - request->req_union_context.clear(baseUnion); - request->req_dt_context.clear(baseDT); - request->req_context->clear(base); + statement->req_union_context.clear(baseUnion); + statement->req_dt_context.clear(baseDT); + statement->req_context->clear(base); return node; } @@ -3565,32 +3565,32 @@ static dsql_nod* pass1_any( dsql_req* request, dsql_nod* input, NOD_TYPE ntype) @brief Process a blob get or put segment. - @param request + @param statement @param input **/ -static void pass1_blob( dsql_req* request, dsql_nod* input) +static void pass1_blob( CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); thread_db* tdbb = JRD_get_thread_data(); - PASS1_make_context(request, input->nod_arg[e_blb_relation]); - dsql_nod* field = pass1_field(request, input->nod_arg[e_blb_field], false, NULL); + PASS1_make_context(statement, input->nod_arg[e_blb_relation]); + dsql_nod* field = pass1_field(statement, input->nod_arg[e_blb_field], false, NULL); if (field->nod_desc.dsc_dtype != dtype_blob) ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 206, isc_arg_gds, isc_dsql_blob_err, 0); - request->req_type = (input->nod_type == nod_get_segment) ? + statement->req_type = (input->nod_type == nod_get_segment) ? REQ_GET_SEGMENT : REQ_PUT_SEGMENT; dsql_blb* blob = FB_NEW(*tdbb->getDefaultPool()) dsql_blb; - request->req_blob = blob; + statement->req_blob = blob; //blob->blb_field = field; - blob->blb_open_in_msg = request->req_send; + blob->blb_open_in_msg = statement->req_send; blob->blb_open_out_msg = FB_NEW(*tdbb->getDefaultPool()) dsql_msg; - blob->blb_segment_msg = request->req_receive; + blob->blb_segment_msg = statement->req_receive; // Create a parameter for the blob segment @@ -3616,17 +3616,17 @@ static void pass1_blob( dsql_req* request, dsql_nod* input) blob->blb_open_in_msg : blob->blb_open_out_msg; blob->blb_blob_id = parameter = MAKE_parameter(temp_msg, true, true, 0, NULL); - MAKE_desc(request, ¶meter->par_desc, field, NULL); + MAKE_desc(statement, ¶meter->par_desc, field, NULL); parameter->par_desc.dsc_dtype = dtype_quad; parameter->par_desc.dsc_scale = 0; dsql_nod* list = input->nod_arg[e_blb_filter]; if (list) { if (list->nod_arg[0]) { - blob->blb_from = pass1_node_psql(request, list->nod_arg[0], false); + blob->blb_from = pass1_node_psql(statement, list->nod_arg[0], false); } if (list->nod_arg[1]) { - blob->blb_to = pass1_node_psql(request, list->nod_arg[1], false); + blob->blb_to = pass1_node_psql(statement, list->nod_arg[1], false); } } if (!blob->blb_from) { @@ -3660,13 +3660,13 @@ static void pass1_blob( dsql_req* request, dsql_nod* input) is the same as : CASE WHEN (expr-1 IS NULL) THEN expr-2 ELSE expr-1 END - @param request + @param statement @param input **/ -static dsql_nod* pass1_coalesce( dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_coalesce( CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); DEV_BLKCHK(input->nod_arg[0], dsql_type_nod); @@ -3675,8 +3675,8 @@ static dsql_nod* pass1_coalesce( dsql_req* request, dsql_nod* input) // Pass list of arguments 2..n on stack and make a list from it { // scope DsqlNodStack stack; - pass1_put_args_on_stack(request, input->nod_arg[0], stack); - pass1_put_args_on_stack(request, input->nod_arg[1], stack); + pass1_put_args_on_stack(statement, input->nod_arg[0], stack); + pass1_put_args_on_stack(statement, input->nod_arg[1], stack); node->nod_arg[0] = MAKE_list(stack); } // end scope @@ -3684,24 +3684,24 @@ static dsql_nod* pass1_coalesce( dsql_req* request, dsql_nod* input) // We can't copy else we get an 'context in use error' with sub-selects. { // scope DsqlNodStack stack; - pass1_put_args_on_stack(request, input->nod_arg[0], stack); - pass1_put_args_on_stack(request, input->nod_arg[1], stack); + pass1_put_args_on_stack(statement, input->nod_arg[0], stack); + pass1_put_args_on_stack(statement, input->nod_arg[1], stack); node->nod_arg[1] = MAKE_list(stack); } // end scope // Set descriptor for output node - MAKE_desc(request, &node->nod_desc, node, NULL); + MAKE_desc(statement, &node->nod_desc, node, NULL); // Set parameter-types if parameters are there dsql_nod** ptr = node->nod_arg[0]->nod_arg; const dsql_nod* const* end = ptr + node->nod_arg[0]->nod_count; for (; ptr < end; ptr++) { - set_parameter_type(request, *ptr, node, false); + set_parameter_type(statement, *ptr, node, false); } ptr = node->nod_arg[1]->nod_arg; end = ptr + node->nod_arg[1]->nod_count; for (; ptr < end; ptr++) { - set_parameter_type(request, *ptr, node, false); + set_parameter_type(statement, *ptr, node, false); } return node; @@ -3717,15 +3717,15 @@ static dsql_nod* pass1_coalesce( dsql_req* request, dsql_nod* input) (SQL 92: Section 13.1, pg 308, item 11) - @param request + @param statement @param sub1 @param collation **/ -static dsql_nod* pass1_collate( dsql_req* request, dsql_nod* sub1, +static dsql_nod* pass1_collate( CompiledStatement* statement, dsql_nod* sub1, const dsql_str* collation) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(sub1, dsql_type_nod); DEV_BLKCHK(collation, dsql_type_str); @@ -3735,7 +3735,7 @@ static dsql_nod* pass1_collate( dsql_req* request, dsql_nod* sub1, dsql_fld* field = FB_NEW(*tdbb->getDefaultPool()) dsql_fld(*tdbb->getDefaultPool()); node->nod_arg[e_cast_target] = (dsql_nod*) field; node->nod_arg[e_cast_source] = sub1; - MAKE_desc(request, &sub1->nod_desc, sub1, NULL); + MAKE_desc(statement, &sub1->nod_desc, sub1, NULL); if (sub1->nod_desc.dsc_dtype <= dtype_any_text || (sub1->nod_desc.dsc_dtype == dtype_blob && sub1->nod_desc.dsc_sub_type == isc_blob_text)) @@ -3748,7 +3748,7 @@ static dsql_nod* pass1_collate( dsql_req* request, dsql_nod* sub1, isc_arg_gds, isc_dsql_datatype_err, isc_arg_gds, isc_collation_requires_text, 0); } - DDL_resolve_intl_type(request, field, collation); + DDL_resolve_intl_type(statement, field, collation); MAKE_desc_from_field(&node->nod_desc, field); return node; } @@ -3762,18 +3762,18 @@ static dsql_nod* pass1_collate( dsql_req* request, dsql_nod* sub1, subtype ID. - @param request + @param statement @param constant **/ -static dsql_nod* pass1_constant( dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_constant( CompiledStatement* statement, dsql_nod* input) { thread_db* tdbb = JRD_get_thread_data(); - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); - if (request->req_in_outer_join) + if (statement->req_in_outer_join) input->nod_desc.dsc_flags = DSC_nullable; if (input->nod_desc.dsc_dtype > dtype_any_text) { @@ -3790,7 +3790,7 @@ static dsql_nod* pass1_constant( dsql_req* request, dsql_nod* input) if (string && string->str_charset) { const dsql_intlsym* resolved = - METD_get_charset(request, strlen(string->str_charset), + METD_get_charset(statement, strlen(string->str_charset), string->str_charset); if (!resolved) { @@ -3803,7 +3803,7 @@ static dsql_nod* pass1_constant( dsql_req* request, dsql_nod* input) if (global_temp_collation_name) { const dsql_intlsym* resolved_collation = - METD_get_collation(request, global_temp_collation_name, resolved->intlsym_charset_id); + METD_get_collation(statement, global_temp_collation_name, resolved->intlsym_charset_id); if (!resolved_collation) { /* @@ -3822,10 +3822,10 @@ static dsql_nod* pass1_constant( dsql_req* request, dsql_nod* input) } else { - const Firebird::MetaName charSetName = METD_get_charset_name(request, + const Firebird::MetaName charSetName = METD_get_charset_name(statement, constant->nod_desc.getCharSet()); - const dsql_intlsym* sym = METD_get_charset(request, charSetName.length(), charSetName.c_str()); + const dsql_intlsym* sym = METD_get_charset(statement, charSetName.length(), charSetName.c_str()); fb_assert(sym); if (sym) @@ -3870,15 +3870,15 @@ static dsql_nod* pass1_constant( dsql_req* request, dsql_nod* input) @brief Turn a cursor reference into a record selection expression. - @param request + @param statement @param cursor @param relation_name **/ -static dsql_ctx* pass1_cursor_context( dsql_req* request, const dsql_nod* cursor, +static dsql_ctx* pass1_cursor_context( CompiledStatement* statement, const dsql_nod* cursor, const dsql_nod* relation_name) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(cursor, dsql_type_nod); DEV_BLKCHK(relation_name, dsql_type_nod); @@ -3889,7 +3889,7 @@ static dsql_ctx* pass1_cursor_context( dsql_req* request, const dsql_nod* cursor DEV_BLKCHK(string, dsql_type_str); // this function must throw an error if no cursor was found - const dsql_nod* node = pass1_cursor_name(request, string, NOD_CURSOR_ALL, true); + const dsql_nod* node = pass1_cursor_name(statement, string, NOD_CURSOR_ALL, true); fb_assert(node); const dsql_nod* rse = node->nod_arg[e_cur_rse]; @@ -3956,13 +3956,13 @@ static dsql_ctx* pass1_cursor_context( dsql_req* request, const dsql_nod* cursor @brief Find a cursor. - @param request + @param statement @param string @param mask @param existence_flag **/ -static dsql_nod* pass1_cursor_name(dsql_req* request, const dsql_str* string, +static dsql_nod* pass1_cursor_name(CompiledStatement* statement, const dsql_str* string, USHORT mask, bool existence_flag) { DEV_BLKCHK(string, dsql_type_str); @@ -3981,7 +3981,7 @@ static dsql_nod* pass1_cursor_name(dsql_req* request, const dsql_str* string, } } - for (DsqlNodStack::iterator itr(request->req_cursors); itr.hasData(); ++itr) { + for (DsqlNodStack::iterator itr(statement->req_cursors); itr.hasData(); ++itr) { cursor = itr.object(); const dsql_str* cname = (dsql_str*) cursor->nod_arg[e_cur_name]; if (!strcmp(string->str_data, cname->str_data) && (cursor->nod_flags & mask)) @@ -4015,25 +4015,25 @@ static dsql_nod* pass1_cursor_name(dsql_req* request, const dsql_str* string, @brief Turn a cursor reference into a record selection expression. - @param request + @param statement @param cursor @param relation_name **/ -static dsql_nod* pass1_cursor_reference( dsql_req* request, +static dsql_nod* pass1_cursor_reference( CompiledStatement* statement, const dsql_nod* cursor, dsql_nod* relation_name) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(cursor, dsql_type_nod); DEV_BLKCHK(relation_name, dsql_type_nod); -// Lookup parent request +// Lookup parent statement const dsql_str* string = (dsql_str*) cursor->nod_arg[e_cur_name]; DEV_BLKCHK(string, dsql_type_str); const dsql_sym* symbol = - HSHD_lookup(request->req_dbb, + HSHD_lookup(statement->req_dbb, reinterpret_cast(string->str_data), static_cast(string->str_length), SYM_cursor, 0); @@ -4047,7 +4047,7 @@ static dsql_nod* pass1_cursor_reference( dsql_req* request, 0); } - dsql_req* parent = (dsql_req*) symbol->sym_object; + CompiledStatement* parent = (CompiledStatement*) symbol->sym_object; // Verify that the cursor is appropriate and updatable @@ -4064,18 +4064,18 @@ static dsql_nod* pass1_cursor_reference( dsql_req* request, isc_arg_string, string->str_data, 0); } - request->req_parent = parent; - request->req_parent_dbkey = source; - request->req_parent_rec_version = rv_source; - request->req_sibling = parent->req_offspring; - parent->req_offspring = request; + statement->req_parent = parent; + statement->req_parent_dbkey = source; + statement->req_parent_rec_version = rv_source; + statement->req_sibling = parent->req_offspring; + parent->req_offspring = statement; // Build record selection expression dsql_nod* rse = MAKE_node(nod_rse, e_rse_count); dsql_nod* temp = MAKE_node(nod_list, 1); rse->nod_arg[e_rse_streams] = temp; - dsql_nod* relation_node = pass1_relation(request, relation_name); + dsql_nod* relation_node = pass1_relation(statement, relation_name); temp->nod_arg[0] = relation_node; dsql_nod* node = MAKE_node(nod_eql, 2); rse->nod_arg[e_rse_boolean] = node; @@ -4084,8 +4084,8 @@ static dsql_nod* pass1_cursor_reference( dsql_req* request, node->nod_arg[1] = temp = MAKE_node(nod_parameter, e_par_count); temp->nod_count = 0; - dsql_par* parameter = request->req_dbkey = - MAKE_parameter(request->req_send, false, false, 0, NULL); + dsql_par* parameter = statement->req_dbkey = + MAKE_parameter(statement->req_send, false, false, 0, NULL); temp->nod_arg[e_par_index] = (dsql_nod*) (IPTR) parameter->par_index; temp->nod_arg[e_par_parameter] = (dsql_nod*) parameter; parameter->par_desc = source->par_desc; @@ -4097,8 +4097,8 @@ static dsql_nod* pass1_cursor_reference( dsql_req* request, temp->nod_arg[0] = relation_node; node->nod_arg[1] = temp = MAKE_node(nod_parameter, e_par_count); temp->nod_count = 0; - parameter = request->req_rec_version = - MAKE_parameter(request->req_send, false, false, 0, NULL); + parameter = statement->req_rec_version = + MAKE_parameter(statement->req_send, false, false, 0, NULL); temp->nod_arg[e_par_index] = (dsql_nod*) (IPTR) parameter->par_index; temp->nod_arg[e_par_parameter] = (dsql_nod*) parameter; parameter->par_desc = rv_source->par_desc; @@ -4118,13 +4118,13 @@ static dsql_nod* pass1_cursor_reference( dsql_req* request, @brief Resolve a dbkey to an available context. - @param request + @param statement @param input **/ -static dsql_nod* pass1_dbkey( dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_dbkey( CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); const dsql_str* qualifier = (dsql_str*) input->nod_arg[0]; @@ -4132,9 +4132,9 @@ static dsql_nod* pass1_dbkey( dsql_req* request, dsql_nod* input) DEV_BLKCHK(qualifier, dsql_type_str); // No qualifier, if only one context then use, else error - if (request->req_context->getCount() == 1) + if (statement->req_context->getCount() == 1) { - dsql_ctx* context = request->req_context->object(); + dsql_ctx* context = statement->req_context->object(); if (!context->ctx_relation) { @@ -4159,7 +4159,7 @@ static dsql_nod* pass1_dbkey( dsql_req* request, dsql_nod* input) bool rlxAlias = false; for (;;) { - for (DsqlContextStack::iterator stack(*request->req_context); stack.hasData(); ++stack) + for (DsqlContextStack::iterator stack(*statement->req_context); stack.hasData(); ++stack) { dsql_ctx* context = stack.object(); @@ -4213,55 +4213,55 @@ static dsql_nod* pass1_dbkey( dsql_req* request, dsql_nod* input) @brief Process DELETE statement. - @param request + @param statement @param input **/ -static dsql_nod* pass1_delete( dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_delete( CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); const dsql_nod* cursor = input->nod_arg[e_del_cursor]; dsql_nod* relation = input->nod_arg[e_del_relation]; - if (cursor && request->isPsql()) { + if (cursor && statement->isPsql()) { dsql_nod* anode = MAKE_node(nod_erase_current, e_erc_count); anode->nod_arg[e_erc_context] = - (dsql_nod*) pass1_cursor_context(request, cursor, relation); + (dsql_nod*) pass1_cursor_context(statement, cursor, relation); anode->nod_arg[e_erc_return] = - process_returning(request, input->nod_arg[e_del_return]); + process_returning(statement, input->nod_arg[e_del_return]); return anode; } - request->req_type = (cursor) ? REQ_DELETE_CURSOR : REQ_DELETE; + statement->req_type = (cursor) ? REQ_DELETE_CURSOR : REQ_DELETE; dsql_nod* node = MAKE_node(nod_erase, e_era_count); // Generate record selection expression dsql_nod* rse; if (cursor) - rse = pass1_cursor_reference(request, cursor, relation); + rse = pass1_cursor_reference(statement, cursor, relation); else { rse = MAKE_node(nod_rse, e_rse_count); dsql_nod* temp = MAKE_node(nod_list, 1); rse->nod_arg[e_rse_streams] = temp; - temp->nod_arg[0] = pass1_node_psql(request, relation, false); + temp->nod_arg[0] = pass1_node_psql(statement, relation, false); if ( (temp = input->nod_arg[e_del_boolean]) ) { - rse->nod_arg[e_rse_boolean] = pass1_node_psql(request, temp, false); + rse->nod_arg[e_rse_boolean] = pass1_node_psql(statement, temp, false); } if ( (temp = input->nod_arg[e_del_plan]) ) { - rse->nod_arg[e_rse_plan] = pass1_node_psql(request, temp, false); + rse->nod_arg[e_rse_plan] = pass1_node_psql(statement, temp, false); } if ( (temp = input->nod_arg[e_del_sort]) ) { - rse->nod_arg[e_rse_sort] = pass1_sort(request, temp, NULL); + rse->nod_arg[e_rse_sort] = pass1_sort(statement, temp, NULL); } if ( (temp = input->nod_arg[e_del_rows]) ) { - rse->nod_arg[e_rse_first] = pass1_node_psql(request, temp->nod_arg[e_rows_length], false); - rse->nod_arg[e_rse_skip] = pass1_node_psql(request, temp->nod_arg[e_rows_skip], false); + rse->nod_arg[e_rse_first] = pass1_node_psql(statement, temp->nod_arg[e_rows_length], false); + rse->nod_arg[e_rse_skip] = pass1_node_psql(statement, temp->nod_arg[e_rows_skip], false); } if (input->nod_arg[e_del_return]) @@ -4271,11 +4271,11 @@ static dsql_nod* pass1_delete( dsql_req* request, dsql_nod* input) node->nod_arg[e_era_rse] = rse; node->nod_arg[e_era_relation] = rse->nod_arg[e_rse_streams]->nod_arg[0]; - node->nod_arg[e_era_return] = process_returning(request, input->nod_arg[e_del_return]); + node->nod_arg[e_era_return] = process_returning(statement, input->nod_arg[e_del_return]); - node = nullify_returning(request, node); + node = nullify_returning(statement, node); - request->req_context->pop(); + statement->req_context->pop(); return node; } @@ -4287,11 +4287,11 @@ static dsql_nod* pass1_delete( dsql_req* request, dsql_nod* input) @brief check if table reference is recursive i.e. its name is equal to the name of current processing CTE - @param request + @param statement @param input **/ -static bool pass1_relproc_is_recursive(dsql_req* request, dsql_nod* input) +static bool pass1_relproc_is_recursive(CompiledStatement* statement, dsql_nod* input) { const dsql_str* rel_name = NULL; const dsql_str* rel_alias = NULL; @@ -4312,15 +4312,15 @@ static bool pass1_relproc_is_recursive(dsql_req* request, dsql_nod* input) return false; } - fb_assert(request->req_curr_ctes.hasData()); - const dsql_nod* curr_cte = request->req_curr_ctes.object(); + fb_assert(statement->req_curr_ctes.hasData()); + const dsql_nod* curr_cte = statement->req_curr_ctes.object(); const dsql_str* cte_name = (dsql_str*) curr_cte->nod_arg[e_derived_table_alias]; const bool recursive = (cte_name->str_length == rel_name->str_length) && (strncmp(rel_name->str_data, cte_name->str_data, cte_name->str_length) == 0); if (recursive) { - request->addCTEAlias(rel_alias ? rel_alias : rel_name); + statement->addCTEAlias(rel_alias ? rel_alias : rel_name); } return recursive; @@ -4337,11 +4337,11 @@ static bool pass1_relproc_is_recursive(dsql_req* request, dsql_nod* input) Punt if recursive reference is found in outer join or more than one recursive reference is found - @param request + @param statement @param input **/ -static dsql_nod* pass1_join_is_recursive(dsql_req* request, dsql_nod*& input) +static dsql_nod* pass1_join_is_recursive(CompiledStatement* statement, dsql_nod*& input) { const NOD_TYPE join_type = input->nod_arg[e_join_type]->nod_type; bool remove = false; @@ -4351,13 +4351,13 @@ static dsql_nod* pass1_join_is_recursive(dsql_req* request, dsql_nod*& input) dsql_nod** join_table = &input->nod_arg[e_join_left_rel]; if ((*join_table)->nod_type == nod_join) { - leftBool = pass1_join_is_recursive(request, *join_table); + leftBool = pass1_join_is_recursive(statement, *join_table); leftRecursive = (leftBool != NULL); } else { leftBool = input->nod_arg[e_join_boolean]; - leftRecursive = pass1_relproc_is_recursive(request, *join_table); + leftRecursive = pass1_relproc_is_recursive(statement, *join_table); if (leftRecursive) remove = true; } @@ -4373,13 +4373,13 @@ static dsql_nod* pass1_join_is_recursive(dsql_req* request, dsql_nod*& input) join_table = &input->nod_arg[e_join_rght_rel]; if ((*join_table)->nod_type == nod_join) { - rightBool = pass1_join_is_recursive(request, *join_table); + rightBool = pass1_join_is_recursive(statement, *join_table); rightRecursive = (rightBool != NULL); } else { rightBool = input->nod_arg[e_join_boolean]; - rightRecursive = pass1_relproc_is_recursive(request, *join_table); + rightRecursive = pass1_relproc_is_recursive(statement, *join_table); if (rightRecursive) remove = true; } @@ -4424,11 +4424,11 @@ static dsql_nod* pass1_join_is_recursive(dsql_req* request, dsql_nod*& input) join add join boolean (returned by pass1_join_is_recursive) to the WHERE clause. Punt if more than one recursive reference is found - @param request + @param statement @param input **/ -static bool pass1_rse_is_recursive(dsql_req* request, dsql_nod* input) +static bool pass1_rse_is_recursive(CompiledStatement* statement, dsql_nod* input) { fb_assert(input->nod_type == nod_query_spec); @@ -4444,7 +4444,7 @@ static bool pass1_rse_is_recursive(dsql_req* request, dsql_nod* input) { case nod_rel_proc_name: case nod_relation_name: - if (pass1_relproc_is_recursive(request, *table)) + if (pass1_relproc_is_recursive(statement, *table)) { if (found) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, @@ -4460,7 +4460,7 @@ static bool pass1_rse_is_recursive(dsql_req* request, dsql_nod* input) case nod_join: { - dsql_nod* joinBool = pass1_join_is_recursive(request, *table); + dsql_nod* joinBool = pass1_join_is_recursive(statement, *table); if (joinBool) { if (found) { @@ -4501,17 +4501,17 @@ static bool pass1_rse_is_recursive(dsql_req* request, dsql_nod* input) will be first in union's list - @param request + @param statement @param input **/ -static dsql_nod* pass1_recursive_cte(dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_recursive_cte(CompiledStatement* statement, dsql_nod* input) { dsql_str* const cte_alias = (dsql_str*) input->nod_arg[e_derived_table_alias]; dsql_nod* const select_expr = input->nod_arg[e_derived_table_rse]; dsql_nod* query = select_expr->nod_arg[e_sel_query_spec]; - if (query->nod_type != nod_list && pass1_rse_is_recursive(request, query)) + if (query->nod_type != nod_list && pass1_rse_is_recursive(statement, query)) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_dsql_cte_not_a_union, // Recursive CTE (%s) must be an UNION @@ -4530,7 +4530,7 @@ static dsql_nod* pass1_recursive_cte(dsql_req* request, dsql_nod* input) else rse = qry; - if (pass1_rse_is_recursive(request, rse)) // rse is recursive + if (pass1_rse_is_recursive(statement, rse)) // rse is recursive { if (anchor_rse) { @@ -4638,25 +4638,25 @@ static dsql_nod* pass1_recursive_cte(dsql_req* request, dsql_nod* input) @brief Compile a RETURNING clause (nod_returning or not). - @param request + @param statement @param input **/ -static dsql_nod* process_returning(dsql_req* request, +static dsql_nod* process_returning(CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); dsql_nod* node; if (!input || input->nod_type == nod_returning) - node = PASS1_node(request, input); + node = PASS1_node(statement, input); else - node = pass1_node_psql(request, input, false); + node = pass1_node_psql(statement, input, false); - if (input && !request->isPsql()) - request->req_type = REQ_EXEC_PROCEDURE; + if (input && !statement->isPsql()) + statement->req_type = REQ_EXEC_PROCEDURE; return node; } @@ -4669,13 +4669,13 @@ static dsql_nod* process_returning(dsql_req* request, @brief Process derived table which is part of a from clause. - @param request + @param statement @param input **/ -static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_str* cte_alias) +static dsql_nod* pass1_derived_table(CompiledStatement* statement, dsql_nod* input, dsql_str* cte_alias) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); thread_db* tdbb = JRD_get_thread_data(); @@ -4686,21 +4686,21 @@ static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_st node->nod_arg[e_derived_table_column_alias] = input->nod_arg[e_derived_table_column_alias]; // Create the context now, because we need to know it for the tables inside. - dsql_ctx* const context = PASS1_make_context(request, node); + dsql_ctx* const context = PASS1_make_context(statement, node); node->nod_arg[e_derived_table_context] = (dsql_nod*) context; // Save some values to restore after rse process. - DsqlContextStack* const req_base = request->req_context; - dsql_str* const req_alias_relation_prefix = request->req_alias_relation_prefix; + DsqlContextStack* const req_base = statement->req_context; + dsql_str* const req_alias_relation_prefix = statement->req_alias_relation_prefix; // Change req_context, because when we are processing the derived table rse // it may not reference to other streams in the same scope_level. DsqlContextStack temp; // Put special contexts (NEW/OLD) also on the stack - for (DsqlContextStack::iterator stack(*request->req_context); stack.hasData(); ++stack) + for (DsqlContextStack::iterator stack(*statement->req_context); stack.hasData(); ++stack) { dsql_ctx* local_context = stack.object(); - if ((local_context->ctx_scope_level < request->req_scope_level) || + if ((local_context->ctx_scope_level < statement->req_scope_level) || (local_context->ctx_flags & CTX_system)) { temp.push(local_context); @@ -4710,8 +4710,8 @@ static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_st if (temp.hasData()) { baseContext = temp.object(); } - request->req_context = &temp; - request->req_alias_relation_prefix = pass1_alias_concat(req_alias_relation_prefix, alias); + statement->req_context = &temp; + statement->req_alias_relation_prefix = pass1_alias_concat(req_alias_relation_prefix, alias); dsql_nod* const select_expr = input->nod_arg[e_derived_table_rse]; dsql_nod* query = select_expr->nod_arg[e_sel_query_spec]; @@ -4729,24 +4729,24 @@ static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_st query->nod_count = 1; query->nod_flags &= ~NOD_UNION_RECURSIVE; - dsql_ctx* baseUnionCtx = request->req_union_context.hasData() ? - request->req_union_context.object() : NULL; + dsql_ctx* baseUnionCtx = statement->req_union_context.hasData() ? + statement->req_union_context.object() : NULL; // reserve extra context number for map's secondary context - recursive_map_ctx = request->req_context_number++; + recursive_map_ctx = statement->req_context_number++; - request->req_recursive_ctx_id = request->req_context_number; - rse = pass1_union(request, query, NULL, NULL, 0); - request->req_context_number = request->req_recursive_ctx_id + 1; + statement->req_recursive_ctx_id = statement->req_context_number; + rse = pass1_union(statement, query, NULL, NULL, 0); + statement->req_context_number = statement->req_recursive_ctx_id + 1; // recursive union always have exactly 2 members query->nod_count = 2; query->nod_flags |= NOD_UNION_RECURSIVE; - while (request->req_union_context.hasData() && - request->req_union_context.object() != baseUnionCtx) + while (statement->req_union_context.hasData() && + statement->req_union_context.object() != baseUnionCtx) { - request->req_union_context.pop(); + statement->req_union_context.pop(); } } else @@ -4771,10 +4771,10 @@ static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_st dsql_nod* union_expr = MAKE_node(nod_list, 1); union_expr->nod_arg[0] = select_expr; union_expr->nod_flags = NOD_UNION_ALL; - rse = pass1_union(request, union_expr, NULL, NULL, 0); + rse = pass1_union(statement, union_expr, NULL, NULL, 0); } else { - rse = PASS1_rse(request, select_expr, NULL); + rse = PASS1_rse(statement, select_expr, NULL); } // Finish off by cleaning up contexts and put them into req_dt_context @@ -4782,7 +4782,7 @@ static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_st // Also add the used contexts into the childs stack. while (temp.hasData() && (temp.object() != baseContext)) { - request->req_dt_context.push(temp.object()); + statement->req_dt_context.push(temp.object()); context->ctx_childs_derived_table.push(temp.pop()); } while (temp.hasData()) @@ -4838,7 +4838,7 @@ static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_st dsql_nod* derived_field = MAKE_node(nod_derived_field, e_derived_field_count); derived_field->nod_arg[e_derived_field_value] = select_item; derived_field->nod_arg[e_derived_field_name] = list->nod_arg[count]; - derived_field->nod_arg[e_derived_field_scope] = (dsql_nod*)(IPTR) request->req_scope_level; + derived_field->nod_arg[e_derived_field_scope] = (dsql_nod*)(IPTR) statement->req_scope_level; derived_field->nod_desc = select_item->nod_desc; rse->nod_arg[e_rse_items]->nod_arg[count] = derived_field; @@ -4849,7 +4849,7 @@ static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_st // to generate one from the field_name. for (int count = 0; count < rse->nod_arg[e_rse_items]->nod_count; count++) { dsql_nod* select_item = - pass1_make_derived_field(request, tdbb, rse->nod_arg[e_rse_items]->nod_arg[count]); + pass1_make_derived_field(statement, tdbb, rse->nod_arg[e_rse_items]->nod_arg[count]); // Auto-create dummy column name for pass1_any() if (ignoreColumnChecks && (select_item->nod_type != nod_derived_field)) { @@ -4868,7 +4868,7 @@ static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_st derived_field->nod_arg[e_derived_field_name] = (dsql_nod*) field_alias; derived_field->nod_arg[e_derived_field_scope] = - (dsql_nod*)(IPTR) request->req_scope_level; + (dsql_nod*)(IPTR) statement->req_scope_level; derived_field->nod_desc = select_item->nod_desc; select_item = derived_field; } @@ -4926,19 +4926,19 @@ static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_st // developed context block. if (isRecursive) { - request->req_recursive_ctx = context; - request->req_context = &temp; + statement->req_recursive_ctx = context; + statement->req_context = &temp; - request->resetCTEAlias(); + statement->resetCTEAlias(); - rse = PASS1_rse(request, input->nod_arg[e_derived_table_rse], NULL); + rse = PASS1_rse(statement, input->nod_arg[e_derived_table_rse], NULL); // Finish off by cleaning up contexts and put them into req_dt_context // so create view (ddl) can deal with it. // Also add the used contexts into the childs stack. while (temp.hasData() && (temp.object() != baseContext)) { - request->req_dt_context.push(temp.object()); + statement->req_dt_context.push(temp.object()); context->ctx_childs_derived_table.push(temp.pop()); } @@ -4956,7 +4956,7 @@ static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_st context->ctx_alias = cte_alias->str_data; } - request->req_context = req_base; + statement->req_context = req_base; // mark union's map context as recursive and assign // secondary context number to it @@ -4971,10 +4971,10 @@ static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_st map_context->ctx_recursive = recursive_map_ctx; } - delete request->req_alias_relation_prefix; + delete statement->req_alias_relation_prefix; // Restore our original values. - request->req_context = req_base; - request->req_alias_relation_prefix = req_alias_relation_prefix; + statement->req_context = req_base; + statement->req_alias_relation_prefix = req_alias_relation_prefix; return node; } @@ -4987,12 +4987,12 @@ static dsql_nod* pass1_derived_table(dsql_req* request, dsql_nod* input, dsql_st @brief Expand asterisk nodes into fields. - @param request + @param statement @param list @param streams **/ -static dsql_nod* pass1_expand_select_list(dsql_req* request, dsql_nod* list, +static dsql_nod* pass1_expand_select_list(CompiledStatement* statement, dsql_nod* list, dsql_nod* streams) { if (!list) @@ -5003,7 +5003,7 @@ static dsql_nod* pass1_expand_select_list(dsql_req* request, dsql_nod* list, for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr++) { - pass1_expand_select_node(request, *ptr, stack, true); + pass1_expand_select_node(statement, *ptr, stack, true); } dsql_nod* node = MAKE_list(stack); return node; @@ -5016,19 +5016,19 @@ static dsql_nod* pass1_expand_select_list(dsql_req* request, dsql_nod* list, @brief Expand a select item node. - @param request + @param statement @param node @param stack **/ -static void pass1_expand_select_node(dsql_req* request, dsql_nod* node, DsqlNodStack& stack, +static void pass1_expand_select_node(CompiledStatement* statement, dsql_nod* node, DsqlNodStack& stack, bool hide_using) { DEV_BLKCHK(node, dsql_type_nod); if (node->nod_type == nod_join) { - pass1_expand_select_node(request, node->nod_arg[e_join_left_rel], stack, true); - pass1_expand_select_node(request, node->nod_arg[e_join_rght_rel], stack, true); + pass1_expand_select_node(statement, node->nod_arg[e_join_left_rel], stack, true); + pass1_expand_select_node(statement, node->nod_arg[e_join_rght_rel], stack, true); } else if (node->nod_type == nod_derived_table) { // AB: Derived table support @@ -5096,9 +5096,9 @@ static void pass1_expand_select_node(dsql_req* request, dsql_nod* node, DsqlNodS } } else if (node->nod_type == nod_field_name) { - dsql_nod* select_item = pass1_field(request, node, true, NULL); + dsql_nod* select_item = pass1_field(statement, node, true, NULL); // The node could be a relation so call recursively. - pass1_expand_select_node(request, select_item, stack, false); + pass1_expand_select_node(statement, select_item, stack, false); } else { stack.push(node); @@ -5122,22 +5122,22 @@ static void pass1_expand_select_node(dsql_req* request, dsql_nod* node, DsqlNodS While inoffensive on inner joins, it changes the result on outer joins. - @param request + @param statement @param input @param list **/ -static dsql_nod* pass1_field( dsql_req* request, dsql_nod* input, +static dsql_nod* pass1_field( CompiledStatement* statement, dsql_nod* input, const bool list, dsql_nod* select_list) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); // CVC: This shameful hack added to allow CHECK constraint implementation via triggers // to be able to work. bool is_check_constraint = false; { // scope block - const dsql_nod* ddl_node = request->req_ddl_node; + const dsql_nod* ddl_node = statement->req_ddl_node; if (ddl_node && ddl_node->nod_type == nod_def_constraint) { is_check_constraint = true; } @@ -5214,7 +5214,7 @@ static dsql_nod* pass1_field( dsql_req* request, dsql_nod* input, // AB: Check first against the select list for matching column. // When no matches at all are found we go on with our // normal way of field name lookup. - dsql_nod* node = pass1_lookup_alias(request, name, select_list, true); + dsql_nod* node = pass1_lookup_alias(statement, name, select_list, true); if (node) { return node; } @@ -5234,7 +5234,7 @@ static dsql_nod* pass1_field( dsql_req* request, dsql_nod* input, { // AB: Loop through the scope_levels starting by its own. bool done = false; - USHORT current_scope_level = request->req_scope_level + 1; + USHORT current_scope_level = statement->req_scope_level + 1; for (; (current_scope_level > 0) && !done; current_scope_level--) { // If we've found a node we're done. @@ -5242,7 +5242,7 @@ static dsql_nod* pass1_field( dsql_req* request, dsql_nod* input, break; } - for (DsqlContextStack::iterator stack(*request->req_context); stack.hasData(); ++stack) + for (DsqlContextStack::iterator stack(*statement->req_context); stack.hasData(); ++stack) { // resolve_context() checks the type of the // given context, so the cast to dsql_ctx* is safe. @@ -5253,7 +5253,7 @@ static dsql_nod* pass1_field( dsql_req* request, dsql_nod* input, continue; } - dsql_fld* field = resolve_context(request, qualifier, context, is_check_constraint, + dsql_fld* field = resolve_context(statement, qualifier, context, is_check_constraint, resolve_by_alias); // AB: When there's no relation and no procedure then we have a derived table. @@ -5310,7 +5310,7 @@ static dsql_nod* pass1_field( dsql_req* request, dsql_nod* input, // Intercept any reference to a field with datatype that // did not exist prior to V6 and post an error - if (request->req_client_dialect <= SQL_DIALECT_V5 && field && + if (statement->req_client_dialect <= SQL_DIALECT_V5 && field && (field->fld_dtype == dtype_sql_date || field->fld_dtype == dtype_sql_time || field->fld_dtype == dtype_int64)) @@ -5321,7 +5321,7 @@ static dsql_nod* pass1_field( dsql_req* request, dsql_nod* input, isc_arg_string, field->fld_name.c_str(), isc_arg_gds, isc_sql_dialect_datatype_unsupport, - isc_arg_number, (SLONG) request->req_client_dialect, + isc_arg_number, (SLONG) statement->req_client_dialect, isc_arg_string, DSC_dtype_tostring(static_cast (field->fld_dtype)), 0); @@ -5337,7 +5337,7 @@ static dsql_nod* pass1_field( dsql_req* request, dsql_nod* input, } if (indices) { - indices = pass1_node_psql(request, indices, false); + indices = pass1_node_psql(statement, indices, false); } if (context->ctx_flags & CTX_null) @@ -5345,7 +5345,7 @@ static dsql_nod* pass1_field( dsql_req* request, dsql_nod* input, else if (field) node = MAKE_field(context, field, indices); else - node = list ? using_field : pass1_node_psql(request, using_field, false); + node = list ? using_field : pass1_node_psql(statement, using_field, false); } } else if (is_derived_table) { @@ -5454,7 +5454,7 @@ static dsql_nod* pass1_field( dsql_req* request, dsql_nod* input, // Don't check ambiguity if we don't have a field. if (node && name) { - node = ambiguity_check(request, node, name, ambiguous_ctx_stack); + node = ambiguity_check(statement, node, name, ambiguous_ctx_stack); } // Clean up stack @@ -6070,14 +6070,14 @@ static bool pass1_found_sub_select(const dsql_nod* node) an ordinal or alias which references the select list. - @param request + @param statement @param input @param select_list **/ -static dsql_nod* pass1_group_by_list(dsql_req* request, dsql_nod* input, dsql_nod* selectList) +static dsql_nod* pass1_group_by_list(CompiledStatement* statement, dsql_nod* input, dsql_nod* selectList) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); DEV_BLKCHK(selectList, dsql_type_nod); @@ -6100,7 +6100,7 @@ static dsql_nod* pass1_group_by_list(dsql_req* request, dsql_nod* input, dsql_no if (sub->nod_type == nod_field_name) { // check for alias or field node - frnode = pass1_field(request, sub, false, selectList); + frnode = pass1_field(statement, sub, false, selectList); } else if ((sub->nod_type == nod_constant) && (sub->nod_desc.dsc_dtype == dtype_long)) { @@ -6113,11 +6113,11 @@ static dsql_nod* pass1_group_by_list(dsql_req* request, dsql_nod* input, dsql_no isc_arg_string, "GROUP BY", 0); // Invalid column position used in the GROUP BY clause } - frnode = pass1_node_psql(request, selectList->nod_arg[position - 1], false); + frnode = pass1_node_psql(statement, selectList->nod_arg[position - 1], false); } else { - frnode = pass1_node_psql(request, *ptr, false); + frnode = pass1_node_psql(statement, *ptr, false); } stack.push(frnode); @@ -6136,16 +6136,16 @@ static dsql_nod* pass1_group_by_list(dsql_req* request, dsql_nod* input, dsql_no @brief Process INSERT statement. - @param request + @param statement @param input **/ -static dsql_nod* pass1_insert( dsql_req* request, dsql_nod* input, bool insert_or_update) +static dsql_nod* pass1_insert( CompiledStatement* statement, dsql_nod* input, bool insert_or_update) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); - request->req_type = REQ_INSERT; + statement->req_type = REQ_INSERT; dsql_nod* node = MAKE_node(nod_store, e_sto_count); // Process SELECT expression, if present @@ -6156,15 +6156,15 @@ static dsql_nod* pass1_insert( dsql_req* request, dsql_nod* input, bool insert_o if (input->nod_arg[e_ins_return]) rse->nod_flags |= NOD_SELECT_EXPR_SINGLETON; - node->nod_arg[e_sto_rse] = rse = PASS1_rse(request, rse, NULL); + node->nod_arg[e_sto_rse] = rse = PASS1_rse(statement, rse, NULL); values = rse->nod_arg[e_rse_items]; } else - values = pass1_node_psql(request, input->nod_arg[e_ins_values], false); + values = pass1_node_psql(statement, input->nod_arg[e_ins_values], false); // Process relation - dsql_nod* temp_rel = pass1_relation(request, input->nod_arg[e_ins_relation]); + dsql_nod* temp_rel = pass1_relation(statement, input->nod_arg[e_ins_relation]); node->nod_arg[e_sto_relation] = temp_rel; dsql_ctx* context = (dsql_ctx*) temp_rel->nod_arg[0]; DEV_BLKCHK(context, dsql_type_ctx); @@ -6176,7 +6176,7 @@ static dsql_nod* pass1_insert( dsql_req* request, dsql_nod* input, bool insert_o if (fields) { const dsql_nod* old_fields = fields; // for error reporting. - fields = pass1_node_psql(request, fields, false); + fields = pass1_node_psql(statement, fields, false); // We do not allow cases like INSERT INTO T(f1, f2, f1)... field_appears_once(fields, old_fields, true, "INSERT"); @@ -6222,7 +6222,7 @@ static dsql_nod* pass1_insert( dsql_req* request, dsql_nod* input, bool insert_o // end IBO hack } else - fields = pass1_node_psql(request, explode_fields(relation), false); + fields = pass1_node_psql(statement, explode_fields(relation), false); // Match field fields and values @@ -6247,7 +6247,7 @@ static dsql_nod* pass1_insert( dsql_req* request, dsql_nod* input, bool insert_o temp->nod_arg[e_asgn_field] = *ptr; stack.push(temp); temp = *ptr2; - set_parameter_type(request, temp, *ptr, false); + set_parameter_type(statement, temp, *ptr, false); } } @@ -6257,39 +6257,39 @@ static dsql_nod* pass1_insert( dsql_req* request, dsql_nod* input, bool insert_o { // Clone the insert context, push with name "OLD" in the same scope level and // marks it with CTX_null so all fields be resolved to NULL constant. - dsql_ctx* old_context = FB_NEW(request->req_pool) dsql_ctx(request->req_pool); + dsql_ctx* old_context = FB_NEW(statement->req_pool) dsql_ctx(statement->req_pool); *old_context = *context; old_context->ctx_alias = old_context->ctx_internal_alias = MAKE_cstring(OLD_CONTEXT)->str_data; old_context->ctx_flags |= CTX_system | CTX_null | CTX_returning; - request->req_context->push(old_context); + statement->req_context->push(old_context); // clone the insert context and push with name "NEW" in a greater scope level - dsql_ctx* new_context = FB_NEW(request->req_pool) dsql_ctx(request->req_pool); + dsql_ctx* new_context = FB_NEW(statement->req_pool) dsql_ctx(statement->req_pool); *new_context = *context; - new_context->ctx_scope_level = ++request->req_scope_level; + new_context->ctx_scope_level = ++statement->req_scope_level; new_context->ctx_alias = new_context->ctx_internal_alias = MAKE_cstring(NEW_CONTEXT)->str_data; new_context->ctx_flags |= CTX_system | CTX_returning; - request->req_context->push(new_context); + statement->req_context->push(new_context); } - node->nod_arg[e_sto_return] = process_returning(request, input->nod_arg[e_ins_return]); + node->nod_arg[e_sto_return] = process_returning(statement, input->nod_arg[e_ins_return]); if (insert_or_update) { - --request->req_scope_level; - request->req_context->pop(); - request->req_context->pop(); + --statement->req_scope_level; + statement->req_context->pop(); + statement->req_context->pop(); } set_parameters_name(node->nod_arg[e_sto_statement], node->nod_arg[e_sto_relation]); if (!insert_or_update) - node = nullify_returning(request, node); + node = nullify_returning(statement, node); - request->req_context->pop(); + statement->req_context->pop(); return node; } @@ -6303,53 +6303,53 @@ static dsql_nod* pass1_insert( dsql_req* request, dsql_nod* input, bool insert_o if they are in outer joins (req_in_outer_join). - @param request + @param statement @param input **/ -static dsql_nod* pass1_join(dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_join(CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); dsql_nod* const node = MAKE_node(input->nod_type, input->nod_count); // First process type - node->nod_arg[e_join_type] = PASS1_node(request, input->nod_arg[e_join_type]); + node->nod_arg[e_join_type] = PASS1_node(statement, input->nod_arg[e_join_type]); // Process relations switch (node->nod_arg[e_join_type]->nod_type) { case nod_join_inner: node->nod_arg[e_join_left_rel] = - PASS1_node(request, input->nod_arg[e_join_left_rel]); + PASS1_node(statement, input->nod_arg[e_join_left_rel]); node->nod_arg[e_join_rght_rel] = - PASS1_node(request, input->nod_arg[e_join_rght_rel]); + PASS1_node(statement, input->nod_arg[e_join_rght_rel]); break; case nod_join_left: node->nod_arg[e_join_left_rel] = - PASS1_node(request, input->nod_arg[e_join_left_rel]); - request->req_in_outer_join++; + PASS1_node(statement, input->nod_arg[e_join_left_rel]); + statement->req_in_outer_join++; node->nod_arg[e_join_rght_rel] = - PASS1_node(request, input->nod_arg[e_join_rght_rel]); - request->req_in_outer_join--; + PASS1_node(statement, input->nod_arg[e_join_rght_rel]); + statement->req_in_outer_join--; break; case nod_join_right: - request->req_in_outer_join++; + statement->req_in_outer_join++; node->nod_arg[e_join_left_rel] = - PASS1_node(request, input->nod_arg[e_join_left_rel]); - request->req_in_outer_join--; + PASS1_node(statement, input->nod_arg[e_join_left_rel]); + statement->req_in_outer_join--; node->nod_arg[e_join_rght_rel] = - PASS1_node(request, input->nod_arg[e_join_rght_rel]); + PASS1_node(statement, input->nod_arg[e_join_rght_rel]); break; case nod_join_full: - request->req_in_outer_join++; + statement->req_in_outer_join++; node->nod_arg[e_join_left_rel] = - PASS1_node(request, input->nod_arg[e_join_left_rel]); + PASS1_node(statement, input->nod_arg[e_join_left_rel]); node->nod_arg[e_join_rght_rel] = - PASS1_node(request, input->nod_arg[e_join_rght_rel]); - request->req_in_outer_join--; + PASS1_node(statement, input->nod_arg[e_join_rght_rel]); + statement->req_in_outer_join--; break; default: @@ -6362,12 +6362,12 @@ static dsql_nod* pass1_join(dsql_req* request, dsql_nod* input) dsql_nod* boolean = input->nod_arg[e_join_boolean]; if (boolean && (boolean->nod_type == nod_flag || boolean->nod_type == nod_list)) { - if (request->req_client_dialect < SQL_DIALECT_V6) + if (statement->req_client_dialect < SQL_DIALECT_V6) { ERRD_post( isc_sqlerr, isc_arg_number, (SLONG) -901, isc_arg_gds, isc_dsql_unsupp_feature_dialect, - isc_arg_number, request->req_client_dialect, + isc_arg_number, statement->req_client_dialect, 0); } @@ -6375,11 +6375,11 @@ static dsql_nod* pass1_join(dsql_req* request, dsql_nod* input) if (boolean->nod_type == nod_flag) // NATURAL JOIN { - StrArray leftNames(request->req_pool); + StrArray leftNames(statement->req_pool); DsqlNodStack matched; - pass1_expand_select_node(request, node->nod_arg[e_join_left_rel], leftStack, true); - pass1_expand_select_node(request, node->nod_arg[e_join_rght_rel], rightStack, true); + pass1_expand_select_node(statement, node->nod_arg[e_join_left_rel], leftStack, true); + pass1_expand_select_node(statement, node->nod_arg[e_join_rght_rel], rightStack, true); // verify columns that exist in both sides for (int i = 0; i < 2; ++i) @@ -6437,7 +6437,7 @@ static dsql_nod* pass1_join(dsql_req* request, dsql_nod* input) fb_assert(boolean->nod_type == nod_list); dsql_nod* newBoolean = NULL; - StrArray usedColumns(request->req_pool); + StrArray usedColumns(statement->req_pool); for (int i = 0; i < boolean->nod_count; ++i) { @@ -6464,14 +6464,14 @@ static dsql_nod* pass1_join(dsql_req* request, dsql_nod* input) rightStack.clear(); // get the column names from both sides - pass1_expand_select_node(request, node->nod_arg[e_join_left_rel], leftStack, true); - pass1_expand_select_node(request, node->nod_arg[e_join_rght_rel], rightStack, true); + pass1_expand_select_node(statement, node->nod_arg[e_join_left_rel], leftStack, true); + pass1_expand_select_node(statement, node->nod_arg[e_join_rght_rel], rightStack, true); // create the boolean dsql_nod* eqlNode = MAKE_node(nod_eql, 2); - eqlNode->nod_arg[0] = resolve_using_field(request, + eqlNode->nod_arg[0] = resolve_using_field(statement, fldName, leftStack, field, "left", leftCtx); - eqlNode->nod_arg[1] = resolve_using_field(request, + eqlNode->nod_arg[1] = resolve_using_field(statement, fldName, rightStack, field, "right", rightCtx); fb_assert(leftCtx); @@ -6481,7 +6481,7 @@ static dsql_nod* pass1_join(dsql_req* request, dsql_nod* input) ImplicitJoin* impJoinLeft; if (!leftCtx->ctx_imp_join.get(fldName->str_data, impJoinLeft)) { - impJoinLeft = FB_NEW(request->req_pool) ImplicitJoin(); + impJoinLeft = FB_NEW(statement->req_pool) ImplicitJoin(); impJoinLeft->value = eqlNode->nod_arg[0]; impJoinLeft->visibleInContext = leftCtx; } @@ -6491,7 +6491,7 @@ static dsql_nod* pass1_join(dsql_req* request, dsql_nod* input) ImplicitJoin* impJoinRight; if (!rightCtx->ctx_imp_join.get(fldName->str_data, impJoinRight)) { - impJoinRight = FB_NEW(request->req_pool) ImplicitJoin(); + impJoinRight = FB_NEW(statement->req_pool) ImplicitJoin(); impJoinRight->value = eqlNode->nod_arg[1]; } else @@ -6505,25 +6505,25 @@ static dsql_nod* pass1_join(dsql_req* request, dsql_nod* input) temp = temp->nod_arg[e_alias_value]; { // scope - PsqlChanger changer(request, false); + PsqlChanger changer(statement, false); if (temp->nod_type == nod_coalesce) { - pass1_put_args_on_stack(request, temp->nod_arg[0], stack); - pass1_put_args_on_stack(request, temp->nod_arg[1], stack); + pass1_put_args_on_stack(statement, temp->nod_arg[0], stack); + pass1_put_args_on_stack(statement, temp->nod_arg[1], stack); } else - pass1_put_args_on_stack(request, temp, stack); + pass1_put_args_on_stack(statement, temp, stack); if ((temp = impJoinRight->value)->nod_type == nod_alias) temp = temp->nod_arg[e_alias_value]; if (temp->nod_type == nod_coalesce) { - pass1_put_args_on_stack(request, temp->nod_arg[0], stack); - pass1_put_args_on_stack(request, temp->nod_arg[1], stack); + pass1_put_args_on_stack(statement, temp->nod_arg[0], stack); + pass1_put_args_on_stack(statement, temp->nod_arg[1], stack); } else - pass1_put_args_on_stack(request, temp, stack); + pass1_put_args_on_stack(statement, temp, stack); } dsql_nod* coalesce = MAKE_node(nod_coalesce, 2); @@ -6556,7 +6556,7 @@ static dsql_nod* pass1_join(dsql_req* request, dsql_nod* input) } } - node->nod_arg[e_join_boolean] = PASS1_node(request, boolean); + node->nod_arg[e_join_boolean] = PASS1_node(statement, boolean); return node; } @@ -6569,13 +6569,13 @@ static dsql_nod* pass1_join(dsql_req* request, dsql_nod* input) @brief Process loop interruption - @param request + @param statement @param input **/ -static dsql_nod* pass1_label(dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_label(CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); dsql_nod* label = NULL; @@ -6612,8 +6612,8 @@ static dsql_nod* pass1_label(dsql_req* request, dsql_nod* input) fb_assert(label->nod_type == nod_label); string = (dsql_str*) label->nod_arg[e_label_name]; const TEXT* label_string = (TEXT*) string->str_data; - int index = request->req_loop_level; - for (DsqlStrStack::iterator stack(request->req_labels); stack.hasData(); ++stack) { + int index = statement->req_loop_level; + for (DsqlStrStack::iterator stack(statement->req_labels); stack.hasData(); ++stack) { const dsql_str* obj = stack.object(); if (obj) { const TEXT* obj_string = (TEXT*) obj->str_data; @@ -6642,7 +6642,7 @@ static dsql_nod* pass1_label(dsql_req* request, dsql_nod* input) } else { // break the current loop - number = request->req_loop_level; + number = statement->req_loop_level; } } else { @@ -6656,12 +6656,12 @@ static dsql_nod* pass1_label(dsql_req* request, dsql_nod* input) } else { // store label name, if specified - request->req_labels.push(string); - number = request->req_loop_level; + statement->req_labels.push(string); + number = statement->req_loop_level; } } - fb_assert(number > 0 && number <= request->req_loop_level); + fb_assert(number > 0 && number <= statement->req_loop_level); if (!label) { label = MAKE_node(nod_label, e_label_count); @@ -6681,12 +6681,12 @@ static dsql_nod* pass1_label(dsql_req* request, dsql_nod* input) Return node if found else return NULL. If more matches are found we raise ambiguity error. - @param request + @param statement @param name @param selectList **/ -static dsql_nod* pass1_lookup_alias(dsql_req* request, const dsql_str* name, dsql_nod* selectList, +static dsql_nod* pass1_lookup_alias(CompiledStatement* statement, const dsql_str* name, dsql_nod* selectList, bool process) { dsql_nod* returnNode = NULL; @@ -6727,7 +6727,7 @@ static dsql_nod* pass1_lookup_alias(dsql_req* request, const dsql_str* name, dsq } if (matchingNode) { if (process) - matchingNode = pass1_node_psql(request, matchingNode, false); + matchingNode = pass1_node_psql(statement, matchingNode, false); if (returnNode) { // There was already a node matched, thus raise ambiguous field name error. @@ -6797,12 +6797,12 @@ static dsql_nod* pass1_lookup_alias(dsql_req* request, const dsql_str* name, dsq @brief Create a derived field based on underlying expressions - @param request + @param statement @param tdbb @param select_item **/ -static dsql_nod* pass1_make_derived_field(dsql_req* request, thread_db* tdbb, +static dsql_nod* pass1_make_derived_field(CompiledStatement* statement, thread_db* tdbb, dsql_nod* select_item) { DEV_BLKCHK(select_item, dsql_type_nod); @@ -6815,7 +6815,7 @@ static dsql_nod* pass1_make_derived_field(dsql_req* request, thread_db* tdbb, dsql_nod* derived_field = MAKE_node(nod_derived_field, e_derived_field_count); derived_field->nod_arg[e_derived_field_value] = select_item; derived_field->nod_arg[e_derived_field_name] = select_item->nod_arg[e_derived_field_name]; - derived_field->nod_arg[e_derived_field_scope] = (dsql_nod*)(IPTR) request->req_scope_level; + derived_field->nod_arg[e_derived_field_scope] = (dsql_nod*)(IPTR) statement->req_scope_level; derived_field->nod_desc = select_item->nod_desc; return derived_field; } @@ -6834,7 +6834,7 @@ static dsql_nod* pass1_make_derived_field(dsql_req* request, thread_db* tdbb, dsql_nod* derived_field = MAKE_node(nod_derived_field, e_derived_field_count); derived_field->nod_arg[e_derived_field_value] = select_item; derived_field->nod_arg[e_derived_field_name] = (dsql_nod*) alias; - derived_field->nod_arg[e_derived_field_scope] = (dsql_nod*)(IPTR) request->req_scope_level; + derived_field->nod_arg[e_derived_field_scope] = (dsql_nod*)(IPTR) statement->req_scope_level; derived_field->nod_desc = select_item->nod_desc; return derived_field; } @@ -6851,7 +6851,7 @@ static dsql_nod* pass1_make_derived_field(dsql_req* request, thread_db* tdbb, dsql_nod* derived_field = MAKE_node(nod_derived_field, e_derived_field_count); derived_field->nod_arg[e_derived_field_value] = select_item->nod_arg[e_alias_value]; derived_field->nod_arg[e_derived_field_name] = (dsql_nod*) alias; - derived_field->nod_arg[e_derived_field_scope] = (dsql_nod*)(IPTR) request->req_scope_level; + derived_field->nod_arg[e_derived_field_scope] = (dsql_nod*)(IPTR) statement->req_scope_level; derived_field->nod_desc = select_item->nod_desc; return derived_field; } @@ -6860,13 +6860,13 @@ static dsql_nod* pass1_make_derived_field(dsql_req* request, thread_db* tdbb, { // Aggregate's have map on top. dsql_map* map = (dsql_map*) select_item->nod_arg[e_map_map]; - dsql_nod* derived_field = pass1_make_derived_field(request, tdbb, map->map_node); + dsql_nod* derived_field = pass1_make_derived_field(statement, tdbb, map->map_node); // If we had succesfully made a derived field node change it // with orginal map. if (derived_field->nod_type == nod_derived_field) { derived_field->nod_arg[e_derived_field_value] = select_item; - derived_field->nod_arg[e_derived_field_scope] = (dsql_nod*)(IPTR) request->req_scope_level; + derived_field->nod_arg[e_derived_field_scope] = (dsql_nod*)(IPTR) statement->req_scope_level; derived_field->nod_desc = select_item->nod_desc; return derived_field; } @@ -6877,7 +6877,7 @@ static dsql_nod* pass1_make_derived_field(dsql_req* request, thread_db* tdbb, case nod_via : { // Try to generate derived field from sub-select - dsql_nod* derived_field = pass1_make_derived_field(request, tdbb, + dsql_nod* derived_field = pass1_make_derived_field(statement, tdbb, select_item->nod_arg[e_via_value_1]); derived_field->nod_arg[e_derived_field_value] = select_item; return derived_field; @@ -6897,13 +6897,13 @@ static dsql_nod* pass1_make_derived_field(dsql_req* request, thread_db* tdbb, @brief Process MERGE statement. - @param request + @param statement @param input **/ -static dsql_nod* pass1_merge(dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_merge(CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); dsql_nod* source = input->nod_arg[e_mrg_using]; // USING @@ -6936,7 +6936,7 @@ static dsql_nod* pass1_merge(dsql_req* request, dsql_nod* input) dsql_nod* for_select = MAKE_node(nod_for_select, e_flp_count); for_select->nod_arg[e_flp_select] = select; for_select->nod_arg[e_flp_action] = MAKE_node(nod_list, 0); - for_select = PASS1_statement(request, for_select); + for_select = PASS1_statement(statement, for_select); // get the already processed relations source = for_select->nod_arg[e_flp_select]->nod_arg[e_select_expr]-> @@ -6972,34 +6972,34 @@ static dsql_nod* pass1_merge(dsql_req* request, dsql_nod* input) modify->nod_arg[e_mdc_context] = (dsql_nod*) context; - request->req_scope_level++; // go to the same level of source and target contexts - request->req_context->push(get_context(source)); // push the USING context - request->req_context->push(context); // process old context values + statement->req_scope_level++; // go to the same level of source and target contexts + statement->req_context->push(get_context(source)); // push the USING context + statement->req_context->push(context); // process old context values for (ptr = org_values.begin(); ptr < org_values.end(); ++ptr) - *ptr = pass1_node_psql(request, *ptr, false); + *ptr = pass1_node_psql(statement, *ptr, false); // and pop the contexts - request->req_context->pop(); - request->req_context->pop(); - request->req_scope_level--; + statement->req_context->pop(); + statement->req_context->pop(); + statement->req_scope_level--; // process relation - modify->nod_arg[e_mdc_update] = pass1_relation(request, input->nod_arg[e_mrg_relation]); + modify->nod_arg[e_mdc_update] = pass1_relation(statement, input->nod_arg[e_mrg_relation]); // process new context values for (ptr = new_values.begin(); ptr < new_values.end(); ++ptr) - *ptr = pass1_node_psql(request, *ptr, false); + *ptr = pass1_node_psql(statement, *ptr, false); - request->req_context->pop(); + statement->req_context->pop(); // recreate list of assignments modify->nod_arg[e_mdc_statement] = list = MAKE_node(nod_list, list->nod_count); for (i = 0; i < list->nod_count; ++i) { - if (!set_parameter_type(request, org_values[i], new_values[i], false)) - set_parameter_type(request, new_values[i], org_values[i], false); + if (!set_parameter_type(statement, org_values[i], new_values[i], false)) + set_parameter_type(statement, new_values[i], org_values[i], false); dsql_nod* assign = MAKE_node(nod_assign, e_asgn_count); assign->nod_arg[e_asgn_value] = org_values[i]; @@ -7017,11 +7017,11 @@ static dsql_nod* pass1_merge(dsql_req* request, dsql_nod* input) if (input->nod_arg[e_mrg_when]->nod_arg[e_mrg_when_not_matched]) { - request->req_scope_level++; // go to the same level of the source context - request->req_context->push(get_context(source)); // push the USING context + statement->req_scope_level++; // go to the same level of the source context + statement->req_context->push(get_context(source)); // push the USING context // the INSERT relation should be processed in a higher level than the source context - request->req_scope_level++; + statement->req_scope_level++; // build the INSERT node insert = MAKE_node(nod_insert, e_ins_count); @@ -7030,14 +7030,14 @@ static dsql_nod* pass1_merge(dsql_req* request, dsql_nod* input) input->nod_arg[e_mrg_when]->nod_arg[e_mrg_when_not_matched]->nod_arg[e_mrg_insert_fields]; insert->nod_arg[e_ins_values] = input->nod_arg[e_mrg_when]->nod_arg[e_mrg_when_not_matched]->nod_arg[e_mrg_insert_values]; - insert = pass1_insert(request, insert, false); + insert = pass1_insert(statement, insert, false); // restore the scope level - request->req_scope_level--; + statement->req_scope_level--; // pop the USING context - request->req_scope_level--; - request->req_context->pop(); + statement->req_scope_level--; + statement->req_context->pop(); } // build a IF (target.RDB$DB_KEY IS NULL) @@ -7065,18 +7065,18 @@ static dsql_nod* pass1_merge(dsql_req* request, dsql_nod* input) for_select->nod_arg[e_flp_action] = action; // describe it as an INSERT - request->req_type = REQ_INSERT; + statement->req_type = REQ_INSERT; // and return the whole FOR SELECT return for_select; } -// Changes request->isPsql() value, calls PASS1_node and restore request->isPsql(). -static dsql_nod* pass1_node_psql(dsql_req* request, dsql_nod* input, bool psql) +// Changes statement->isPsql() value, calls PASS1_node and restore statement->isPsql(). +static dsql_nod* pass1_node_psql(CompiledStatement* statement, dsql_nod* input, bool psql) { - PsqlChanger changer(request, psql); - return PASS1_node(request, input); + PsqlChanger changer(statement, psql); + return PASS1_node(statement, input); } @@ -7088,16 +7088,16 @@ static dsql_nod* pass1_node_psql(dsql_req* request, dsql_nod* input, bool psql) possible. Get rid of redundant nested NOT predicates. - @param request + @param statement @param input @param invert **/ -static dsql_nod* pass1_not(dsql_req* request, +static dsql_nod* pass1_not(CompiledStatement* statement, const dsql_nod* input, bool invert) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); fb_assert(input->nod_type == nod_not); @@ -7106,7 +7106,7 @@ static dsql_nod* pass1_not(dsql_req* request, if (sub->nod_type == nod_not) { // recurse until different node is found // (every even call means no inversion required) - return pass1_not(request, sub, !invert); + return pass1_not(statement, sub, !invert); } dsql_nod* node; @@ -7206,7 +7206,7 @@ static dsql_nod* pass1_not(dsql_req* request, // and return immediately to avoid infinite recursion later fb_assert(node_type == nod_not); node = MAKE_node(input->nod_type, 1); - node->nod_arg[0] = PASS1_node(request, sub); + node->nod_arg[0] = PASS1_node(statement, sub); return node; } else if (is_between) { @@ -7239,7 +7239,7 @@ static dsql_nod* pass1_not(dsql_req* request, } } - return PASS1_node(request, node); + return PASS1_node(statement, node); } @@ -7250,19 +7250,19 @@ static dsql_nod* pass1_not(dsql_req* request, @brief Put recursive non list nodes on the stack - @param request + @param statement @param input @param stack **/ -static void pass1_put_args_on_stack( dsql_req* request, dsql_nod* input, +static void pass1_put_args_on_stack( CompiledStatement* statement, dsql_nod* input, DsqlNodStack& stack) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); if (input->nod_type != nod_list) { - stack.push(PASS1_node(request, input)); + stack.push(PASS1_node(statement, input)); return; } @@ -7270,7 +7270,7 @@ static void pass1_put_args_on_stack( dsql_req* request, dsql_nod* input, for (const dsql_nod* const* const end = ptr + input->nod_count; ptr < end; ptr++) { - pass1_put_args_on_stack(request, *ptr, stack); + pass1_put_args_on_stack(statement, *ptr, stack); } } @@ -7283,18 +7283,18 @@ static void pass1_put_args_on_stack( dsql_req* request, dsql_nod* input, Allocate a new relation node. - @param request + @param statement @param input **/ -static dsql_nod* pass1_relation( dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_relation( CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); dsql_nod* node = MAKE_node(nod_relation, e_rel_count); - node->nod_arg[e_rel_context] = (dsql_nod*) PASS1_make_context(request, input); + node->nod_arg[e_rel_context] = (dsql_nod*) PASS1_make_context(statement, input); return node; } @@ -7313,13 +7313,13 @@ static dsql_nod* pass1_relation( dsql_req* request, dsql_nod* input) view stack are those used in the view definition. - @param request + @param statement @param alias_list **/ -static dsql_nod* pass1_alias_list(dsql_req* request, dsql_nod* alias_list) +static dsql_nod* pass1_alias_list(CompiledStatement* statement, dsql_nod* alias_list) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(alias_list, dsql_type_nod); dsql_nod** arg = alias_list->nod_arg; @@ -7328,7 +7328,7 @@ static dsql_nod* pass1_alias_list(dsql_req* request, dsql_nod* alias_list) // Loop through every alias and find the context for that alias. // All aliases should have a corresponding context. int aliasCount = alias_list->nod_count; - USHORT savedScopeLevel = request->req_scope_level; + USHORT savedScopeLevel = statement->req_scope_level; dsql_ctx* context = NULL; while (aliasCount > 0) { @@ -7337,8 +7337,8 @@ static dsql_nod* pass1_alias_list(dsql_req* request, dsql_nod* alias_list) if (context->ctx_rse && !context->ctx_relation && !context->ctx_procedure) { // Derived table - request->req_scope_level++; - context = pass1_alias(request, context->ctx_childs_derived_table, (dsql_str*) *arg); + statement->req_scope_level++; + context = pass1_alias(statement, context->ctx_childs_derived_table, (dsql_str*) *arg); } else { @@ -7349,7 +7349,7 @@ static dsql_nod* pass1_alias_list(dsql_req* request, dsql_nod* alias_list) // since we already matched it to the context. for (; arg < end; arg++, aliasCount--) { - if (!(relation = pass1_base_table(request, relation, (dsql_str*) *arg))) + if (!(relation = pass1_base_table(statement, relation, (dsql_str*) *arg))) break; } @@ -7396,7 +7396,7 @@ static dsql_nod* pass1_alias_list(dsql_req* request, dsql_nod* alias_list) } else { - context = pass1_alias(request, *request->req_context, (dsql_str*) *arg); + context = pass1_alias(statement, *statement->req_context, (dsql_str*) *arg); } if (!context) { @@ -7406,7 +7406,7 @@ static dsql_nod* pass1_alias_list(dsql_req* request, dsql_nod* alias_list) arg++; aliasCount--; } - request->req_scope_level = savedScopeLevel; + statement->req_scope_level = savedScopeLevel; if (!context) { // there is no alias or table named %s at this scope level. @@ -7430,15 +7430,15 @@ static dsql_nod* pass1_alias_list(dsql_req* request, dsql_nod* alias_list) proper context. - @param request + @param statement @param alias **/ -static dsql_ctx* pass1_alias(dsql_req* request, DsqlContextStack& stack, dsql_str* alias) +static dsql_ctx* pass1_alias(CompiledStatement* statement, DsqlContextStack& stack, dsql_str* alias) { dsql_ctx* relation_context = NULL; - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(alias, dsql_type_str); // CVC: Getting rid of trailing spaces. @@ -7451,7 +7451,7 @@ static dsql_ctx* pass1_alias(dsql_req* request, DsqlContextStack& stack, dsql_st // name which matches the identifier passed. for (DsqlContextStack::iterator itr(stack); itr.hasData(); ++itr) { dsql_ctx* context = itr.object(); - if (context->ctx_scope_level != request->req_scope_level) { + if (context->ctx_scope_level != statement->req_scope_level) { continue; } @@ -7550,20 +7550,20 @@ static dsql_str* pass1_alias_concat(const dsql_str* input1, const dsql_str* inpu has a base table which matches the passed alias. - @param request + @param statement @param relation @param alias **/ -static dsql_rel* pass1_base_table( dsql_req* request, const dsql_rel* relation, +static dsql_rel* pass1_base_table( CompiledStatement* statement, const dsql_rel* relation, const dsql_str* alias) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(relation, dsql_type_dsql_rel); DEV_BLKCHK(alias, dsql_type_str); - return METD_get_view_relation(request, + return METD_get_view_relation(statement, relation->rel_name.c_str(), alias->str_data); } @@ -7576,30 +7576,30 @@ static dsql_rel* pass1_base_table( dsql_req* request, const dsql_rel* relation, @brief Compile a RETURNING clause. - @param request + @param statement @param input **/ -static dsql_nod* pass1_returning(dsql_req* request, const dsql_nod* input) +static dsql_nod* pass1_returning(CompiledStatement* statement, const dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); - dsql_nod* const source = pass1_node_psql(request, input->nod_arg[e_ret_source], false); + dsql_nod* const source = pass1_node_psql(statement, input->nod_arg[e_ret_source], false); - request->req_flags |= REQ_returning_into; + statement->req_flags |= REQ_returning_into; dsql_nod* const target = - PASS1_node(request, input->nod_arg[e_ret_target]); - request->req_flags &= ~REQ_returning_into; + PASS1_node(statement, input->nod_arg[e_ret_target]); + statement->req_flags &= ~REQ_returning_into; - if (!request->isPsql() && target) + if (!statement->isPsql() && target) { // RETURNING INTO is not allowed syntax for DSQL ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) -104, isc_arg_gds, isc_token_err, // Token unknown isc_arg_gds, isc_random, isc_arg_string, "INTO", 0); } - else if (request->isPsql() && !target) + else if (statement->isPsql() && !target) { // This trick because we don't copy lexer positions when copying lists. const dsql_nod* errSrc = input->nod_arg[e_ret_source]; @@ -7619,7 +7619,7 @@ static dsql_nod* pass1_returning(dsql_req* request, const dsql_nod* input) if (target) { // PSQL case - fb_assert(request->isPsql()); + fb_assert(statement->isPsql()); if (count != target->nod_count) { // count of column list and value list don't match ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) -804, @@ -7641,7 +7641,7 @@ static dsql_nod* pass1_returning(dsql_req* request, const dsql_nod* input) else { // DSQL case - fb_assert(!request->isPsql()); + fb_assert(!statement->isPsql()); dsql_nod** src = source->nod_arg; dsql_nod** ptr = node->nod_arg; @@ -7649,9 +7649,9 @@ static dsql_nod* pass1_returning(dsql_req* request, const dsql_nod* input) ptr < end; src++, ptr++) { dsql_par* parameter = - MAKE_parameter(request->req_receive, true, true, 0, *src); + MAKE_parameter(statement->req_receive, true, true, 0, *src); parameter->par_node = *src; - MAKE_desc(request, ¶meter->par_desc, *src, NULL); + MAKE_desc(statement, ¶meter->par_desc, *src, NULL); parameter->par_desc.dsc_flags |= DSC_nullable; dsql_nod* p_node = MAKE_node(nod_parameter, e_par_count); @@ -7666,9 +7666,9 @@ static dsql_nod* pass1_returning(dsql_req* request, const dsql_nod* input) } } - if (!request->isPsql()) + if (!statement->isPsql()) { - request->req_type = REQ_EXEC_PROCEDURE; + statement->req_type = REQ_EXEC_PROCEDURE; } return node; @@ -7683,7 +7683,7 @@ static dsql_nod* pass1_returning(dsql_req* request, const dsql_nod* input) substitute recursive CTE alias (if needed) and call pass1_rse_impl - @param request + @param statement @param input @param order @param rows @@ -7691,7 +7691,7 @@ static dsql_nod* pass1_returning(dsql_req* request, const dsql_nod* input) @param flags **/ -static dsql_nod* pass1_rse( dsql_req* request, dsql_nod* input, dsql_nod* order, +static dsql_nod* pass1_rse( CompiledStatement* statement, dsql_nod* input, dsql_nod* order, dsql_nod* rows, dsql_nod* update_lock, USHORT flags) { TEXT* save_alias = 0; @@ -7699,16 +7699,16 @@ static dsql_nod* pass1_rse( dsql_req* request, dsql_nod* input, dsql_nod* order, if (isRecursive) { - fb_assert(request->req_recursive_ctx); - save_alias = request->req_recursive_ctx->ctx_alias; + fb_assert(statement->req_recursive_ctx); + save_alias = statement->req_recursive_ctx->ctx_alias; - request->req_recursive_ctx->ctx_alias = (TEXT*) request->getNextCTEAlias()->str_data; + statement->req_recursive_ctx->ctx_alias = (TEXT*) statement->getNextCTEAlias()->str_data; } - dsql_nod* ret = pass1_rse_impl(request, input, order, rows, update_lock, flags); + dsql_nod* ret = pass1_rse_impl(statement, input, order, rows, update_lock, flags); if (isRecursive) { - request->req_recursive_ctx->ctx_alias = save_alias; + statement->req_recursive_ctx->ctx_alias = save_alias; } return ret; @@ -7724,7 +7724,7 @@ static dsql_nod* pass1_rse( dsql_req* request, dsql_nod* input, dsql_nod* order, or a "list" (an implicit union) or a "query specification". - @param request + @param statement @param input @param order @param rows @@ -7732,10 +7732,10 @@ static dsql_nod* pass1_rse( dsql_req* request, dsql_nod* input, dsql_nod* order, @param flags **/ -static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* order, +static dsql_nod* pass1_rse_impl( CompiledStatement* statement, dsql_nod* input, dsql_nod* order, dsql_nod* rows, dsql_nod* update_lock, USHORT flags) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); DEV_BLKCHK(order, dsql_type_nod); @@ -7747,24 +7747,24 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o try { if (node_with) - request->addCTEs(node_with); + statement->addCTEs(node_with); dsql_nod* ret = - pass1_rse(request, input->nod_arg[e_sel_query_spec], + pass1_rse(statement, input->nod_arg[e_sel_query_spec], input->nod_arg[e_sel_order], input->nod_arg[e_sel_rows], update_lock, input->nod_flags); if (node_with) { - request->checkUnusedCTEs(); - request->clearCTEs(); + statement->checkUnusedCTEs(); + statement->clearCTEs(); } return ret; } catch (const Firebird::Exception&) { if (node_with) - request->clearCTEs(); + statement->clearCTEs(); throw; } } @@ -7777,7 +7777,7 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o isc_token_err, // Token unknown isc_arg_gds, isc_random, isc_arg_string, "WITH LOCK", 0); - return pass1_union(request, input, order, rows, flags); + return pass1_union(statement, input, order, rows, flags); } fb_assert(input->nod_type == nod_query_spec); @@ -7789,7 +7789,7 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o rse->nod_arg[e_rse_lock] = update_lock; dsql_nod* list = rse->nod_arg[e_rse_streams] = - pass1_node_psql(request, input->nod_arg[e_qry_from], false); + pass1_node_psql(statement, input->nod_arg[e_qry_from], false); { // scope block const dsql_rel* relation; @@ -7816,28 +7816,28 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o const int skip_index = rows ? e_rows_skip : e_limit_skip; if (node->nod_arg[length_index]) { - dsql_nod* sub = pass1_node_psql(request, node->nod_arg[length_index], false); + dsql_nod* sub = pass1_node_psql(statement, node->nod_arg[length_index], false); rse->nod_arg[e_rse_first] = sub; - set_parameter_type(request, sub, node, false); + set_parameter_type(statement, sub, node, false); } if (node->nod_arg[skip_index]) { - dsql_nod* sub = pass1_node_psql(request, node->nod_arg[skip_index], false); + dsql_nod* sub = pass1_node_psql(statement, node->nod_arg[skip_index], false); rse->nod_arg[e_rse_skip] = sub; - set_parameter_type(request, sub, node, false); + set_parameter_type(statement, sub, node, false); } } // Process boolean, if any if ( (node = input->nod_arg[e_qry_where]) ) { - ++request->req_in_where_clause; - rse->nod_arg[e_rse_boolean] = pass1_node_psql(request, node, false); - --request->req_in_where_clause; + ++statement->req_in_where_clause; + rse->nod_arg[e_rse_boolean] = pass1_node_psql(statement, node, false); + --statement->req_in_where_clause; /* AB: An aggregate pointing to it's own parent_context isn't allowed, HAVING should be used instead */ if (pass1_found_aggregate(rse->nod_arg[e_rse_boolean], - request->req_scope_level, FIELD_MATCH_TYPE_EQUAL, true)) + statement->req_scope_level, FIELD_MATCH_TYPE_EQUAL, true)) ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_dsql_agg_where_err, 0); // Cannot use an aggregate in a WHERE clause, use HAVING instead @@ -7853,8 +7853,8 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o // Process select list, if any. If not, generate one dsql_nod* selectList = input->nod_arg[e_qry_list]; // First expand select list, this will expand nodes with asterisk. - ++request->req_in_select_list; - selectList = pass1_expand_select_list(request, selectList, rse->nod_arg[e_rse_streams]); + ++statement->req_in_select_list; + selectList = pass1_expand_select_list(statement, selectList, rse->nod_arg[e_rse_streams]); if ((flags & NOD_SELECT_EXPR_VALUE) && (!selectList || selectList->nod_count > 1)) { @@ -7865,14 +7865,14 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o } // Pass select list - rse->nod_arg[e_rse_items] = pass1_sel_list(request, selectList); - --request->req_in_select_list; + rse->nod_arg[e_rse_items] = pass1_sel_list(statement, selectList); + --statement->req_in_select_list; // Process ORDER clause, if any if (order) { - ++request->req_in_order_by_clause; - rse->nod_arg[e_rse_sort] = pass1_sort(request, order, selectList); - --request->req_in_order_by_clause; + ++statement->req_in_order_by_clause; + rse->nod_arg[e_rse_sort] = pass1_sort(statement, order, selectList); + --statement->req_in_order_by_clause; } // A GROUP BY, HAVING, or any aggregate function in the select list @@ -7883,8 +7883,8 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o if (input->nod_arg[e_qry_group] || input->nod_arg[e_qry_having] || - (rse->nod_arg[e_rse_items] && aggregate_found(request, rse->nod_arg[e_rse_items])) || - (rse->nod_arg[e_rse_sort] && aggregate_found(request, rse->nod_arg[e_rse_sort]))) + (rse->nod_arg[e_rse_items] && aggregate_found(statement, rse->nod_arg[e_rse_items])) || + (rse->nod_arg[e_rse_sort] && aggregate_found(statement, rse->nod_arg[e_rse_sort]))) { // dimitr: don't allow WITH LOCK for aggregates @@ -7897,8 +7897,8 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o parent_context = FB_NEW(*tdbb->getDefaultPool()) dsql_ctx(*tdbb->getDefaultPool()); - parent_context->ctx_context = request->req_context_number++; - parent_context->ctx_scope_level = request->req_scope_level; + parent_context->ctx_context = statement->req_context_number++; + parent_context->ctx_scope_level = statement->req_scope_level; aggregate = MAKE_node(nod_aggregate, e_agg_count); aggregate->nod_arg[e_agg_context] = (dsql_nod*) parent_context; aggregate->nod_arg[e_agg_rse] = rse; @@ -7915,7 +7915,7 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o rse->nod_arg[e_rse_skip] = NULL; } - request->req_context->push(parent_context); + statement->req_context->push(parent_context); // replace original contexts with parent context remap_streams_to_parent_context(rse->nod_arg[e_rse_streams], parent_context); } @@ -7924,18 +7924,18 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o if (node = input->nod_arg[e_qry_group]) { // if there are positions in the group by clause then replace them // by the (newly pass) items from the select_list - ++request->req_in_group_by_clause; + ++statement->req_in_group_by_clause; aggregate->nod_arg[e_agg_group] = - pass1_group_by_list(request, input->nod_arg[e_qry_group], selectList); - --request->req_in_group_by_clause; + pass1_group_by_list(statement, input->nod_arg[e_qry_group], selectList); + --statement->req_in_group_by_clause; // AB: An field pointing to another parent_context isn't // allowed and GROUP BY items can't contain aggregates bool field; if (pass1_found_field(aggregate->nod_arg[e_agg_group], - request->req_scope_level, FIELD_MATCH_TYPE_LOWER, &field) || + statement->req_scope_level, FIELD_MATCH_TYPE_LOWER, &field) || pass1_found_aggregate(aggregate->nod_arg[e_agg_group], - request->req_scope_level, FIELD_MATCH_TYPE_LOWER_EQUAL, true)) + statement->req_scope_level, FIELD_MATCH_TYPE_LOWER_EQUAL, true)) { ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 104, isc_arg_gds, isc_dsql_agg_group_err, 0); @@ -7944,7 +7944,7 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o } // Parse a user-specified access PLAN - rse->nod_arg[e_rse_plan] = pass1_node_psql(request, input->nod_arg[e_qry_plan], false); + rse->nod_arg[e_rse_plan] = pass1_node_psql(statement, input->nod_arg[e_qry_plan], false); // AB: Pass select-items for distinct operation again, because for // sub-selects a new context number should be generated @@ -7955,9 +7955,9 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o isc_arg_gds, isc_random, isc_arg_string, "WITH LOCK", 0); } - ++request->req_in_select_list; - target_rse->nod_arg[e_rse_reduced] = pass1_sel_list(request, selectList); - --request->req_in_select_list; + ++statement->req_in_select_list; + target_rse->nod_arg[e_rse_reduced] = pass1_sel_list(statement, selectList); + --statement->req_in_select_list; } // Unless there was a parent, we're done @@ -7970,7 +7970,7 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o // Reset context of select items to point to the parent stream parent_rse->nod_arg[e_rse_items] = - remap_fields(request, rse->nod_arg[e_rse_items], parent_context); + remap_fields(statement, rse->nod_arg[e_rse_items], parent_context); rse->nod_arg[e_rse_items] = NULL; // AB: Check for invalid contructions inside selected-items list @@ -7996,7 +7996,7 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o if (order) { parent_rse->nod_arg[e_rse_sort] = - remap_fields(request, rse->nod_arg[e_rse_sort], parent_context); + remap_fields(statement, rse->nod_arg[e_rse_sort], parent_context); rse->nod_arg[e_rse_sort] = NULL; // AB: Check for invalid contructions inside the ORDER BY clause @@ -8021,18 +8021,18 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o if (input->nod_arg[e_qry_distinct]) { parent_rse->nod_arg[e_rse_reduced] = - remap_fields(request, parent_rse->nod_arg[e_rse_reduced], parent_context); + remap_fields(statement, parent_rse->nod_arg[e_rse_reduced], parent_context); } // Process HAVING clause, if any if ( (node = input->nod_arg[e_qry_having]) ) { - ++request->req_in_having_clause; - parent_rse->nod_arg[e_rse_boolean] = pass1_node_psql(request, node, false); - --request->req_in_having_clause; + ++statement->req_in_having_clause; + parent_rse->nod_arg[e_rse_boolean] = pass1_node_psql(statement, node, false); + --statement->req_in_having_clause; parent_rse->nod_arg[e_rse_boolean] = - remap_fields(request, parent_rse->nod_arg[e_rse_boolean], parent_context); + remap_fields(statement, parent_rse->nod_arg[e_rse_boolean], parent_context); // AB: Check for invalid contructions inside the HAVING clause list = parent_rse->nod_arg[e_rse_boolean]; @@ -8077,13 +8077,13 @@ static dsql_nod* pass1_rse_impl( dsql_req* request, dsql_nod* input, dsql_nod* o @brief Handle a reference to a searched case expression. - @param request + @param statement @param input **/ -static dsql_nod* pass1_searched_case( dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_searched_case( CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); DEV_BLKCHK(input->nod_arg[0], dsql_type_nod); @@ -8098,7 +8098,7 @@ static dsql_nod* pass1_searched_case( dsql_req* request, dsql_nod* input) for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr += 2) { - pass1_put_args_on_stack(request, *ptr, stack); + pass1_put_args_on_stack(statement, *ptr, stack); } node->nod_arg[e_searched_case_search_conditions] = MAKE_list(stack); } // end scope block @@ -8110,14 +8110,14 @@ static dsql_nod* pass1_searched_case( dsql_req* request, dsql_nod* input) dsql_nod** ptr = list->nod_arg; const dsql_nod* const* const end = ptr + list->nod_count; for (++ptr; ptr < end; ptr += 2) { - pass1_put_args_on_stack(request, *ptr, stack); + pass1_put_args_on_stack(statement, *ptr, stack); } - pass1_put_args_on_stack(request, input->nod_arg[1], stack); + pass1_put_args_on_stack(statement, input->nod_arg[1], stack); node->nod_arg[e_searched_case_results] = MAKE_list(stack); } // end scope block // Set describer for output node - MAKE_desc(request, &node->nod_desc, node, NULL); + MAKE_desc(statement, &node->nod_desc, node, NULL); // Set parameter-types if parameters are there in the result nodes dsql_nod* case_results = node->nod_arg[e_searched_case_results]; @@ -8125,7 +8125,7 @@ static dsql_nod* pass1_searched_case( dsql_req* request, dsql_nod* input) for (const dsql_nod* const* const end = ptr + case_results->nod_count; ptr < end; ptr++) { - set_parameter_type(request, *ptr, node, false); + set_parameter_type(statement, *ptr, node, false); } return node; @@ -8138,13 +8138,13 @@ static dsql_nod* pass1_searched_case( dsql_req* request, dsql_nod* input) @brief Compile a select list. - @param request + @param statement @param input **/ -static dsql_nod* pass1_sel_list( dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_sel_list( CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); DsqlNodStack stack; @@ -8153,7 +8153,7 @@ static dsql_nod* pass1_sel_list( dsql_req* request, dsql_nod* input) ptr < end; ptr++) { DEV_BLKCHK(*ptr, dsql_type_nod); - stack.push(pass1_node_psql(request, *ptr, false)); + stack.push(pass1_node_psql(statement, *ptr, false)); } dsql_nod* node = MAKE_list(stack); @@ -8168,20 +8168,20 @@ static dsql_nod* pass1_sel_list( dsql_req* request, dsql_nod* input) @brief Handle a reference to a simple case expression. - @param request + @param statement @param input **/ -static dsql_nod* pass1_simple_case( dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_simple_case( CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); DEV_BLKCHK(input->nod_arg[0], dsql_type_nod); dsql_nod* node = MAKE_node(nod_simple_case, 3); // build case_operand node - node->nod_arg[e_simple_case_case_operand] = PASS1_node(request, input->nod_arg[0]); + node->nod_arg[e_simple_case_case_operand] = PASS1_node(statement, input->nod_arg[0]); dsql_nod* list = input->nod_arg[1]; @@ -8192,7 +8192,7 @@ static dsql_nod* pass1_simple_case( dsql_req* request, dsql_nod* input) for (const dsql_nod* const* const end = ptr + list->nod_count; ptr < end; ptr += 2) { - pass1_put_args_on_stack(request, *ptr, stack); + pass1_put_args_on_stack(statement, *ptr, stack); } node->nod_arg[e_simple_case_when_operands] = MAKE_list(stack); } // end scope block @@ -8204,9 +8204,9 @@ static dsql_nod* pass1_simple_case( dsql_req* request, dsql_nod* input) dsql_nod** ptr = list->nod_arg; const dsql_nod* const* const end = ptr + list->nod_count; for (++ptr; ptr < end; ptr += 2) { - pass1_put_args_on_stack(request, *ptr, stack); + pass1_put_args_on_stack(statement, *ptr, stack); } - pass1_put_args_on_stack(request, input->nod_arg[2], stack); + pass1_put_args_on_stack(statement, input->nod_arg[2], stack); node->nod_arg[e_simple_case_results] = MAKE_list(stack); } // end scope block @@ -8243,9 +8243,9 @@ static dsql_nod* pass1_simple_case( dsql_req* request, dsql_nod* input) { node1->nod_arg[i] = *ptr; } - MAKE_desc_from_list(request, &node1->nod_desc, node1, NULL, "CASE"); + MAKE_desc_from_list(statement, &node1->nod_desc, node1, NULL, "CASE"); // Set parameter describe information - set_parameter_type(request, node->nod_arg[e_simple_case_case_operand], node1, false); + set_parameter_type(statement, node->nod_arg[e_simple_case_case_operand], node1, false); } // end scope block { // scope block @@ -8254,7 +8254,7 @@ static dsql_nod* pass1_simple_case( dsql_req* request, dsql_nod* input) for (const dsql_nod* const* const end = ptr + simple_when->nod_count; ptr < end; ptr++) { - set_parameter_type(request, *ptr, node1, false); + set_parameter_type(statement, *ptr, node1, false); } } // end scope block @@ -8263,14 +8263,14 @@ static dsql_nod* pass1_simple_case( dsql_req* request, dsql_nod* input) } // Set describer for output node - MAKE_desc(request, &node->nod_desc, node, NULL); + MAKE_desc(statement, &node->nod_desc, node, NULL); // Set parameter describe information for evt. results parameters dsql_nod* simple_res = node->nod_arg[e_simple_case_results]; dsql_nod** ptr = simple_res->nod_arg; for (const dsql_nod* const* const end = ptr + simple_res->nod_count; ptr < end; ptr++) { - set_parameter_type(request, *ptr, node, false); + set_parameter_type(statement, *ptr, node, false); } return node; @@ -8285,14 +8285,14 @@ static dsql_nod* pass1_simple_case( dsql_req* request, dsql_nod* input) an ordinal or alias which references the select list. - @param request + @param statement @param input @param selectList **/ -static dsql_nod* pass1_sort( dsql_req* request, dsql_nod* input, dsql_nod* selectList) +static dsql_nod* pass1_sort( CompiledStatement* statement, dsql_nod* input, dsql_nod* selectList) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); DEV_BLKCHK(selectList, dsql_type_nod); @@ -8341,7 +8341,7 @@ static dsql_nod* pass1_sort( dsql_req* request, dsql_nod* input, dsql_nod* selec if (node1->nod_type == nod_field_name) { // check for alias or field node - node1 = pass1_field(request, node1, false, selectList); + node1 = pass1_field(statement, node1, false, selectList); } else if (node1->nod_type == nod_constant && node1->nod_desc.dsc_dtype == dtype_long) @@ -8356,15 +8356,15 @@ static dsql_nod* pass1_sort( dsql_req* request, dsql_nod* input, dsql_nod* selec // Invalid column position used in the ORDER BY clause } // substitute ordinal with appropriate field - node1 = pass1_node_psql(request, selectList->nod_arg[position - 1], false); + node1 = pass1_node_psql(statement, selectList->nod_arg[position - 1], false); } else { - node1 = pass1_node_psql(request, node1, false); + node1 = pass1_node_psql(statement, node1, false); } if (collate) { // finally apply collation order, if necessary - node1 = pass1_collate(request, node1, collate); + node1 = pass1_collate(statement, node1, collate); } // store actual value to be ordered by @@ -8383,13 +8383,13 @@ static dsql_nod* pass1_sort( dsql_req* request, dsql_nod* input, dsql_nod* selec @brief Handle a reference to a system defined function. - @param request + @param statement @param input **/ -static dsql_nod* pass1_sys_function(dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_sys_function(CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); dsql_nod* node; @@ -8398,7 +8398,7 @@ static dsql_nod* pass1_sys_function(dsql_req* request, dsql_nod* input) if (!(input->nod_flags & NOD_SPECIAL_SYNTAX)) { const dsql_str* name = (dsql_str*) input->nod_arg[e_sysfunc_name]; - dsql_udf* userFunc = METD_get_function(request, name); + dsql_udf* userFunc = METD_get_function(statement, name); if (userFunc) { @@ -8406,13 +8406,13 @@ static dsql_nod* pass1_sys_function(dsql_req* request, dsql_nod* input) node->nod_arg[0] = (dsql_nod*) name; node->nod_arg[1] = input->nod_arg[e_sysfunc_args]; - return pass1_udf(request, node); + return pass1_udf(statement, node); } } node = MAKE_node(input->nod_type, e_sysfunc_count); node->nod_arg[e_sysfunc_name] = input->nod_arg[e_sysfunc_name]; - node->nod_arg[e_sysfunc_args] = PASS1_node(request, input->nod_arg[e_sysfunc_args]); + node->nod_arg[e_sysfunc_args] = PASS1_node(statement, input->nod_arg[e_sysfunc_args]); if (node->nod_arg[e_sysfunc_args]) { @@ -8428,17 +8428,17 @@ static dsql_nod* pass1_sys_function(dsql_req* request, dsql_nod* input) for (unsigned int i = 0; i < in_args->nod_count; ++i) { dsql_nod* p = in_args->nod_arg[i]; - MAKE_desc(request, &p->nod_desc, p, p); + MAKE_desc(statement, &p->nod_desc, p, p); args.add(&p->nod_desc); } - DSqlDataTypeUtil dataTypeUtil(request); + DSqlDataTypeUtil dataTypeUtil(statement); sf->setParamsFunc(&dataTypeUtil, sf, args.getCount(), args.begin()); for (unsigned int j = 0; j < in_args->nod_count; ++j) { dsql_nod* p = in_args->nod_arg[j]; - set_parameter_type(request, p, p, false); + set_parameter_type(statement, p, p, false); } } } @@ -8454,18 +8454,18 @@ static dsql_nod* pass1_sys_function(dsql_req* request, dsql_nod* input) @brief Handle a reference to a user defined function. - @param request + @param statement @param input **/ -static dsql_nod* pass1_udf( dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_udf( CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); const dsql_str* name = (dsql_str*) input->nod_arg[0]; DEV_BLKCHK(name, dsql_type_str); - dsql_udf* userFunc = METD_get_function(request, name); + dsql_udf* userFunc = METD_get_function(statement, name); if (!userFunc) ERRD_post(isc_sqlerr, isc_arg_number, (SLONG) - 804, isc_arg_gds, isc_dsql_function_err, @@ -8477,7 +8477,7 @@ static dsql_nod* pass1_udf( dsql_req* request, dsql_nod* input) if (input->nod_count == 2) { DsqlNodStack stack; USHORT arg_pos = 0; - pass1_udf_args(request, input->nod_arg[1], userFunc, arg_pos, stack); + pass1_udf_args(statement, input->nod_arg[1], userFunc, arg_pos, stack); node->nod_arg[1] = MAKE_list(stack); } @@ -8492,17 +8492,17 @@ static dsql_nod* pass1_udf( dsql_req* request, dsql_nod* input) @brief Handle references to function arguments. - @param request + @param statement @param input @param udf @param arg_pos @param stack **/ -static void pass1_udf_args(dsql_req* request, dsql_nod* input, +static void pass1_udf_args(CompiledStatement* statement, dsql_nod* input, dsql_udf* userFunc, USHORT& arg_pos, DsqlNodStack& stack) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(userFunc, dsql_type_udf); if (!input) @@ -8511,11 +8511,11 @@ static void pass1_udf_args(dsql_req* request, dsql_nod* input, DEV_BLKCHK(input, dsql_type_nod); if (input->nod_type != nod_list) { - dsql_nod* temp = PASS1_node(request, input); + dsql_nod* temp = PASS1_node(statement, input); if (arg_pos < userFunc->udf_arguments.getCount()) { dsql_nod temp2; temp2.nod_desc = userFunc->udf_arguments[arg_pos]; - set_parameter_type(request, temp, &temp2, false); + set_parameter_type(statement, temp, &temp2, false); } else { // We should complain here in the future! The parameter is @@ -8530,7 +8530,7 @@ static void pass1_udf_args(dsql_req* request, dsql_nod* input, for (const dsql_nod* const* const end = ptr + input->nod_count; ptr < end; ptr++) { - pass1_udf_args(request, *ptr, userFunc, arg_pos, stack); + pass1_udf_args(statement, *ptr, userFunc, arg_pos, stack); } } @@ -8545,16 +8545,16 @@ static void pass1_udf_args(dsql_req* request, dsql_nod* input, the records returned are unique. - @param request + @param statement @param input @param order_list @param rows **/ -static dsql_nod* pass1_union( dsql_req* request, dsql_nod* input, +static dsql_nod* pass1_union( CompiledStatement* statement, dsql_nod* input, dsql_nod* order_list, dsql_nod* rows, USHORT flags) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); DEV_BLKCHK(order_list, dsql_type_nod); @@ -8571,32 +8571,32 @@ static dsql_nod* pass1_union( dsql_req* request, dsql_nod* input, dsql_ctx(*tdbb->getDefaultPool()); if (input->nod_flags & NOD_UNION_RECURSIVE) { - union_context->ctx_context = request->req_recursive_ctx_id; + union_context->ctx_context = statement->req_recursive_ctx_id; } else { - union_context->ctx_context = request->req_context_number++; + union_context->ctx_context = statement->req_context_number++; } // process all the sub-rse's. { // scope block dsql_nod** uptr = union_node->nod_arg; - const DsqlContextStack::const_iterator base(*request->req_context); + const DsqlContextStack::const_iterator base(*statement->req_context); dsql_nod** ptr = input->nod_arg; for (const dsql_nod* const* const end = ptr + input->nod_count; ptr < end; ++ptr, ++uptr) { - request->req_scope_level++; - *uptr = pass1_rse(request, *ptr, NULL, NULL, NULL, 0); - request->req_scope_level--; - while (*(request->req_context) != base) + statement->req_scope_level++; + *uptr = pass1_rse(statement, *ptr, NULL, NULL, NULL, 0); + statement->req_scope_level--; + while (*(statement->req_context) != base) { - request->req_union_context.push(request->req_context->pop()); + statement->req_union_context.push(statement->req_context->pop()); } // Push recursive context after initial select has been processed. // Corresponding pop occurs in pass1_derived_table if ((input->nod_flags & NOD_UNION_RECURSIVE) && (ptr == input->nod_arg)) - request->req_context->push(request->req_recursive_ctx); + statement->req_context->push(statement->req_recursive_ctx); } } // end scope block @@ -8637,7 +8637,7 @@ static dsql_nod* pass1_union( dsql_req* request, dsql_nod* input, int i; // please the MS compiler for (i = 0; i < union_node->nod_count; i++) { dsql_nod* nod1 = union_node->nod_arg[i]->nod_arg[e_rse_items]; - MAKE_desc(request, &nod1->nod_arg[j]->nod_desc, nod1->nod_arg[j], NULL); + MAKE_desc(statement, &nod1->nod_arg[j]->nod_desc, nod1->nod_arg[j], NULL); tmp_list->nod_arg[i] = nod1->nod_arg[j]; // We look only at the items->nod_arg[] when creating the @@ -8652,7 +8652,7 @@ static dsql_nod* pass1_union( dsql_req* request, dsql_nod* input, } } dsc desc; - MAKE_desc_from_list(request, &desc, tmp_list, NULL, "UNION"); + MAKE_desc_from_list(statement, &desc, tmp_list, NULL, "UNION"); // Only mark upper node as a NULL node when all sub-nodes are NULL items->nod_arg[j]->nod_desc.dsc_flags &= ~DSC_null; items->nod_arg[j]->nod_desc.dsc_flags |= (desc.dsc_flags & DSC_null); @@ -8726,7 +8726,7 @@ static dsql_nod* pass1_union( dsql_req* request, dsql_nod* input, order2->nod_arg[e_order_flag] = order1->nod_arg[e_order_flag]; if (collate) { order2->nod_arg[e_order_field] = - pass1_collate(request, order2->nod_arg[e_order_field], collate); + pass1_collate(statement, order2->nod_arg[e_order_field], collate); } order2->nod_arg[e_order_nulls] = order1->nod_arg[e_order_nulls]; } @@ -8735,14 +8735,14 @@ static dsql_nod* pass1_union( dsql_req* request, dsql_nod* input, if (rows) { if (rows->nod_arg[e_rows_length]) { - dsql_nod* sub = pass1_node_psql(request, rows->nod_arg[e_rows_length], false); + dsql_nod* sub = pass1_node_psql(statement, rows->nod_arg[e_rows_length], false); union_rse->nod_arg[e_rse_first] = sub; - set_parameter_type(request, sub, rows, false); + set_parameter_type(statement, sub, rows, false); } if (rows->nod_arg[e_rows_skip]) { - dsql_nod* sub = pass1_node_psql(request, rows->nod_arg[e_rows_skip], false); + dsql_nod* sub = pass1_node_psql(statement, rows->nod_arg[e_rows_skip], false); union_rse->nod_arg[e_rse_skip] = sub; - set_parameter_type(request, sub, rows, false); + set_parameter_type(statement, sub, rows, false); } } @@ -8951,13 +8951,13 @@ static void pass1_union_auto_cast(dsql_nod* input, const dsc& desc, @brief Process UPDATE statement. - @param request + @param statement @param input **/ -static dsql_nod* pass1_update(dsql_req* request, dsql_nod* input, bool insert_or_update) +static dsql_nod* pass1_update(CompiledStatement* statement, dsql_nod* input, bool insert_or_update) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); // NOTE!!! Macro SQL_COMPLIANT_UPDATE shows what code should be @@ -8985,40 +8985,40 @@ static dsql_nod* pass1_update(dsql_req* request, dsql_nod* input, bool insert_or dsql_nod* cursor = input->nod_arg[e_upd_cursor]; dsql_nod* relation = input->nod_arg[e_upd_relation]; - if (cursor && request->isPsql()) { + if (cursor && statement->isPsql()) { dsql_nod* anode = MAKE_node(nod_modify_current, e_mdc_count); - dsql_ctx* context = pass1_cursor_context(request, cursor, relation); + dsql_ctx* context = pass1_cursor_context(statement, cursor, relation); anode->nod_arg[e_mdc_context] = (dsql_nod*) context; #ifdef SQL_COMPLIANT_UPDATE // Process old context values - request->req_context->push(context); - request->req_scope_level++; + statement->req_context->push(context); + statement->req_scope_level++; for (ptr = org_values.begin(); ptr < org_values.end(); ++ptr) { - *ptr = PASS1_node(request, *ptr, false); + *ptr = PASS1_node(statement, *ptr, false); } - request->req_scope_level--; - request->req_context->pop(); + statement->req_scope_level--; + statement->req_context->pop(); #endif // Process relation - anode->nod_arg[e_mdc_update] = pass1_node_psql(request, relation, false); + anode->nod_arg[e_mdc_update] = pass1_node_psql(statement, relation, false); #ifndef SQL_COMPLIANT_UPDATE // Process old context values for (ptr = org_values.begin(); ptr < org_values.end(); ++ptr) { - *ptr = pass1_node_psql(request, *ptr, false); + *ptr = pass1_node_psql(statement, *ptr, false); } #endif // Process new context values for (ptr = new_values.begin(); ptr < new_values.end(); ++ptr) { - *ptr = pass1_node_psql(request, *ptr, false); + *ptr = pass1_node_psql(statement, *ptr, false); } anode->nod_arg[e_mdc_return] = - process_returning(request, input->nod_arg[e_upd_return]); + process_returning(statement, input->nod_arg[e_upd_return]); - request->req_context->pop(); + statement->req_context->pop(); // Recreate list of assignments anode->nod_arg[e_mdc_statement] = list = MAKE_node(nod_list, list->nod_count); @@ -9036,32 +9036,32 @@ static dsql_nod* pass1_update(dsql_req* request, dsql_nod* input, bool insert_or return anode; } - request->req_type = (cursor) ? REQ_UPDATE_CURSOR : REQ_UPDATE; + statement->req_type = (cursor) ? REQ_UPDATE_CURSOR : REQ_UPDATE; dsql_nod* node = MAKE_node(nod_modify, e_mod_count); - node->nod_arg[e_mod_update] = pass1_node_psql(request, relation, false); + node->nod_arg[e_mod_update] = pass1_node_psql(statement, relation, false); dsql_ctx* mod_context = get_context(node->nod_arg[e_mod_update]); #ifndef SQL_COMPLIANT_UPDATE // Process old context values for (ptr = org_values.begin(); ptr < org_values.end(); ++ptr) { - *ptr = pass1_node_psql(request, *ptr, false); + *ptr = pass1_node_psql(statement, *ptr, false); } #endif // Process new context values for (ptr = new_values.begin(); ptr < new_values.end(); ++ptr) { - *ptr = pass1_node_psql(request, *ptr, false); + *ptr = pass1_node_psql(statement, *ptr, false); } - request->req_context->pop(); + statement->req_context->pop(); // Generate record selection expression dsql_nod* rse; if (cursor) { - rse = pass1_cursor_reference(request, cursor, relation); + rse = pass1_cursor_reference(statement, cursor, relation); } else { rse = MAKE_node(nod_rse, e_rse_count); @@ -9071,24 +9071,24 @@ static dsql_nod* pass1_update(dsql_req* request, dsql_nod* input, bool insert_or dsql_nod* temp = MAKE_node(nod_list, 1); rse->nod_arg[e_rse_streams] = temp; - temp->nod_arg[0] = pass1_node_psql(request, relation, false); + temp->nod_arg[0] = pass1_node_psql(statement, relation, false); dsql_ctx* old_context = get_context(temp->nod_arg[0]); if ( (temp = input->nod_arg[e_upd_boolean]) ) { - rse->nod_arg[e_rse_boolean] = pass1_node_psql(request, temp, false); + rse->nod_arg[e_rse_boolean] = pass1_node_psql(statement, temp, false); } if ( (temp = input->nod_arg[e_upd_plan]) ) { - rse->nod_arg[e_rse_plan] = pass1_node_psql(request, temp, false); + rse->nod_arg[e_rse_plan] = pass1_node_psql(statement, temp, false); } if ( (temp = input->nod_arg[e_upd_sort]) ) { - rse->nod_arg[e_rse_sort] = pass1_sort(request, temp, NULL); + rse->nod_arg[e_rse_sort] = pass1_sort(statement, temp, NULL); } if ( (temp = input->nod_arg[e_upd_rows]) ) { - rse->nod_arg[e_rse_first] = pass1_node_psql(request, temp->nod_arg[e_rows_length], false); - rse->nod_arg[e_rse_skip] = pass1_node_psql(request, temp->nod_arg[e_rows_skip], false); + rse->nod_arg[e_rse_first] = pass1_node_psql(statement, temp->nod_arg[e_rows_length], false); + rse->nod_arg[e_rse_skip] = pass1_node_psql(statement, temp->nod_arg[e_rows_skip], false); } if (input->nod_arg[e_upd_return]) @@ -9104,28 +9104,28 @@ static dsql_nod* pass1_update(dsql_req* request, dsql_nod* input, bool insert_or old_context->ctx_flags |= CTX_system | CTX_returning; // push the modify context in the same scope level - request->req_context->push(mod_context); + statement->req_context->push(mod_context); // clone the modify context and push with name "NEW" in a greater scope level - dsql_ctx* new_context = FB_NEW(request->req_pool) - dsql_ctx(request->req_pool); + dsql_ctx* new_context = FB_NEW(statement->req_pool) + dsql_ctx(statement->req_pool); *new_context = *mod_context; - new_context->ctx_scope_level = ++request->req_scope_level; + new_context->ctx_scope_level = ++statement->req_scope_level; new_context->ctx_alias = new_context->ctx_internal_alias = MAKE_cstring(NEW_CONTEXT)->str_data; new_context->ctx_flags |= CTX_system | CTX_returning; - request->req_context->push(new_context); + statement->req_context->push(new_context); // Process the RETURNING with the stack (NEW, (modify, OLD)), // so unqualified or qualified by NEW or the table name fields be // resolved to the changed record. node->nod_arg[e_mod_return] = - process_returning(request, input->nod_arg[e_upd_return]); + process_returning(statement, input->nod_arg[e_upd_return]); // restore the stack with only the RSE context - --request->req_scope_level; - request->req_context->pop(); - request->req_context->pop(); + --statement->req_scope_level; + statement->req_context->pop(); + statement->req_context->pop(); old_context->ctx_flags = save_flags; old_context->ctx_internal_alias = save_internal_alias; @@ -9140,10 +9140,10 @@ static dsql_nod* pass1_update(dsql_req* request, dsql_nod* input, bool insert_or // Process old context values for (ptr = org_values.begin(); ptr < org_values.end(); ++ptr) { - *ptr = PASS1_node(request, *ptr, false); + *ptr = PASS1_node(statement, *ptr, false); } #endif - request->req_context->pop(); + statement->req_context->pop(); // Recreate list of assignments node->nod_arg[e_mod_statement] = list = @@ -9152,9 +9152,9 @@ static dsql_nod* pass1_update(dsql_req* request, dsql_nod* input, bool insert_or { dsql_nod* const sub1 = org_values[j]; dsql_nod* const sub2 = new_values[j]; - if (!set_parameter_type(request, sub1, sub2, false)) + if (!set_parameter_type(statement, sub1, sub2, false)) { - set_parameter_type(request, sub2, sub1, false); + set_parameter_type(statement, sub2, sub1, false); } dsql_nod* assign = MAKE_node(nod_assign, e_asgn_count); assign->nod_arg[e_asgn_value] = sub1; @@ -9171,7 +9171,7 @@ static dsql_nod* pass1_update(dsql_req* request, dsql_nod* input, bool insert_or node->nod_arg[e_mod_update]); if (!insert_or_update) - node = nullify_returning(request, node); + node = nullify_returning(statement, node); return node; } @@ -9184,17 +9184,17 @@ static dsql_nod* pass1_update(dsql_req* request, dsql_nod* input, bool insert_or @brief Process UPDATE OR INSERT statement. - @param request + @param statement @param input **/ -static dsql_nod* pass1_update_or_insert(dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_update_or_insert(CompiledStatement* statement, dsql_nod* input) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); - if (!request->isPsql()) - request->req_flags |= REQ_dsql_upd_or_ins; + if (!statement->isPsql()) + statement->req_flags |= REQ_dsql_upd_or_ins; dsql_str* relation_name = (dsql_str*) input->nod_arg[e_upi_relation]->nod_arg[e_rpn_name]; @@ -9208,7 +9208,7 @@ static dsql_nod* pass1_update_or_insert(dsql_req* request, dsql_nod* input) insert->nod_arg[e_ins_fields] = input->nod_arg[e_upi_fields]; insert->nod_arg[e_ins_values] = values; insert->nod_arg[e_ins_return] = input->nod_arg[e_upi_return]; - insert = pass1_insert(request, insert, true); + insert = pass1_insert(statement, insert, true); // PASS1_statement will transform nod_insert to nod_store fb_assert(insert->nod_type == nod_store); @@ -9230,7 +9230,7 @@ static dsql_nod* pass1_update_or_insert(dsql_req* request, dsql_nod* input) if ((relation->rel_flags & REL_view) && !input->nod_arg[e_upi_matching]) { dsql_rel* base_rel = - METD_get_view_base(request, relation_name->str_data, view_fields); + METD_get_view_base(statement, relation_name->str_data, view_fields); // get the base table name if there is only one if (base_rel) @@ -9246,13 +9246,13 @@ static dsql_nod* pass1_update_or_insert(dsql_req* request, dsql_nod* input) { equality_type = nod_equiv; - request->req_context->push(context); - request->req_scope_level++; + statement->req_context->push(context); + statement->req_scope_level++; - dsql_nod* matching_fields = pass1_node_psql(request, matching, false); + dsql_nod* matching_fields = pass1_node_psql(statement, matching, false); - request->req_scope_level--; - request->req_context->pop(); + statement->req_scope_level--; + statement->req_context->pop(); field_appears_once(matching_fields, matching, true, "UPDATE OR INSERT"); } @@ -9260,7 +9260,7 @@ static dsql_nod* pass1_update_or_insert(dsql_req* request, dsql_nod* input) { equality_type = nod_eql; - matching = METD_get_primary_key(request, base_name); + matching = METD_get_primary_key(statement, base_name); if (!matching) { @@ -9291,7 +9291,7 @@ static dsql_nod* pass1_update_or_insert(dsql_req* request, dsql_nod* input) temp = *value_ptr; dsql_nod* temp2 = insert->nod_arg[e_sto_statement]->nod_arg[field_ptr - fields->nod_arg]->nod_arg[1]; - set_parameter_type(request, temp, temp2, false); + set_parameter_type(statement, temp, temp2, false); fb_assert((*field_ptr)->nod_type == nod_field_name); @@ -9392,7 +9392,7 @@ static dsql_nod* pass1_update_or_insert(dsql_req* request, dsql_nod* input) } } - update = pass1_update(request, update, true); + update = pass1_update(statement, update, true); // PASS1_statement will transform nod_update to nod_modify fb_assert(update->nod_type == nod_modify); @@ -9403,10 +9403,10 @@ static dsql_nod* pass1_update_or_insert(dsql_req* request, dsql_nod* input) eql->nod_arg[0]->nod_arg[e_internal_info] = MAKE_const_slong(internal_rows_affected); eql->nod_arg[1] = MAKE_const_slong(0); - ULONG req_flags = request->req_flags; - request->req_flags |= REQ_block; // to compile ROW_COUNT - eql = PASS1_node(request, eql); - request->req_flags = req_flags; + ULONG req_flags = statement->req_flags; + statement->req_flags |= REQ_block; // to compile ROW_COUNT + eql = PASS1_node(statement, eql); + statement->req_flags = req_flags; // if (ROW_COUNT = 0) then INSERT dsql_nod* if_nod = MAKE_node(nod_if, e_if_count); @@ -9420,7 +9420,7 @@ static dsql_nod* pass1_update_or_insert(dsql_req* request, dsql_nod* input) // if RETURNING is present, req_type is already REQ_EXEC_PROCEDURE if (!input->nod_arg[e_upi_return]) - request->req_type = REQ_INSERT; + statement->req_type = REQ_INSERT; return list; } @@ -9461,26 +9461,26 @@ static dsql_nod* resolve_variable_name(const dsql_nod* var_nodes, const dsql_str @brief Resolve a variable name to an available variable. - @param request + @param statement @param input **/ -static dsql_nod* pass1_variable( dsql_req* request, dsql_nod* input) +static dsql_nod* pass1_variable( CompiledStatement* statement, dsql_nod* input) { // CVC: I commented this variable and its usage because it wasn't useful for // anything. I didn't delete it in case it's an implementation in progress // by someone. //SSHORT position; - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(input, dsql_type_nod); const dsql_str* var_name = 0; if (input->nod_type == nod_field_name) { if (input->nod_arg[e_fln_context]) { - if (request->req_flags & REQ_trigger) // triggers only - return pass1_field(request, input, false, NULL); + if (statement->req_flags & REQ_trigger) // triggers only + return pass1_field(statement, input, false, NULL); field_unknown(0, 0, input); } @@ -9492,11 +9492,11 @@ static dsql_nod* pass1_variable( dsql_req* request, dsql_nod* input) DEV_BLKCHK(var_name, dsql_type_str); dsql_nod* var_nodes; - if (request->req_flags & REQ_procedure) // procedures and triggers + if (statement->req_flags & REQ_procedure) // procedures and triggers { - dsql_nod* procedure_node = request->req_ddl_node; + dsql_nod* procedure_node = statement->req_ddl_node; fb_assert(procedure_node); - if (!(request->req_flags & REQ_trigger)) // no, procedures only + if (!(statement->req_flags & REQ_trigger)) // no, procedures only { // try to resolve variable name against input and output parameters var_nodes = procedure_node->nod_arg[e_prc_inputs]; @@ -9566,23 +9566,23 @@ static dsql_nod* pass1_variable( dsql_req* request, dsql_nod* input) } } - if (request->req_blk_node) + if (statement->req_blk_node) { dsql_nod* var_node; - if (var_nodes = request->req_blk_node->nod_arg[e_exe_blk_dcls]) + if (var_nodes = statement->req_blk_node->nod_arg[e_exe_blk_dcls]) { if (var_node = resolve_variable_name(var_nodes, var_name)) return var_node; } - if (var_nodes = request->req_blk_node->nod_arg[e_exe_blk_inputs]) + if (var_nodes = statement->req_blk_node->nod_arg[e_exe_blk_inputs]) { if (var_node = resolve_variable_name(var_nodes, var_name)) return var_node; } - if (var_nodes = request->req_blk_node->nod_arg[e_exe_blk_outputs]) + if (var_nodes = statement->req_blk_node->nod_arg[e_exe_blk_outputs]) { if (var_node = resolve_variable_name(var_nodes, var_name)) return var_node; @@ -9659,16 +9659,16 @@ static dsql_nod* post_map( dsql_nod* node, dsql_ctx* context) to the given context with the post_map function. - @param request + @param statement @param field @param context @param current_level **/ -static dsql_nod* remap_field(dsql_req* request, dsql_nod* field, +static dsql_nod* remap_field(CompiledStatement* statement, dsql_nod* field, dsql_ctx* context, USHORT current_level) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(field, dsql_type_nod); DEV_BLKCHK(context, dsql_type_ctx); @@ -9679,7 +9679,7 @@ static dsql_nod* remap_field(dsql_req* request, dsql_nod* field, case nod_alias: field->nod_arg[e_alias_value] = - remap_field(request, field->nod_arg[e_alias_value], context, current_level); + remap_field(statement, field->nod_arg[e_alias_value], context, current_level); return field; case nod_derived_field: @@ -9694,7 +9694,7 @@ static dsql_nod* remap_field(dsql_req* request, dsql_nod* field, } else if (context->ctx_scope_level < lscope_level) { field->nod_arg[e_derived_field_value] = - remap_field(request, field->nod_arg[e_derived_field_value], + remap_field(statement, field->nod_arg[e_derived_field_value], context, current_level); } return field; @@ -9717,7 +9717,7 @@ static dsql_nod* remap_field(dsql_req* request, dsql_nod* field, reinterpret_cast(field->nod_arg[e_map_context]); if (lcontext->ctx_scope_level != context->ctx_scope_level) { dsql_map* lmap = reinterpret_cast(field->nod_arg[e_map_map]); - lmap->map_node = remap_field(request, lmap->map_node, context, + lmap->map_node = remap_field(statement, lmap->map_node, context, lcontext->ctx_scope_level); } return field; @@ -9732,16 +9732,16 @@ static dsql_nod* remap_field(dsql_req* request, dsql_nod* field, case nod_agg_total2: case nod_agg_list: { - USHORT ldeepest_level = request->req_scope_level; + USHORT ldeepest_level = statement->req_scope_level; USHORT lcurrent_level = current_level; - if (aggregate_found2(request, field, &lcurrent_level, &ldeepest_level, false)) { - if (request->req_scope_level == ldeepest_level) { + if (aggregate_found2(statement, field, &lcurrent_level, &ldeepest_level, false)) { + if (statement->req_scope_level == ldeepest_level) { return post_map(field, context); } else { if (field->nod_count) { field->nod_arg[e_agg_function_expression] = - remap_field(request, field->nod_arg[e_agg_function_expression], + remap_field(statement, field->nod_arg[e_agg_function_expression], context, current_level); } return field; @@ -9750,7 +9750,7 @@ static dsql_nod* remap_field(dsql_req* request, dsql_nod* field, else { if (field->nod_count) { field->nod_arg[e_agg_function_expression] = - remap_field(request, field->nod_arg[e_agg_function_expression], + remap_field(statement, field->nod_arg[e_agg_function_expression], context, current_level); } return field; @@ -9759,18 +9759,18 @@ static dsql_nod* remap_field(dsql_req* request, dsql_nod* field, case nod_via: field->nod_arg[e_via_rse] = - remap_field(request, field->nod_arg[e_via_rse], context, current_level); + remap_field(statement, field->nod_arg[e_via_rse], context, current_level); field->nod_arg[e_via_value_1] = field->nod_arg[e_via_rse]->nod_arg[e_rse_items]->nod_arg[0]; return field; case nod_rse: current_level++; field->nod_arg[e_rse_streams] = - remap_field(request, field->nod_arg[e_rse_streams], context, current_level); + remap_field(statement, field->nod_arg[e_rse_streams], context, current_level); field->nod_arg[e_rse_boolean] = - remap_field(request, field->nod_arg[e_rse_boolean], context, current_level); + remap_field(statement, field->nod_arg[e_rse_boolean], context, current_level); field->nod_arg[e_rse_items] = - remap_field(request, field->nod_arg[e_rse_items], context, current_level); + remap_field(statement, field->nod_arg[e_rse_items], context, current_level); current_level--; return field; @@ -9782,19 +9782,19 @@ static dsql_nod* remap_field(dsql_req* request, dsql_nod* field, for (const dsql_nod* const* const end = ptr + field->nod_count; ptr < end; ptr++) { - *ptr = remap_field(request, *ptr, context, current_level); + *ptr = remap_field(statement, *ptr, context, current_level); } return field; } case nod_aggregate: field->nod_arg[e_agg_rse] = - remap_field(request, field->nod_arg[e_agg_rse], context, current_level); + remap_field(statement, field->nod_arg[e_agg_rse], context, current_level); return field; case nod_order: field->nod_arg[e_order_field] = - remap_field(request, field->nod_arg[e_order_field], context, current_level); + remap_field(statement, field->nod_arg[e_order_field], context, current_level); return field; case nod_or: @@ -9858,7 +9858,7 @@ static dsql_nod* remap_field(dsql_req* request, dsql_nod* field, for (const dsql_nod* const* const end = ptr + field->nod_count; ptr < end; ptr++) { - *ptr = remap_field(request, *ptr, context, current_level); + *ptr = remap_field(statement, *ptr, context, current_level); } return field; } @@ -9869,7 +9869,7 @@ static dsql_nod* remap_field(dsql_req* request, dsql_nod* field, case nod_udf: case nod_sys_function: if (field->nod_count == 2) { - field->nod_arg[1] = remap_field(request, field->nod_arg[1], + field->nod_arg[1] = remap_field(statement, field->nod_arg[1], context, current_level); } return field; @@ -9882,13 +9882,13 @@ static dsql_nod* remap_field(dsql_req* request, dsql_nod* field, if (lrelation_context->ctx_procedure) { // Remap the input parameters lrelation_context->ctx_proc_inputs = - remap_field(request, lrelation_context->ctx_proc_inputs, context, current_level); + remap_field(statement, lrelation_context->ctx_proc_inputs, context, current_level); } return field; } case nod_derived_table: - remap_field(request, field->nod_arg[e_derived_table_rse], context, current_level); + remap_field(statement, field->nod_arg[e_derived_table_rse], context, current_level); return field; default: @@ -9905,25 +9905,25 @@ static dsql_nod* remap_field(dsql_req* request, dsql_nod* field, an artificial context. - @param request + @param statement @param fields @param context **/ -static dsql_nod* remap_fields(dsql_req* request, dsql_nod* fields, dsql_ctx* context) +static dsql_nod* remap_fields(CompiledStatement* statement, dsql_nod* fields, dsql_ctx* context) { - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(fields, dsql_type_nod); DEV_BLKCHK(context, dsql_type_ctx); if (fields->nod_type == nod_list) { for (int i = 0; i < fields->nod_count; i++) { - fields->nod_arg[i] = remap_field(request, fields->nod_arg[i], context, - request->req_scope_level); + fields->nod_arg[i] = remap_field(statement, fields->nod_arg[i], context, + statement->req_scope_level); } } else { - fields = remap_field(request, fields, context, request->req_scope_level); + fields = remap_field(statement, fields, context, statement->req_scope_level); } return fields; @@ -9995,24 +9995,24 @@ static void remap_streams_to_parent_context( dsql_nod* input, dsql_ctx* parent_c NULL if not. - @param request + @param statement @param name @param qualifier @param context **/ -static dsql_fld* resolve_context( dsql_req* request, const dsql_str* qualifier, +static dsql_fld* resolve_context( CompiledStatement* statement, const dsql_str* qualifier, dsql_ctx* context, bool isCheckConstraint, bool resolveByAlias) { // CVC: Warning: the second param, "name" was is not used anymore and // therefore it was removed. Thus, the local variable "table_name" // is being stripped here to avoid mismatches due to trailing blanks. - DEV_BLKCHK(request, dsql_type_req); + DEV_BLKCHK(statement, dsql_type_req); DEV_BLKCHK(qualifier, dsql_type_str); DEV_BLKCHK(context, dsql_type_ctx); - if ((request->req_flags & REQ_returning_into) && (context->ctx_flags & CTX_returning)) + if ((statement->req_flags & REQ_returning_into) && (context->ctx_flags & CTX_returning)) return NULL; dsql_rel* relation = context->ctx_relation; @@ -10024,7 +10024,7 @@ static dsql_fld* resolve_context( dsql_req* request, const dsql_str* qualifier, // if there is no qualifier, then we cannot match against // a context of a different scoping level // AB: Yes we can, but the scope level where the field is has priority. -// if (!qualifier && context->ctx_scope_level != request->req_scope_level) { +// if (!qualifier && context->ctx_scope_level != statement->req_scope_level) { // return NULL; // } @@ -10090,11 +10090,11 @@ static dsql_fld* resolve_context( dsql_req* request, const dsql_str* qualifier, // Resolve a field for JOIN USING purposes -static dsql_nod* resolve_using_field(dsql_req* request, dsql_str* name, DsqlNodStack& stack, +static dsql_nod* resolve_using_field(CompiledStatement* statement, dsql_str* name, DsqlNodStack& stack, const dsql_nod* flawedNode, const TEXT* side, dsql_ctx*& ctx) { dsql_nod* list = MAKE_list(stack); - dsql_nod* node = pass1_lookup_alias(request, name, list, false); + dsql_nod* node = pass1_lookup_alias(statement, name, list, false); if (!node) { @@ -10135,7 +10135,7 @@ static dsql_nod* resolve_using_field(dsql_req* request, dsql_str* name, DsqlNodS @param force_varchar **/ -static bool set_parameter_type(dsql_req* request, dsql_nod* in_node, dsql_nod* node, bool force_varchar) +static bool set_parameter_type(CompiledStatement* statement, dsql_nod* in_node, dsql_nod* node, bool force_varchar) { thread_db* tdbb = JRD_get_thread_data(); Attachment* att = tdbb->getAttachment(); @@ -10154,7 +10154,7 @@ static bool set_parameter_type(dsql_req* request, dsql_nod* in_node, dsql_nod* n return false; } - MAKE_desc(request, &in_node->nod_desc, node, NULL); + MAKE_desc(statement, &in_node->nod_desc, node, NULL); if (att->att_charset != CS_NONE && att->att_charset != CS_BINARY) { @@ -10178,8 +10178,8 @@ static bool set_parameter_type(dsql_req* request, dsql_nod* in_node, dsql_nod* n if (toCharSet != fromCharSet) { - USHORT fromCharSetBPC = METD_get_charset_bpc(request, fromCharSet); - USHORT toCharSetBPC = METD_get_charset_bpc(request, toCharSet); + USHORT fromCharSetBPC = METD_get_charset_bpc(statement, fromCharSet); + USHORT toCharSetBPC = METD_get_charset_bpc(statement, toCharSet); INTL_ASSIGN_TTYPE(&in_node->nod_desc, INTL_CS_COLL_TO_TTYPE(toCharSet, (fromCharSet == toCharSet ? INTL_GET_COLLATE(&in_node->nod_desc) : 0))); @@ -10203,7 +10203,7 @@ static bool set_parameter_type(dsql_req* request, dsql_nod* in_node, dsql_nod* n if (!parameter) { in_node->nod_arg[e_par_parameter] = (dsql_nod*) - (parameter = MAKE_parameter(request->req_send, + (parameter = MAKE_parameter(statement->req_send, true, true, (USHORT)(IPTR) in_node->nod_arg[e_par_index], NULL)); @@ -10293,7 +10293,7 @@ static bool set_parameter_type(dsql_req* request, dsql_nod* in_node, dsql_nod* n for (const dsql_nod* const* const end = ptr + in_node->nod_count; ptr < end; ptr++) { - result |= set_parameter_type(request, *ptr, node, force_varchar); + result |= set_parameter_type(statement, *ptr, node, force_varchar); } return result; } @@ -10426,16 +10426,16 @@ static void set_parameter_name( dsql_nod* par_node, const dsql_nod* fld_node, pass1_savepoint @brief Add savepoint pair of nodes - to request having error handlers. + to statement having error handlers. - @param request + @param statement @param node **/ -static dsql_nod* pass1_savepoint(const dsql_req* request, dsql_nod* node) +static dsql_nod* pass1_savepoint(const CompiledStatement* statement, dsql_nod* node) { - if (request->req_error_handlers) { + if (statement->req_error_handlers) { dsql_nod* temp = MAKE_node(nod_list, 3); temp->nod_arg[0] = MAKE_node(nod_start_savepoint, 0); temp->nod_arg[1] = node; @@ -10447,7 +10447,7 @@ static dsql_nod* pass1_savepoint(const dsql_req* request, dsql_nod* node) } -void dsql_req::addCTEs(dsql_nod* with) +void CompiledStatement::addCTEs(dsql_nod* with) { DEV_BLKCHK(with, dsql_type_nod); fb_assert(with->nod_type == nod_with); @@ -10480,7 +10480,7 @@ void dsql_req::addCTEs(dsql_nod* with) } -dsql_nod* dsql_req::findCTE(const dsql_str* name) +dsql_nod* CompiledStatement::findCTE(const dsql_str* name) { for (size_t i = 0; i < req_ctes.getCount(); i++) { @@ -10498,7 +10498,7 @@ dsql_nod* dsql_req::findCTE(const dsql_str* name) } -void dsql_req::clearCTEs() +void CompiledStatement::clearCTEs() { req_flags &= ~REQ_CTE_recursive; req_ctes.clear(); @@ -10506,7 +10506,7 @@ void dsql_req::clearCTEs() } -void dsql_req::checkUnusedCTEs() const +void CompiledStatement::checkUnusedCTEs() const { for (size_t i = 0; i < req_ctes.getCount(); i++) { diff --git a/src/dsql/pass1_proto.h b/src/dsql/pass1_proto.h index 442450fb75..34a9b4067e 100644 --- a/src/dsql/pass1_proto.h +++ b/src/dsql/pass1_proto.h @@ -24,10 +24,10 @@ #ifndef DSQL_PASS1_PROTO_H #define DSQL_PASS1_PROTO_H -Jrd::dsql_ctx* PASS1_make_context(Jrd::dsql_req* request, const Jrd::dsql_nod* relation_node); -Jrd::dsql_nod* PASS1_node(Jrd::dsql_req*, Jrd::dsql_nod*); -Jrd::dsql_nod* PASS1_rse(Jrd::dsql_req*, Jrd::dsql_nod*, Jrd::dsql_nod*); -Jrd::dsql_nod* PASS1_statement(Jrd::dsql_req*, Jrd::dsql_nod*); +Jrd::dsql_ctx* PASS1_make_context(Jrd::CompiledStatement* request, const Jrd::dsql_nod* relation_node); +Jrd::dsql_nod* PASS1_node(Jrd::CompiledStatement*, Jrd::dsql_nod*); +Jrd::dsql_nod* PASS1_rse(Jrd::CompiledStatement*, Jrd::dsql_nod*, Jrd::dsql_nod*); +Jrd::dsql_nod* PASS1_statement(Jrd::CompiledStatement*, Jrd::dsql_nod*); #endif // DSQL_PASS1_PROTO_H diff --git a/src/dsql/utld.cpp b/src/dsql/utld.cpp index 39427322b1..039246056f 100644 --- a/src/dsql/utld.cpp +++ b/src/dsql/utld.cpp @@ -1082,12 +1082,12 @@ static void xsqlvar_to_sqlvar(const XSQLVAR* xsqlvar, SQLVAR* sqlvar) UCHAR DSqlDataTypeUtil::maxBytesPerChar(UCHAR charSet) { - return METD_get_charset_bpc(request, charSet); + return METD_get_charset_bpc(statement, charSet); } USHORT DSqlDataTypeUtil::getDialect() const { - return request->req_client_dialect; + return statement->req_client_dialect; } #endif diff --git a/src/dsql/utld_proto.h b/src/dsql/utld_proto.h index ed21d30abd..845cd6663c 100644 --- a/src/dsql/utld_proto.h +++ b/src/dsql/utld_proto.h @@ -46,13 +46,13 @@ SCHAR* UTLD_skip_sql_info(SCHAR*); namespace Jrd { - class dsql_req; + class CompiledStatement; class DSqlDataTypeUtil : public DataTypeUtilBase { public: - explicit DSqlDataTypeUtil(dsql_req* req) - : request(req) + explicit DSqlDataTypeUtil(CompiledStatement* aStatement) + : statement(aStatement) { } @@ -61,7 +61,7 @@ namespace Jrd { virtual USHORT getDialect() const; private: - dsql_req* request; + CompiledStatement* statement; }; } // namespace