Esempio n. 1
0
static void
write_class_info (FILE * fp, DB_OBJECT * classobj)
{
  DB_OBJLIST *objlist, *temp;
  DB_OBJECT *obj;
  DB_VALUE v;

  fprintf (fp, MSGFMT, "open", "class");
  fprintf (fp, MSGFMT, "classname", db_get_class_name (classobj));

  obj = db_get_owner (classobj);
  db_get (obj, "name", &v);
  fprintf (fp, MSGFMT, "owner", db_get_string (&v));

  objlist = db_get_superclasses (classobj);
  for (temp = objlist; temp != NULL; temp = temp->next)
    {
      fprintf (fp, MSGFMT, "superclass", db_get_class_name (temp->op));
    }
  if (objlist != NULL)
    db_objlist_free (objlist);

  if (db_is_vclass (classobj))
    fprintf (fp, MSGFMT, "virtual", "view");
  else
    fprintf (fp, MSGFMT, "virtual", "normal");

  fprintf (fp, MSGFMT, "close", "class");
}
Esempio n. 2
0
/*
 * orp_oid_get_classname - 
 *    return:
 *    pool():
 *    xoid():
 *    name():
 *    size():
 */
static int
orp_oid_get_classname (API_OBJECT_RESULTSET_POOL * pool, CI_OID * xoid, char *name, size_t size)
{
  OBJECT_RESULTSET_POOL *p;
  OID oid;
  int res;
  void *r;
  DB_OBJECT *obj;

  assert (pool != NULL);
  assert (xoid != NULL);
  p = (OBJECT_RESULTSET_POOL *) pool;
  /* delete object resultset */
  xoid2oid (xoid, &oid);
  res = hash_lookup (p->ht, &oid, &r);
  if (res != NO_ERROR)
    return res;

  obj = ws_mop (&oid, NULL);
  if (obj)
    {
      char *tmp;
      tmp = (char *) db_get_class_name (obj);
      if (tmp)
	{
	  strncpy (name, tmp, size);
	  return NO_ERROR;
	}
    }

  strncpy (name, "NULL", size);

  return NO_ERROR;
}
Esempio n. 3
0
/*
 * get_name_from_class_oid - get the name of the class from class oid
 *    return:  the name of the class
 *    class_oid(in) : class oid
 */
static char *
get_name_from_class_oid (OID * class_oid)
{
  MOP class_mop = NULL;
  char *temp_class_name;
  char *result;

  if (!class_oid)
    {
      return NULL;
    }

  class_mop = db_object (class_oid);
  if (class_mop == NULL)
    {
      return NULL;
    }

  temp_class_name = (char *) db_get_class_name (class_mop);
  if (temp_class_name == NULL)
    {
      return NULL;
    }

  result = (char *) malloc (sizeof (char) * (strlen (temp_class_name) + 1));
  if (result == NULL)
    {
      return NULL;
    }

  strcpy (result, temp_class_name);

  return result;
}
Esempio n. 4
0
/*
 * object_to_string() - convert object to string
 *   return: formatted string
 *   object(in): object value to convert
 *   format(in): conversion format type
 */
static char *
object_to_string (DB_OBJECT * object, int format)
{
  if (object == NULL)
    return NULL;

  if (format == OBJECT_FORMAT_OID)
    {
      char temp_string[OBJECT_SYMBOL_MAX];

      if (!db_print_mop (object, temp_string, OBJECT_SYMBOL_MAX))
	{
	  return (NULL);
	}
      return (duplicate_string (temp_string));
    }
  else
    {
      char *name;

      name = (char *) db_get_class_name (object);
      if (name == NULL)
	{
	  return (NULL);
	}
      else
	{
	  return (duplicate_string (name));
	}
    }
}
Esempio n. 5
0
/*
 * otable_insert - This inserts a new entry in the instance array of a class
 * table.
 *    return: NO_ERROR if successful, error code otherwise
 *    table(out): class table
 *    instance(in): instance OID
 *    id(in): instance id number
 */
