Exemple #1
0
static void
my_crs_printlist (FILE * fp, DB_QUERY_RESULT * result)
{
  DB_VALUE *value_list, *valp;
  int cnt, k;
  int pos;

  cnt = db_query_column_count (result);
  value_list = (DB_VALUE *) malloc (cnt * sizeof (DB_VALUE));
  if (value_list == NULL)
    {
      return;
    }

  fprintf (fp, "=================   Q U E R Y   R E S U L T S   "
	   "=================\n");
  fprintf (fp, "\n");

  pos = db_query_first_tuple (result);
  while (pos == DB_CURSOR_SUCCESS)
    {
      if (db_query_get_tuple_valuelist (result, cnt, value_list) != NO_ERROR)
	{
	  goto cleanup;
	}

      fprintf (fp, "\n ");

      for (k = 0, valp = value_list; k < cnt; k++, valp++)
	{
	  fprintf (fp, "  ");
	  if (DB_VALUE_TYPE (valp) == DB_TYPE_SET
	      || DB_VALUE_TYPE (valp) == DB_TYPE_MULTISET
	      || DB_VALUE_TYPE (valp) == DB_TYPE_SEQUENCE)
	    {
	      my_db_set_print (fp, DB_GET_SET (valp));
	    }
	  else
	    {
	      db_value_fprint (fp, valp);
	    }
	  fprintf (fp, "  ");
	}

      /* clear the value list */
      for (k = 0, valp = value_list; k < cnt; k++, valp++)
	{
	  db_value_clear (valp);
	}

      pos = db_query_next_tuple (result);
    }

  fprintf (fp, "\n");

cleanup:
  free (value_list);
}
Exemple #2
0
/*
 * cursor_fixup_set_vobjs() - if val is a set/seq of vobjs then
 * 			    turn it into a set/seq of vmops
 *   return: NO_ERROR on all ok, ER status( or ER_FAILED) otherwise
 *   val(in/out): a db_value
 */
static int
cursor_fixup_set_vobjs (DB_VALUE * value_p)
{
  DB_TYPE type;
  int rc, i, size;
  DB_VALUE element;
  DB_SET *set, *new_set;

  type = DB_VALUE_TYPE (value_p);
  if (!pr_is_set_type (type))
    {
      return ER_FAILED;
    }

  set = DB_GET_SET (value_p);
  size = db_set_size (set);

  if (cursor_has_set_vobjs (set) == false)
    {
      return set_convert_oids_to_objects (set);
    }

  switch (type)
    {
    case DB_TYPE_SET:
      new_set = db_set_create_basic (NULL, NULL);
      break;
    case DB_TYPE_MULTISET:
      new_set = db_set_create_multi (NULL, NULL);
      break;
    case DB_TYPE_SEQUENCE:
      new_set = db_seq_create (NULL, NULL, size);
      break;
    default:
      return ER_FAILED;
    }

  /* fixup element vobjs into vmops and add them to new */
  for (i = 0; i < size; i++)
    {
      if (db_set_get (set, i, &element) != NO_ERROR)
	{
	  db_set_free (new_set);
	  return ER_FAILED;
	}

      if (cursor_fixup_vobjs (&element) != NO_ERROR)
	{
	  db_set_free (new_set);
	  return ER_FAILED;
	}

      if (type == DB_TYPE_SEQUENCE)
	{
	  rc = db_seq_put (new_set, i, &element);
	}
      else
	{
	  rc = db_set_add (new_set, &element);
	}

      if (rc != NO_ERROR)
	{
	  db_set_free (new_set);
	  return ER_FAILED;
	}
    }

  pr_clear_value (value_p);

  switch (type)
    {
    case DB_TYPE_SET:
      DB_MAKE_SET (value_p, new_set);
      break;
    case DB_TYPE_MULTISET:
      DB_MAKE_MULTISET (value_p, new_set);
      break;
    case DB_TYPE_SEQUENCE:
      DB_MAKE_SEQUENCE (value_p, new_set);
      break;
    default:
      db_set_free (new_set);
      return ER_FAILED;
    }

  return NO_ERROR;
}
Exemple #3
0
/*
 * cursor_print_list () - Dump the content of the list file to the standard output
 *   return:
 *   query_id(in):
 *   list_id(in): List File Identifier
 */
void
cursor_print_list (QUERY_ID query_id, QFILE_LIST_ID * list_id_p)
{
  CURSOR_ID cursor_id;
  DB_VALUE *value_list_p, *value_p;
  int count, i, status;

  count = list_id_p->type_list.type_cnt;
  value_list_p = (DB_VALUE *) malloc (count * sizeof (DB_VALUE));
  if (value_list_p == NULL)
    {
      return;
    }

  fprintf (stdout,
	   "\n=================   Q U E R Y   R E S U L T S   =================\n\n");

  if (cursor_open (&cursor_id, list_id_p, false, false) == false)
    {
      free_and_init (value_list_p);
      return;
    }

  cursor_id.query_id = query_id;

  while (true)
    {
      status = cursor_next_tuple (&cursor_id);
      if (status != DB_CURSOR_SUCCESS)
	{
	  break;
	}

      if (cursor_get_tuple_value_list (&cursor_id, count, value_list_p) !=
	  NO_ERROR)
	{
	  goto cleanup;
	}

      fprintf (stdout, "\n ");

      for (i = 0, value_p = value_list_p; i < count; i++, value_p++)
	{
	  fprintf (stdout, "  ");

	  if (DB_VALUE_TYPE (value_p) == DB_TYPE_SET ||
	      DB_VALUE_TYPE (value_p) == DB_TYPE_MULTISET ||
	      DB_VALUE_TYPE (value_p) == DB_TYPE_SEQUENCE ||
	      DB_VALUE_TYPE (value_p) == DB_TYPE_VOBJ)
	    {
	      db_set_print (DB_GET_SET (value_p));
	    }
	  else
	    {
	      db_value_print (value_p);
	    }

	  db_value_clear (value_p);
	  fprintf (stdout, "  ");
	}
    }

  fprintf (stdout, "\n");

cleanup:

  cursor_close (&cursor_id);

  free_and_init (value_list_p);
  return;
}
Exemple #4
0
/*
 * process_value () - process a value
 *
 * return : error status
 *  value(in,out) - the processed value
 *
 */
