📄 gen.c
字号:
break; case dtype_quad: case dtype_blob: case dtype_array: case dtype_timestamp: gen_descriptor (request, desc, TRUE); value = *(SLONG*) p; STUFF_WORD (value); STUFF_WORD (value >> 16); value = *(SLONG*) (p + 4); STUFF_WORD (value); STUFF_WORD (value >> 16); break; case dtype_text: gen_descriptor (request, desc, TRUE); if (l) do STUFF (*p++); while (--l); break; default: /* gen_constant: datatype not understood */ ERRD_post (gds__sqlerr, gds_arg_number, (SLONG) -103, gds_arg_gds, gds__dsql_constant_err, 0); }}static void gen_descriptor ( REQ request, DSC *desc, USHORT texttype){/************************************** * * g e n _ d e s c r i p t o r * ************************************** * * Functional description * Generate a blr descriptor from an internal descriptor. * **************************************/switch (desc->dsc_dtype) { case dtype_text: if (request->req_dbb->dbb_flags & DBB_v3) STUFF (blr_text); else if (texttype || desc->dsc_ttype == ttype_binary) { STUFF (blr_text2); STUFF_WORD (desc->dsc_ttype); } else { STUFF (blr_text2); /* automatic transliteration */ STUFF_WORD (ttype_dynamic); } STUFF_WORD (desc->dsc_length); break; case dtype_varying: if (request->req_dbb->dbb_flags & DBB_v3) STUFF (blr_varying); else if (texttype || desc->dsc_ttype == ttype_binary) { STUFF (blr_varying2); STUFF_WORD (desc->dsc_ttype); } else { STUFF (blr_varying2); /* automatic transliteration */ STUFF_WORD (ttype_dynamic); } STUFF_WORD (desc->dsc_length - sizeof(USHORT)); break; case dtype_short: STUFF (blr_short); STUFF (desc->dsc_scale); break; case dtype_long: STUFF (blr_long); STUFF (desc->dsc_scale); break; case dtype_quad: STUFF (blr_quad); STUFF (desc->dsc_scale); break; case dtype_int64: STUFF (blr_int64); STUFF (desc->dsc_scale); break; case dtype_real: STUFF (blr_float); break; case dtype_double: STUFF (blr_double); break; case dtype_sql_date: STUFF (blr_sql_date); break; case dtype_sql_time: STUFF (blr_sql_time); break; case dtype_timestamp: STUFF (blr_timestamp); break; case dtype_blob: case dtype_array: STUFF (blr_quad); STUFF (0); break; default: /* don't understand dtype */ ERRD_post (gds__sqlerr, gds_arg_number, (SLONG) -804, gds_arg_gds, gds__dsql_datatype_err, 0); }}static void gen_error_condition ( REQ request, NOD node){/************************************** * * g e n _ e r r o r _ c o n d i t i o n * ************************************** * * Functional description * Generate blr for an error condtion * **************************************/STR string;switch (node->nod_type) { case nod_sqlcode: STUFF (blr_sql_code); STUFF_WORD (node->nod_arg [0]); return; case nod_gdscode: STUFF (blr_gds_code); string = (STR) node->nod_arg [0]; STUFF_CSTRING (string->str_data); return; case nod_exception: STUFF (blr_exception); string = (STR) node->nod_arg [0]; STUFF_CSTRING (string->str_data); return; case nod_default: STUFF (blr_default_code); return; default: assert (FALSE); return; }}static void gen_field ( REQ request, CTX context, FLD field, NOD indices){/************************************** * * g e n _ f i e l d * ************************************** * * Functional description * Generate blr for a field - field id's * are preferred but not for trigger or view blr. * **************************************/NOD *ptr, *end;/* 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) { switch (field->fld_dtype) { case dtype_sql_date: case dtype_sql_time: case dtype_int64: ERRD_post (gds__sqlerr, gds_arg_number, (SLONG) -804, gds_arg_gds, gds__dsql_datatype_err, gds_arg_gds, isc_sql_dialect_datatype_unsupport, gds_arg_number, request->req_client_dialect, gds_arg_string, DSC_dtype_tostring (field->fld_dtype), 0); break; default: /* No special action for other data types */ break; } }if (indices) STUFF (blr_index);if (DDL_ids (request)) { STUFF (blr_fid); STUFF (context->ctx_context); STUFF_WORD (field->fld_id); }else { STUFF (blr_field); STUFF (context->ctx_context); STUFF_CSTRING (field->fld_name); }if (indices) { STUFF (indices->nod_count); for (ptr = indices->nod_arg, end = ptr + indices->nod_count; ptr < end; ptr++) GEN_expr (request, *ptr); }}static void gen_for_select ( REQ request, NOD for_select){/************************************** * * g e n _ f o r _ s e l e c t * ************************************** * * Functional description * Generate BLR for a SELECT statement. * **************************************/NOD list, list_to, *ptr, *ptr_to, *end, rse;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 (blr_label); STUFF ((int) for_select->nod_arg [e_flp_number]);}/* Generate FOR loop */STUFF (blr_for);if (!for_select->nod_arg [e_flp_action] && !(request->req_dbb->dbb_flags & DBB_v3)) STUFF (blr_singular);gen_rse (request, rse);STUFF (blr_begin);/* Build body of FOR loop */list = rse->nod_arg [e_rse_items];list_to = for_select->nod_arg [e_flp_into];if (list->nod_count != list_to->nod_count) ERRD_post (gds__sqlerr, gds_arg_number, (SLONG) -313, gds_arg_gds, gds__dsql_count_mismatch, 0);for (ptr = list->nod_arg, ptr_to = list_to->nod_arg, end = ptr + list->nod_count; ptr < end; ptr++, ptr_to++) { STUFF (blr_assignment); GEN_expr (request, *ptr); GEN_expr (request, *ptr_to); }if (for_select->nod_arg [e_flp_action]) GEN_statement (request, for_select->nod_arg [e_flp_action]);STUFF (blr_end);}static void gen_gen_id ( REQ request, NOD node){/************************************** * * g e n _ g e n _ i d * ************************************** * * Functional description * Generate BLR for gen_id * **************************************/STR string;STUFF (blr_gen_id);string = (STR) node->nod_arg [e_gen_id_name];STUFF_CSTRING (string->str_data);GEN_expr (request, node->nod_arg [e_gen_id_value]);}static void gen_join_rse ( REQ request, NOD rse){/************************************** * * g e n _ j o i n _ r s e * ************************************** * * Functional description * Generate a record selection expression * with an explicit join type. * **************************************/NOD node;STUFF (blr_rs_stream);STUFF (2);GEN_expr (request, rse->nod_arg [e_join_left_rel]);GEN_expr (request, rse->nod_arg [e_join_rght_rel]);node = rse->nod_arg [e_join_type];if (node->nod_type != nod_join_inner) { STUFF (blr_join_type); if (node->nod_type == nod_join_left) STUFF (blr_left); else if (node->nod_type == nod_join_right) STUFF (blr_right); else STUFF (blr_full); }STUFF (blr_boolean);GEN_expr (request, rse->nod_arg [e_join_boolean]);STUFF (blr_end);}static void gen_map ( REQ request, MAP map){/************************************** * * g e n _ m a p * ************************************** * * Functional description * Generate a value map for a record selection expression. * **************************************/USHORT count;MAP temp;count = 0;for (temp = map; temp; temp = temp->map_next) temp->map_position = count++;STUFF (blr_map);STUFF_WORD (count);for (temp = map; temp; temp = temp->map_next) { STUFF_WORD (temp->map_position); GEN_expr (request, temp->map_node); }}static void gen_parameter ( REQ request, PAR parameter){/************************************** * * g e n _ p a r a m e t e r * ************************************** * * Functional description * Generate a parameter reference. * **************************************/MSG message;PAR null;message = parameter->par_message;if ((null = parameter->par_null) != NULL) { STUFF (blr_parameter2); STUFF (message->msg_number); STUFF_WORD (parameter->par_parameter); STUFF_WORD (null->par_parameter); return; }STUFF (blr_parameter);STUFF (message->msg_number);STUFF_WORD (parameter->par_parameter);}static void gen_plan ( REQ request, NOD plan_expression){/************************************** * * g e n _ p l a n * ************************************** * * Functional description * Generate blr for an access plan expression. * **************************************/NOD list, node, arg, *ptr, *end, *ptr2, *end2;STR index_string;/* stuff the join type */list = plan_expression->nod_arg [1];if (list->nod_count > 1) { if (node = plan_expression->nod_arg [0]) STUFF (blr_merge); else STUFF (blr_join); STUFF (list->nod_count); }/* stuff one or more plan items */for (ptr = list->nod_arg, end = ptr + list->nod_count; ptr < end; ptr++) { node = *ptr; if (node->nod_type == nod_plan_expr) { gen_plan (request, node); continue; } /* if we're here, it must be a nod_plan_item */ STUFF (blr_retrieve); /* stuff the relation--the relation id itself is redundant except when there is a need to differentiate the base tables of views */ arg = node->nod_arg [0]; gen_relation (request, (CTX) arg->nod_arg [e_rel_context]); /* now stuff the access method for this stream */ arg = node->nod_arg [1]; switch (arg->nod_type) { case nod_natural: STUFF (blr_sequential); break; case nod_index_order: STUFF (blr_navigational); index_string = (STR) arg->nod_arg [0]; STUFF_CSTRING (index_string->str_data); break; case nod_index: STUFF (blr_indices); arg = arg->nod_arg [0]; STUFF (arg->nod_count); for (ptr2 = arg->nod_arg, end2 = ptr2 + arg->nod_count; ptr2 < end2; ptr2++) { index_string = (STR) *ptr2; STUFF_CSTRING (index_string->str_data); } break; default: assert (FALSE); break; } }}static void gen_relation ( REQ request, CTX context){/************************************** * * g e n _ r e l a t i o n * ************************************** * * Functional description * Generate blr for a relation reference. * **************************************/DSQL_REL relation;PRC procedure;NOD inputs, *ptr, *end;relation = context->ctx_relation;procedure = context->ctx_procedure;/* if this is a trigger or procedure , don't want relation id used */if (relation) { if (DDL_ids (request)) { if (context->ctx_alias) STUFF (blr_rid2); else STUFF (blr_rid); STUFF_WORD (relation->rel_id); } else { if (context->ctx_alias) STUFF (blr_relation2); else STUFF (blr_relation); STUFF_CSTRING (relation->rel_name); } if (context->ctx_alias) STUFF_CSTRING (context->ctx_alias); STUFF (context->ctx_context); }else { if (DDL_ids (request)) { STUFF (blr_pid); STUFF_WORD (procedure->prc_id); } else { STUFF (blr_procedure); STUFF_CSTRING (procedure->prc_name); } STUFF (context->ctx_context); STUFF_WORD (procedure->prc_in_count); if (inputs = context->ctx_proc_inputs) for (ptr = inputs->nod_arg, end = ptr + inputs->nod_count; ptr < end; ptr++) GEN_expr (request, *ptr); }}void GEN_return ( REQ request, NOD procedure, BOOLEAN eos_flag){/************************************** * * g e n _ r e t u r n * ************************************** * * Functional description * Generate blr for a procedure return. * **************************************/NOD parameters, parameter, *ptr, *end;VAR variable;USHORT outputs;if (!procedure) return;if (!eos_flag) STUFF (blr_begin);STUFF (blr_send);STUFF (1);STUFF (blr_begin);outputs = 0;if (parameters = procedure->nod_arg [e_prc_outputs]) { for (ptr = parameters->nod_arg, end = ptr + parameters->nod_count; ptr < end; ptr++) { outputs++; parameter = *ptr; variable = (VAR) parameter->nod_arg[e_var_variable]; STUFF (blr_assignment); STUFF (blr_variable); STUFF_WORD (variable->var_variable_number); STUFF (blr_parameter2); STUFF (variable->var_msg_number); STUFF_WORD (variable->var_msg_item); STUFF_WORD (variable->var_msg_item + 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -