gpre_usn* MSC_username(const SCHAR* name, USHORT name_dyn) { gpre_usn* username = (gpre_usn*) MSC_alloc(USN_LEN); char* newname = (char*) MSC_alloc(static_cast<int>(strlen(name) + 1)); username->usn_name = newname; strcpy(newname, name); username->usn_dyn = name_dyn; username->usn_next = 0; return username; }
static void cmp_any( gpre_req* request) { // Build the primary send statement gpre_port* port = request->req_primary; make_send(port, request); request->add_byte(blr_if); request->add_byte(blr_any); CME_rse(request->req_rse, request); gpre_nod* value = MSC_unary(nod_value, (gpre_nod*) port->por_references); // Make a send to signal end of file request->add_byte(blr_assignment); CME_expr(lit1, request); CME_expr(value, request); request->add_byte(blr_assignment); CME_expr(lit0, request); CME_expr(value, request); port = request->req_vport; if (port) { for (ref* reference = port->por_references; reference; reference = reference->ref_next) { ref* source = (ref*) MSC_alloc(REF_LEN); reference->ref_source = source; source->ref_ident = CMP_next_ident(); } } }
SCHAR* MSC_string(const TEXT* input) { TEXT* string = (TEXT*) MSC_alloc(static_cast<int>(strlen(input) + 1)); strcpy(string, input); return string; }
gpre_nod* MSC_node(nod_t type, SSHORT count) { gpre_nod* node = (gpre_nod*) MSC_alloc(NOD_LEN(count)); node->nod_count = count; node->nod_type = type; return node; }
PRV MSC_privilege_block() { PRV privilege_block = (PRV) MSC_alloc(PRV_LEN); privilege_block->prv_privileges = PRV_no_privs; privilege_block->prv_username = 0; privilege_block->prv_relation = 0; privilege_block->prv_fields = 0; privilege_block->prv_next = 0; return privilege_block; }
ref* MSC_reference(ref** link) { ref* reference = (ref*) MSC_alloc(REF_LEN); if (link) { reference->ref_next = *link; *link = reference; } return reference; }
void MSC_push( gpre_nod* object, gpre_lls** pointer) { gpre_lls* stack = free_lls; if (stack) free_lls = stack->lls_next; else stack = (gpre_lls*) MSC_alloc(LLS_LEN); stack->lls_object = object; stack->lls_next = *pointer; *pointer = stack; }
gpre_sym* MSC_symbol(sym_t type, const TEXT* string, USHORT length, gpre_ctx* object) { gpre_sym* symbol = (gpre_sym*) MSC_alloc(SYM_LEN + length); symbol->sym_type = type; symbol->sym_object = object; TEXT* p = symbol->sym_name; symbol->sym_string = p; if (length) memcpy(p, string, length); return symbol; }
act* MSC_action( gpre_req* request, act_t type) { act* action = (act*) MSC_alloc(ACT_LEN); action->act_type = type; if (request) { action->act_next = request->req_actions; request->req_actions = action; action->act_request = request; } return action; }
gpre_ctx* MSC_context(gpre_req* request) { // allocate and initialize gpre_ctx* context = (gpre_ctx*) MSC_alloc(CTX_LEN); context->ctx_request = request; context->ctx_internal = request->req_internal++; context->ctx_scope_level = request->req_scope_level; // link in with the request block context->ctx_next = request->req_contexts; request->req_contexts = context; return context; }
gpre_req* MSC_request(req_t type) { gpre_req* request = (gpre_req*) MSC_alloc(REQ_LEN); request->req_type = type; request->req_next = gpreGlob.requests; gpreGlob.requests = request; request->req_routine = (gpre_req*) gpreGlob.cur_routine->act_object; gpreGlob.cur_routine->act_object = (ref*) request; if (!(gpreGlob.cur_routine->act_flags & ACT_main)) request->req_flags |= REQ_local; if (gpreGlob.sw_sql_dialect <= SQL_DIALECT_V5) request->req_flags |= REQ_blr_version4; return request; }
void CMP_check( gpre_req* request, SSHORT min_reqd) { const int length = request->req_blr - request->req_base; if (!min_reqd && (length < request->req_length - 100)) return; const int n = ((length + min_reqd + 100) > request->req_length * 2) ? length + min_reqd + 100 : request->req_length * 2; UCHAR* const old = request->req_base; UCHAR* p = MSC_alloc(n); request->req_base = p; request->req_length = n; request->req_blr = request->req_base + length; memcpy(p, old, length); MSC_free(old); }
void CMP_t_start( gpre_tra* trans) { char rrl_buffer[MAX_TPB]; char tpb_buffer[MAX_TRA_OPTIONS + 1]; // fill out a standard tpb buffer ahead of time so we know // how large it is char* text = tpb_buffer; *text++ = isc_tpb_version1; *text++ = (trans->tra_flags & TRA_ro) ? isc_tpb_read : isc_tpb_write; if (trans->tra_flags & TRA_con) *text++ = isc_tpb_consistency; else if (trans->tra_flags & TRA_read_committed) *text++ = isc_tpb_read_committed; else *text++ = isc_tpb_concurrency; *text++ = (trans->tra_flags & TRA_nw) ? isc_tpb_nowait : isc_tpb_wait; if (trans->tra_flags & TRA_read_committed) { *text++ = (trans->tra_flags & TRA_rec_version) ? isc_tpb_rec_version : isc_tpb_no_rec_version; } if (trans->tra_flags & TRA_autocommit) *text++ = isc_tpb_autocommit; if (trans->tra_flags & TRA_no_auto_undo) *text++ = isc_tpb_no_auto_undo; *text = 0; const USHORT tpb_len = text - tpb_buffer; for (gpre_dbb* database = gpreGlob.isc_databases; database; database = database->dbb_next) { // figure out if this is a simple transaction or a reserving // transaction. Allocate a TPB of the right size in either // case. tpb* new_tpb = 0; if (trans->tra_flags & TRA_inc) { if (database->dbb_flags & DBB_in_trans) { new_tpb = (tpb*) MSC_alloc(TPB_LEN(tpb_len)); new_tpb->tpb_length = tpb_len; database->dbb_flags &= ~DBB_in_trans; } else continue; } else if (!(trans->tra_flags & TRA_rrl)) { new_tpb = (tpb*) MSC_alloc(TPB_LEN(tpb_len)); new_tpb->tpb_length = tpb_len; } else if (database->dbb_rrls) { char* p = rrl_buffer; for (const rrl* lock_block = database->dbb_rrls; lock_block; lock_block = lock_block->rrl_next) { *p++ = lock_block->rrl_lock_mode; const char* q = lock_block->rrl_relation->rel_symbol->sym_string; *p++ = static_cast<char>(strlen(q)); while (*q) *p++ = *q++; *p++ = lock_block->rrl_lock_level; } *p = 0; const USHORT buff_len = (p - rrl_buffer); new_tpb = (tpb*) MSC_alloc(TPB_LEN(buff_len + tpb_len)); new_tpb->tpb_length = buff_len + tpb_len; database->dbb_rrls = NULL; } else // this database isn't referenced continue; // link this into the TPB chains (gpre_tra and gpre_dbb) new_tpb->tpb_database = database; new_tpb->tpb_dbb_next = database->dbb_tpbs; database->dbb_tpbs = new_tpb; new_tpb->tpb_tra_next = trans->tra_tpb; trans->tra_tpb = new_tpb; trans->tra_db_count++; // fill in the standard TPB and concatenate the relation names new_tpb->tpb_ident = CMP_next_ident(); text = reinterpret_cast<char*>(new_tpb->tpb_string); for (const char* pb = tpb_buffer; *pb;) *text++ = *pb++; if (trans->tra_flags & TRA_rrl) strcpy(text, rrl_buffer); } }
void CMP_compile_request( gpre_req* request) { // if there isn't a request handle specified, make one! if (!request->req_handle && (request->req_type != REQ_procedure)) { request->req_handle = (TEXT*) MSC_alloc(20); sprintf(request->req_handle, gpreGlob.ident_pattern, CMP_next_ident()); } if (!request->req_trans) request->req_trans = gpreGlob.transaction_name; if (!request->req_request_level) request->req_request_level = "0"; request->req_ident = CMP_next_ident(); // If this is an SQL blob cursor, compile the blob and get out fast. if (request->req_flags & (REQ_sql_blob_open | REQ_sql_blob_create)) { for (blb* blob = request->req_blobs; blob; blob = blob->blb_next) cmp_blob(blob, true); return; } // Before we get too far, make sure an eof field has been // constructed. If not, do so now. ref* reference; if (!eof_field) { eof_field = MET_make_field(gpreGlob.utility_name, dtype_short, sizeof(SSHORT), false); count_field = MET_make_field(gpreGlob.count_name, dtype_long, sizeof(SLONG), false); slack_byte_field = MET_make_field(gpreGlob.slack_name, dtype_text, 1, false); reference = (ref*) MSC_alloc(REF_LEN); reference->ref_value = "0"; lit0 = MSC_unary(nod_literal, (gpre_nod*) reference); reference = (ref*) MSC_alloc(REF_LEN); reference->ref_value = "1"; lit1 = MSC_unary(nod_literal, (gpre_nod*) reference); } // Handle different request types differently switch (request->req_type) { case REQ_create_database: case REQ_ddl: CMD_compile_ddl(request); return; case REQ_slice: cmp_slice(request); return; case REQ_ready: cmp_ready(request); return; case REQ_procedure: cmp_procedure(request); return; } // expand any incomplete references or values expand_references(request->req_references); expand_references(request->req_values); // Initialize the blr string request->req_blr = request->req_base = MSC_alloc(500); request->req_length = 500; if (request->req_flags & REQ_blr_version4) request->add_byte(blr_version4); else request->add_byte(blr_version5); // If there are values to be transmitted, make a port // to hold them if (request->req_values) request->req_vport = make_port(request, request->req_values); // If this is a FOR type request, an eof field reference needs // to be generated. Do it. switch (request->req_type) { case REQ_for: case REQ_cursor: case REQ_any: reference = (ref*) MSC_alloc(REF_LEN); reference->ref_field = eof_field; reference->ref_next = request->req_references; break; case REQ_mass_update: reference = (ref*) MSC_alloc(REF_LEN); reference->ref_field = count_field; reference->ref_next = request->req_references; break; default: reference = request->req_references; } // Assume that a general port needs to be constructed. gpre_port* port; if ((request->req_type != REQ_insert) && (request->req_type != REQ_store2) && (request->req_type != REQ_set_generator)) { request->req_primary = port = make_port(request, reference); } // Loop thru actions looking for something interesting to do. Not // all action types are "interesting", so don't worry about missing // ones. upd* update; for (act* action = request->req_actions; action; action = action->act_next) { switch (action->act_type) { case ACT_modify: case ACT_erase: case ACT_update: update = (upd*) action->act_object; expand_references(update->upd_references); update->upd_port = make_port(request, update->upd_references); if (!request->req_sync) request->req_sync = make_port(request, 0); break; case ACT_store: if (request->req_type == REQ_store2) { request->req_primary = make_port(request, action->act_object); update_references(request->req_primary->por_references); } break; case ACT_store2: update = (upd*) action->act_object; expand_references(update->upd_references); update->upd_port = make_port(request, update->upd_references); update_references(update->upd_port->por_references); break; case ACT_select: case ACT_fetch: cmp_fetch(action); break; } } cmp_blr(request); request->add_byte(blr_eoc); // Compute out final blr lengths request->req_length = request->req_blr - request->req_base; request->req_blr = request->req_base; // Finally, assign identifiers to any blobs that may have been referenced for (blb* blob = request->req_blobs; blob; blob = blob->blb_next) cmp_blob(blob, false); }
void JRDMET_init( gpre_dbb* db) { const int* relfld = relfields; while (relfld[RFLD_R_NAME]) { gpre_rel* relation = (gpre_rel*) MSC_alloc(REL_LEN); relation->rel_database = db; relation->rel_next = db->dbb_relations; relation->rel_id = relfld[RFLD_R_ID]; db->dbb_relations = relation; gpre_sym* symbol = (gpre_sym*) MSC_alloc(SYM_LEN); relation->rel_symbol = symbol; symbol->sym_type = SYM_relation; symbol->sym_object = (gpre_ctx*) relation; symbol->sym_string = names[relfld[RFLD_R_NAME]]; HSH_insert(symbol); const int* fld = relfld + RFLD_RPT; for (int n = 0; fld[RFLD_F_NAME]; ++n, fld += RFLD_F_LENGTH) { const gfld* gfield = &gfields[fld[RFLD_F_ID]]; gpre_fld* field = (gpre_fld*) MSC_alloc(FLD_LEN); relation->rel_fields = field; field->fld_relation = relation; field->fld_next = relation->rel_fields; field->fld_id = n; field->fld_length = gfield->gfld_length; field->fld_dtype = gfield->gfld_dtype; field->fld_sub_type = gfield->gfld_sub_type; if (field->fld_dtype == dtype_varying || field->fld_dtype == dtype_text) { field->fld_dtype = dtype_cstring; field->fld_flags |= FLD_text; if (gfield->gfld_sub_type == dsc_text_type_metadata) { if (gpreGlob.sw_language == lang_internal) field->fld_flags |= FLD_charset; else field->fld_length *= 4; field->fld_charset_id = CS_METADATA; field->fld_collate_id = COLLATE_NONE; field->fld_ttype = ttype_metadata; } else { if (gpreGlob.sw_language == lang_internal) field->fld_flags |= FLD_charset; field->fld_charset_id = CS_NONE; field->fld_collate_id = COLLATE_NONE; field->fld_ttype = ttype_none; } ++field->fld_length; } else if (field->fld_dtype == dtype_blob) { field->fld_dtype = dtype_blob; field->fld_flags |= FLD_blob; if (gfield->gfld_sub_type == isc_blob_text) field->fld_charset_id = CS_METADATA; } field->fld_symbol = symbol = (gpre_sym*) MSC_alloc(SYM_LEN); symbol->sym_type = SYM_field; symbol->sym_object = (gpre_ctx*) field; symbol->sym_string = names[fld[RFLD_F_NAME]]; HSH_insert(symbol); field->fld_global = symbol = (gpre_sym*) MSC_alloc(SYM_LEN); symbol->sym_type = SYM_field; symbol->sym_object = (gpre_ctx*) field; symbol->sym_string = names[gfield->gfld_name]; } relfld = fld + 1; } for (const rtyp* rtype = types; rtype->rtyp_name; rtype++) { field_type* type = (field_type*) MSC_alloc(TYP_LEN); gpre_sym* symbol = (gpre_sym*) MSC_alloc(SYM_LEN); type->typ_symbol = symbol; type->typ_value = rtype->rtyp_value; symbol->sym_type = SYM_type; symbol->sym_object = (gpre_ctx*) type; symbol->sym_string = rtype->rtyp_name; HSH_insert(symbol); } }