📄 oracle_txns8.c
字号:
/* c_id != 0, use id to find customer */
sprintf((char *) stmbuf, SQL_ORD_CUR2);
OCIERROR(p,OCIStmtPrepare(octx->curo2,p->errhp,stmbuf,
strlen((char *)stmbuf),OCI_NTV_SYNTAX,OCI_DEFAULT));
OCIERROR(p,OCIAttrSet(octx->curo2,OCI_HTYPE_STMT,(dvoid*)&octx->norow,0,
OCI_ATTR_PREFETCH_ROWS,p->errhp));
sprintf((char *) stmbuf, SQL_ORD_CUR3);
OCIERROR(p,OCIStmtPrepare(octx->curo3,p->errhp,stmbuf,
strlen((char *)stmbuf),
OCI_NTV_SYNTAX,OCI_DEFAULT));
OCIERROR(p,OCIAttrSet(octx->curo3,OCI_HTYPE_STMT,(dvoid*)&octx->norow,0,
OCI_ATTR_PREFETCH_ROWS,p->errhp));
sprintf((char *) stmbuf, SQL_ORD_CUR4);
OCIERROR(p,OCIStmtPrepare(octx->curo4,p->errhp,stmbuf,strlen((char *)stmbuf),
OCI_NTV_SYNTAX,OCI_DEFAULT));
OCIERROR(p,OCIAttrSet(octx->curo4,OCI_HTYPE_STMT,(dvoid*)&octx->norow,0,
OCI_ATTR_PREFETCH_ROWS,p->errhp));
for (i = 0; i < NITEMS; i++)
{
octx->ol_supply_w_id_ind[i] = TRUE;
octx->ol_i_id_ind[i] = TRUE;
octx->ol_quantity_ind[i] = TRUE;
octx->ol_amount_ind[i] = TRUE;
octx->ol_delivery_d_ind[i] = TRUE;
octx->ol_supply_w_id_len[i] = sizeof(int);
octx->ol_i_id_len[i] = sizeof(int);
octx->ol_quantity_len[i] = sizeof(int);
octx->ol_amount_len[i] = sizeof(int);
octx->ol_delivery_d_len[i] = sizeof(OCIDate);
/* octx->ol_delivery_d_len[i] = sizeof(pOrd->s_ol->ol_delivery_d); */
}
octx->ol_supply_w_id_csize = NITEMS;
octx->ol_i_id_csize = NITEMS;
octx->ol_quantity_csize = NITEMS;
octx->ol_amount_csize = NITEMS;
octx->ol_delivery_d_csize = NITEMS;
octx->ol_w_id_csize = NITEMS;
octx->ol_o_id_csize = NITEMS;
octx->ol_d_id_csize = NITEMS;
octx->ol_w_id_ind = TRUE;
octx->ol_d_id_ind = TRUE;
octx->ol_o_id_ind = TRUE;
octx->ol_w_id_len = sizeof(int);
octx->ol_d_id_len = sizeof(int);
octx->ol_o_id_len = sizeof(int);
/* bind variables */
/* c_id (customer id) is not known */
/* cursor 0 */
OCIBND(octx->curo0,octx->w_id_bp0,p,":w_id",ADR(pOrd->w_id),SIZ(int),SQLT_INT);
OCIBND(octx->curo0,octx->d_id_bp0,p,":d_id",ADR(pOrd->d_id),SIZ(int),SQLT_INT);
OCIBND(octx->curo0,octx->c_last_bp,p,":c_last",pOrd->c_last,SIZ(pOrd->c_last),SQLT_STR);
ocierror(__FILE__,__LINE__,p, \
OCIDefineByPos(octx->curo0,&octx->c_rowid_dp,p->errhp,1, \
octx->c_rowid_ptr, sizeof(OCIRowid*),SQLT_RDD,octx->c_rowid_ind,\
NULL,NULL, OCI_DYNAMIC_FETCH));
ocierror(__FILE__,__LINE__,p, OCIDefineDynamic(octx->c_rowid_dp,\
p->errhp,\
p,rid_data));
/** sth OCIDFNDYN( octx->curo0,octx->c_rowid_dp,p,1,
octx->c_rowid_ptr,sizeof(OCIRowid*),SQLT_RDD,octx->c_rowid_ind,
p,rid_data);
**/
OCIBND(octx->curo1,octx->c_rowid_bp,p,":cust_rowid",
&octx->middle_cust,sizeof(octx->middle_cust),SQLT_RDD);
OCIDEF(octx->curo1,octx->c_id_dp,p->errhp,1,ADR(pOrd->c_id),SIZ(int),
SQLT_INT);
OCIDEF(octx->curo1,octx->c_balance_dp1,p->errhp,2,ADR(pOrd->c_balance),
SIZ(double),SQLT_FLT);
OCIDEF(octx->curo1,octx->c_first_dp1,p->errhp,3,pOrd->c_first,
SIZ(pOrd->c_first)-1,SQLT_CHR);
OCIDEF(octx->curo1,octx->c_middle_dp1,p->errhp,4,pOrd->c_middle,
SIZ(pOrd->c_middle)-1,SQLT_AFC);
OCIDEF(octx->curo1,octx->c_last_dp1,p->errhp,5,pOrd->c_last,
SIZ(pOrd->c_last)-1, SQLT_CHR);
OCIDEF(octx->curo1,octx->o_id_dp1,p->errhp,6,ADR(pOrd->o_id),SIZ(int),SQLT_INT);
OCIDEF(octx->curo1,octx->o_entry_d_dp1,p->errhp,7,
&otemp->entry_date,SIZ(otemp->entry_date),SQLT_ODT);
OCIDEF(octx->curo1,octx->o_cr_id_dp1,p->errhp,8,ADR(pOrd->o_carrier_id),
SIZ(int),SQLT_INT);
OCIDEF(octx->curo1,octx->o_ol_cnt_dp1,p->errhp,9,ADR(pOrd->o_ol_cnt),
SIZ(int),SQLT_INT);
/* Bind for cursor 2 , no-zero customer id */
OCIBND(octx->curo2,octx->w_id_bp2,p,":w_id",ADR(pOrd->w_id),SIZ(int),SQLT_INT);
OCIBND(octx->curo2,octx->d_id_bp2,p,":d_id",ADR(pOrd->d_id),SIZ(int),SQLT_INT);
OCIBND(octx->curo2,octx->c_id_bp,p,":c_id",ADR(pOrd->c_id),SIZ(int),SQLT_INT);
OCIDEF(octx->curo2,octx->c_balance_dp2,p->errhp,1,ADR(pOrd->c_balance),
SIZ(double),SQLT_FLT);
OCIDEF(octx->curo2,octx->c_first_dp2,p->errhp,2,pOrd->c_first,
SIZ(pOrd->c_first)-1,SQLT_CHR);
OCIDEF(octx->curo2,octx->c_middle_dp2,p->errhp,3,pOrd->c_middle,
SIZ(pOrd->c_middle)-1,SQLT_AFC);
OCIDEF(octx->curo2,octx->c_last_dp,p->errhp,4,pOrd->c_last,
SIZ(pOrd->c_last)-1,SQLT_CHR);
OCIDEF(octx->curo2,octx->o_id_dp2,p->errhp,5,ADR(pOrd->o_id),SIZ(int),SQLT_INT);
OCIDEF(octx->curo2,octx->o_entry_d_dp2,p->errhp,6,
&otemp->entry_date,SIZ(otemp->entry_date),SQLT_ODT);
OCIDEF(octx->curo2, octx->o_cr_id_dp2,p->errhp,7,ADR(pOrd->o_carrier_id),
SIZ(int), SQLT_INT);
OCIDEF(octx->curo2,octx->o_ol_cnt_dp2,p->errhp,8,ADR(pOrd->o_ol_cnt),SIZ(int),SQLT_INT);
OCIDEF(octx->curo2,octx->c_id_dp1,p->errhp,9,ADR(pOrd->c_id),SIZ(int),SQLT_INT);
/* Bind for last cursor - 3 */
OCIBND(octx->curo3,octx->w_id_bp3,p,":w_id",ADR(pOrd->w_id),SIZ(int),SQLT_INT);
OCIBND(octx->curo3,octx->d_id_bp3,p,":d_id",ADR(pOrd->d_id),SIZ(int),SQLT_INT);
OCIBND(octx->curo3,octx->o_id_bp,p,":o_id",ADR(pOrd->o_id),SIZ(int),SQLT_INT);
OCIDFNRA(octx->curo3, octx->ol_i_id_dp, p->errhp, 1, otemp->loc_ol_i_id,
SIZ(int), SQLT_INT,octx->ol_i_id_ind,octx->ol_i_id_len, octx->ol_i_id_rcode);
OCIDFNRA(octx->curo3,octx->ol_supply_w_id_dp,p->errhp,2,otemp->loc_ol_supply_w_id,
SIZ(int),SQLT_INT, octx->ol_supply_w_id_ind,
octx->ol_supply_w_id_len, octx->ol_supply_w_id_rcode);
OCIDFNRA(octx->curo3, octx->ol_quantity_dp,p->errhp,3,
otemp->loc_ol_quantity, SIZ(int),
SQLT_INT, octx->ol_quantity_ind,octx->ol_quantity_len,octx->ol_quantity_rcode);
OCIDFNRA(octx->curo3,octx->ol_amount_dp,p->errhp,4,otemp->loc_ol_amount,
SIZ(int),SQLT_INT,octx->ol_amount_ind, octx->ol_amount_len,
octx->ol_amount_rcode);
OCIDFNRA(octx->curo3,octx->ol_d_base_dp,p->errhp,5,
otemp->loc_ol_delivery_date,SIZ(OCIDate), SQLT_ODT,
octx->ol_delivery_d_ind,octx->ol_delivery_d_len,
octx->ol_delivery_d_rcode);
OCIBND(octx->curo4, octx->w_id_bp4, p, ":w_id", ADR(pOrd->w_id),SIZ(int),SQLT_INT);
OCIBND(octx->curo4,octx->d_id_bp4,p,":d_id",ADR(pOrd->d_id),SIZ(int),SQLT_INT);
OCIBND(octx->curo4,octx->c_last_bp4,p,":c_last",ADR(pOrd->c_last),
SIZ(pOrd->c_last), SQLT_STR);
OCIDEF(octx->curo4,octx->c_count_dp,p,1,ADR(octx->rcount),SIZ(int),SQLT_INT);
return (ERR_DB_SUCCESS);
}
tkvco (OrderStatusData *pOrd, OraContext *p)
{
ordctx *octx = &(p->octx);
defctx *cbctx = &(p->cbctx);
ordtemp *otemp = &(p->tempvars.ord);
int i;
int execstatus;
int errcode;
int entry_date_str_len = sizeof (otemp->entry_date_str);
int rcount;
for (i = 0; i < NITEMS; i++)
{
octx->ol_supply_w_id_ind[i] = TRUE;
octx->ol_i_id_ind[i] = TRUE;
octx->ol_quantity_ind[i] = TRUE;
octx->ol_amount_ind[i] = TRUE;
octx->ol_delivery_d_ind[i] = TRUE;
octx->ol_supply_w_id_len[i] = sizeof(int);
octx->ol_i_id_len[i] = sizeof(int);
octx->ol_quantity_len[i] = sizeof(int);
octx->ol_amount_len[i] = sizeof(int);
octx->ol_delivery_d_len[i] = sizeof(otemp->loc_ol_delivery_date[i]);
}
octx->ol_supply_w_id_csize = NITEMS;
octx->ol_i_id_csize = NITEMS;
octx->ol_quantity_csize = NITEMS;
octx->ol_amount_csize = NITEMS;
octx->ol_delivery_d_csize = NITEMS;
/* initialize bound output variables to null for oracle v8 */
/* octx->o_ol_cnt_ind = NA;*/
/* pOrd->o_ol_cnt = 0;*/
if(pOrd->byname)
{
cbctx->reexec = FALSE;
execstatus=OCIStmtExecute(p->tpcsvc,octx->curo0,p->errhp,
100,0,0,0,OCI_DEFAULT);
if ((execstatus != OCI_NO_DATA) && (execstatus !=OCI_SUCCESS))
/* will get OCI_NO_DATA if <100 found */
{
errcode = OCIERROR(p,execstatus);
if ((errcode == NOT_SERIALIZABLE) || (errcode == RECOVERR) || (errcode == SNAPSHOT_TOO_OLD))
{
OCITransCommit(p->tpcsvc,p->errhp,OCI_DEFAULT);
return RECOVERR;
}
else
{
return ERR_DB_ERROR;
}
}
if (execstatus == OCI_NO_DATA) /* there are no more rows */
{
/* get rowcount, find middle one */
OCIAttrGet(octx->curo0,OCI_HTYPE_STMT,&rcount,NULL,OCI_ATTR_ROW_COUNT,p->errhp);
/*
if (rcount <1)
{
TPCCErr("No Data Found");
return ERR_DB_ERROR;
}
*/
octx->cust_idx=(rcount-1)/2 ;
}
else
{
/* count the number of rows */
execstatus = OCIStmtExecute(p->tpcsvc,octx->curo4,p->errhp,1,0,0,0,OCI_DEFAULT);
if ((execstatus != OCI_NO_DATA) && (execstatus != OCI_SUCCESS))
{
errcode = OCIERROR(p,execstatus);
if ((errcode == NOT_SERIALIZABLE) || (errcode == RECOVERR) || (errcode == SNAPSHOT_TOO_OLD))
{
OCITransCommit(p->tpcsvc,p->errhp,OCI_DEFAULT);
return RECOVERR;
}
else
{
return ERR_DB_ERROR;
}
}
if (octx->rcount+1 < 200)
octx->cust_idx=(octx->rcount-1)/2;
else
{
cbctx->reexec = TRUE;
cbctx->count = (octx->rcount+1)/2;
execstatus = OCIStmtExecute(p->tpcsvc,octx->curo0,p->errhp,
cbctx->count,0,0,0,OCI_DEFAULT);
/* will get OCI_NO_DATA if <100 found */
if (cbctx->count>0)
{
TPCCErr("Did not get all rows.");
return ERR_DB_ERROR;
}
if ((execstatus != OCI_NO_DATA) && (execstatus != OCI_SUCCESS))
{
errcode=OCIERROR(p,execstatus);
if ((errcode == NOT_SERIALIZABLE) || (errcode == RECOVERR)
|| (errcode == SNAPSHOT_TOO_OLD))
{
OCITransCommit(p->tpcsvc,p->errhp,OCI_DEFAULT);
return RECOVERR;
}
else
{
return ERR_DB_ERROR;
}
}
octx->cust_idx=0;
}
}
octx->middle_cust=octx->c_rowid_ptr[octx->cust_idx];
execstatus = OCIStmtExecute(p->tpcsvc,octx->curo1,p->errhp,1,0,0,0,OCI_DEFAULT);
if (execstatus != OCI_SUCCESS)
{
errcode = OCIERROR(p,execstatus);
OCITransCommit(p->tpcsvc,p->errhp,OCI_DEFAULT);
if ((errcode == NOT_SERIALIZABLE) || (errcode == RECOVERR) ||
(errcode == SNAPSHOT_TOO_OLD))
{
return RECOVERR;
}
else
{
return ERR_DB_ERROR;
}
}
}
else
{
/* execstatus = OCIStmtExecute(p->tpcsvc,octx->curo2,p->errhp,
1,0,0,0,OCI_DEFAULT); */
execstatus = OCIStmtExecute(p->tpcsvc,octx->curo2,p->errhp,1,0,0,0,OCI_DEFAULT);
if (execstatus != OCI_SUCCESS)
{
errcode = OCIERROR(p,execstatus);
OCITransCommit(p->tpcsvc,p->errhp,OCI_DEFAULT);
if ((errcode == NOT_SERIALIZABLE) || (errcode == RECOVERR) || (errcode == SNAPSHOT_TOO_OLD))
{
return RECOVERR;
}
else
{
return ERR_DB_ERROR;
}
}
}
octx->ol_w_id_ind = TRUE;
octx->ol_d_id_ind = TRUE;
octx->ol_o_id_ind = TRUE;
octx->ol_w_id_len = sizeof(int);
octx->ol_d_id_len = sizeof(int);
octx->ol_o_id_len = sizeof(int);
execstatus = OCIStmtExecute(p->tpcsvc,octx->curo3,p->errhp,pOrd->o_ol_cnt,
0,0,0, OCI_DEFAULT | OCI_COMMIT_ON_SUCCESS);
if (execstatus != OCI_SUCCESS)
{
errcode = OCIERROR(p,execstatus);
OCITransCommit(p->tpcsvc,p->errhp,OCI_DEFAULT);
if ((errcode == NOT_SERIALIZABLE) || (errcode == RECOVERR) || (errcode == SNAPSHOT_TOO_OLD))
{
return RECOVERR;
}
else
{
return ERR_DB_ERROR;
}
}
/*
#ifdef NOTMORE
OCIERROR(errhp,OCITransCommit(tpcsvc,errhp,OCI_DEFAULT));
#endif
*/
/* clean up and convert the delivery dates */
for (i = 0; i < pOrd->o_ol_cnt; i++)
{
if (octx->ol_delivery_d_ind[i] == -1) /* null date in field*/
strncpy(otemp->ol_delivery_date_str[i],"01-01-1811",10);
else
/* cvtdmy(otemp->loc_ol_delivery_date[i], otemp->ol_delivery_date_str[i]); */
{
octx->ol_delivery_d_len[i]=sizeof(otemp->ol_delivery_date_str[i]);
OCIERROR(p, OCIDateToText(p->errhp,&otemp->loc_ol_delivery_date[i],
(text*)"dd-mm-yyyy",strlen("dd-mm-yyyy"),(text*)0,0,
&octx->ol_delivery_d_len[i],&otemp->ol_delivery_date_str[i]));
}
}
/* convert the order entry date */
/* cvtdmyhms(otemp->entry_date, otemp->entry_date_str); */
OCIERROR(p, OCIDateToText(p->errhp,&otemp->entry_date,
(text*)"dd-mm-yyyy HH24:MI:SS",strlen("dd-mm-yyyy HH:MI:SS"),(text*)0,0,
&entry_date_str_len,&otemp->entry_date_str));
return (ERR_DB_SUCCESS);
}
void tkvcodone (ordctx *poctx)
{
ordctx octx = *poctx;
if(NULL != octx.curo0)
OCIHandleFree((dvoid *)octx.curo0,OCI_HTYPE_STMT);
if(NULL != octx.curo1)
OCIHandleFree((dvoid *)octx.curo1,OCI_HTYPE_STMT);
if(NULL != octx.curo2)
OCIHandleFree((dvoid *)octx.curo2,OCI_HTYPE_STMT);
if(NULL != octx.curo3)
OCIHandleFree((dvoid *)octx.curo3,OCI_HTYPE_STMT);
if(NULL != octx.curo4)
OCIHandleFree((dvoid *)octx.curo4,OCI_HTYPE_STMT);
}
/**** delivery transaction */
#if defined(ISO) || defined(ISO5) || defined(ISO6) || defined(ISO8)
#define SQLTXT0 "SELECT substr(value,1,5) FROM v$parameter \
WHERE name = 'instance_number'"
#endif
#define SQLTXT1 "DELETE FROM nord WHERE no_d_id = :d_id \
AND no_w_id=:w_id and rownum <=1 \
RETURNING no_o_id into :o_id "
#define SQLTXT3 "UPDATE ordr SET o_carrier_id = :carrier_id \
WHERE o_id=:o_id and o_d_id=:d_id and o_w_id=:w_id \
returning o_c_id into :o_c_id"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -