📄 oracle_txns8.c
字号:
/***
TPCCErr("TPC-C server %d: reordering items and stocks\n",proc_no); ***/
/* not the last item - shift up */
for (j = i; j < pNew->o_ol_cnt-1; j++)
{
shiftitemstock (j, j+1, nctx, p);
}
/* zero the last item */
i = pNew->o_ol_cnt-1;
nctx->nol_i_id_ind[i] = NA;
nctx->nol_supply_w_id_ind[i] = NA;
nctx->nol_quantity_ind[i] = NA;
nctx->nol_amount_ind[i] = NA;
nctx->ol_w_id_ind[i] = NA;
nctx->ol_d_id_ind[i] = NA;
nctx->ol_o_id_ind[i] = NA;
nctx->null_date_ind[i]= NA;
nctx->ol_number_ind[i] = NA;
nctx->ol_dist_info_ind[i] = NA;
nctx->s_remote_ind[i] = NA;
nctx->s_quant_ind[i] = NA;
nctx->nol_i_id_len[i] = 0;
nctx->nol_supply_w_id_len[i] = 0;
nctx->nol_quantity_len[i] = 0;
nctx->nol_amount_len[i] = 0;
nctx->ol_w_id_len[i] = 0;
nctx->ol_d_id_len[i] = 0;
nctx->ol_o_id_len[i] = 0;
nctx->ol_number_len[i] = 0;
nctx->ol_dist_info_len[i] = 0;
nctx->null_date_ind[i] = 0;
nctx->s_remote_len[i] = 0;
nctx->s_quant_len[i] = 0;
return (rpc3);
}
UpdStk (OraContext *p, NewOrderData *pNew, int proc_no)
{
int rcount;
int execstatus;
int errcode;
newctx *nctx = &(p->nctx);
#ifdef OL_CHECK
int i;
newtemp *ntemp = &(p->tempvars.new);
for (i = 0; i < MAX_OL; i++)
{
if((TRUE == nctx->nol_supply_w_id_ind[i]) && ( ntemp->nol_supply_w_id[i] > iMaxWareHouses ))
{
TPCCErr( "Bad supply warehouse ol in updstk: %d, s_w_id: %d,query: %s",
i+1, ntemp->nol_supply_w_id[i],((EXTENSION_CONTROL_BLOCK *)pNew->pCC)->lpszQueryString );
}
}
#endif
/* array update of stock table */
execstatus = OCIStmtExecute(p->tpcsvc,nctx->curn2,p->errhp,pNew->o_ol_cnt,0,0,0,OCI_DEFAULT);
if(execstatus != OCI_SUCCESS)
{
OCITransRollback(p->tpcsvc,p->errhp,OCI_DEFAULT);
errcode = OCIERROR(p, execstatus);
if((errcode == NOT_SERIALIZABLE) || (errcode == RECOVERR))
{
return (RECOVERR);
}
else
{
return (IRRECERR);
}
}
OCIAttrGet(nctx->curn2,OCI_HTYPE_STMT,&rcount,NULL,OCI_ATTR_ROW_COUNT, p->errhp);
if (rcount != (pNew->o_ol_cnt) )
{
TPCCErr ("Error in TPC-C server %d: array update failed in UpdStk()\n",proc_no);
OCITransRollback(p->tpcsvc,p->errhp,OCI_DEFAULT);
return (IRRECERR);
}
return (rcount);
}
UpdStk2 (OraContext *p, NewOrderData *pNew, int status, int proc_no)
{
int rcount;
int execstatus;
int errcode;
newctx *nctx = &(p->nctx);
#ifdef OL_CHECK
int i;
newtemp *ntemp = &(p->tempvars.new);
for (i = 0; i < MAX_OL; i++)
{
if((TRUE == nctx->nol_supply_w_id_ind[i]) &&
( ntemp->nol_supply_w_id[i] > iMaxWareHouses ))
{
TPCCErr( "Bad supply warehouse ol in updstk2: %d, s_w_id:%d, query: %s",
i+1, ntemp->nol_supply_w_id[i],
((EXTENSION_CONTROL_BLOCK *)pNew->pCC)->lpszQueryString );
}
}
#endif
/* array update of stock table */
execstatus = OCIStmtExecute(p->tpcsvc,nctx->curn2,p->errhp,pNew->o_ol_cnt-status,
0,0,0,OCI_DEFAULT);
if(execstatus != OCI_SUCCESS)
{
OCITransRollback(p->tpcsvc,p->errhp,OCI_DEFAULT);
errcode = OCIERROR(p,execstatus);
if(errcode == NOT_SERIALIZABLE)
{
return (RECOVERR);
}
else if (errcode == RECOVERR)
{
return (RECOVERR);
}
else
{
return (IRRECERR);
}
}
OCIAttrGet(nctx->curn2,OCI_HTYPE_STMT,&rcount,NULL,OCI_ATTR_ROW_COUNT,p->errhp);
if (rcount != (pNew->o_ol_cnt - status))
{
TPCCErr("Error in TPC-C server %d: array update failed in UpdStk2()\n",proc_no);
OCITransRollback(p->tpcsvc,p->errhp,OCI_DEFAULT);
return (NO_COMMIT);
}
return (rcount);
}
/* stock level transaction */
#define SLSQLTXT "SELECT /*+ nocache(stok) */ count (DISTINCT s_i_id) \
FROM ordl, stok, dist \
WHERE d_id = :d_id AND d_w_id = :w_id AND \
d_id = ol_d_id AND d_w_id = ol_w_id AND \
ol_i_id = s_i_id AND ol_w_id = s_w_id AND \
s_quantity < :threshold AND \
ol_o_id BETWEEN (d_next_o_id - 20) AND (d_next_o_id - 1)"
#define SQLTXTTEST "BEGIN stocklevel.getstocklevel (:w_id, :d_id, \ :threshold); END;"
tkvcsinit (StockLevelData *pSL,OraContext *p)
{
stoctx *sctx = &(p->sctx);
text stmbuf[SQL_BUF_SIZE];
sctx->curs = NULL;
memset(sctx,(char)0,sizeof(stoctx));
sctx->norow=0;
OCIERROR(p, OCIHandleAlloc(p->tpcenv,(dvoid**)&(sctx->curs),OCI_HTYPE_STMT,0,(dvoid**)0));
sprintf ((char *) stmbuf, SLSQLTXT);
OCIERROR(p,OCIStmtPrepare(sctx->curs,p->errhp,stmbuf,strlen((char*)stmbuf),
OCI_NTV_SYNTAX,OCI_DEFAULT));
OCIERROR(p, OCIAttrSet(sctx->curs,OCI_HTYPE_STMT,(dvoid*)&sctx->norow,0,
OCI_ATTR_PREFETCH_ROWS,p->errhp));
/* bind variables */
OCIBND(sctx->curs,sctx->w_id_bp,p, ":w_id", ADR(pSL->w_id),sizeof(int),SQLT_INT);
OCIBND(sctx->curs,sctx->d_id_bp,p, ":d_id", ADR(pSL->ld_id),sizeof(int),SQLT_INT);
OCIBND(sctx->curs,sctx->threshold_bp,p, ":threshold", ADR(pSL->threshold),
sizeof(int),SQLT_INT);
OCIDEF(sctx->curs,sctx->low_stock_bp,p->errhp, 1, ADR(pSL->low_stock),
sizeof(int), SQLT_INT);
return (ERR_DB_SUCCESS);
}
tkvcs (OraContext *p)
{
stoctx *sctx = &(p->sctx);
int execstatus = 0;
int errcode = 0;
execstatus = OCIStmtExecute(p->tpcsvc,sctx->curs,p->errhp,1,0,0,0,
OCI_COMMIT_ON_SUCCESS |OCI_DEFAULT);
if(execstatus != OCI_SUCCESS)
{
OCITransCommit(p->tpcsvc,p->errhp,OCI_DEFAULT);
errcode = OCIERROR(p,execstatus);
if(errcode == NOT_SERIALIZABLE)
{
return (RECOVERR);
}
else if (errcode == RECOVERR)
{
return (RECOVERR);
}
else if (errcode == SNAPSHOT_TOO_OLD)
{
return (RECOVERR);
}
else
{
return (ERR_DB_ERROR);
}
}
return (ERR_DB_SUCCESS);
}
void tkvcsdone (stoctx *psctx)
{
stoctx sctx = *psctx;
if(NULL != sctx.curs)
OCIHandleFree((dvoid *)sctx.curs,OCI_HTYPE_STMT);
}
#define SQLTXT_PAY_ZERO "BEGIN apayment.adopayment(:w_id, :d_id,
:c_w_id, :c_d_id, \
:c_id, 0, \
:h_amount, :c_last, :w_street_1, :w_street_2, :w_city, :w_state,\
:w_zip, :d_street_1, :d_street_2, :d_city, :d_state, :d_zip,:c_first, \
:c_middle, :c_street_1, :c_street_2, :c_city, :c_state, :c_zip,:c_phone, \
:c_since, :c_credit, :c_credit_lim, :c_discount, :c_balance,:c_data, \
:h_date, :retry, :cr_date); END;"
#define SQLTXT_PAY_NONZERO "BEGIN apayment.adopayment(:w_id, :d_id,
:c_w_id, :c_d_id, \
:c_id, 1, \
:h_amount, :c_last, :w_street_1, :w_street_2, :w_city, :w_state,\
:w_zip, :d_street_1, :d_street_2, :d_city, :d_state, :d_zip,:c_first, \
:c_middle, :c_street_1, :c_street_2, :c_city, :c_state, :c_zip,:c_phone, \
:c_since, :c_credit, :c_credit_lim, :c_discount, :c_balance,:c_data, \
:h_date, :retry, :cr_date); END;"
#define SQLTXT_PAY_INIT "BEGIN initpay.pay_init; END;"
tkvcpinit (PaymentData *pPay,OraContext *p)
{
payctx *pctx = &(p->pctx);
paytemp *ptemp = &(p->tempvars.pay);
text stmbuf[SQL_BUF_SIZE];
pctx->curpi = NULL;
pctx->curp0 = NULL;
pctx->curp1 = NULL;
memset(pctx,(char)0,sizeof(payctx));
/* cursor for init */
OCIERROR(p,OCIHandleAlloc(p->tpcenv, (dvoid **)(&(pctx->curpi)),OCI_HTYPE_STMT,0,(dvoid**)0));
OCIERROR(p,OCIHandleAlloc(p->tpcenv, (dvoid **)(&(pctx->curp0)),OCI_HTYPE_STMT,0,(dvoid**)0));
OCIERROR(p,OCIHandleAlloc(p->tpcenv, (dvoid **)(&(pctx->curp1)),OCI_HTYPE_STMT,0,(dvoid**)0));
/* build the init statement and execute it */
sprintf ((char*)stmbuf, SQLTXT_PAY_INIT);
OCIERROR(p,OCIStmtPrepare(pctx->curpi, p->errhp, stmbuf,strlen((char *)stmbuf), OCI_NTV_SYNTAX, OCI_DEFAULT));
OCIERROR(p,OCIStmtExecute(p->tpcsvc,pctx->curpi,p->errhp,1,0,0,0,OCI_DEFAULT));
/* customer id != 0, go by customer id */
if(ERR_DB_ERROR == getfile("paynz.sql",stmbuf))
{
TPCCErr("Error opening the file paynz.sql");
return ERR_DB_ERROR;
}
OCIERROR(p,OCIStmtPrepare(pctx->curp0, p->errhp, stmbuf,strlen((char *)stmbuf), OCI_NTV_SYNTAX, OCI_DEFAULT));
/* customer id == 0, go by last name */
if(ERR_DB_ERROR == getfile("payz.sql",stmbuf))
{
TPCCErr("Error opening the file payz.sql");
return ERR_DB_ERROR;
}
OCIERROR(p,OCIStmtPrepare(pctx->curp1, p->errhp, stmbuf,strlen((char *)stmbuf), OCI_NTV_SYNTAX, OCI_DEFAULT));
pctx->w_id_ind = TRUE;
pctx->w_id_len = SIZ(pPay->w_id);
pctx->d_id_ind = TRUE;
pctx->d_id_len = SIZ(pPay->d_id);
pctx->c_w_id_ind = TRUE;
pctx->c_w_id_len = SIZ(pPay->c_w_id);
pctx->c_d_id_ind = TRUE;
pctx->c_d_id_len = SIZ(pPay->c_d_id);
pctx->c_id_ind = TRUE;
pctx->c_id_len = 0;
pctx->h_amount_len = SIZ(ptemp->h_amount);
pctx->h_amount_ind = TRUE;
pctx->c_last_ind = TRUE;
pctx->c_last_len = 0;
pctx->w_street_1_ind = TRUE;
pctx->w_street_1_len = 0;
pctx->w_street_2_ind = TRUE;
pctx->w_street_2_len = 0;
pctx->w_city_ind = TRUE;
pctx->w_city_len = 0;
pctx->w_state_ind = TRUE;
pctx->w_state_len = 0;
pctx->w_zip_ind = TRUE;
pctx->w_zip_len = 0;
pctx->d_street_1_ind = TRUE;
pctx->d_street_1_len = 0;
pctx->d_street_2_ind = TRUE;
pctx->d_street_2_len = 0;
pctx->d_city_ind = TRUE;
pctx->d_city_len = 0;
pctx->d_state_ind = TRUE;
pctx->d_state_len = 0;
pctx->d_zip_ind = TRUE;
pctx->d_zip_len = 0;
pctx->c_first_ind = TRUE;
pctx->c_first_len = 0;
pctx->c_middle_ind = TRUE;
pctx->c_middle_len = 0;
pctx->c_street_1_ind = TRUE;
pctx->c_street_1_len = 0;
pctx->c_street_2_ind = TRUE;
pctx->c_street_2_len = 0;
pctx->c_city_ind = TRUE;
pctx->c_city_len = 0;
pctx->c_state_ind = TRUE;
pctx->c_state_len = 0;
pctx->c_zip_ind = TRUE;
pctx->c_zip_len = 0;
pctx->c_phone_ind = TRUE;
pctx->c_phone_len = 0;
pctx->c_since_ind = TRUE;
pctx->c_since_len = 0;
pctx->c_credit_ind = TRUE;
pctx->c_credit_len = 0;
pctx->c_credit_lim_ind = TRUE;
pctx->c_credit_lim_len = 0;
pctx->c_discount_ind = TRUE;
pctx->c_discount_len = 0;
pctx->c_balance_ind = TRUE;
pctx->c_balance_len = sizeof(double);
pctx->c_data_ind = TRUE;
pctx->c_data_len = 0;
pctx->h_date_ind = TRUE;
pctx->h_date_len = 0;
pctx->retries_ind = TRUE;
pctx->retries_len = 0;
pctx->cr_date_ind = TRUE;
/* pctx->cr_date_len = 7; */
pctx->cr_date_len = sizeof(ptemp->cr_date);
/* bind variables */
OCIBNDR(pctx->curp0, pctx->w_id_bp, p,":w_id",ADR(pPay->w_id),
SIZ(int), SQLT_INT, &pctx->w_id_ind, NULL, NULL);
OCIBNDR(pctx->curp0, pctx->d_id_bp, p,":d_id",ADR(pPay->d_id),
SIZ(int), SQLT_INT, &pctx->d_id_ind, NULL, NULL);
OCIBND(pctx->curp0, pctx->c_w_id_bp, p,":c_w_id",ADR(pPay->c_w_id),SIZ(int), SQLT_INT);
OCIBND(pctx->curp0, pctx->c_d_id_bp, p,":c_d_id",ADR(pPay->c_d_id),SIZ(int), SQLT_INT);
OCIBND(pctx->curp0, pctx->c_id_bp, p,":c_id",ADR(pPay->c_id),SIZ(int), SQLT_INT);
OCIBNDR(pctx->curp0, pctx->h_amount_bp, p,":h_amount",
ADR(ptemp->h_amount), SIZ(ptemp->h_amount),SQLT_INT,
&pctx->h_amount_ind, &pctx->h_amount_len, &pctx->h_amount_rc);
OCIBNDR(pctx->curp0, pctx->c_last_bp, p,":c_last",pPay->c_last,
SIZ(pPay->c_last), SQLT_STR, &pctx->c_last_ind, &pctx->c_last_len,
&pctx->c_last_rc);
OCIBNDR(pctx->curp0, pctx->w_street_1_bp, p,":w_street_1",
pPay->w_street_1, SIZ(pPay->w_street_1),SQLT_STR,
&pctx->w_street_1_ind, &pctx->w_street_1_len, &pctx->w_street_1_rc);
OCIBNDR(pctx->curp0, pctx->w_street_2_bp, p,":w_street_2",
pPay->w_street_2, SIZ(pPay->w_street_2),SQLT_STR,
&pctx->w_street_2_ind, &pctx->w_street_2_len, &pctx->w_street_2_rc);
OCIBNDR(pctx->curp0, pctx->w_city_bp, p,":w_city",pPay->w_city,SIZ(pPay->w_city),
SQLT_STR, &pctx->w_city_ind, &pctx->w_city_len, &pctx->w_city_rc);
OCIBNDR(pctx->curp0, pctx->w_state_bp, p,":w_state",pPay->w_state,
SIZ(pPay->w_state), SQLT_STR, &pctx->w_state_ind,
&pctx->w_state_len, &pctx->w_state_rc);
OCIBNDR(pctx->curp0, pctx->w_zip_bp, p,":w_zip",pPay->w_zip,SIZ(pPay->w_zip),
SQLT_STR, &pctx->w_zip_ind, &pctx->w_zip_len, &pctx->w_zip_rc);
OCIBNDR(pctx->curp0, pctx->d_street_1_bp, p,":d_street_1",pPay->d_street_1,
SIZ(pPay->d_street_1),SQLT_STR, &pctx->d_street_1_ind,
&pctx->d_street_1_len, &pctx->d_street_1_rc);
OCIBNDR(pctx->curp0, pctx->d_street_2_bp, p,":d_street_2",pPay->d_street_2,
SIZ(pPay->d_street_2),SQLT_STR, &pctx->d_street_2_ind,
&pctx->d_street_2_len, &pctx->d_street_2_rc);
OCIBNDR(pctx->curp0, pctx->d_city_bp, p,":d_city",pPay->d_city,SIZ(pPay->d_city),
SQLT_STR, &pctx->d_city_ind, &pctx->d_city_len, &pctx->d_city_rc);
OCIBNDR(pctx->curp0, pctx->d_state_bp, p,":d_state",pPay->d_state,
SIZ(pPay->d_state), SQLT_STR,&pctx->d_state_ind, &pctx->d_state_len, &pctx->d_state_rc);
OCIBNDR(pctx->curp0, pctx->d_zip_bp, p,":d_zip",pPay->d_zip,SIZ(pPay->d_zip),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -