void rf_att_dflt(i4 NumRels, char *RelList[]) { FE_ATT_QBLK qblk; FE_ATT_INFO attinfo; FE_REL_INFO relinfo; register ATTRIB id; i4 i = 0; bool RepeatedField; char ColName [FE_MAXNAME + 1]; i4 ins = 0; FE_RSLV_NAME *rfa_ferslv[MQ_MAXRELS]; RFCOLDESC *coldesc; ATT *attptr; char *cname; ATTRIB did; i4 real_cols; char dsply_name[(FE_UNRML_MAXNAME + 1)]; /* ** If the user went through the choose columns path, we will ** use that information to create the structures since we ** alredy have all the needed information. */ if (IIRFcccount != 0) { En_n_attribs = IIRFcccount; real_cols = IIRFcccount - IIRFcdcount; /* Allocate memory for the ATT array. */ if ((Ptr_att_top = (ATT *)FEreqmem((u_i4)Rst4_tag, (u_i4)(IIRFcccount*(sizeof(ATT))), TRUE, (STATUS *)NULL)) == NULL) { IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - Ptr_att_top")); } /* ** Step through the set of column names. Deleted ones are ** placed at the end of the array. We need to keep them ** around so that the user can add them back in the layout ** frame. */ for (i = 0, id = 0, did = real_cols, coldesc = IIRFcollist; i < IIRFcccount; i++, coldesc++) { if (coldesc->deleted) { attptr = &(Ptr_att_top[did++]); attptr->pre_deleted = TRUE; } else { attptr = &(Ptr_att_top[id++]); } cname = coldesc->name; attptr->att_name = FEtsalloc(Rst4_tag, cname); /* check if attribute name is a keyword */ if (!St_silent && (r_gt_pcode(cname) != PC_ERROR || r_gt_wcode(cname) != A_ERROR || r_gt_vcode(cname) != VC_NONE || r_gt_cagg(cname) || STcompare(cname, NAM_REPORT) == 0 || STcompare(cname, NAM_PAGE) == 0 || STcompare(cname, NAM_DETAIL) == 0)) { IIUGmsg(ERget(S_RF0047_Column_name_keyword), (bool) FALSE, 1, cname); } /* set up the data type field */ attptr->att_value.db_datatype = coldesc->datatype; attptr->att_prev_val.db_datatype = coldesc->datatype; attptr->att_value.db_length = coldesc->length; attptr->att_prev_val.db_length = coldesc->length; attptr->att_value.db_prec = coldesc->prec; attptr->att_prev_val.db_prec = coldesc->prec; /* ** Do not allocate value buffers for un-supported datatypes. ** We already let the user know that they're being ignored ** when we passed through ChooseColumns, so don't do it again! */ if (!IIAFfedatatype(&attptr->att_value)) { attptr->att_value.db_data = (PTR)NULL; attptr->att_prev_val.db_data = (PTR)NULL; } else { if ((attptr->att_value.db_data = (PTR)FEreqmem((u_i4)Rst4_tag, (u_i4)(attptr->att_value.db_length), TRUE, (STATUS *)NULL)) == NULL) { IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - db_data")); } if ((attptr->att_prev_val.db_data = (PTR)FEreqmem((u_i4)Rst4_tag, (u_i4)(attptr->att_prev_val.db_length), TRUE, (STATUS *)NULL)) == NULL) { IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - prev db_data")); } } /* flag to indicate when done */ attptr->att_position = 0; attptr->att_lac = NULL; } return; } /* ** determine number of attributes in base table: */ for (i = 0; i < NumRels; i ++) { /* ** Decompose any owner.tablename, validate the components, ** and normalize them for later use. */ if ((rfa_ferslv[i] = (FE_RSLV_NAME *)MEreqmem((u_i4)0, (u_i4)sizeof(FE_RSLV_NAME),TRUE, (STATUS *)NULL)) == (FE_RSLV_NAME *)NULL) { IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - rfa_ferslv")); } if ((rfa_ferslv[i]->name_dest = (char *)MEreqmem((u_i4)0, (u_i4)(FE_UNRML_MAXNAME+1),TRUE,(STATUS *)NULL)) == NULL) { IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - name_dest")); } if ((rfa_ferslv[i]->owner_dest = (char *)MEreqmem((u_i4)0, (u_i4)(FE_UNRML_MAXNAME+1),TRUE,(STATUS *)NULL)) == NULL) { IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - owner_dest")); } rfa_ferslv[i]->name = RelList[i]; rfa_ferslv[i]->is_nrml = FALSE; FE_decompose(rfa_ferslv[i]); if ((rfa_ferslv[i]->owner_spec) && (((STcompare(IIUIcsl_CommonSQLLevel(),UI_LEVEL_65) < 0) && (IIUIdcd_dist() == FALSE) || IIUIdcd_dist() == TRUE && (STcompare(IIUIcsl_CommonSQLLevel(), UI_LEVEL_61) < 0)))) { continue; } if ((IIUGdlm_ChkdlmBEobject(rfa_ferslv[i]->name_dest, rfa_ferslv[i]->name_dest, rfa_ferslv[i]->is_nrml) == UI_BOGUS_ID) || ((rfa_ferslv[i]->owner_spec) && ((IIUGdlm_ChkdlmBEobject(rfa_ferslv[i]->owner_dest, rfa_ferslv[i]->owner_dest, rfa_ferslv[i]->is_nrml) == UI_BOGUS_ID) && STcompare(rfa_ferslv[i]->owner_dest, UI_FE_CAT_ID_65)))) { continue; } if (FE_resolve(rfa_ferslv[i],rfa_ferslv[i]->name_dest, rfa_ferslv[i]->owner_dest)) { En_n_attribs += FEnumatts(rfa_ferslv[i]->name_dest, rfa_ferslv[i]->owner_dest); } } /* ** Allocate array of ATT structures: */ if ((Ptr_att_top = (ATT *)FEreqmem((u_i4)Rst4_tag, (u_i4)(En_n_attribs*(sizeof(ATT))), TRUE, (STATUS *)NULL)) == NULL) { IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - Ptr_att_top")); } /* ** For each relation fill out the ATT structures: */ id = 0; if (En_SrcTyp == JDRepSrc) _VOID_ r_JDMaintTabList(JD_TAB_INIT_INS_CNT, NULL, NULL, NULL, NULL); for (i = 0; i < NumRels; i ++) { /* ** open access to base table */ /* ** Fill out relinfo with table information, including table owner. */ FErel_ffetch(rfa_ferslv[i]->name_dest,rfa_ferslv[i]->owner_dest, &relinfo); MEfree((PTR)rfa_ferslv[i]->name_dest); MEfree((PTR)rfa_ferslv[i]->owner_dest); MEfree((PTR)rfa_ferslv[i]); FEatt_fopen(&qblk, &relinfo); if (En_SrcTyp == JDRepSrc) _VOID_ r_JDMaintTabList(JD_TAB_TAB_ADV_INS_CNT, NULL, relinfo.name, relinfo.owner, &ins); /* ** For each attribute in table, fill ATT structure ** (make sure no DB access will take place in this loop!) */ while (FEatt_fetch(&qblk, &attinfo) == OK) { register ATT *r_att; register ATTRIB chk_id; register char *attname; attname = attinfo.column_name; /* ** Check for duplicate column names. If found one, and ** the source of data is not a JoinDef we have a problem, ** Bug #5952: */ RepeatedField = FALSE; chk_id = id - 1; while ((--chk_id >= 0) && (!RepeatedField)) { register ATT *chk_p = &(Ptr_att_top[chk_id]); if (STcompare(chk_p->att_name, attname) == 0) RepeatedField = TRUE; } if ((RepeatedField) && (En_SrcTyp == TabRepSrc)) { r_error(0x2C8, FATAL, attname, NULL); } /* ** Make sure that if the source of data is a JoinDef ** the attribute is being used, and if it's being used ** in more than one table get the constructed name for ** it. Be sure and include the owner in the table look-up! */ if (En_SrcTyp == JDRepSrc) { i4 cnt = 0; /* ** If we can't find the field then it's not being used so ** skip it: */ if (!r_JDMaintAttrList(JD_ATT_GET_FIELD_CNT, r_JDTabNameToRv(relinfo.name, relinfo.owner, ins), attname, &cnt)) continue; if (cnt > 1) { _VOID_ r_JDMaintAttrList(JD_ATT_GET_ATTR_NAME, r_JDTabNameToRv(relinfo.name, relinfo.owner, ins), attname, &ColName [0]); attname = ColName; } } r_att = &(Ptr_att_top[id++]); r_att->att_name = FEtsalloc(Rst4_tag, attname); /* check if attribute name is a keyword */ if (!St_silent && (r_gt_pcode(attname) != PC_ERROR || r_gt_wcode(attname) != A_ERROR || r_gt_vcode(attname) != VC_NONE || r_gt_cagg(attname) || STcompare(attname, NAM_REPORT) == 0 || STcompare(attname, NAM_PAGE) == 0 || STcompare(attname, NAM_DETAIL) == 0)) { IIUGmsg(ERget(S_RF0047_Column_name_keyword), (bool) FALSE, 1, attname); } /* set up the data type field */ r_att->att_value.db_datatype = attinfo.adf_type; r_att->att_prev_val.db_datatype = attinfo.adf_type; r_att->att_value.db_length = attinfo.intern_length; r_att->att_prev_val.db_length = attinfo.intern_length; r_att->att_value.db_prec = attinfo.intern_prec; r_att->att_prev_val.db_prec = attinfo.intern_prec; /* ** Do not allocate value buffers for un-supported datatypes. ** Let the user know that they're being ignored. */ if (!IIAFfedatatype(&r_att->att_value)) { _VOID_ IIUGxri_id(&attinfo.column_name[0], &dsply_name[0]); IIUGerr(E_RW1414_ignored_attrib, UG_ERR_ERROR,1,&dsply_name[0]); r_att->att_value.db_data = (PTR)NULL; r_att->att_prev_val.db_data = (PTR)NULL; } else { if ((r_att->att_value.db_data = (PTR)FEreqmem((u_i4)Rst4_tag, (u_i4)(r_att->att_value.db_length), TRUE, (STATUS *)NULL)) == NULL) { IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - db_data")); } if ((r_att->att_prev_val.db_data = (PTR)FEreqmem((u_i4)Rst4_tag, (u_i4)(r_att->att_prev_val.db_length), TRUE, (STATUS *)NULL)) == NULL) { IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - prev db_data")); } } r_att->att_position = 0; /* flag to indicate when done */ r_att->att_lac = NULL; } FEatt_close(&qblk); } /* for */ /* ** Just in case if we have skipped any attributes, ** we're leaking memory though: Note that unsupported ** datatypes will not be reflected as skipped as far as the ** id count is concerned! */ En_n_attribs = id; return; }
ADF_CB * FEadfcb () { if (!done) { char *cp; DB_STATUS rval; PTR srv_cb_ptr; SIZE_TYPE srv_size; SIZE_TYPE dbinfo_size; PTR dbinfoptr; STATUS tmtz_status; STATUS date_status; char date_type_alias[100]; char col[] = "udefault"; STATUS status = OK; CL_ERR_DESC sys_err; ADUUCETAB *ucode_ctbl; /* unicode collation information */ PTR ucode_cvtbl; done = TRUE; /* first, get the size of the ADF's server control block */ srv_size = adg_srv_size(); /* allocate enough memory for it */ if ((srv_cb_ptr = MEreqmem(0, srv_size, FALSE, (STATUS *)NULL)) == NULL) { EXsignal(EXFEBUG, 1, ERx("FEadfcb(alloc)")); } /* ** Fix up code so that "now" works properly for frontends. ** Only allocating enough for one (1) dbmsinfo() request. */ dbinfo_size = sizeof(ADF_TAB_DBMSINFO); if ((dbinfoptr = MEreqmem(0, dbinfo_size, TRUE, (STATUS*)NULL)) == NULL) { IIUGbmaBadMemoryAllocation(ERx("FEadfcb")); } dbinfo = (ADF_TAB_DBMSINFO *) dbinfoptr; dbinfo->tdbi_next = NULL; dbinfo->tdbi_prev = NULL; dbinfo->tdbi_length = dbinfo_size; dbinfo->tdbi_type = ADTDBI_TYPE; dbinfo->tdbi_s_reserved = -1; dbinfo->tdbi_l_reserved = (PTR)-1; dbinfo->tdbi_owner = (PTR)-1; dbinfo->tdbi_ascii_id = ADTDBI_ASCII_ID; dbinfo->tdbi_numreqs = 1; /* ** Now define request. */ dbinfo->tdbi_reqs[0].dbi_func = IIUGnfNowFunc; dbinfo->tdbi_reqs[0].dbi_num_inputs = 0; dbinfo->tdbi_reqs[0].dbi_lenspec.adi_lncompute = ADI_FIXED; STcopy("_BINTIM", dbinfo->tdbi_reqs[0].dbi_reqname); dbinfo->tdbi_reqs[0].dbi_reqcode = 1; dbinfo->tdbi_reqs[0].dbi_lenspec.adi_fixedsize = 4; dbinfo->tdbi_reqs[0].dbi_dtr = DB_INT_TYPE; /* ** set timezone in ADF cb - Any errors must be reported ** after adg_init() called. */ if ( (tmtz_status = TMtz_init(&cb.adf_tzcb)) == OK) { tmtz_status = TMtz_year_cutoff(&cb.adf_year_cutoff); } /* Always use INGRESDATE by default, and check ** 'ii.<node>.config.date_alias' (kibro01) b118702 */ cb.adf_date_type_alias = AD_DATE_TYPE_ALIAS_INGRES; STprintf(date_type_alias,ERx("ii.%s.config.date_alias"),PMhost()); date_status = PMget(date_type_alias, &cp); if (date_status == OK && cp != NULL && STlength(cp)) { if (STbcompare(cp, 0, ERx("ansidate"), 0, 1) == 0) cb.adf_date_type_alias = AD_DATE_TYPE_ALIAS_ANSI; else if (STbcompare(cp, 0, ERx("ingresdate"), 0, 1) == 0) cb.adf_date_type_alias = AD_DATE_TYPE_ALIAS_INGRES; else cb.adf_date_type_alias = AD_DATE_TYPE_ALIAS_NONE; } /* set timezone table to NULL in ADF cb, adg_init() will fill it */ /* cb.adf_tz_table = NULL; - not needed, done in declaration above */ /* Start up ADF */ rval = adg_startup(srv_cb_ptr, srv_size, dbinfo, 0); if (DB_FAILURE_MACRO(rval)) { /* ** Before bailing out, try to be helpful. Since the environment ** is likely not set up correctly, write hard coded messages ** since error message fetch will likely fail in this situation. */ char *tempchar; i4 dummy; LOCATION temploc; NMgtAt("II_SYSTEM", &tempchar); if (tempchar && *tempchar) { LOfroms(PATH, tempchar, &temploc); if (LOexist(&temploc)) { tempchar = ERx("FEadfcb: II_SYSTEM DOES NOT EXIST\n"); SIwrite(STlength(tempchar), tempchar, &dummy, stderr); } else { NMloc(ADMIN, FILENAME, ERx("config.dat"), &temploc); if (LOexist(&temploc)) { tempchar = ERx("FEadfcb: II_SYSTEM IS NOT SET CORRECTLY\n"); SIwrite(STlength(tempchar), tempchar, &dummy, stderr); } } } else { tempchar = ERx("FEadfcb: II_SYSTEM IS NOT SET\n"); SIwrite(STlength(tempchar), tempchar, &dummy, stderr); } EXsignal(EXFEBUG, 1, ERx("FEadfcb(start)")); } /* put the pointer to ADF's server control block in the ADF_CB */ cb.adf_srv_cb = srv_cb_ptr; /* set up the error message buffer */ cb.adf_errcb.ad_ebuflen = DB_ERR_SIZE; cb.adf_errcb.ad_errmsgp = ebuffer; /* initialize the ADF_CB */ rval = adg_init(&cb); if (DB_FAILURE_MACRO(rval)) { EXsignal(EXFEBUG, 1, ERx("FEadfcb(init)")); } /* find out which natural language we should speak */ cb.adf_slang = iiuglcd_langcode(); /* Always QUEL; for SQL explictly change this with 'IIAFdsDmlSet()'. */ cb.adf_qlang = DB_QUEL; /* lets get the multinational info */ /* ** Defaults for all of these are initially set statically, above. */ NMgtAt(ERx("II_DATE_FORMAT"), &cp); if ( cp != NULL && *cp != EOS ) { FEapply_date_format(&cb,cp); } NMgtAt(ERx("II_MONEY_FORMAT"), &cp); if ( cp != NULL && *cp != EOS ) { FEapply_money_format(&cb,cp); } NMgtAt(ERx("II_MONEY_PREC"), &cp); if ( cp != NULL && *cp != EOS ) { FEapply_money_prec(&cb,cp); } NMgtAt(ERx("II_DECIMAL"), &cp); if ( cp != NULL && *cp != EOS ) { FEapply_decimal(&cb,cp); } NMgtAt(ERx("II_UNICODE_SUBS"), &cp); if ( !cp ) { cb.adf_unisub_status = AD_UNISUB_OFF; } else { /* As with SET unicode_substitution take the first char */ cb.adf_unisub_status = AD_UNISUB_ON; *cb.adf_unisub_char = cp[0]; } NMgtAt(ERx("II_NULL_STRING"), &cp); if ( cp != NULL && *cp != EOS ) { FEapply_null(&cb,cp); } /* If there was a Timezone error other than the expected ingbuild ** error TM_PMFILE_OPNERR, then lets report it now. */ if (tmtz_status && (tmtz_status != TM_PMFILE_OPNERR)) { LOCATION loc_root; STATUS status = OK; status = NMloc(FILES, PATH, ERx("zoneinfo"), &loc_root); #if defined(conf_BUILD_ARCH_32_64) && defined(BUILD_ARCH64) status = LOfaddpath(&loc_root, ERx("lp64"), &loc_root); #endif #if defined(conf_BUILD_ARCH_64_32) && defined(BUILD_ARCH32) { /* ** Reverse hybrid support must be available in ALL ** 32bit binaries */ char *rhbsup; NMgtAt("II_LP32_ENABLED", &rhbsup); if ( (rhbsup && *rhbsup) && ( !(STbcompare(rhbsup, 0, "ON", 0, TRUE)) || !(STbcompare(rhbsup, 0, "TRUE", 0, TRUE)))) status = LOfaddpath(&loc_root, "lp32", &loc_root); } #endif /* ! LP64 */ if ( status == OK ) { status = LOexist(&loc_root); } if ( status == OK ) { IIUGerr(tmtz_status, 0, 0); /* As this may disappear from the screen quickly, ** let's pause to allow the users to reflect on the ** fact that the timezone info is (probably) wrong. */ if (!IIugefa_err_function) PCsleep(5000); } } /* Initialize unicode collation for UTF8 installations */ if (CMischarset_utf8()) { if (status = aduucolinit(col, MEreqmem, &ucode_ctbl, &ucode_cvtbl, &sys_err)) { EXsignal(EXFEBUG, 1, ERx("FEadfcb(alloc)")); } cb.adf_ucollation = (PTR) ucode_ctbl; /* Set unicode normalization to NFC just in case ** Front end will need it. */ if ((status = adg_setnfc(&cb)) != E_DB_OK) EXsignal(EXFEBUG, 1, ERx("FEadfcb(alloc)")); } /* lets not do this again! */ } return &cb; }
VOID r_rep_load () { char *outname; char *tempname; /* start of routine */ r_open_db(); /* open database. If not there, abort */ STtrmwhite(En_report); /* start object-oriented facility for retrieving reports */ IIOOinit((OO_OBJECT **)NULL); En_rid = -1; /* set up report environment. */ if (St_style==RS_NULL && (St_ispec || r_env_set())) { /* report found. Read in report specifications */ if (!St_silent) { SIprintf(ERget(F_RW0005_Reading_report_spec)); SIflush(stdout); } r_rco_set(); /* read in the RCOMMANDS table into core */ } else { /* no report found. Use report name */ if (St_repspec) { /* error because report does not exist */ r_error(0x3F7, FATAL, En_report, NULL); } En_rtype = RT_DEFAULT; En_ferslv.name = En_report; if ((En_ferslv.name_dest = (char *)FEreqmem((u_i4)Rst4_tag, (u_i4)(FE_MAXNAME+1),TRUE,(STATUS *)NULL)) == NULL) { IIUGbmaBadMemoryAllocation( ERx("r_rep_loadld - name_dest")); } if ((En_ferslv.owner_dest = (char *)FEreqmem((u_i4)Rst4_tag, (u_i4)(FE_MAXNAME+1),TRUE,(STATUS *)NULL)) == NULL) { IIUGbmaBadMemoryAllocation( ERx("r_rep_loadld - owner_dest")); } /* ** If the server supports delimited identifiers, then ** ensure that .DELIMID is enabled since we're doing a report ** based upon a table, and it may require such services. */ if (IIUIdlmcase() != UI_UNDEFCASE) { St_xns_given = TRUE; } } /* ** set up (and maybe prompt for) declared variables */ r_dcl_set(TRUE); if ((En_qlang == FEDMLSQL) && (IIUIdbdata()->firstAutoCom == FALSE)) { IIUIautocommit(UI_AC_OFF); } if( r_sc_qry(Ptr_set_top) == FAIL ) { return; } IIUIdlmcase(); /* Hack for bug 96801 ingcbt198 */ if(!r_chk_dat()) /* check for a valid data relation */ { return; } if( !r_sendqry())/* send the query to the backend */ { return; } if (!r_att_dflt()) /* set up ATT structures for each */ { /* attribute in the data relation */ return; } if (En_rtype == RT_DEFAULT) { /* set up the default report */ if (!St_silent) { SIprintf(ERget(F_RW0006_Setting_up_default)); SIflush(stdout); } /* Set up first column as a sort column */ if (!r_m_dsort()) { r_error(0x416,NONFATAL,NULL); return; } } if (!r_srt_set()) /* set up the SORT data structures */ { /* bad RSORT */ r_error(0x0C, FATAL, NULL); } /* set up the BRK data structures ** for each sort attribute with a ** RACTION tuple defined for it */ if( !r_brk_set()) { return; } /* ** If there is a .PAGEWIDTH command and no -l flag has been specified ** on the commandline, then reset En_lmax. (The -l flag overrides the ** .PAGEWIDTH command). (#129, #588) */ if( STlength(En_pg_width) > 0 && !St_lspec) { /* If the pagewidth value is preceded by * a dollar, evaluate it as a parameter */ r_g_set(En_pg_width); if( r_g_skip() == TK_DOLLAR ) { CMnext(Tokchar); outname = r_g_name(); if( (tempname = r_par_get(outname)) == NULL ) { r_error(0x3F0, FATAL, outname, NULL); } STcopy(tempname, En_pg_width); } /* need to convert to a number and set it to En_lmax */ if (CVan(En_pg_width, &En_lmax) != OK) { /* Unable to convert so ignore input */ r_error(0x403, NONFATAL, outname, NULL); } } if (En_rtype == RT_DEFAULT) { /* set up default report */ r_m_rprt(); } else { Tcmd_tag = FEbegintag(); r_tcmd_set(); /* set up the tcmd data structures */ FEendtag(); } r_lnk_agg(); /* set up the CLR and OP structures for ** fast processing of aggregates. */ return; }