DB_STATUS qee_d2_tmp( QEF_RCB *qef_rcb, QEE_DSH *dsh, ULM_RCB *ulm) { DB_STATUS status = E_DB_OK; QEF_QP_CB *qp_p = dsh->dsh_qp_ptr; QEQ_DDQ_CB *ddq_p = & qp_p->qp_ddq_cb; QEE_DDB_CB *qee_p = dsh->dsh_ddb_cb; DB_CURSOR_ID *csr_p; if (ddq_p->qeq_d3_elt_cnt > 0) { SYSTIME tm_now, tm_last; char hi_ascii[QEK_015_LEN], lo_ascii[QEK_015_LEN], /* pid_ascii[QEK_015_LEN], */ temp[QEK_050_LEN+DB_MAXNAME];/* must be > DB_MAXNAME */ DD_TAB_NAME *name_p; i4 *long_p; /* PID pid; ** an i4 ** */ i4 m, n; char *p, *q; u_i2 hi_len, /* lo_len, */ tmp_len; #define QEE_10SQL_NAME_LEN 10 /* allocate space for array of temporary-table names and ** generate their names */ /* 1. allocate array for DD_TAB_NAMEs */ ulm->ulm_psize = ddq_p->qeq_d3_elt_cnt * sizeof(DD_TAB_NAME); if (status = qec_malloc(ulm)) { qef_rcb->error.err_code = ulm->ulm_error.err_code; qed_u10_trap(); return(status); } qee_p->qee_d1_tmp_p = (DD_TAB_NAME *) ulm->ulm_pptr; /* ptr to array of DD_TAB_NAMEs */ /* 2. allocate array for i4 status */ ulm->ulm_psize = ddq_p->qeq_d3_elt_cnt * sizeof(i4); if (status = qec_malloc(ulm)) { qef_rcb->error.err_code = ulm->ulm_error.err_code; qed_u10_trap(); return(status); } qee_p->qee_d2_sts_p = (i4 *) ulm->ulm_pptr; /* ptr to array of i4s */ /* initialize both allocated arrays */ name_p = qee_p->qee_d1_tmp_p; long_p = qee_p->qee_d2_sts_p; tm_last.TM_secs = 0; tm_last.TM_msecs = 0; /* PCpid(& pid); ** get process (server) id ** CVla(pid, pid_ascii); ** convert to ascii ** */ for (n = 0; n < ddq_p->qeq_d3_elt_cnt; n++) { /* 3. generate temporary table name */ TMnow(& tm_now); if (tm_now.TM_secs == tm_last.TM_secs) { if (tm_now.TM_msecs <= tm_last.TM_msecs) tm_now.TM_msecs = tm_last.TM_msecs + 1; } CVla(tm_now.TM_secs, hi_ascii); CVla(tm_now.TM_msecs, lo_ascii); hi_len = STlength(hi_ascii); /* transpose the hi_ascii string to get lower digits */ p = hi_ascii; q = hi_ascii + hi_len - 1; /* backup past EOS */ for (m = 0; m < (i4) hi_len - 1; m++) /* do length - 1 characters */ { *p = *q; p++; q--; } STpolycat((i4) 3, /* 3 constituent pieces */ "z", lo_ascii, hi_ascii, temp); tmp_len = STlength(temp); /* use at most 10 characters */ if (tmp_len > QEE_10SQL_NAME_LEN) tmp_len = QEE_10SQL_NAME_LEN; MEmove(tmp_len, temp, ' ', sizeof(DD_TAB_NAME), (char *)name_p); STRUCT_ASSIGN_MACRO(tm_now, tm_last); /* save for comparison */ name_p++; /* pt to next slot */ /* 4. initialize status word for this table */ *long_p = QEE_00M_NIL; long_p++; /* pt to next status word */ } /* for */ } else { qee_p->qee_d1_tmp_p = (DD_TAB_NAME *) NULL; qee_p->qee_d2_sts_p = (i4 *) NULL; } /* 5. initialize */ qee_p->qee_d3_status = QEE_00Q_NIL; if (! (qp_p->qp_status & QEQP_RPT)) { /* initialize if not repeat query */ csr_p = & qee_p->qee_d4_given_qid; csr_p->db_cursor_id[0] = 0; csr_p->db_cursor_id[1] = 0; MEfill(DB_CURSOR_MAXNAME, ' ', (PTR) csr_p->db_cur_name); } csr_p = & qee_p->qee_d5_local_qid; csr_p->db_cursor_id[0] = 0; csr_p->db_cursor_id[1] = 0; MEfill(DB_CURSOR_MAXNAME, ' ', (PTR) csr_p->db_cur_name); return(status); }
DB_STATUS qee_d3_agg( QEF_RCB *qef_rcb, QEE_DSH *dsh, ULM_RCB *ulm) { DB_STATUS status = E_DB_OK; QEF_QP_CB *qp_p = dsh->dsh_qp_ptr; QEQ_DDQ_CB *ddq_p = & qp_p->qp_ddq_cb; QEE_DDB_CB *qee_p = dsh->dsh_ddb_cb; QEQ_D1_QRY *sub_p; DB_DATA_VALUE *dv1_p, *dv2_p; if (ddq_p->qeq_d4_total_cnt == 0) return(E_DB_OK); /* no aggregate actions */ qee_p->qee_d6_dynamic_cnt = ddq_p->qeq_d4_total_cnt - ddq_p->qeq_d5_fixed_cnt; /* 1. allocate array for DB_DATA_VALUEs */ ulm->ulm_psize = (ddq_p->qeq_d4_total_cnt + 1) * sizeof(DB_DATA_VALUE); /* 1-based */ if (status = qec_malloc(ulm)) { qef_rcb->error.err_code = ulm->ulm_error.err_code; qed_u10_trap(); return(status); } qee_p->qee_d7_dv_p = (DB_DATA_VALUE *) ulm->ulm_pptr; /* ptr to array */ /* 2. copy user's parameters if any */ if (ddq_p->qeq_d5_fixed_cnt > 0) { i4 m; dv1_p = ddq_p->qeq_d6_fixed_data; dv2_p = qee_p->qee_d7_dv_p + 1; /* 1-based */ for (m = 0; m < ddq_p->qeq_d5_fixed_cnt; ++m) { STRUCT_ASSIGN_MACRO(*dv1_p, *dv2_p); ++dv1_p; ++dv2_p; } } if (qee_p->qee_d6_dynamic_cnt > 0) { QEF_AHD *act_p = qp_p->qp_ahd; i4 maxbind = 0, aggcnt, ptrcnt, i, j; char **pp; /* 3. allocate space for array of ptrs to aggregate spaces */ ptrcnt = ddq_p->qeq_d4_total_cnt + 1; ulm->ulm_psize = ptrcnt * sizeof(char *); /* extra ptr space for safety */ if (status = qec_malloc(ulm)) { qef_rcb->error.err_code = ulm->ulm_error.err_code; qed_u10_trap(); return(status); } qee_p->qee_d8_attr_pp = (char **) ulm->ulm_pptr; /* ptr to ptrs to attribute space */ pp = qee_p->qee_d8_attr_pp; for (i = 0; i < ptrcnt; i++, pp++) *pp = (char *) NULL; pp = qee_p->qee_d8_attr_pp + 1; /* initialize as 1-based */ /* 4. traverse the action list to allocate space for aggregates */ aggcnt = 0; for (i = 0; i < qp_p->qp_ahd_cnt && act_p; ++i) { char *attr_p; i4 curaggsize = 0; if (act_p->ahd_atype == QEA_D6_AGG) { /* 5. allocate space to hold intermediate results ** for current aggregate action */ sub_p = & act_p->qhd_obj.qhd_d1_qry; if (sub_p->qeq_q6_col_cnt > maxbind) maxbind = sub_p->qeq_q6_col_cnt; /* record maximum bind space */ aggcnt += sub_p->qeq_q6_col_cnt; ulm->ulm_psize = sub_p->qeq_q10_agg_size; if (status = qec_malloc(ulm)) { qef_rcb->error.err_code = ulm->ulm_error.err_code; qed_u10_trap(); return(status); } *pp = (char *) ulm->ulm_pptr; /* set ptr to attribute space */ /* 6. set up DB_DATA_VALUE ptr for current aggregate action */ dv1_p = sub_p->qeq_q9_dv_p; /* ptr to expected DB_DATA_VALUEs */ dv2_p = qee_p->qee_d7_dv_p + sub_p->qeq_q11_dv_offset; /* ptr into DB_DATA_VALUE array */ curaggsize = 0; attr_p = *pp; for (j = 0; j < sub_p->qeq_q6_col_cnt; ++j) { STRUCT_ASSIGN_MACRO(*dv1_p, *dv2_p); dv2_p->db_data = (PTR) attr_p; attr_p += DB_ALIGN_MACRO(dv1_p->db_length); curaggsize += DB_ALIGN_MACRO(dv1_p->db_length); ++dv1_p; ++dv2_p; } if (curaggsize != sub_p->qeq_q10_agg_size) { qed_u10_trap(); status = qed_u2_set_interr(E_QE1995_BAD_AGGREGATE_ACTION, & qef_rcb->error); return(status); } ++pp; /* advance to pt to next slot */ } act_p = act_p->ahd_next; /* advance */ } if (aggcnt != qee_p->qee_d6_dynamic_cnt || maxbind <= 0) { qed_u10_trap(); status = qed_u2_set_interr(E_QE1999_BAD_QP, & qef_rcb->error); return(status); } /* 7. allocate max space for RQB_BIND array */ ulm->ulm_psize = maxbind * sizeof(RQB_BIND); if (status = qec_malloc(ulm)) { qef_rcb->error.err_code = ulm->ulm_error.err_code; qed_u10_trap(); return(status); } qee_p->qee_d9_bind_p = (PTR) ulm->ulm_pptr; /* ptr to RQR_BIND array */ } return(status); }
DB_STATUS qeq_c4_open( QEF_RCB *v_qer_p, QEE_DSH *v_dsh_p ) { DB_STATUS status = E_DB_OK; QEF_CB *qef_cb = v_qer_p->qef_cb; QEF_AHD *act_p = (QEF_AHD *) NULL, *def_act_p = (QEF_AHD *) NULL; i4 def_act_cnt = 0, get_act_cnt = 0, lnk_act_cnt = 0; QEQ_D1_QRY *sub_p = (QEQ_D1_QRY *) NULL; bool read_b = FALSE, last_b = FALSE, val_qp_51 = FALSE, log_qry_55 = FALSE, log_err_59 = FALSE; i4 i4_1, i4_2; if (ult_check_macro(& v_qer_p->qef_cb->qef_trace, QEF_TRACE_DDB_LOG_QRY_55, & i4_1, & i4_2)) { log_qry_55 = TRUE; qeq_p31_opn_csr(v_qer_p, v_dsh_p);; } if (ult_check_macro(& v_qer_p->qef_cb->qef_trace, QEF_TRACE_DDB_LOG_ERR_59, & i4_1, & i4_2)) log_err_59 = TRUE; /* verify that the following conditions are true of the query plan: ** ** 1) there is exactly one last QEA_D7_OPN action, ** 2) there are no QEA_D2_GET, QEA_D4_LNK actions, ** 3) there are no read actions */ act_p = v_dsh_p->dsh_qp_ptr->qp_ahd; while (act_p != (QEF_AHD *) NULL) { if (act_p->ahd_atype == QEA_D7_OPN) { def_act_cnt++; if (act_p->ahd_next == (QEF_AHD *) NULL) last_b = TRUE; } else if (act_p->ahd_atype == QEA_D2_GET) get_act_cnt++; else if (act_p->ahd_atype == QEA_D4_LNK) lnk_act_cnt++; else if (act_p->ahd_atype == QEA_D1_QRY) { sub_p = & act_p->qhd_obj.qhd_d1_qry; if (sub_p->qeq_q3_ctl_info & QEQ_001_READ_TUPLES) read_b = TRUE; } act_p = act_p->ahd_next; } if (! last_b || def_act_cnt != 1 || get_act_cnt != 0 || lnk_act_cnt != 0 || read_b) { if (log_err_59 && !log_qry_55) qeq_p31_opn_csr(v_qer_p, v_dsh_p);; status = qed_u2_set_interr(E_QE1999_BAD_QP, & v_qer_p->error); return(status); } qee_d1_qid(v_dsh_p); /* generate query id for ** sending to LDB */ /* process each action in the QP */ for (act_p = v_dsh_p->dsh_qp_ptr->qp_ahd; act_p != (QEF_AHD *)NULL; act_p = act_p->ahd_next) { /* check for deferred cursor, only one at a time is allowed */ if (act_p->ahd_flags & QEA_DEF) { v_dsh_p->dsh_qp_status |= DSH_DEFERRED_CURSOR; if (qef_cb->qef_defr_curs) { qed_u10_trap(); v_qer_p->error.err_code = E_QE0026_DEFERRED_EXISTS; return(E_DB_ERROR); } } switch (act_p->ahd_atype) { case QEA_D1_QRY: case QEA_D8_CRE: case QEA_D9_UPD: status = qeq_d1_qry_act(v_qer_p, & act_p); if (status) qed_u10_trap(); break; case QEA_D3_XFR: status = qeq_d5_xfr_act(v_qer_p, act_p); if (status) qed_u10_trap(); break; case QEA_D6_AGG: status = qeq_d10_agg_act(v_qer_p, act_p); if (status) qed_u10_trap(); break; case QEA_D7_OPN: def_act_p = act_p; /* keep track */ status = qeq_d8_def_act(v_qer_p, act_p); if (status) qed_u10_trap(); break; default: status = qed_u1_gen_interr(& v_qer_p->error); qed_u10_trap(); break; } if (! status) v_dsh_p->dsh_act_ptr = act_p; /* promote to current dsh */ } /* cleanup done by caller */ v_dsh_p->dsh_act_ptr = def_act_p; /* pt to define action */ return (status); }