DB_STATUS qeu_d6_cre_view( QEF_CB *qef_cb, QEUQ_CB *i_quq_p) { DB_STATUS status, sav_status = E_DB_OK; DB_ERROR sav_error; QEF_RCB qer, *qer_p = & qer; QES_DDB_SES *dds_p = & qef_cb->qef_c2_ddb_ses; QED_DDL_INFO *ddl_p = & qer_p->qef_r3_ddb_req.qer_d7_ddl_info; DD_LDB_DESC *cdb_p = & dds_p->qes_d4_ddb_p-> dd_d3_cdb_info.dd_i1_ldb_desc; QEC_L16_TABLES tables; /* used for IITABLES-style info */ QEC_D6_OBJECTS objects; /* used for object info */ QEC_LINK link, /* used as global control block */ *lnk_p = & link; QEQ_1CAN_QRY ins, sel, upd; /* used for ordering canned query */ RQB_BIND rq_bind[QEC_CAT_COL_COUNT_MAX + 1]; QEP_PTR_UNION ptr_u; DMU_CB *dmu_p; SYSTIME now; bool xact_b = FALSE; /* assume no begin transaction */ i4 xact_mode; 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; /* 1. check input information */ if (i_quq_p->qeuq_type != QEUQCB_CB || i_quq_p->qeuq_length != sizeof(*i_quq_p)) { i_quq_p->error.err_code = E_QE0017_BAD_CB; return(E_DB_ERROR); } if ((i_quq_p->qeuq_cq == 0 || i_quq_p->qeuq_qry_tup == 0) || (i_quq_p->qeuq_ct == 0 || i_quq_p->qeuq_tre_tup == 0) || (i_quq_p->qeuq_db_id == 0) || (i_quq_p->qeuq_d_id == 0) || (i_quq_p->qeuq_dmf_cb == 0)) { i_quq_p->error.err_code = E_QE0018_BAD_PARAM_IN_CB; return(E_DB_ERROR); } /* 2. set up control information */ MEfill(sizeof(qer), '\0', (PTR) & qer); qer_p->qef_cb = qef_cb; qer_p->error.err_code = 0; qer_p->qef_r3_ddb_req.qer_d13_ctl_info = QEF_00DD_NIL_INFO; qef_cb->qef_rcb = qer_p; MEcopy(dmu_p->dmu_table_name.db_tab_name, sizeof(ddl_p->qed_d1_obj_name), ddl_p->qed_d1_obj_name); MEcopy(dmu_p->dmu_owner.db_own_name, sizeof(ddl_p->qed_d2_obj_owner), ddl_p->qed_d2_obj_owner); ddl_p->qed_d3_col_count = i_quq_p->qeuq_ano; ddl_p->qed_d4_ddb_cols_pp = NULL; ddl_p->qed_d5_qry_info_p = NULL; ddl_p->qed_d6_tab_info_p = NULL; ddl_p->qed_d7_obj_id.db_tab_base = 0; ddl_p->qed_d7_obj_id.db_tab_index = 0; ddl_p->qed_d9_reg_info_p = NULL; sel.qeq_c2_rqf_bind_p = rq_bind; /* must set up */ ins.qeq_c2_rqf_bind_p = (RQB_BIND *) NULL; upd.qeq_c2_rqf_bind_p = (RQB_BIND *) NULL; lnk_p->qec_1_ddl_info_p = ddl_p; lnk_p->qec_2_tableinfo_p = NULL; lnk_p->qec_3_ldb_id = 0; lnk_p->qec_4_col_cnt = 0; MEfill(DB_DB_MAXNAME, ' ', lnk_p->qec_5_ldb_alias); lnk_p->qec_6_select_p = & sel; lnk_p->qec_7_ldbids_p = NULL; lnk_p->qec_8_longnames_p = NULL; lnk_p->qec_9_tables_p = & tables; lnk_p->qec_10_haves = QEC_07_CREATE; lnk_p->qec_11_ldb_obj_cnt = 0; lnk_p->qec_12_indexes_p = NULL; lnk_p->qec_13_objects_p = & objects; lnk_p->qec_15_ndx_cnt = 0; lnk_p->qec_16_ndx_ids_p = NULL; lnk_p->qec_19_ldb_p = NULL; lnk_p->qec_20_rqf_bind_p = rq_bind; lnk_p->qec_21_delete_p = NULL; lnk_p->qec_22_insert_p = & ins; lnk_p->qec_23_update_p = & upd; status = qed_u8_gmt_now(qer_p, lnk_p->qec_24_cur_time); if (status) { STRUCT_ASSIGN_MACRO(qer_p->error, i_quq_p->error); return(status); } lnk_p->qec_24_cur_time[DD_25_DATE_SIZE] = EOS; lnk_p->qec_25_pre_mins_p = NULL; lnk_p->qec_26_aft_mins_p = NULL; TMnow(& now); lnk_p->qec_17_ts1 = now.TM_secs; lnk_p->qec_18_ts2 = now.TM_msecs; /* transaction semantics ** ** 1. pre-processing: ** ** 1.1 if no outstanding transaction, begin a transaction ** and set xact_b to TRUE; ** 1.2 if not in auto-commit mode, escalate transaction to MST; ** ** 2. post-processing: ** ** 2.1 if processing terminates normally, commit transaction ** only if xact_b is TRUE and not in auto-commit mode; ** 2.2 if processing terminates abnormally, abort transaction ** only if xact_b is TRUE; */ /* 2. begin a transaction if necessary */ if (qef_cb->qef_stat == QEF_NOTRAN) { status = qet_begin(qef_cb); if (status) return(status); xact_b = TRUE; } if (qef_cb->qef_auto == QEF_OFF) qef_cb->qef_stat = QEF_MSTRAN; /* escalate to MST */ /* 3. inform TPF of read intention on CDB */ status = qet_t5_register(qer_p, cdb_p, DB_SQL, QEK_2TPF_READ); if (status) { if (! xact_b) { STRUCT_ASSIGN_MACRO(qer_p->error, i_quq_p->error); return(status); /* ok to return */ } /* fall thru to terminate SST */ } if (status == E_DB_OK) { /* 4. set up new object base, query id */ status = qeu_10_get_obj_base(qer_p, lnk_p); if (status) { if (! xact_b) { STRUCT_ASSIGN_MACRO(qer_p->error, i_quq_p->error); return(status); /* ok to return */ } /* fall thru to terminate SST */ } else { objects.d6_4_qry_id.db_qry_high_time = now.TM_secs; objects.d6_4_qry_id.db_qry_low_time = now.TM_msecs; } } if (status == E_DB_OK) { /* 5. inform TPF of update intention on CDB */ /* 5.1 2PC is required if DDL concurrency is off. */ if (dds_p->qes_d9_ctl_info & QES_01CTL_DDL_CONCURRENCY_ON) xact_mode = QEK_4TPF_1PC; else xact_mode = QEK_3TPF_UPDATE; status = qet_t5_register(qer_p, cdb_p, DB_SQL, xact_mode); if (status) { if (! xact_b) { STRUCT_ASSIGN_MACRO(qer_p->error, i_quq_p->error); return(status); /* ok to return */ } /* fall thru to terminate SST */ } } if (status == E_DB_OK) { /* 6. update IIDD_DDB_OBJECT_BASE */ status = qeu_11_object_base(qer_p, lnk_p); if (status) qef_cb->qef_abort = TRUE; } if (status == E_DB_OK) { /* 7. update IIDD_DDB_OBJECTS */ status = qeu_12_objects(qer_p, lnk_p); if (status) qef_cb->qef_abort = TRUE; } if (status == E_DB_OK) { /* 8. update IIDD_IITABLES */ status = qeu_13_tables(qer_p, i_quq_p, lnk_p); if (status) qef_cb->qef_abort = TRUE; } if (status == E_DB_OK) { /* 9. update IIDD_COLUMNS */ status = qeu_14_columns(qer_p, i_quq_p, lnk_p); if (status) qef_cb->qef_abort = TRUE; } if (status == E_DB_OK) { /* 10. update IIDD_VIEWS */ status = qeu_15_views(qer_p, i_quq_p, lnk_p); if (status) qef_cb->qef_abort = TRUE; } if (status == E_DB_OK) { /* 11. update IIDD_DDB_TREE */ status = qeu_16_tree(qer_p, i_quq_p, lnk_p); if (status) qef_cb->qef_abort = TRUE; } if (status == E_DB_OK) { /* 12. update IIDD_DDB_DDB_DBDEPENDS */ status = qeu_17_dbdepends(qer_p, i_quq_p, lnk_p); if (status) qef_cb->qef_abort = TRUE; } /* 13. end transaction if necessary */ if (status) { /* error condition */ sav_status = status; STRUCT_ASSIGN_MACRO(qer_p->error, sav_error); if (xact_b || qef_cb->qef_abort) /* SST or abort */ status = qet_abort(qef_cb); } else { /* ok condition */ if (xact_b && qef_cb->qef_auto == QEF_ON) status = qet_commit(qef_cb); /* commit SST */ else { /* send message to commit CDB association to avoid deadlocks */ status = qed_u11_ddl_commit(qef_cb->qef_rcb); } } if (sav_status) { /* returned saved error */ STRUCT_ASSIGN_MACRO(sav_error, i_quq_p->error); return(sav_status); } else if (status) { /* return qef_cb error */ STRUCT_ASSIGN_MACRO(qef_cb->qef_rcb->error, i_quq_p->error); return(status); } return(E_DB_OK); }
DB_STATUS qel_c0_cre_lnk( QEF_RCB *v_qer_p ) { DB_STATUS status; QEF_CB *qef_cb = v_qer_p->qef_cb; QES_DDB_SES *dds_p = & v_qer_p->qef_cb->qef_c2_ddb_ses; QED_DDL_INFO *ddl_p = & v_qer_p->qef_r3_ddb_req.qer_d7_ddl_info; DD_0LDB_PLUS *plus_p = & ddl_p->qed_d6_tab_info_p-> dd_t9_ldb_p->dd_i2_ldb_plus; DD_CAPS *caps_p = & plus_p->dd_p3_ldb_caps; DD_LDB_DESC ldb, /* for replicating LDB desc */ *ldb_p = & ldb, *cdb_p = & dds_p->qes_d4_ddb_p-> dd_d3_cdb_info.dd_i1_ldb_desc, *ddl_ldb_p = & ddl_p->qed_d6_tab_info_p-> dd_t9_ldb_p->dd_i1_ldb_desc; QEC_D9_TABLEINFO tabinfo; /* used for table info of link */ QEC_D2_LDBIDS ldbids; /* used for internal LDB id info */ QEC_D5_LONG_LDBNAMES longnames; /* used for excessively long LDB ** name */ QEC_L16_TABLES tables; /* used for IITABLES-style info */ QEC_D6_OBJECTS objects; /* used for object info */ QEC_L6_INDEXES indexes; QEC_MIN_CAP_LVLS pre_mins, aft_mins; QEC_LINK link, /* used as global control block */ *link_p = & link; QEQ_1CAN_QRY del, ins, sel, upd, /* used for ordering canned query */ *upd_p = & upd; u_i4 len; SYSTIME now; bool log_ddl_56 = FALSE, log_err_59 = FALSE; i4 i4_1, i4_2; QEC_INDEX_ID ndx_ids[QEK_0MAX_NDX_COUNT + 1]; /* working space for index ids */ RQB_BIND rq_bind[QEC_CAT_COL_COUNT_MAX + 1]; QEC_D7_OBJECT_BASE obj_base, *base_p = & obj_base; i4 xact_mode; char *cbuf = v_qer_p->qef_cb->qef_trfmt; i4 cbufsize = v_qer_p->qef_cb->qef_trsize; if (ult_check_macro(& qef_cb->qef_trace, QEF_TRACE_DDB_LOG_DDL_56, & i4_1, & i4_2)) { log_ddl_56 = TRUE; } if (ult_check_macro(& qef_cb->qef_trace, QEF_TRACE_DDB_LOG_ERR_59, & i4_1, & i4_2)) { log_err_59 = TRUE; } sel.qeq_c2_rqf_bind_p = rq_bind; /* must set up */ del.qeq_c2_rqf_bind_p = (RQB_BIND *) NULL; ins.qeq_c2_rqf_bind_p = (RQB_BIND *) NULL; upd.qeq_c2_rqf_bind_p = (RQB_BIND *) NULL; /* 1. set up control block */ if (dds_p->qes_d7_ses_state == QES_4ST_REFRESH) /* REGISTER WITH REFRESH ? */ STRUCT_ASSIGN_MACRO(ddl_p->qed_d7_obj_id, tabinfo.d9_1_obj_id); /* yes */ else /* no */ { tabinfo.d9_1_obj_id.db_tab_base = 0; /* unknown */ tabinfo.d9_1_obj_id.db_tab_index = 0; /* always 0 for non-index */ } link_p->qec_1_ddl_info_p = ddl_p; link_p->qec_2_tableinfo_p = & tabinfo; link_p->qec_3_ldb_id = 0; link_p->qec_4_col_cnt = 0; MEfill(DB_DB_MAXNAME, ' ', link_p->qec_5_ldb_alias); link_p->qec_6_select_p = & sel; link_p->qec_7_ldbids_p = & ldbids; link_p->qec_8_longnames_p = & longnames; link_p->qec_9_tables_p = & tables; link_p->qec_10_haves = QEC_07_CREATE; if (caps_p->dd_c6_name_case == DD_2CASE_UPPER) link_p->qec_10_haves |= QEC_06_UPPER_LDB; if (caps_p->dd_c1_ldb_caps & DD_7CAP_USE_PHYSICAL_SOURCE) link_p->qec_10_haves |= QEC_10_USE_PHY_SRC; if (caps_p->dd_c2_ldb_caps & DD_201CAP_DIFF_ARCH) link_p->qec_10_haves |= QEC_11_LDB_DIFF_ARCH; /* make a copy of the LDB descriptor for non-$ingrs access if necessary */ if (ddl_ldb_p->dd_l1_ingres_b) { /* make a copy for non-$ingres access */ STRUCT_ASSIGN_MACRO(*ddl_ldb_p, ldb); ldb_p->dd_l1_ingres_b = FALSE; ldb_p->dd_l5_ldb_id = DD_0_IS_UNASSIGNED; } else { /* use provided LDB descriptor but determine if LDB has a long name */ qed_u0_trimtail( ddl_ldb_p->dd_l3_ldb_name, (u_i4) DD_256_MAXDBNAME, ldb_p->dd_l3_ldb_name); len = STlength(ldb_p->dd_l3_ldb_name); if (len > DB_DB_MAXNAME) link_p->qec_10_haves |= QEC_04_LONG_LDBNAME; ldb_p = ddl_ldb_p; } link_p->qec_11_ldb_obj_cnt = 0; link_p->qec_12_indexes_p = & indexes; link_p->qec_13_objects_p = & objects; link_p->qec_15_ndx_cnt = 0; link_p->qec_16_ndx_ids_p = ndx_ids; link_p->qec_19_ldb_p = ldb_p; link_p->qec_20_rqf_bind_p = rq_bind; link_p->qec_21_delete_p = & del; link_p->qec_22_insert_p = & ins; link_p->qec_23_update_p = & upd; status = qed_u8_gmt_now(v_qer_p, link_p->qec_24_cur_time); if (status) return(status); link_p->qec_24_cur_time[DD_25_DATE_SIZE] = EOS; link_p->qec_25_pre_mins_p = & pre_mins; link_p->qec_26_aft_mins_p = & aft_mins; link_p->qec_27_select_cnt = 0; link_p->qec_28_iistats_cnt = 0; TMnow(& now); link_p->qec_17_ts1 = now.TM_secs; link_p->qec_18_ts2 = now.TM_msecs; /* 2. inform TPF of update intention on CDB (note that only CREATE does ** LDB retrievals */ /* 2.1 2PC is required if DDL concurrency is off. */ if (dds_p->qes_d9_ctl_info & QES_01CTL_DDL_CONCURRENCY_ON) xact_mode = QEK_4TPF_1PC; else xact_mode = QEK_3TPF_UPDATE; status = qet_t5_register(v_qer_p, cdb_p, DB_SQL, xact_mode); if (status) return(status); if (log_ddl_56) { /* display beginning, CDB and LDB info */ STprintf(cbuf, "\n%s %p: %s REGISTRATION begins%s\n", IIQE_61_qefsess, (PTR) v_qer_p->qef_cb, IIQE_65_tracing, IIQE_62_3dots); qec_tprintf(v_qer_p, cbufsize, cbuf); STprintf(cbuf, "%s %p: ...the CDB:\n", IIQE_61_qefsess, (PTR) v_qer_p->qef_cb); qec_tprintf(v_qer_p, cbufsize, cbuf); qed_w1_prt_ldbdesc(v_qer_p, cdb_p); STprintf(cbuf, "%s %p: ...the LDB:\n", IIQE_61_qefsess, (PTR) v_qer_p->qef_cb); qec_tprintf(v_qer_p, cbufsize, cbuf); qed_w1_prt_ldbdesc(v_qer_p, ldb_p); STprintf(cbuf, "\n"); qec_tprintf(v_qer_p, cbufsize, cbuf); } /* 3. update OBJECT_BASE in II_DD_DB_OBJECT_BASE */ upd_p->qeq_c1_can_id = UPD_716_DD_DDB_OBJECT_BASE; upd_p->qeq_c3_ptr_u.d7_object_base_p = base_p; upd_p->qeq_c4_ldb_p = cdb_p; status = qel_u1_update(v_qer_p, link_p); if (status) goto END_TRACING; /* 4. enter phase 1: set up necessary information */ status = qel_c1_cre_p1(v_qer_p, link_p); if (status) goto END_TRACING; /* 2. enter phase 2: promote information into STAR catalogs */ status = qel_c2_cre_p2(v_qer_p, link_p); if (status) v_qer_p->qef_cb->qef_abort = TRUE; END_TRACING: if (log_ddl_56) { /* display end tracing message */ STprintf(cbuf, "%s %p: %s REGISTRATION ends\n\n", IIQE_61_qefsess, (PTR) v_qer_p->qef_cb, IIQE_65_tracing); qec_tprintf(v_qer_p, cbufsize, cbuf); } return(status); }
DB_STATUS qeu_d5_alt_tab( QEF_RCB *v_qer_p, DMT_CB *i_dmt_p) { DB_STATUS status; QES_DDB_SES *dds_p = & v_qer_p->qef_cb->qef_c2_ddb_ses; DD_LDB_DESC *cdb_p = & dds_p->qes_d4_ddb_p->dd_d3_cdb_info.dd_i1_ldb_desc; QEC_D9_TABLEINFO tabinfo; /* dummy part of link */ QEC_D6_OBJECTS objects, *objs_p = & objects; QEC_L16_TABLES tables, *tabs_p = & tables; QEQ_1CAN_QRY upd, *upd_p = & upd; QEC_LINK link, *lnk_p = & link; DMT_CHAR_ENTRY *chr_p; bool err_b = FALSE; /* assume no error */ i4 xact_mode; MEfill(sizeof(link), '\0', (PTR) & link); lnk_p->qec_2_tableinfo_p = & tabinfo; lnk_p->qec_13_objects_p = objs_p; /* 1. vefify input parameters */ chr_p = (DMT_CHAR_ENTRY *) i_dmt_p->dmt_char_array.data_address; if (chr_p->char_id != DMT_C_ZOPTSTATS) err_b = TRUE; else { if (chr_p->char_value == DMT_C_ON) { tabs_p->l16_9_stats[0] = 'Y'; tabs_p->l16_9_stats[1] = EOS; } else if (chr_p->char_value == DMT_C_OFF) { tabs_p->l16_9_stats[0] = 'N'; tabs_p->l16_9_stats[1] = EOS; } else err_b = TRUE; } if (err_b) { status = qed_u2_set_interr(E_QE0018_BAD_PARAM_IN_CB, & v_qer_p->error); return(status); } /* 2. inform TPF of update */ /* 2.1 2PC is required if DDL concurrency is off. */ if (dds_p->qes_d9_ctl_info & QES_01CTL_DDL_CONCURRENCY_ON) xact_mode = QEK_4TPF_1PC; else xact_mode = QEK_3TPF_UPDATE; status = qet_t5_register(v_qer_p, cdb_p, DB_SQL, xact_mode); if (status) return(status); /* 3. set up to update TABLE_STATS and MODIFY_DATE of IIDD_TABLES */ qed_u0_trimtail( (char *) & i_dmt_p->dmt_table, DB_TAB_MAXNAME, tabs_p->l16_1_tab_name); qed_u0_trimtail( (char *) & i_dmt_p->dmt_owner, DB_OWN_MAXNAME, tabs_p->l16_2_tab_owner); status = qed_u8_gmt_now(v_qer_p, tabs_p->l16_21_mod_date); if (status) return(status); tabs_p->l16_21_mod_date[DD_25_DATE_SIZE] = EOS; upd_p->qeq_c1_can_id = UPD_731_DD_TABLES; upd_p->qeq_c2_rqf_bind_p = NULL; upd_p->qeq_c3_ptr_u.l16_tables_p = tabs_p; upd_p->qeq_c4_ldb_p = cdb_p; lnk_p->qec_23_update_p = upd_p; status = qel_u1_update(v_qer_p, lnk_p); if (status) { return(status); } return(E_DB_OK); }