?? oracle_txns8.c
字號:
/***************************
oracle_txns8.c
***************************/
/*+ file: oracle_txns8.c based on Oracle files - plpay.c plnew.c
plord.c
pldel.c plsto.c
-*/
/*+================================================================
=+
| Copyright (c) 1995 Oracle Corp, Redwood Shores, CA
|
| OPEN SYSTEMS PERFORMANCE GROUP
|
| All Rights Reserved
|
+==================================================================
+
| DESCRIPTION
| OCI version (using PL/SQL stored procedure) of
| PAYMENT transaction in TPC-C benchmark.
| OCI version (using PL/SQL stored procedure) of
| NEW ORDER transaction in TPC-C benchmark.
| OCI version (using PL/SQL anynomous block) of
| ORDER STATUS transaction in TPC-C benchmark.
| OCI version of DELIVERY transaction in TPC-C benchmark.
| OCI version of STOCK LEVEL transaction in TPC-C benchmark.
+=================================================================-
*/
/*+****************************************************************
**********
*
*
* COPYRIGHT (c) 1998 BY
*
* DIGITAL EQUIPMENT CORPORATION, MAYNARD, MASSACHUSETTS.
*
* ALL RIGHTS RESERVED.
*
*
*
* THIS SOFTWARE IS FURNISHED UNDER A LICENSE AND MAY BE USED AND COPIED *
* ONLY IN ACCORDANCE WITH THE TERMS OF SUCH LICENSE AND WITH THE *
* INCLUSION OF THE ABOVE COPYRIGHT NOTICE. THIS SOFTWARE OR ANY OTHER *
* COPIES THEREOF MAY NOT BE PROVIDED OR OTHERWISE MADE AVAILABLE TO ANY *
* OTHER PERSON. NO TITLE TO AND OWNERSHIP OF THE SOFTWARE IS HEREBY *
* TRANSFERRED.
*
*
*
* THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE *
* AND SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT *
* CORPORATION.
*
*
*
* DIGITAL ASSUMES NO RESPONSIBILITY FOR THE USE OR RELIABILITY OF ITS *
* SOFTWARE ON EQUIPMENT WHICH IS NOT SUPPLIED BY DIGITAL.
*
*
*
*
*
*******************************************************************
*********/
/*+
* Abstract: This file contains the transaction routines for connection
* to the oracle v8 database - for the tpcc benchmark.
*
*
* Modification history:
*
*
* 08/01/2002 Andrew Bond, HP Corporation
* - Conversion to run under Linux
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ocidfn.h>
#include <oci.h>
#include <ociapr.h>
#include <tpccerr.h>
#include <tpccstruct.h>
#include <oracle_db8.h>
#include <tpcc.h>
#ifdef OL_CHECK
#include <httpext.h>
extern int iMaxWareHouses;
#endif
/* prototypes */
int getfile(char *filename, text *filebuf);
void vgetdate (unsigned char *oradt)
{
struct tm *loctime;
time_t int_time;
struct ORADATE
{
unsigned char century;
unsigned char year;
unsigned char month;
unsigned char day;
unsigned char hour;
unsigned char minute;
unsigned char second;
} Date;
int century;
int cnvrtOK;/* assume convert is successful */
cnvrtOK = 1;/* get the current date and time as an integer */
time( &int_time);/* Convert the current date and time into local time */
loctime = localtime( &int_time);
century = (1900+loctime->tm_year) / 100;
Date.century = (unsigned char)(century + 100);
if (Date.century < 119 || Date.century > 120) cnvrtOK = 0;
Date.year = (unsigned char)(loctime->tm_year%100+100);
if (Date.year < 100 || Date.year > 199) cnvrtOK = 0;
Date.month = (unsigned char)(loctime->tm_mon + 1);
if (Date.month < 1 || Date.month > 12) cnvrtOK = 0;
Date.day = (unsigned char)loctime->tm_mday;
if (Date.day < 1 || Date.day > 31) cnvrtOK = 0;
Date.hour = (unsigned char)(loctime->tm_hour + 1);
if (Date.hour < 1 || Date.hour > 24) cnvrtOK = 0;
Date.minute= (unsigned char)(loctime->tm_min + 1);
if (Date.minute < 1 || Date.minute > 60) cnvrtOK = 0;
Date.second= (unsigned char)(loctime->tm_sec + 1);
if (Date.second < 1 || Date.second > 60) cnvrtOK = 0;
if (cnvrtOK)
memcpy(oradt,&Date,7);
else
*oradt = '\0';
return;
}
void cvtdmy (unsigned char *oradt, char *outdate)
{
struct ORADATE
{
unsigned char century;
unsigned char year;
unsigned char month;
unsigned char day;
unsigned char hour;
unsigned char minute;
unsigned char second;
} Date;
int day,month,year;
memcpy(&Date,oradt,7);
year = (Date.century-100)*100 + Date.year-100;
month = Date.month;
day = Date.day;/* sprintf(outdate,"%02d-%02d-%4d\0",day,month,year); */
sprintf(outdate,"%02d-%02d-%4d",day,month,year);
return;
}
void cvtdmyhms (unsigned char *oradt, char *outdate)
{
struct ORADATE
{
unsigned char century;
unsigned char year;
unsigned char month;
unsigned char day;
unsigned char hour;
unsigned char minute;
unsigned char second;
} Date;
int day,month,year;
int hour,min,sec;
memcpy(&Date,oradt,7);
year = (Date.century-100)*100 + Date.year-100;
month = Date.month;
day = Date.day;
hour = Date.hour - 1;
min = Date.minute - 1;
sec = Date.second - 1;/*sprintf(outdate,"%02d-%02d-%4d %02d:%02d:%02d\0", */
sprintf(outdate,"%02d-%02d-%4d %02d:%02d:%02d",day,month,year,hour,min,sec);
return;
}
swapitemstock (int i, int j, int *i_price, char i_name[][25],int *s_quantity, newctx *nctx)
{
int tempi;
int tempf;
char tempstr[52];
ub2 tempub2;
sb2 tempsb2;
OCIRowid *tmprid;
tempsb2 = nctx->cons_ind[i];
nctx->cons_ind[i] = nctx->cons_ind[j];
nctx->cons_ind[j] = tempsb2;
tempub2 = nctx->cons_len[i];
nctx->cons_len[i] = nctx->cons_len[j];
nctx->cons_len[j] = tempub2;
tempub2 = nctx->cons_rcode[i];
nctx->cons_rcode[i] = nctx->cons_rcode[j];
nctx->cons_rcode[j] = tempub2;
tempi = nctx->cons[i];
nctx->cons[i] = nctx->cons[j];
nctx->cons[j] = tempi;
tempsb2 = nctx->s_rowid_ind[i];
nctx->s_rowid_ind[i] = nctx->s_rowid_ind[j];
nctx->s_rowid_ind[j] = tempsb2;
tempub2 = nctx->s_rowid_len[i];
nctx->s_rowid_len[i] = nctx->s_rowid_len[j];
nctx->s_rowid_len[j] = tempub2;
tempub2 = nctx->s_rowid_rcode[i];
nctx->s_rowid_rcode[i] = nctx->s_rowid_rcode[j];
nctx->s_rowid_rcode[j] = tempub2;
tmprid = nctx->s_rowid_ptr[i];
nctx->s_rowid_ptr[i]= nctx->s_rowid_ptr[j];
nctx->s_rowid_ptr[j]=tmprid;
tempsb2 = nctx->i_price_ind[i];
nctx->i_price_ind[i] = nctx->i_price_ind[j];
nctx->i_price_ind[j] = tempsb2;
tempub2 = nctx->i_price_len[i];
nctx->i_price_len[i] = nctx->i_price_len[j];
nctx->i_price_len[j] = tempub2;
tempub2 = nctx->i_price_rcode[i];
nctx->i_price_rcode[i] = nctx->i_price_rcode[j];
nctx->i_price_rcode[j] = tempub2;
tempf = i_price[i];
i_price[i] = i_price[j];
i_price[j] = tempf;
tempsb2 = nctx->i_name_ind[i];
nctx->i_name_ind[i] = nctx->i_name_ind[j];
nctx->i_name_ind[j] = tempsb2;
tempub2 = nctx->i_name_len[i];
nctx->i_name_len[i] = nctx->i_name_len[j];
nctx->i_name_len[j] = tempub2;
tempub2 = nctx->i_name_rcode[i];
nctx->i_name_rcode[i] = nctx->i_name_rcode[j];
nctx->i_name_rcode[j] = tempub2;
strncpy (tempstr, i_name[i], 25);
strncpy (i_name[i], i_name[j], 25);
strncpy (i_name[j], tempstr, 25);
tempsb2 = nctx->i_data_ind[i];
nctx->i_data_ind[i] = nctx->i_data_ind[j];
nctx->i_data_ind[j] = tempsb2;
tempub2 = nctx->i_data_len[i];
nctx->i_data_len[i] = nctx->i_data_len[j];
nctx->i_data_len[j] = tempub2;
tempub2 = nctx->i_data_rcode[i];
nctx->i_data_rcode[i] = nctx->i_data_rcode[j];
nctx->i_data_rcode[j] = tempub2;
strncpy (tempstr, nctx->i_data[i], 51);
strncpy (nctx->i_data[i], nctx->i_data[j], 51);
strncpy (nctx->i_data[j], tempstr, 51);
tempsb2 = nctx->s_quantity_ind[i];
nctx->s_quantity_ind[i] = nctx->s_quantity_ind[j];
nctx->s_quantity_ind[j] = tempsb2;
tempub2 = nctx->s_quantity_len[i];
nctx->s_quantity_len[i] = nctx->s_quantity_len[j];
nctx->s_quantity_len[j] = tempub2;
tempub2 = nctx->s_quantity_rcode[i];
nctx->s_quantity_rcode[i] = nctx->s_quantity_rcode[j];
nctx->s_quantity_rcode[j] = tempub2;
tempi = s_quantity[i];
s_quantity[i] = s_quantity[j];
s_quantity[j] = tempi;
tempsb2 = nctx->s_dist_info_ind[i];
nctx->s_dist_info_ind[i] = nctx->s_dist_info_ind[j];
nctx->s_dist_info_ind[j] = tempsb2;
tempub2 = nctx->s_dist_info_len[i];
nctx->s_dist_info_len[i] = nctx->s_dist_info_len[j];
nctx->s_dist_info_len[j] = tempub2;
tempub2 = nctx->s_dist_info_rcode[i];
nctx->s_dist_info_rcode[i] = nctx->s_dist_info_rcode[j];
nctx->s_dist_info_rcode[j] = tempub2;
strncpy (tempstr, nctx->s_dist_info[i], 25);
strncpy (nctx->s_dist_info[i], nctx->s_dist_info[j], 25);
strncpy (nctx->s_dist_info[j], tempstr, 25);
tempsb2 = nctx->s_data_ind[i];
nctx->s_data_ind[i] = nctx->s_data_ind[j];
nctx->s_data_ind[j] = tempsb2;
tempub2 = nctx->s_data_len[i];
nctx->s_data_len[i] = nctx->s_data_len[j];
nctx->s_data_len[j] = tempub2;
tempub2 = nctx->s_data_rcode[i];
nctx->s_data_rcode[i] = nctx->s_data_rcode[j];
nctx->s_data_rcode[j] = tempub2;
strncpy (tempstr, nctx->s_data[i], 51);
strncpy (nctx->s_data[i], nctx->s_data[j], 51);
strncpy (nctx->s_data[j], tempstr, 51);
return 0;
}
/* the arrays are initialized based on a successful select from */
/* stock/item. We need to shift the values in the orderline array*/
/* one position up to compensate when we have an invalid item */
shiftitemstock (int i, int j, newctx *nctx, OraContext *p)
{
newtemp *ntemp = &(p->tempvars.new);/* shift up the values for the stock table */
nctx->s_remote[i] = nctx->s_remote[j];/* shift up the order_line values */
nctx->nol_i_id_ind[i]=nctx->nol_i_id_ind[j];
ntemp->nol_i_id[i] = ntemp->nol_i_id[j];
nctx->nol_quantity_ind[i] = nctx->nol_quantity_ind[j];
ntemp->nol_quantity[i] = ntemp->nol_quantity[j];
nctx->nol_supply_w_id_ind [i] = nctx->nol_supply_w_id_ind[j];
ntemp->nol_supply_w_id[i] = ntemp->nol_supply_w_id[j];
return 0;
}
int SelItemStk (NewOrderData *pNew,int *pstatus,int retries, int proc_no, newctx *nctx,OraContext *p)
{
int i, j, rpc3,rcount;
int errcode;
int execstatus;
#ifdef OL_CHECK
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: %d, s_w_id: %d, query:%s",i+1, ntemp->nol_supply_w_id[i],
((EXTENSION_CONTROL_BLOCK *)pNew->pCC)->lpszQueryString );
}
}
#endif
/* array select from item and stock tables */
execstatus=OCIStmtExecute(p->tpcsvc,(nctx->curn3)[pNew->d_id-1],p->errhp,
pNew->o_ol_cnt,0,0,0,OCI_DEFAULT);
if((execstatus != OCI_SUCCESS) && (execstatus != OCI_NO_DATA))
{
errcode = OCIERROR(p,execstatus);
if((errcode == NOT_SERIALIZABLE) || (errcode == RECOVERR))
{
/* In case of NO_DATA this should NOT return, but simply fall through */
OCITransRollback(p->tpcsvc,p->errhp,OCI_DEFAULT);
return (RECOVERR);
}
else
{
OCITransRollback(p->tpcsvc,p->errhp,OCI_DEFAULT);
return (IRRECERR);
}
}/* mark invalid items */
OCIAttrGet((nctx->curn3)[pNew->d_id-1],OCI_HTYPE_STMT,&rcount,NULL,OCI_ATTR_ROW_COUNT, p->errhp);
rpc3 = rcount;
/* the result is in order, so we have to shift up to fill */
/* the slot for the line with the invalid item. */
/* If more than one item is wrong, this is not an simulated */
/* error and we'll blow off */
if ((*pstatus = pNew->o_ol_cnt - rcount) >1)
{
TPCCErr ("TPC-C server %d: more than 1 invalid item?\n",proc_no);
return (rpc3);
}
if (*pstatus == 0) return (rpc3);
/* find the invalid item, transfer the rowid information */
for (i = 0; i < pNew->o_ol_cnt; i++)
{
if (nctx->cons[i] != i) break; /* this item is invalid */
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -