Ejemplo n.º 1
0
static OID *
cursor_get_oid_from_vobj (OID * current_oid_p, int length)
{
  char *vobject_p;
  OR_BUF buffer;
  DB_VALUE value;
  DB_OBJECT *object_p, *tmp_object_p;

  vobject_p = (char *) current_oid_p;
  current_oid_p = NULL;
  or_init (&buffer, vobject_p, length);
  DB_MAKE_NULL (&value);

  if (cursor_copy_vobj_to_dbvalue (&buffer, &value) == NO_ERROR)
    {
      tmp_object_p = DB_GET_OBJECT (&value);

      if (vid_is_updatable (tmp_object_p) == true)
	{
	  object_p = vid_base_instance (tmp_object_p);

	  if (object_p && !WS_ISVID (object_p))
	    {
	      current_oid_p = WS_OID (object_p);
	    }
	}
    }

  return current_oid_p;
}
Ejemplo n.º 2
0
/*
 * csql_db_value_as_string() - convert DB_VALUE to string
 *   return: formatted string
 *   value(in): value to convert
 *   length(out): length of output string
 *   plain_output(in): refine string for plain output
 */
char *
csql_db_value_as_string (DB_VALUE * value, int *length, bool plain_string)
{
  char *result = NULL;
  int len = 0;

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

  switch (DB_VALUE_TYPE (value))
    {
    case DB_TYPE_BIGINT:
      result =
	bigint_to_string (DB_GET_BIGINT (value), default_bigint_profile.fieldwidth, default_bigint_profile.leadingzeros,
			  default_bigint_profile.leadingsymbol, default_bigint_profile.commas,
			  default_bigint_profile.format);
      if (result)
	{
	  len = strlen (result);
	}
      break;
    case DB_TYPE_INTEGER:
      result =
	bigint_to_string (DB_GET_INTEGER (value), default_int_profile.fieldwidth, default_int_profile.leadingzeros,
			  default_int_profile.leadingsymbol, default_int_profile.commas, default_int_profile.format);
      if (result)
	{
	  len = strlen (result);
	}
      break;
    case DB_TYPE_SHORT:
      result =
	bigint_to_string (SHORT_TO_INT (DB_GET_SHORT (value)), default_short_profile.fieldwidth,
			  default_short_profile.leadingzeros, default_short_profile.leadingsymbol,
			  default_short_profile.commas, default_short_profile.format);
      if (result)
	{
	  len = strlen (result);
	}
      break;
    case DB_TYPE_FLOAT:
      result =
	double_to_string ((double) DB_GET_FLOAT (value), default_float_profile.fieldwidth,
			  default_float_profile.precision, default_float_profile.leadingsign, NULL, NULL,
			  default_float_profile.leadingzeros, default_float_profile.trailingzeros,
			  default_float_profile.commas, default_float_profile.format);
      if (result)
	{
	  len = strlen (result);
	}
      break;
    case DB_TYPE_DOUBLE:
      result =
	double_to_string (DB_GET_DOUBLE (value), default_double_profile.fieldwidth, default_double_profile.precision,
			  default_double_profile.leadingsign, NULL, NULL, default_double_profile.leadingzeros,
			  default_double_profile.trailingzeros, default_double_profile.commas,
			  default_double_profile.format);
      if (result)
	{
	  len = strlen (result);
	}
      break;
    case DB_TYPE_NUMERIC:
      result = numeric_to_string (value, default_numeric_profile.commas);
      if (result)
	{
	  len = strlen (result);
	}
      break;
    case DB_TYPE_VARCHAR:
    case DB_TYPE_CHAR:
      {
	int dummy, bytes_size, decomp_size;
	bool need_decomp = false;
	char *str;
	char *decomposed = NULL;

	str = db_get_char (value, &dummy);
	bytes_size = db_get_string_size (value);
	if (bytes_size > 0 && DB_GET_STRING_CODESET (value) == INTL_CODESET_UTF8)
	  {
	    need_decomp =
	      unicode_string_need_decompose (str, bytes_size, &decomp_size, lang_get_generic_unicode_norm ());
	  }

	if (need_decomp)
	  {
	    decomposed = (char *) malloc (decomp_size * sizeof (char));
	    if (decomposed != NULL)
	      {
		unicode_decompose_string (str, bytes_size, decomposed, &decomp_size, lang_get_generic_unicode_norm ());

		str = decomposed;
		bytes_size = decomp_size;
	      }
	    else
	      {
		return NULL;
	      }
	  }

	result = string_to_string (str, default_string_profile.string_delimiter, '\0', bytes_size, &len, plain_string);

	if (decomposed != NULL)
	  {
	    free_and_init (decomposed);
	  }

      }
      break;
    case DB_TYPE_VARNCHAR:
    case DB_TYPE_NCHAR:
      {
	int dummy, bytes_size, decomp_size;
	bool need_decomp = false;
	char *str;
	char *decomposed = NULL;

	str = db_get_char (value, &dummy);
	bytes_size = db_get_string_size (value);
	if (bytes_size > 0 && DB_GET_STRING_CODESET (value) == INTL_CODESET_UTF8)
	  {
	    need_decomp =
	      unicode_string_need_decompose (str, bytes_size, &decomp_size, lang_get_generic_unicode_norm ());
	  }

	if (need_decomp)
	  {
	    decomposed = (char *) malloc (decomp_size * sizeof (char));
	    if (decomposed != NULL)
	      {
		unicode_decompose_string (str, bytes_size, decomposed, &decomp_size, lang_get_generic_unicode_norm ());

		str = decomposed;
		bytes_size = decomp_size;
	      }
	    else
	      {
		return NULL;
	      }
	  }

	result = string_to_string (str, default_string_profile.string_delimiter, 'N', bytes_size, &len, plain_string);

	if (decomposed != NULL)
	  {
	    free_and_init (decomposed);
	  }
      }
      break;
    case DB_TYPE_VARBIT:
    case DB_TYPE_BIT:
      result = bit_to_string (value, default_string_profile.string_delimiter, plain_string);
      if (result)
	{
	  len = strlen (result);
	}
      break;
    case DB_TYPE_OBJECT:
      result = object_to_string (DB_GET_OBJECT (value), get_object_print_format ());
      if (result == NULL)
	{
	  result = duplicate_string ("NULL");
	}
      if (result)
	{
	  len = strlen (result);
	}
      break;
    case DB_TYPE_VOBJ:
      result = object_to_string (DB_GET_OBJECT (value), get_object_print_format ());
      if (result == NULL)
	{
	  result = duplicate_string ("NULL");
	}
      if (result)
	{
	  len = strlen (result);
	}
      break;
    case DB_TYPE_SET:
    case DB_TYPE_MULTISET:
    case DB_TYPE_SEQUENCE:
      result =
	set_to_string (value, default_set_profile.begin_notation, default_set_profile.end_notation,
		       default_set_profile.max_entries, plain_string);
      if (result)
	{
	  len = strlen (result);
	}
      break;
    case DB_TYPE_TIME:
      {
	char buf[TIME_BUF_SIZE];
	if (db_time_to_string (buf, sizeof (buf), DB_GET_TIME (value)))
	  {
	    result = duplicate_string (buf);
	  }
	if (result)
	  {
	    len = strlen (result);
	  }
	break;
      }
    case DB_TYPE_TIMETZ:
      {
	char buf[TIMETZ_BUF_SIZE];
	DB_TIMETZ *time_tz = DB_GET_TIMETZ (value);
	if (db_timetz_to_string (buf, sizeof (buf), &(time_tz->time), &time_tz->tz_id))
	  {
	    result = duplicate_string (buf);
	  }

	if (result)
	  {
	    len = strlen (result);
	  }
      }
      break;
    case DB_TYPE_TIMELTZ:
      {
	char buf[TIMETZ_BUF_SIZE];

	if (db_timeltz_to_string (buf, sizeof (buf), DB_GET_TIME (value)))
	  {
	    result = duplicate_string (buf);
	  }

	if (result)
	  {
	    len = strlen (result);
	  }
      }
      break;
    case DB_TYPE_MONETARY:
      {
	char *leading_str = NULL;
	char *trailing_str = NULL;
	DB_CURRENCY currency = ((DB_GET_MONETARY (value))->type);

	if (default_monetary_profile.currency_symbol)
	  {
	    if (intl_get_currency_symbol_position (currency) == 1)
	      {
		trailing_str = intl_get_money_symbol_console (currency);
	      }
	    else
	      {
		leading_str = intl_get_money_symbol_console (currency);
	      }
	  }

	result =
	  (DB_GET_MONETARY (value) == NULL) ? NULL : double_to_string ((DB_GET_MONETARY (value))->amount,
								       default_monetary_profile.fieldwidth,
								       default_monetary_profile.decimalplaces,
								       default_monetary_profile.leadingsign,
								       leading_str, trailing_str,
								       default_monetary_profile.leadingzeros,
								       default_monetary_profile.trailingzeros,
								       default_monetary_profile.commas,
								       DOUBLE_FORMAT_DECIMAL);

	if (result)
	  {
	    len = strlen (result);
	  }
      }
      break;
    case DB_TYPE_DATE:
      /* default format for all locales */
      result = date_as_string (DB_GET_DATE (value), default_date_profile.format);
      if (result)
	{
	  len = strlen (result);
	}
      break;
    case DB_TYPE_UTIME:
      {
	char buf[TIMESTAMP_BUF_SIZE];
	if (db_utime_to_string (buf, sizeof (buf), DB_GET_UTIME (value)))
	  {
	    result = duplicate_string (buf);
	  }

	if (result)
	  {
	    len = strlen (result);
	  }
      }
      break;
    case DB_TYPE_TIMESTAMPTZ:
      {
	char buf[TIMESTAMPTZ_BUF_SIZE];
	DB_TIMESTAMPTZ *ts_tz = DB_GET_TIMESTAMPTZ (value);
	if (db_timestamptz_to_string (buf, sizeof (buf), &(ts_tz->timestamp), &(ts_tz->tz_id)))
	  {
	    result = duplicate_string (buf);
	  }

	if (result)
	  {
	    len = strlen (result);
	  }
      }
      break;
    case DB_TYPE_TIMESTAMPLTZ:
      {
	char buf[TIMESTAMPTZ_BUF_SIZE];

	if (db_timestampltz_to_string (buf, sizeof (buf), DB_GET_UTIME (value)))
	  {
	    result = duplicate_string (buf);
	  }

	if (result)
	  {
	    len = strlen (result);
	  }
      }
      break;
    case DB_TYPE_DATETIME:
      {
	char buf[DATETIME_BUF_SIZE];
	if (db_datetime_to_string (buf, sizeof (buf), DB_GET_DATETIME (value)))
	  {
	    result = duplicate_string (buf);
	  }

	if (result)
	  {
	    len = strlen (result);
	  }
      }
      break;
    case DB_TYPE_DATETIMETZ:
      {
	char buf[DATETIMETZ_BUF_SIZE];
	DB_DATETIMETZ *dt_tz = DB_GET_DATETIMETZ (value);
	if (db_datetimetz_to_string (buf, sizeof (buf), &(dt_tz->datetime), &(dt_tz->tz_id)))
	  {
	    result = duplicate_string (buf);
	  }

	if (result)
	  {
	    len = strlen (result);
	  }
      }
      break;
    case DB_TYPE_DATETIMELTZ:
      {
	char buf[DATETIMETZ_BUF_SIZE];

	if (db_datetimeltz_to_string (buf, sizeof (buf), DB_GET_DATETIME (value)))
	  {
	    result = duplicate_string (buf);
	  }

	if (result)
	  {
	    len = strlen (result);
	  }
      }
      break;
    case DB_TYPE_NULL:
      result = duplicate_string ("NULL");
      if (result)
	{
	  len = strlen (result);
	}
      break;

    case DB_TYPE_BLOB:
    case DB_TYPE_CLOB:
      {
	DB_ELO *elo = DB_GET_ELO (value);

	if (elo != NULL)
	  {
	    result = duplicate_string (elo->locator);
	  }

	if (result != NULL)
	  {
	    len = strlen (result);
	  }
      }
      break;

    case DB_TYPE_ENUMERATION:
      {
	int bytes_size, decomp_size;
	bool need_decomp = false;
	const char *str;
	char *decomposed = NULL;

	if (db_get_enum_short (value) == 0 && db_get_enum_string (value) == NULL)
	  {
	    /* ENUM special error value */
	    str = "";
	    bytes_size = 0;
	  }
	else
	  {
	    str = db_get_enum_string (value);
	    bytes_size = db_get_enum_string_size (value);
	  }
	if (bytes_size > 0 && db_get_enum_codeset (value) == INTL_CODESET_UTF8)
	  {
	    need_decomp =
	      unicode_string_need_decompose (str, bytes_size, &decomp_size, lang_get_generic_unicode_norm ());
	  }

	if (need_decomp)
	  {
	    decomposed = (char *) malloc (decomp_size * sizeof (char));
	    if (decomposed != NULL)
	      {
		unicode_decompose_string (str, bytes_size, decomposed, &decomp_size, lang_get_generic_unicode_norm ());

		str = decomposed;
		bytes_size = decomp_size;
	      }
	    else
	      {
		return NULL;
	      }
	  }

	result = string_to_string (str, default_string_profile.string_delimiter, '\0', bytes_size, &len, plain_string);
	if (decomposed != NULL)
	  {
	    free_and_init (decomposed);
	  }
      }
      break;

    default:
      {
	char temp_buffer[256];

	(void) sprintf (temp_buffer, "<%s>", db_get_type_name (DB_VALUE_TYPE (value)));
	result = duplicate_string (temp_buffer);
	if (result)
	  {
	    len = strlen (result);
	  }
      }
    }

  if (length)
    {
      *length = len;
    }
  return result;
}