/* * pt_check_show_index () - semantic check for show index. * return: * parser(in): * node(in): */ static PT_NODE * pt_check_show_index (PARSER_CONTEXT * parser, PT_NODE * node) { PT_NODE *show_args_node = NULL; MOP cls; const char *table_name = NULL; const char *index_name = NULL; SM_CLASS *sm_class = NULL; SM_CLASS_CONSTRAINT *sm_all_constraints = NULL; SM_CLASS_CONSTRAINT *sm_constraint = NULL; PT_NODE *entity = NULL; PT_NODE *derived_table = NULL; SHOWSTMT_TYPE show_type; int error = NO_ERROR; int save; int partition_type = DB_NOT_PARTITIONED_CLASS; PT_NODE *partition_node = NULL; if (node->node_type != PT_SELECT) { return node; } entity = node->info.query.q.select.from; assert (entity != NULL); derived_table = entity->info.spec.derived_table; assert (derived_table != NULL); show_type = derived_table->info.showstmt.show_type; assert (show_type == SHOWSTMT_INDEX_HEADER || show_type == SHOWSTMT_INDEX_CAPACITY || show_type == SHOWSTMT_ALL_INDEXES_HEADER || show_type == SHOWSTMT_ALL_INDEXES_CAPACITY); show_args_node = derived_table->info.showstmt.show_args; assert (show_args_node != NULL); assert (show_args_node->node_type == PT_VALUE); assert (show_args_node->type_enum == PT_TYPE_CHAR); assert (show_args_node->info.value.data_value.str->length < DB_MAX_IDENTIFIER_LENGTH); /* check table name */ table_name = (const char *) show_args_node->info.value.data_value.str->bytes; cls = sm_find_class (table_name); if (cls == NULL) { PT_ERRORmf (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_LC_UNKNOWN_CLASSNAME), table_name); return node; } AU_DISABLE (save); error = au_fetch_class_force (cls, &sm_class, AU_FETCH_READ); AU_ENABLE (save); if (error == NO_ERROR) { if (sm_get_class_type (sm_class) != SM_CLASS_CT) { PT_ERRORm (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_OBJ_NOT_A_CLASS)); return node; } } /* check index name */ if (show_type == SHOWSTMT_INDEX_HEADER || show_type == SHOWSTMT_INDEX_CAPACITY) { show_args_node = show_args_node->next; assert (show_args_node != NULL); assert (show_args_node->node_type == PT_VALUE); assert (show_args_node->type_enum == PT_TYPE_CHAR); assert (show_args_node->info.value.data_value.str->length < DB_MAX_IDENTIFIER_LENGTH); index_name = (const char *) show_args_node->info.value.data_value.str->bytes; sm_all_constraints = sm_class_constraints (cls); sm_constraint = classobj_find_constraint_by_name (sm_all_constraints, index_name); if (sm_all_constraints == NULL || sm_constraint == NULL) { PT_ERRORmf (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_SM_NO_INDEX), index_name); return node; } } /* get partition type and pass it by args */ error = sm_partitioned_class_type (cls, &partition_type, NULL, NULL); if (error != NO_ERROR) { PT_ERRORc (parser, show_args_node, er_msg ()); return node; } partition_node = pt_make_integer_value (parser, partition_type); if (partition_node == NULL) { PT_INTERNAL_ERROR (parser, "allocate new node"); return node; } parser_append_node (partition_node, show_args_node); return node; }
/* * pt_check_show_heap () - check table exists or not * return: PT_NODE pointer * * parser(in): * node(in): */ static PT_NODE * pt_check_table_in_show_heap (PARSER_CONTEXT * parser, PT_NODE * node) { int error = NO_ERROR; PT_NODE *show_args_node = NULL, *spec, *derived_table; PT_NODE *partition_node = NULL; SHOWSTMT_TYPE show_type; int partition_type = DB_NOT_PARTITIONED_CLASS; const char *table_name = NULL; MOP cls; SM_CLASS *sm_class = NULL; int save; if (node->node_type != PT_SELECT) { return node; } spec = node->info.query.q.select.from; assert (spec != NULL); derived_table = spec->info.spec.derived_table; assert (derived_table != NULL); show_type = derived_table->info.showstmt.show_type; assert (show_type == SHOWSTMT_HEAP_HEADER || show_type == SHOWSTMT_ALL_HEAP_HEADER || show_type == SHOWSTMT_HEAP_CAPACITY || show_type == SHOWSTMT_ALL_HEAP_CAPACITY); show_args_node = derived_table->info.showstmt.show_args; assert (show_args_node != NULL); assert (show_args_node->node_type == PT_VALUE); assert (show_args_node->type_enum == PT_TYPE_CHAR); table_name = (const char *) show_args_node->info.value.data_value.str->bytes; cls = sm_find_class (table_name); if (cls == NULL) { PT_ERRORmf (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_LC_UNKNOWN_CLASSNAME), table_name); return node; } AU_DISABLE (save); error = au_fetch_class_force (cls, &sm_class, AU_FETCH_READ); AU_ENABLE (save); if (error == NO_ERROR) { if (sm_get_class_type (sm_class) != SM_CLASS_CT) { PT_ERRORm (parser, show_args_node, MSGCAT_SET_ERROR, -(ER_OBJ_NOT_A_CLASS)); return node; } } error = sm_partitioned_class_type (cls, &partition_type, NULL, NULL); if (error != NO_ERROR) { PT_ERRORc (parser, show_args_node, er_msg ()); return node; } partition_node = pt_make_integer_value (parser, partition_type); if (partition_node == NULL) { PT_INTERNAL_ERROR (parser, "allocate new node"); return node; } parser_append_node (partition_node, show_args_node); return node; }
DB_QUERY_TYPE * pt_fillin_type_size (PARSER_CONTEXT * parser, PT_NODE * query, DB_QUERY_TYPE * list, const int oids_included, bool want_spec_entity_name, bool fixup_columns_type) { DB_QUERY_TYPE *q, *t; PT_NODE *s, *from_list; const char *spec_name; PT_NODE *node, *spec; UINTPTR spec_id; char *original_name; s = pt_get_select_list (parser, query); if (s == NULL || list == NULL) { return list; } if (fixup_columns_type) { /* fixup the columns of union statement */ pt_fixup_select_columns_type (s); } from_list = pt_get_from_list (parser, query); /* from_list is allowed to be NULL for supporting SELECT without references to tables */ if (oids_included == 1) { /* * prepend single oid column onto the type list * the first node of the select list will be the oid column. */ q = pt_get_node_title (parser, s, from_list); if (q == NULL) { db_free_query_format (list); return NULL; } q->visible_type = OID_COLUMN; /* oid columns are NOT user visible */ q->next = list; list = q; } if (pt_length_of_select_list (s, EXCLUDE_HIDDEN_COLUMNS) != pt_arity_of_query_type (list)) { PT_INTERNAL_ERROR (parser, "query result"); return list; } for (t = list; s && t; s = s->next, t = t->next) { t->col_type = pt_get_col_type (parser, s); t->db_type = pt_type_enum_to_db (s->type_enum); t->size = pt_find_size_from_dbtype (t->db_type); t->domain = pt_xasl_node_to_domain (parser, s); t->src_domain = pt_get_src_domain (parser, s, from_list); spec_name = NULL; /* if it is attribute, find spec name */ if (pt_is_attr (s)) { node = s; while (node->node_type == PT_DOT_) { node = node->info.dot.arg1; /* root node for path expression */ } if (node->node_type == PT_NAME && (spec_id = node->info.name.spec_id) && (spec = pt_find_entity (parser, from_list, spec_id))) { if (want_spec_entity_name == true && spec->info.spec.entity_name) { spec_name = spec->info.spec.entity_name->info.name.original; } else if (want_spec_entity_name == false && spec->info.spec.range_var) { spec_name = spec->info.spec.range_var->info.name.original; } } } /* if it is method, find spec name */ if (pt_is_method_call (s)) { node = s; while (node->node_type == PT_DOT_) { node = node->info.dot.arg2; /* leaf node for qualified method */ } node = node->info.method_call.method_name; if (node->node_type == PT_NAME && (spec_id = node->info.name.spec_id) && (spec = pt_find_entity (parser, from_list, spec_id))) { if (want_spec_entity_name == true && spec->info.spec.entity_name) { spec_name = spec->info.spec.entity_name->info.name.original; } else if (want_spec_entity_name == false && spec->info.spec.range_var) { spec_name = spec->info.spec.range_var->info.name.original; } } } t->spec_name = (spec_name) ? strdup (spec_name) : NULL; if (!t->original_name) { /* PT_NAME comes from classname.* or build original_name( = spec_name.name) */ if (pt_length_of_list (from_list) == 1) { /* there is only one class spec */ original_name = pt_append_string (parser, NULL, t->name); t->original_name = (char *) malloc (strlen (original_name) + 1); } else { /* there are plural class specs */ original_name = pt_append_string (parser, pt_append_string (parser, (char *) t->spec_name, "."), t->name); t->original_name = (char *) malloc (strlen (original_name) + 1); } if (!t->original_name) { PT_INTERNAL_ERROR (parser, "insufficient memory"); return list; } strcpy ((char *) t->original_name, original_name); } } return list; }