13.07.2015 Views

IBM Flex System x240 w

IBM Flex System x240 w

IBM Flex System x240 w

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

* tpcccli.sqc - Client/Server code for TPCC*/#include#include#include "db2tpcc.h"#include "tpccapp.h"#include "tpccdbg.h"#include "sqlca.h"#include "sql.h"// ----------------------------------------------------------------// New Order CLIENT// ----------------------------------------------------------------static int itemComparison ( const void * a , const void * b ){struct in_items_struct * one = (struct in_items_struct *) a ;struct in_items_struct * two = (struct in_items_struct *) b ;}// Primary comparison key: I_ID// Secondary comparison key: W_IDif ( one->s_OL_I_ID != two->s_OL_I_ID ){return ( one->s_OL_I_ID - two->s_OL_I_ID ) ;}else{return ( one->s_OL_SUPPLY_W_ID - two->s_OL_SUPPLY_W_ID ) ;}int neword_sql ( struct in_neword_struct * in_neword, struct out_neword_struct * neword ){struct sqlca sqlca ;EXEC SQL BEGIN DECLARE SECTION;struct vc_new_in{short len;char data[ 262 ] ;} * pHostvarInput ;struct vc_new_out{short len;char data[ 682 ] ;} * pHostvarOutput ;EXEC SQL END DECLARE SECTION;int clientRc = TRAN_OK ;int itemIndex = 0 ;// Determine if order is "all-local" or not// NOTE: This loop will exit on the iteration *after* finding the last// item; this effectively takes care of the 0-based/1-based conversion// and we don't have to add one when assigning to s_O_OL_CNT below.in_neword->s_all_local = 1 ;for ( itemIndex = 0 ;itemIndex < 15 && in_neword->in_item[ itemIndex ].s_OL_I_ID != UNUSED_ITEM_ID ;itemIndex++){if ( in_neword->in_item[ itemIndex ].s_OL_SUPPLY_W_ID != in_neword->s_W_ID ){in_neword->s_all_local = 0 ;}}in_neword->s_O_OL_CNT = itemIndex ;// Sort the item list. Since invalid item IDs = 100001, we will remain// compliant with the spec (Section 2.4.2.3 Comment 1.qsort( in_neword->in_item, in_neword->s_O_OL_CNT, sizeof ( in_neword->in_item[ 0 ] ), itemComparison) ;pHostvarInput = (struct vc_new_in *) in_neword ;pHostvarInput->len = sizeof(struct in_neword_struct) - SPGENERAL_ADJUST ;pHostvarOutput = (struct vc_new_out *) neword;pHostvarOutput->len = sizeof(struct out_neword_struct) - SPGENERAL_ADJUST ;#ifdef DEBUGITnew_debug(neword, in_neword, "Client before SP call");#endif /* DEBUGIT */#ifdef SWAP_ENDIANfor (itemIndex=0; itemIndexs_O_OL_CNT; itemIndex++){SWAP_BYTE(in_neword->in_item[ itemIndex ].s_OL_I_ID);SWAP_BYTE(in_neword->in_item[ itemIndex ].s_OL_SUPPLY_W_ID);SWAP_BYTE(in_neword->in_item[ itemIndex ].s_OL_QUANTITY);}SWAP_BYTE(in_neword->s_C_ID);SWAP_BYTE(in_neword->s_W_ID);SWAP_BYTE(in_neword->s_D_ID);SWAP_BYTE(in_neword->s_O_OL_CNT);SWAP_BYTE(in_neword->s_all_local);SWAP_BYTE(in_neword->duplicate_items);#endif //SWAP_ENDIANEXEC SQL CALL news ( :*pHostvarInput, :*pHostvarOutput );#ifdef SWAP_ENDIANSWAP_BYTE(in_neword->s_C_ID);SWAP_BYTE(in_neword->s_W_ID);SWAP_BYTE(in_neword->s_D_ID);SWAP_BYTE(in_neword->s_O_OL_CNT);SWAP_BYTE(in_neword->s_all_local);SWAP_BYTE(in_neword->duplicate_items);for (itemIndex=0; itemIndexs_O_OL_CNT; itemIndex++){SWAP_BYTE(in_neword->in_item[ itemIndex ].s_OL_I_ID);SWAP_BYTE(in_neword->in_item[ itemIndex ].s_OL_SUPPLY_W_ID);SWAP_BYTE(in_neword->in_item[ itemIndex ].s_OL_QUANTITY);}SWAP_BYTE(neword->s_W_TAX);SWAP_BYTE(neword->s_D_TAX);SWAP_BYTE(neword->s_C_DISCOUNT);SWAP_BYTE(neword->s_total_amount);SWAP_BYTE(neword->s_O_ID);SWAP_BYTE(neword->s_O_OL_CNT);SWAP_BYTE(neword->s_transtatus);SWAP_BYTE(neword->deadlocks);for (itemIndex=0; itemIndexs_O_OL_CNT; itemIndex++){SWAP_BYTE(neword->item[ itemIndex ].s_I_PRICE);SWAP_BYTE(neword->item[ itemIndex ].s_OL_AMOUNT);SWAP_BYTE(neword->item[ itemIndex ].s_S_QUANTITY);}#endif //SWAP_ENDIANif ( sqlca.sqlcode == 0 ){float wtax = neword->s_W_TAX ;float dtax = neword->s_D_TAX ;float cdisc = neword->s_C_DISCOUNT ;float factor = (1.0 - cdisc) * (1.0 + wtax + dtax) ;// Compute order totalneword->s_total_amount = 0 ;for ( itemIndex = 0 ;itemIndex < in_neword->s_O_OL_CNT ; // from input , not outputitemIndex++){if ( neword->item[ itemIndex ].s_I_PRICE > 0 ) // A zero price signifies a baditem{neword->item[ itemIndex ].s_OL_AMOUNT = neword->item[ itemIndex ].s_I_PRICE *in_neword->in_item[ itemIndex ].s_OL_QUANTITY ; // reference input value}}neword->s_total_amount += neword->item[ itemIndex ].s_OL_AMOUNT ;neword->s_total_amount *= factor;}else{sqlerror( NEWORD_SQL, "NEW", __FILE__, __LINE__, &sqlca) ;neword->s_transtatus = FATAL_SQLERROR ;clientRc = FATAL_SQLERROR ;}#ifdef DEBUGITnew_debug(neword, in_neword, "Client after SP call");#endif /* DEBUGIT */

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!