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); }
/* * db_seq_insert() - This function inserts a value into a sequence at the * specified position. All elements starting from that position will be * shifted down to make room for the new element. As with other sequence * building functions, the domain of the value must be compatible with the * domain of the sequence. The sequence will automatically grow to make room * for the new value. Any existing slots that contain NULL will not be * reused because NULL is a valid sequence element. If the index is beyond * the length of the sequence, the sequence will grow and the value is * appended. * return : error code * set(in): sequence descriptor * index(in): element index * value(in): value to insert */ int db_seq_insert (DB_SET * set, int index, DB_VALUE * value) { int error = NO_ERROR; CHECK_CONNECT_ERROR (); CHECK_1ARG_ERROR (set); /* Check if modifications are disabled only if the set is owned */ if (set->owner != NULL) { CHECK_MODIFICATION_ERROR (); } if ((value != NULL) && (DB_VALUE_TYPE (value) > DB_TYPE_LAST)) { ERROR_SET (error, ER_OBJ_INVALID_ARGUMENTS); } else { error = set_insert_element (set, index, value); } return (error); }
/* * cursor_has_set_vobjs () - * return: nonzero iff set has some vobjs, zero otherwise * seq(in): set/sequence db_value */ static bool cursor_has_set_vobjs (DB_SET * set) { int i, size; DB_VALUE element; size = db_set_size (set); for (i = 0; i < size; i++) { if (db_set_get (set, i, &element) != NO_ERROR) { return false; } if (DB_VALUE_TYPE (&element) == DB_TYPE_VOBJ) { pr_clear_value (&element); return true; } pr_clear_value (&element); } return false; }
static PARSER_VARCHAR * sl_print_pk (PARSER_CONTEXT * parser, SM_CLASS * sm_class, DB_VALUE * key) { PARSER_VARCHAR *buffer = NULL; PARSER_VARCHAR *value = NULL; DB_MIDXKEY *midxkey; SM_ATTRIBUTE *pk_att; SM_CLASS_CONSTRAINT *pk_cons; pk_cons = classobj_find_class_primary_key (sm_class); if (pk_cons == NULL || pk_cons->attributes == NULL || pk_cons->attributes[0] == NULL) { return NULL; } if (DB_VALUE_TYPE (key) == DB_TYPE_MIDXKEY) { midxkey = db_get_midxkey (key); buffer = sl_print_midxkey (parser, pk_cons->attributes, midxkey); } else { pk_att = pk_cons->attributes[0]; value = describe_value (parser, NULL, key); buffer = pt_append_nulstring (parser, buffer, "\""); buffer = pt_append_nulstring (parser, buffer, pk_att->header.name); buffer = pt_append_nulstring (parser, buffer, "\""); buffer = pt_append_nulstring (parser, buffer, "="); buffer = pt_append_varchar (parser, buffer, value); } return buffer; }
/* * 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; }
/* * 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; }
/* * 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; }
/* * 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; }