Example #1
0
/*
 * pt_find_users_class () -
 *   return: class object if found
 *   parser(in):
 *   name(in/out):
 */
DB_OBJECT *
pt_find_users_class (PARSER_CONTEXT * parser, PT_NODE * name)
{
  DB_OBJECT *object;

  object = db_find_class (name->info.name.original);

  if (!object)
    {
      PT_ERRORmf (parser, name, MSGCAT_SET_PARSER_SEMANTIC, MSGCAT_SEMANTIC_CLASS_DOES_NOT_EXIST,
		  name->info.name.original);
    }
  name->info.name.db_object = object;

  pt_check_user_owns_class (parser, name);

  return object;
}
Example #2
0
static PT_NODE *
pt_check_access_status (PARSER_CONTEXT * parser, PT_NODE * node)
{
  DB_VALUE oid_val;
  MOP classop;
  PT_NODE *entity = NULL;
  PT_NODE *derived_table = NULL;
  PT_NODE *arg = NULL;

  if (!au_is_dba_group_member (Au_user))
    {
      PT_ERRORmf (parser, NULL, MSGCAT_SET_ERROR, -(ER_AU_DBA_ONLY), "show access status");
      return node;
    }

  entity = node->info.query.q.select.from;
  assert (entity != NULL);

  derived_table = entity->info.spec.derived_table;
  assert (derived_table != NULL);

  classop = sm_find_class ("db_user");
  if (classop == NULL)
    {
      assert (er_errid () != NO_ERROR);
      PT_ERRORc (parser, node, er_msg ());
      return node;
    }

  db_make_oid (&oid_val, &classop->oid_info.oid);
  arg = pt_dbval_to_value (parser, &oid_val);

  derived_table->info.showstmt.show_args = parser_append_node (arg, derived_table->info.showstmt.show_args);

  return node;
}
Example #3
0
/*
 * 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;
}
Example #4
0
/*
 * 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;
}