static int
process_value (DB_VALUE * value)
{
  int return_value = 0;

  switch (DB_VALUE_TYPE (value))
    {
    case DB_TYPE_OID:
      {
	OID *ref_oid;
	OID ref_class_oid;

	ref_oid = DB_GET_OID (value);

	if (OID_ISNULL (ref_oid))
	  {
	    break;
	  }

	if (!heap_get_class_oid (NULL, ref_oid, &ref_class_oid))
	  {
	    OID_SET_NULL (ref_oid);
	    return_value = 1;
	    break;
	  }

	if (is_class (ref_oid, &ref_class_oid))
	  {
	    break;
	  }

#if defined(CUBRID_DEBUG)
	printf (msgcat_message (MSGCAT_CATALOG_UTILS,
				MSGCAT_UTIL_SET_COMPACTDB,
				COMPACTDB_MSG_REFOID),
		ref_oid->volid, ref_oid->pageid, ref_oid->slotid,
		ref_class_oid.volid, ref_class_oid.pageid,
		ref_class_oid.slotid);
#endif

	if (!heap_does_exist (NULL, ref_oid, &ref_class_oid))
	  {
	    OID_SET_NULL (ref_oid);
	    return_value = 1;
	  }

	break;
      }

    case DB_TYPE_POINTER:
    case DB_TYPE_MULTISET:
    case DB_TYPE_SEQUENCE:
    case DB_TYPE_SET:
      {
	return_value = process_set (DB_GET_SET (value));
	break;
      }

    default:
      break;
    }

  return return_value;
}
Exemple #5
0
/*
 * set_to_string() - convert set value to string
 *   return: formatted string
 *   value(in): set value to convert
 *   begin_notation(in): character to use to denote begin of set
 *   end_notation(in): character to use to denote end of set
 *   max_entries(in): maximum number of entries to convert. -1 for all
 *   plain_string(in): refine string for plain output
 */
static char *
set_to_string (DB_VALUE * value, char begin_notation, char end_notation, int max_entries, bool plain_string)
{
  int cardinality, total_string_length, i;
  char **string_array;
  char *return_string = NULL;
  DB_VALUE element;
  int set_error;
  DB_SET *set;

  set = DB_GET_SET (value);
  if (set == NULL)
    {
      return (NULL);
    }

  /* pre-fetch any objects in the set, this will prevent multiple server calls during set rendering */
  db_fetch_set (set, DB_FETCH_READ, 0);

  /* formerly we filtered out deleted elements here, now just use db_set_size to get the current size, including NULL & 
   * deleted elements */
  cardinality = db_set_size (set);

  if (cardinality < 0)
    {
      return (NULL);
    }
  else if (cardinality == 0)
    {
      char temp_buffer[4];

      i = 0;
      if (begin_notation != '\0')
	{
	  temp_buffer[i++] = begin_notation;
	}
      if (end_notation != '\0')
	{
	  temp_buffer[i++] = end_notation;
	}
      temp_buffer[i] = '\0';
      return (duplicate_string ((const char *) &(temp_buffer[0])));
    }

  if (max_entries != -1 && max_entries < cardinality)
    {
      cardinality = max_entries;
    }
  string_array = (char **) malloc ((cardinality + 2) * sizeof (char *));
  if (string_array == NULL)
    {
      return (NULL);
    }

  memset (string_array, 0, (cardinality + 2) * sizeof (char *));

  total_string_length = cardinality * 2;
  for (i = 0; i < cardinality; i++)
    {
      set_error = db_set_get (set, i, &element);
      if (set_error != NO_ERROR)
	{
	  goto finalize;
	}
      string_array[i] = csql_db_value_as_string (&element, NULL, plain_string);
      db_value_clear (&element);
      if (string_array[i] == NULL)
	{
	  string_array[i] = duplicate_string ("NULL");
	  if (string_array[i] == NULL)
	    {
	      goto finalize;
	    }
	}
      total_string_length += strlen (string_array[i]);
    }				/* for (i = 0; i < cardinality... */

  return_string = (char *) malloc (total_string_length + 4);
  if (return_string == NULL)
    {
      goto finalize;
    }

  if (begin_notation != '\0')
    {
      (void) sprintf (return_string, "%c%s", begin_notation, string_array[0]);
    }
  else
    {
      (void) strcpy (return_string, string_array[0]);
    }

  for (i = 1; i < cardinality; i++)
    {
      (void) strcat (return_string, ", ");
      (void) strcat (return_string, string_array[i]);
    }
  if (end_notation != '\0')
    {
      int len = strlen (return_string);

      return_string[len++] = end_notation;
      return_string[len] = '\0';
    }

finalize:
  for (i = 0; i < cardinality; i++)
    {
      if (string_array[i] == NULL)
	{
	  break;
	}
      free_and_init (string_array[i]);
    }
  free_and_init (string_array);

  return return_string;
}