/*{ ** Name: psq_dtdump - Dump a datatype id ** ** Description: ** This function dumps a datatype id in human-readable form. ** ** Inputs: ** dt_id The datatype id to dump ** ** Outputs: ** None ** Returns: ** E_DB_OK Success ** E_DB_ERROR Non-catastrophic failure ** E_DB_FATAL Catastrophic failure ** Exceptions: ** None ** ** Side Effects: ** Sends output to terminal and/or log file ** ** History: ** 29-may-86 (jeff) ** written ** 14-nov-88 (stec) ** Initialize ADF_CB on the stack. ** 10-Jan-2001 (jenjo02) ** Use ADF_CB* from session control block ** instead of SCU_INFORMATION. */ DB_STATUS psq_dtdump( DB_DT_ID dt_id) { ADI_DT_NAME adt_name; PSS_SESBLK *sess_cb; ADF_CB *adf_cb; PTR ad_errmsgp; /* Get ADF_CB* from session control block */ sess_cb = psf_sesscb(); adf_cb = (ADF_CB*)sess_cb->pss_adfcb; /* Preserve and restore ad_errmsgp */ ad_errmsgp = adf_cb->adf_errcb.ad_errmsgp; adf_cb->adf_errcb.ad_errmsgp = NULL; if (adi_tyname(adf_cb, dt_id, &adt_name) == E_DB_OK) { TRdisplay("%#s", sizeof (adt_name.adi_dtname), adt_name.adi_dtname); } else { TRdisplay("Bad datatype id %d", dt_id); } adf_cb->adf_errcb.ad_errmsgp = ad_errmsgp; return (E_DB_OK); }
/*{ ** Name: PSQ_TCNVT - convert db_data_value to text form ** ** Description: ** This routine takes any user supplied db_data_value and converts ** it to the value's textual representation. This is required for the ** iiqrytext catalog. It is assumed that all datavalues can be written ** into a character representation. ** ** Inputs: ** sess_cb session control block ** .pss_adfcb adf session control block for output ** arguments. ** header Pointer to chain header ** dbval db_data_value ** result Place to put pointer to new piece ** err_blk Filled in if an error happens ** ** Outputs: ** result Filled in with pointer to chain element ** err_blk Filled in if an error happens ** Returns: ** E_DB_OK Success ** E_DB_ERROR Non-catastrophic failure ** E_DB_FATAL Catastrophic failure ** Exceptions: ** none ** ** Side Effects: ** Allocates memory ** ** History: ** 29-jun-87 (daved) ** written ** 28-jan-91 (andre) ** fix bug 35446: size of a new piece should include quotes, if they ** were added. ** 18-nov-91 (rog) ** Fixed bug 40869, et alia: the above fix missed adding the quotes ** to the total size and not just the piece size. ** 23-Sep-2009 (kiria01) b122578 ** Initialise the ADF_FN_BLK .adf_fi_desc and adf_dv_n members. ** 19-Aug-2010 (kschendel) b124282 ** Make sure fi-desc is always set to something. */ DB_STATUS psq_tcnvt( PSS_SESBLK *sess_cb, PTR header, DB_DATA_VALUE *dbval, PTR *result, DB_ERROR *err_blk) { PSQ_THEAD *hp; PSQ_TEXT *tp; i4 err_code; DB_STATUS status; ADF_CB *adf_cb; ADF_FN_BLK adffn; i4 dv_size; i4 count; char *cptr; char *quote_char; DB_TEXT_STRING *string; ADI_DT_NAME dt_fname; ADI_DT_NAME dt_tname; char f4_style; char f8_style; i4 f4_width; i4 f8_width; i4 f4_prec; i4 f8_prec; i4 totype; i4 is_string; hp = (PSQ_THEAD *) header; adf_cb = (ADF_CB *) sess_cb->pss_adfcb; status = E_DB_OK; totype = (DB_DT_ID) DB_LTXT_TYPE; adffn.adf_r_dv.db_datatype = totype; if (dbval->db_datatype == totype) dv_size = dbval->db_length; else dv_size = 0; /* JRBCMT -- PSF is not allowed to know this!! First of all, date is */ /* missing from the list below and decimal will soon need to be on it. */ /* But also, we need to fix this code so that it doesn't make */ /* assumptions about what types exist. I think the proper approach is */ /* to quote all non-intrinsic types, but this should be investigated. */ /* are we dealing with a string type (incoming). */ if (abs(dbval->db_datatype) == DB_INT_TYPE || abs(dbval->db_datatype) == DB_FLT_TYPE || abs(dbval->db_datatype) == DB_MNY_TYPE || abs(dbval->db_datatype) == DB_BOO_TYPE) { is_string = FALSE; quote_char = (char *) NULL; } else { is_string = TRUE; quote_char = (sess_cb->pss_lang == DB_SQL) ? "\'" : "\""; } /* set the floating point conversion display */ f4_style = adf_cb->adf_outarg.ad_f4style; f8_style = adf_cb->adf_outarg.ad_f8style; f4_width = adf_cb->adf_outarg.ad_f4width; f8_width = adf_cb->adf_outarg.ad_f8width; f4_prec = adf_cb->adf_outarg.ad_f4prec; f8_prec = adf_cb->adf_outarg.ad_f8prec; adf_cb->adf_outarg.ad_f4style = 'n'; adf_cb->adf_outarg.ad_f8style = 'n'; adf_cb->adf_outarg.ad_f4width = 20; adf_cb->adf_outarg.ad_f8width = 20; adf_cb->adf_outarg.ad_f4prec = 10; adf_cb->adf_outarg.ad_f8prec = 10; /* get the function instance id for this conversion */ status = adi_ficoerce(adf_cb, dbval->db_datatype, totype, &adffn.adf_fi_id); if (status != E_DB_OK) { goto exit; } /* determine the result size. */ status = adi_fidesc(adf_cb, adffn.adf_fi_id, &adffn.adf_fi_desc); if (status != E_DB_OK) { goto exit; } if (!dv_size) { /* Now lets fill in the datatype length info and allocate space for the ** data. */ status = adi_0calclen(adf_cb, &adffn.adf_fi_desc->adi_lenspec, 1, &dbval, &adffn.adf_r_dv); dv_size = adffn.adf_r_dv.db_length; if (status != E_DB_OK) { goto exit; } } /* if string, add room for quotes */ if (is_string) dv_size += 2 * CMbytecnt(quote_char); /* Allocate enough space for PSQ_TEXT structure containing piece */ hp->psq_tmem.ulm_psize = dv_size + sizeof(PSQ_TEXT) - 1; status = ulm_palloc(&hp->psq_tmem); if (status != E_DB_OK) { if (hp->psq_tmem.ulm_error.err_code == E_UL0005_NOMEM) { psf_error(E_PS0F02_MEMORY_FULL, 0L, PSF_CALLERR, &err_code, err_blk, 0); } else (VOID) psf_error(E_PS0371_ALLOC_TEXT_CHAIN, hp->psq_tmem.ulm_error.err_code, PSF_INTERR, &err_code, err_blk, 0); return (status); } *result = hp->psq_tmem.ulm_pptr; tp = (PSQ_TEXT*) *result; string = (DB_TEXT_STRING*) tp->psq_tval; /* Fill in text piece */ adffn.adf_r_dv.db_length = dv_size; adffn.adf_r_dv.db_data = (PTR) string; adffn.adf_dv_n = 1; STRUCT_ASSIGN_MACRO(*dbval, adffn.adf_1_dv); adffn.adf_pat_flags = AD_PAT_DOESNT_APPLY; if ((status = adf_func(adf_cb, &adffn)) != E_DB_OK) { goto exit; } /* CAUTION: entering tricky code. ** string is a variable containing a text datatype. We want to convert ** to a C datatype. We also want to add quote characters if the datatype ** was a string type. We grab the count from the string variable first. ** we can then use the 2 byte count for character data. */ count = string->db_t_count; cptr = (char *) string; if (is_string) { /* ** for strings, copy the opening quote (" or ', depending on language) */ CMcpychar(quote_char, cptr); cptr += CMbytecnt(quote_char); } MEcopy((PTR) string->db_t_text, count, (PTR) cptr); cptr += count; if (is_string) { /* ** for strings, copy the closing quote (" or ', depending on language) */ CMcpychar(quote_char, cptr); } /* if storing a string, do not forget to account for quotes (bug 35446) */ tp->psq_psize = (is_string) ? count + 2 * CMbytecnt(quote_char) : count; /* Hook it up to the chain */ tp->psq_next = (PSQ_TEXT *) NULL; if (hp->psq_last != (PSQ_TEXT *) NULL) { hp->psq_last->psq_next = tp; tp->psq_prev = hp->psq_last; } else { tp->psq_prev = NULL; } hp->psq_last = tp; if (hp->psq_first == (PSQ_TEXT *) NULL) hp->psq_first = tp; /* Add in the length to the total for the chain */ hp->psq_tsize += tp->psq_psize; exit: /* set the floating point conversion display */ adf_cb->adf_outarg.ad_f4style = f4_style; adf_cb->adf_outarg.ad_f8style = f8_style; adf_cb->adf_outarg.ad_f4width = f4_width; adf_cb->adf_outarg.ad_f8width = f8_width; adf_cb->adf_outarg.ad_f4prec = f4_prec; adf_cb->adf_outarg.ad_f8prec = f8_prec; if (status != E_DB_OK) { (VOID) adi_tyname(adf_cb, dbval->db_datatype, &dt_fname); (VOID) adi_tyname(adf_cb, totype, &dt_tname); (VOID) psf_error(2911L, 0L, PSF_USERERR, &err_code, err_blk, 3, sizeof (sess_cb->pss_lineno), &sess_cb->pss_lineno, psf_trmwhite(sizeof(dt_fname), (char *) &dt_fname), &dt_fname, psf_trmwhite(sizeof (dt_tname), (char *) &dt_tname), &dt_tname); return (E_DB_ERROR); } return (status); }
DB_STATUS qeu_14_columns( QEF_RCB *i_qer_p, QEUQ_CB *i_quq_p, QEC_LINK *v_lnk_p) { DB_STATUS status; QES_DDB_SES *dds_p = & i_qer_p->qef_cb->qef_c2_ddb_ses; QED_DDL_INFO *ddl_p = v_lnk_p->qec_1_ddl_info_p; DD_LDB_DESC *cdb_p = & dds_p->qes_d4_ddb_p->dd_d3_cdb_info.dd_i1_ldb_desc; QEC_L3_COLUMNS dd_columns, *columns_p = & dd_columns; /* tuple struct */ QEQ_1CAN_QRY *ins_p = v_lnk_p->qec_22_insert_p; QEP_PTR_UNION ptr_u; DMU_CB *dmu_p; DMF_ATTR_ENTRY **col_pp, *curcol_p; i4 colnum, coltype, postype; QEC_LONGNAT_TO_I4 coerce; ADI_DT_NAME adi_dname; ptr_u.qep_ptr_u.qep_1_ptr = i_quq_p->qeuq_dmf_cb; dmu_p = ptr_u.qep_ptr_u.qep_3_dmu_cb_p; ptr_u.qep_ptr_u.qep_1_ptr = dmu_p->dmu_attr_array.ptr_address; col_pp = ptr_u.qep_ptr_u.qep_4_dmu_attr_pp; /* 1. set up constant values for all columns */ qed_u0_trimtail( ddl_p->qed_d1_obj_name, DB_OBJ_MAXNAME, columns_p->l3_1_tab_name); qed_u0_trimtail( ddl_p->qed_d2_obj_owner, DB_OWN_MAXNAME, columns_p->l3_2_tab_owner); columns_p->l3_10_seq_in_key = 0; for (colnum = 0; colnum < i_quq_p->qeuq_ano; colnum++, col_pp++) { curcol_p = *col_pp; /* 2. fill in specific information for current column */ qed_u0_trimtail( curcol_p->attr_name.db_att_name, DB_ATT_MAXNAME, columns_p->l3_3_col_name); coerce.qec_i4_i4.qec_1_i4 = curcol_p->attr_type; coltype = coerce.qec_i4_i4.qec_2_i4; if (coltype < 0) { columns_p->l3_7_nulls[0] = 'Y'; postype = -coltype; /* must make positive */ } else { columns_p->l3_7_nulls[0] = 'N'; postype = coltype; } columns_p->l3_7_nulls[1] = EOS; /* call adi_tyname to get data type name */ status = adi_tyname(i_qer_p->qef_adf_cb, postype, &adi_dname); if (status == E_DB_OK) STcopy(adi_dname.adi_dtname, columns_p->l3_4_data_type); else { status = qed_u2_set_interr(E_QE0018_BAD_PARAM_IN_CB, & i_qer_p->error); return(status); } coerce.qec_i4_i4.qec_1_i4 = curcol_p->attr_size; columns_p->l3_5_length = coerce.qec_i4_i4.qec_2_i4; coerce.qec_i4_i4.qec_1_i4 = curcol_p->attr_precision; columns_p->l3_6_scale = coerce.qec_i4_i4.qec_2_i4; if (curcol_p->attr_flags_mask & DMU_F_NDEFAULT) columns_p->l3_8_defaults[0] = 'N'; else columns_p->l3_8_defaults[0] = 'Y'; columns_p->l3_8_defaults[1] = EOS; columns_p->l3_9_seq_in_row = colnum + 1; columns_p->l3_10_seq_in_key = 0; /* none */ columns_p->l3_11_sort_dir[0] = 'A'; /* assume ascending */ columns_p->l3_11_sort_dir[1] = EOS; /* null terminate */ columns_p->l3_12_ing_datatype = coltype; /* 3. insert into IIDD_COLUMNS */ ins_p->qeq_c1_can_id = INS_602_DD_COLUMNS; ins_p->qeq_c3_ptr_u.l3_columns_p = columns_p; ins_p->qeq_c4_ldb_p = cdb_p; status = qel_i1_insert(i_qer_p, v_lnk_p); if (status) return(status); } return(E_DB_OK); }