/* ora_tpcb.pc v.1.0.1 Programma per effettuare la transazione standard (TPC-B) Il suo utilizzo consente di effettuare prove parametriche sull'utilizzo di Oracle in parallelo da parte di piu' utenti. Copyright (C) meo@bogliolo.name */ #include #include #include EXEC SQL BEGIN DECLARE SECTION; /* Branch ID */ int Bid; /* Teller ID */ int Tid; /* Account ID */ int Aid; /* Delta Money */ int delta; /* Current Money */ double Abalance; VARCHAR username[40]; VARCHAR passwd[40]; VARCHAR connstr[40]; EXEC SQL END DECLARE SECTION; int i; int ntimes; int sleeptime; int logging; int scale; /* EXEC SQL INCLUDE ; */ void sqlerror(); main(argc, argv) int argc; char **argv; { if (argc != 7) { if (argc != 8) { printf("TPC-B for Oracle database: version 1.0.1\n"); printf("Usage: submit user passwd connect sleeptime times log [scale] \n"); exit(2); } } sscanf(argv[4], "%d", &sleeptime); sscanf(argv[5], "%d", &ntimes); sscanf(argv[6], "%d", &logging); if (argc == 7) { scale=1; } else { sscanf(argv[7], "%d", &scale); } if ( ntimes < 1 ) { printf("Usage: submit user passwd connect sleeptime times log [scale] \n"); printf("times must be more than 0\n"); exit(2); } if ( sleeptime < 0 ) { printf("Usage: submit user passwd connect sleeptime times log [scale] \n"); printf("sleeptime must be more or equal than 0\n"); exit(2); } if ( scale < 1 ) { printf("Usage: submit user passwd connect sleeptime times log [scale] \n"); printf("scale must be more than 0\n"); exit(2); } srand(getpid()); strcpy(username.arr, argv[1]); /* copy the username */ username.len = strlen(username.arr); strcpy(passwd.arr, argv[2]); /* copy the password */ passwd.len = strlen(passwd.arr); strcpy(connstr.arr, argv[3]); /* copy the connection string */ connstr.len = strlen(connstr.arr); EXEC SQL WHENEVER SQLERROR DO sqlerror(); EXEC SQL CONNECT :username IDENTIFIED BY :passwd USING :connstr; while (ntimes--) { sleep(sleeptime); Bid = rand(); Bid = Bid - Bid/scale*scale; Tid = rand(); Tid = Tid - Tid/10*10; Tid = Tid + 10*Bid; Aid = rand(); Aid = Aid - Aid/100000*100000; Aid = Aid + 100000*Bid; delta = rand(); delta = delta - delta/2000000*2000000; delta = delta - 1000000; EXEC SQL EXECUTE BEGIN tpcb(:Aid, :Bid, :Tid, :delta, :Abalance); END ; END-EXEC; } EXEC SQL COMMIT WORK RELEASE; exit(0); } void sqlerror() { EXEC SQL WHENEVER SQLERROR CONTINUE; printf("\nORACLE error detected:\n"); printf("\n% .70s \n", sqlca.sqlerrm.sqlerrmc); EXEC SQL ROLLBACK RELEASE; exit(1); }