Example #1
0
DB_STATUS
qee_d6_malloc(
    i4		i_space,
    QEF_RCB		*qef_rcb,
    PTR		*o_pp)
{
    GLOBALREF	    QEF_S_CB *Qef_s_cb;
    QEF_CB	    *qef_cb = qef_rcb->qef_cb;
    DB_STATUS	    status = E_DB_OK;
    ULM_RCB	    ulm;


    o_pp = (PTR *) NULL;

    /* allocate space in QEF memory */

    STRUCT_ASSIGN_MACRO(Qef_s_cb->qef_d_ulmcb, ulm);

    /* 1.  allocate from session's stream */

    ulm.ulm_streamid_p = &qef_cb->qef_c3_streamid;
    ulm.ulm_psize = i_space;
    if (status = qec_malloc(&ulm))
    {
        qef_rcb->error.err_code = ulm.ulm_error.err_code;
        return(status);
    }
    qef_cb->qef_c4_streamsize += i_space;
    o_pp =  (PTR *) ulm.ulm_pptr;


    return(E_DB_OK);
}
Example #2
0
DB_STATUS
qet_t9_ok_w_ldbs(
QEE_DSH		*i_dsh_p,
QEF_RCB		*v_qer_p,
bool		*o1_ok_p)
{
    DB_STATUS	    status_0 = E_DB_OK,
		    status_t = E_DB_OK,
		    status_u = E_DB_OK;		
    DB_ERROR	    ulm_err,
		    tpf_err;
    QES_DDB_SES	    *dds_p = & v_qer_p->qef_cb->qef_c2_ddb_ses;
    TPR_CB	    tpr_cb,
		    *tpr_p = & tpr_cb;
    QEF_QP_CB	    *qp_p = i_dsh_p->dsh_qp_ptr;
    QEF_AHD	    *act_p = qp_p->qp_ahd;
    QEQ_D1_QRY	    *subqry_p;
    ULM_RCB	    ulm;
    i4		    w_ldbcnt;
    TPR_W_LDB	    *wldb1_p = (TPR_W_LDB *) NULL,
		    *wldb2_p = (TPR_W_LDB *) NULL;


    *o1_ok_p = TRUE;	/* assume */

    if (qp_p->qp_qmode == QEQP_01QM_RETRIEVE)
	return(E_DB_OK);	    /* read-only query */

    /* assume that there are update sites within this query plan */

    /* allocate stream to build list of LDB ptrs; note that this 
    ** stream must be closed upon return from this routine */

    STRUCT_ASSIGN_MACRO(Qef_s_cb->qef_s_ulmcb, ulm);
    ulm.ulm_blocksize = sizeof(TPR_W_LDB);  /* allocation size */

    status_u = qec_mopen(&ulm);
    if (status_u)
    {
	v_qer_p->error.err_code = ulm.ulm_error.err_code;
	return(status_u);
    }

    /* traverse the action list to build an LDB ptr list */

    MEfill(sizeof(tpr_cb), '\0', (PTR) & tpr_cb);
    tpr_p->tpr_session = dds_p->qes_d2_tps_p;	/* TPF session CB ptr */
    tpr_p->tpr_rqf = dds_p->qes_d3_rqs_p;	/* RQF session CB ptr */
    tpr_cb.tpr_15_w_ldb_p = (TPR_W_LDB *) NULL;
    w_ldbcnt = 0;
    act_p = qp_p->qp_ahd; 
    while (act_p != (QEF_AHD *) NULL && status_u == E_DB_OK)
    {
	if (act_p->ahd_atype == QEA_D1_QRY)
	{
	    subqry_p = & act_p->qhd_obj.qhd_d1_qry;

	    if (subqry_p->qeq_q3_ctl_info & QEQ_002_USER_UPDATE)
	    {
		/* an update site */

		w_ldbcnt++;

		ulm.ulm_psize = sizeof(TPR_W_LDB);
		status_u = qec_malloc(&ulm);
		if (status_u)
		{
		    STRUCT_ASSIGN_MACRO(ulm.ulm_error, ulm_err);
		    goto dismantle_9;
		}
		else
		{
		    /* allocation ok */

		    wldb2_p = (TPR_W_LDB *) ulm.ulm_pptr;

		    if (wldb1_p == (TPR_W_LDB *) NULL)
		    {
			/* first in list */

			tpr_cb.tpr_15_w_ldb_p = 
			    wldb1_p = wldb2_p;  
			wldb2_p->tpr_1_prev_p = 
			    wldb2_p->tpr_2_next_p = (TPR_W_LDB *) NULL;
		    }
		    else
		    {
			/* append to list */

			wldb1_p->tpr_2_next_p = wldb2_p;  
			wldb2_p->tpr_1_prev_p = wldb1_p;
			wldb2_p->tpr_2_next_p = (TPR_W_LDB *) NULL;
		    }

		    wldb2_p->tpr_3_ldb_p = subqry_p->qeq_q5_ldb_p;
		}
  	    }
	}
	act_p = act_p->ahd_next;	/* advance */
    }
    /* call TPF if any update sites */

    if (tpr_cb.tpr_15_w_ldb_p != (TPR_W_LDB *) NULL)
    {
	status_t = qed_u17_tpf_call(TPF_OK_W_LDBS, & tpr_cb, v_qer_p);
	if (status_t)
	    STRUCT_ASSIGN_MACRO(tpr_cb.tpr_error, tpf_err);
	else
	    *o1_ok_p = tpr_cb.tpr_14_w_ldbs_ok;
    }

dismantle_9:

    /* must always close stream */

    status_0 = ulm_closestream(&ulm);

    if (status_u)
    {
	/* return previous ulm error */

	STRUCT_ASSIGN_MACRO(ulm_err, v_qer_p->error);
	return(status_u);
    }

    if (status_t)
    {
	/* return tpf error */

	STRUCT_ASSIGN_MACRO(tpf_err, v_qer_p->error);
	return(status_t);
    }

    if (status_0)
    {
	/* return close-stream ulm error */

	STRUCT_ASSIGN_MACRO(ulm.ulm_error, v_qer_p->error);
    }
    
    return(status_0);
}
Example #3
0
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);
}
Example #4
0
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);
}