int
otable_insert (CLASS_TABLE * table, OID * instance, int id)
{
  int error = NO_ERROR;
  INST_INFO *inst;

  if (id >= table->count)
    {
      error = grow_instance_table (table, id);
    }

  if (error == NO_ERROR)
    {
      inst = &table->instances[id];
      if (inst->flags & INST_FLAG_INSERTED)
	/* lame, should pass in a stream for this */
	fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS,
					 MSGCAT_UTIL_SET_LOADDB,
					 LOADDB_MSG_REDEFINING_INSTANCE), id,
		 db_get_class_name (table->class_));

      inst->oid = *instance;
      inst->flags = INST_FLAG_INSERTED;
    }
  return error;
}
Esempio n. 6
0
/*
 * otable_reserve - This is used to reserve an element for this instance id.
 *    return: NO_ERROR if successful, error code otherwise
 *    table(out): class table
 *    instance(in): instance OID
 *    id(in): instance id
 * Note:
 *    This is exactly the same as otable_insert except that the
 *    instance element is flagged with INST_FLAG_RESERVED.
 */
int
otable_reserve (CLASS_TABLE * table, OID * instance, int id)
{
  int error = NO_ERROR;
  INST_INFO *inst;

  if (id >= table->count)
    {
      error = grow_instance_table (table, id);
    }

  if (error == NO_ERROR)
    {
      inst = &table->instances[id];
      if (inst->flags)
	{
	  /* should pass in an appropriate stream here */
	  if (inst->flags & INST_FLAG_INSERTED)
	    fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS,
					     MSGCAT_UTIL_SET_LOADDB,
					     LOADDB_MSG_INSTANCE_DEFINED), id,
		     db_get_class_name (table->class_));
	  else
	    fprintf (stdout, msgcat_message (MSGCAT_CATALOG_UTILS,
					     MSGCAT_UTIL_SET_LOADDB,
					     LOADDB_MSG_INSTANCE_RESERVED),
		     id, db_get_class_name (table->class_));
	}
      else
	{
	  inst->oid = *instance;
	  inst->flags = INST_FLAG_RESERVED;
	}
    }
  return error;
}
Esempio n. 7
0
/*
 * rm_api_get_info - 
 *    return:
 *    impl():
 *    index():
 *    type():
 *    arg():
 *    size():
 */
static int
rm_api_get_info (API_RESULTSET_META * impl, int index, CI_RMETA_INFO_TYPE type, void *arg, size_t size)
{
  OBJECT_RESULTSET *or;
  DB_ATTRIBUTE *attr;
  DB_DOMAIN *domain;
  int res;

  assert (impl != NULL);

  /* convert to zero based index */
  index--;

  or = ((OBJECT_RM_BIND *) impl)->or;
  if (index < 0 || index >= or->nattrs)
    {
      return ER_INTERFACE_INVALID_ARGUMENT;	/* index out of range */
    }
  if (arg == NULL || size <= 0)
    {
      return ER_INTERFACE_INVALID_ARGUMENT;
    }
  attr = or->attr_index[index];

  assert (attr != NULL);

  switch (type)
    {
    case CI_RMETA_INFO_COL_LABEL:
      /* col label is not defined. return null string */
      *(char *) arg = '\0';
      return NO_ERROR;

    case CI_RMETA_INFO_COL_NAME:
      {
	size_t namelen;
	const char *attr_name;

	attr_name = db_attribute_name (attr);

	assert (attr_name != NULL);

	namelen = strlen (attr_name) + 1;
	if (namelen > size)
	  {
	    return ER_INTERFACE_INVALID_ARGUMENT;	/* size insufficient */
	  }
	strcpy ((char *) arg, attr_name);
	return NO_ERROR;
      }
    case CI_RMETA_INFO_COL_TYPE:
      if (size < sizeof (CI_TYPE))
	{
	  return ER_INTERFACE_INVALID_ARGUMENT;
	}

      domain = db_attribute_domain (attr);
      if (domain == NULL)
	{
	  return ER_INTERFACE_GENERIC;
	}

      res = db_type_to_type (TP_DOMAIN_TYPE (domain), (CI_TYPE *) arg);
      return res;

    case CI_RMETA_INFO_PRECISION:
      if (size < sizeof (int))
	{
	  return ER_INTERFACE_INVALID_ARGUMENT;
	}

      domain = db_attribute_domain (attr);
      if (domain == NULL)
	{
	  return ER_INTERFACE_GENERIC;
	}

      *(int *) arg = db_domain_precision (domain);
      return NO_ERROR;

    case CI_RMETA_INFO_SCALE:
      if (size < sizeof (int))
	{
	  return ER_INTERFACE_INVALID_ARGUMENT;
	}

      domain = db_attribute_domain (attr);
      if (domain == NULL)
	{
	  return ER_INTERFACE_GENERIC;
	}

      *(int *) arg = db_domain_scale (domain);
      return NO_ERROR;

    case CI_RMETA_INFO_TABLE_NAME:
      {
	const char *tbl_name;
	size_t sz;

	assert (or->clz != NULL);

	tbl_name = db_get_class_name (or->clz);
	if (tbl_name == NULL)
	  {
	    return ER_INTERFACE_GENERIC;
	  }

	sz = strlen (tbl_name) + 1;
	if (sz > size)
	  {
	    return ER_INTERFACE_INVALID_ARGUMENT;
	  }
	strcpy ((char *) arg, tbl_name);
	return NO_ERROR;
      }
    case CI_RMETA_INFO_IS_AUTO_INCREMENT:
      if (size < sizeof (int))
	{
	  return ER_INTERFACE_INVALID_ARGUMENT;
	}

      *(int *) arg = db_attribute_is_auto_increment (attr);
      return NO_ERROR;

    case CI_RMETA_INFO_IS_NULLABLE:
      if (size < sizeof (int))
	{
	  return ER_INTERFACE_INVALID_ARGUMENT;
	}

      *(int *) arg = db_attribute_is_non_null (attr) ? 0 : 1;
      return NO_ERROR;

    case CI_RMETA_INFO_IS_WRITABLE:
      if (size < sizeof (int))
	{
	  return ER_INTERFACE_INVALID_ARGUMENT;
	}

      if (or->obj->lock == X_LOCK || or->obj->lock == U_LOCK)
	{
	  *(int *) arg = 1;
	}
      else
	{
	  *(int *) arg = 0;
	}
      return NO_ERROR;

    default:
      return ER_INTERFACE_INVALID_ARGUMENT;
    }

  assert (0);
  return ER_INTERFACE_GENERIC;
}
Esempio n. 8
0
/*
 * show_statistics - show the statistics for specified class oids
 *    return:  
 *    class_oid(in) : class oid
 *    unlocked_class(in) : true if the class was not locked
 *    valid_class(in): true if the class was valid 
 *    processed_class(in): true if the class was processed 
 *    total_objects(in): total class objects
 *    failed_objects(in): failed class objects
 *    modified_objects(in): modified class objects
 *    big_objects(in): big class objects
 *    delete_old_repr_flag: delete old representation flag
 *    old_repr_deleted(in): old class representations removed from catalog
 */
static void
show_statistics (OID * class_oid,
		 bool unlocked_class,
		 bool valid_class, bool processed_class,
		 int total_objects, int failed_objects,
		 int modified_objects, int big_objects,
		 bool delete_old_repr_flag, bool old_repr_deleted)
{
  MOP class_mop = NULL;
  char *temp_class_name;

  class_mop = db_object (class_oid);
  if (class_mop == NULL)
    {
      printf (msgcat_message (MSGCAT_CATALOG_UTILS,
			      MSGCAT_UTIL_SET_COMPACTDB,
			      COMPACTDB_MSG_INVALID_CLASS));
      return;
    }

  temp_class_name = (char *) db_get_class_name (class_mop);
  if (temp_class_name == NULL || strlen (temp_class_name) == 0)
    {
      printf (msgcat_message (MSGCAT_CATALOG_UTILS,
			      MSGCAT_UTIL_SET_COMPACTDB,
			      COMPACTDB_MSG_UNKNOWN_CLASS_NAME));
    }
  else
    {
      printf (msgcat_message (MSGCAT_CATALOG_UTILS,
			      MSGCAT_UTIL_SET_COMPACTDB,
			      COMPACTDB_MSG_CLASS), temp_class_name);
    }

  if (!valid_class)
    {
      printf (msgcat_message (MSGCAT_CATALOG_UTILS,
			      MSGCAT_UTIL_SET_COMPACTDB,
			      COMPACTDB_MSG_INVALID_CLASS));

      return;
    }

  if (!processed_class)
    {
      printf (msgcat_message (MSGCAT_CATALOG_UTILS,
			      MSGCAT_UTIL_SET_COMPACTDB,
			      COMPACTDB_MSG_PROCESS_CLASS_ERROR));

    }

  if (!unlocked_class)
    {
      printf (msgcat_message (MSGCAT_CATALOG_UTILS,
			      MSGCAT_UTIL_SET_COMPACTDB,
			      COMPACTDB_MSG_LOCKED_CLASS));
    }

  printf (msgcat_message (MSGCAT_CATALOG_UTILS,
			  MSGCAT_UTIL_SET_COMPACTDB,
			  COMPACTDB_MSG_TOTAL_OBJECTS), total_objects);

  printf (msgcat_message (MSGCAT_CATALOG_UTILS,
			  MSGCAT_UTIL_SET_COMPACTDB,
			  COMPACTDB_MSG_FAILED_OBJECTS), failed_objects);

  printf (msgcat_message (MSGCAT_CATALOG_UTILS,
			  MSGCAT_UTIL_SET_COMPACTDB,
			  COMPACTDB_MSG_MODIFIED_OBJECTS), modified_objects);

  printf (msgcat_message (MSGCAT_CATALOG_UTILS,
			  MSGCAT_UTIL_SET_COMPACTDB,
			  COMPACTDB_MSG_BIG_OBJECTS), big_objects);

  if (delete_old_repr_flag)
    {
      if (old_repr_deleted)
	{
	  printf (msgcat_message (MSGCAT_CATALOG_UTILS,
				  MSGCAT_UTIL_SET_COMPACTDB,
				  COMPACTDB_MSG_REPR_DELETED));
	}
      else
	{
	  printf (msgcat_message (MSGCAT_CATALOG_UTILS,
				  MSGCAT_UTIL_SET_COMPACTDB,
				  COMPACTDB_MSG_REPR_CANT_DELETE));
	}
    }
}
Esempio n. 9
0
static void
get_trigger_information (FILE * fp, DB_OBJECT * triggerobj)
{
    char *trigger_name, *action, *attr, *condition;
    DB_OBJECT *target_class;
    DB_TRIGGER_EVENT event;
    DB_TRIGGER_TIME eventtime, actiontime;
    DB_TRIGGER_ACTION action_type;
    DB_TRIGGER_STATUS status;
    double priority;
    char pri_string[10];

    trigger_name = action = NULL;

    /* trigger name */
    db_trigger_name (triggerobj, &trigger_name);
    fprintf (fp, MSGFMT, "name", trigger_name);
    if (trigger_name != NULL)
        db_string_free ((char *) trigger_name);

    /* eventtime */
    db_trigger_condition_time (triggerobj, &eventtime);
    switch (eventtime)
    {
    case TR_TIME_BEFORE:
        fprintf (fp, MSGFMT, "conditiontime", "BEFORE");
        break;
    case TR_TIME_AFTER:
        fprintf (fp, MSGFMT, "conditiontime", "AFTER");
        break;
    case TR_TIME_DEFERRED:
        fprintf (fp, MSGFMT, "conditiontime", "DEFERRED");
        break;
    case TR_TIME_NULL:
        break;
    }

    /* eventtype */
    db_trigger_event (triggerobj, &event);
    switch (event)
    {
    case TR_EVENT_UPDATE:
        fprintf (fp, MSGFMT, "eventtype", "UPDATE");
        break;
    case TR_EVENT_STATEMENT_UPDATE:
        fprintf (fp, MSGFMT, "eventtype", "STATEMENT UPDATE");
        break;
    case TR_EVENT_DELETE:
        fprintf (fp, MSGFMT, "eventtype", "DELETE");
        break;
    case TR_EVENT_STATEMENT_DELETE:
        fprintf (fp, MSGFMT, "eventtype", "STATEMENT DELETE");
        break;
    case TR_EVENT_INSERT:
        fprintf (fp, MSGFMT, "eventtype", "INSERT");
        break;
    case TR_EVENT_STATEMENT_INSERT:
        fprintf (fp, MSGFMT, "eventtype", "STATEMENT INSERT");
        break;

    case TR_EVENT_COMMIT:
        fprintf (fp, MSGFMT, "eventtype", "COMMIT");
        break;
    case TR_EVENT_ROLLBACK:
        fprintf (fp, MSGFMT, "eventtype", "ROLLBACK");
        break;
    default:
        break;
    }

    /* trigger action */
    db_trigger_action_type (triggerobj, &action_type);
    switch (action_type)
    {
    case TR_ACT_EXPRESSION:	/* act like TR_ACT_PRINT */
    case TR_ACT_PRINT:
        db_trigger_action (triggerobj, &action);
        fprintf (fp, MSGFMT, "action", action);
        if (action != NULL)
        {
            db_string_free ((char *) action);
        }
        break;

    case TR_ACT_REJECT:
        fprintf (fp, MSGFMT, "action", "REJECT");
        break;
    case TR_ACT_INVALIDATE:
        fprintf (fp, MSGFMT, "action", "INVALIDATE TRANSACTION");
        break;
    case TR_ACT_NULL:
        break;
    }

    /* target class & att */
    db_trigger_class (triggerobj, &target_class);
    if (target_class != NULL)
    {
        fprintf (fp, MSGFMT, "target_class", db_get_class_name (target_class));
    }

    db_trigger_attribute (triggerobj, &attr);
    if (attr != NULL)
    {
        fprintf (fp, MSGFMT, "target_att", attr);
        db_string_free ((char *) attr);
    }

    /* condition */
    db_trigger_condition (triggerobj, &condition);
    if (condition != NULL)
    {
        fprintf (fp, MSGFMT, "condition", condition);
        db_string_free ((char *) condition);
    }

    /* actiontime */
    db_trigger_action_time (triggerobj, &actiontime);
    switch (actiontime)
    {
    case TR_TIME_BEFORE:
        fprintf (fp, MSGFMT, "actiontime", "BEFORE");
        break;
    case TR_TIME_AFTER:
        fprintf (fp, MSGFMT, "actiontime", "AFTER");
        break;
    case TR_TIME_DEFERRED:
        fprintf (fp, MSGFMT, "actiontime", "DEFERRED");
        break;
    case TR_TIME_NULL:
        break;
    }

    /* status */
    db_trigger_status (triggerobj, &status);
    switch (status)
    {
    case TR_STATUS_ACTIVE:
        fprintf (fp, MSGFMT, "status", "ACTIVE");
        break;
    case TR_STATUS_INACTIVE:
        fprintf (fp, MSGFMT, "status", "INACTIVE");
        break;
    case TR_STATUS_INVALID:
        fprintf (fp, MSGFMT, "status", "INVALID");
    }

    /* priority */
    db_trigger_priority (triggerobj, &priority);
    sprintf (pri_string, "%4.5f", priority);
    fprintf (fp, MSGFMT, "priority", pri_string);
}