/* mypopulate tpc-B benchmark loader Programma per caricare la base dati per il benchmark standard (TPC-B) */ #include #include "mysql.h" int Bid; int Tid; int Aid; int delta; double Abalance; char username[40]; char passwd[40]; char hostname[40]; char query[256]; MYSQL m; int i; int scale; main(argc, argv) int argc; char **argv; { if (argc != 4) { if (argc != 5) { printf("TPC-B populate for MySQL database: version 1.0.0 - SQL\n"); printf("Usage: mypop user passwd hostname [scale] \n"); exit(2); } } strcpy(username, argv[1]); strcpy(passwd, argv[2]); strcpy(hostname, argv[3]); if (argc == 4) { scale=1; } else { sscanf(argv[4], "%d", &scale); } if ( scale < 1 ) { printf("Usage: mypop user passwd hostname [scale] \n"); printf("scale must be more than 0\n"); exit(2); } mysql_init(&m); /* if (!mysql_real_connect(&m, hostname, username, password, "tpc", 0,NULL,0)) */ if (!mysql_real_connect(&m, NULL,NULL,NULL, "tpc", 0,NULL,0)) { fprintf(stderr, "Error in connect: %s\n", mysql_error(&m)); exit(1); } while (ntimes--) { 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; sprintf(query, "UPDATE B_accounts SET Abalance = Abalance + %d WHERE Aid = %d", delta, Aid); if (mysql_query(&m, query)) { fprintf(stderr, "Error in UPD Acc: %s\n", mysql_error(&m)); } sprintf(query,"SELECT Abalance FROM B_accounts WHERE Aid = %d", Aid); if (mysql_query(&m, query)) { fprintf(stderr, "Error in SEL acc: %s\n", mysql_error(&m)); } /* results = mysql_store_result(&m); record = mysql_fetch_row(results); mysql_free_result(results); */ sprintf(query,"UPDATE B_tellers SET Tbalance = Tbalance + %d WHERE Tid = %d", delta, Tid); if (mysql_query(&m, query)) { fprintf(stderr, "Error in UPD tel: %s\n", mysql_error(&m)); } sprintf(query,"UPDATE B_branches SET Bbalance = Bbalance + %d WHERE Bid = %d", delta, Bid); if (mysql_query(&m, query)) { fprintf(stderr, "Error in UPD bra: %s\n", mysql_error(&m)); } sprintf(query,"INSERT INTO B_history0 (Tid,Bid,Aid,delta) VALUES (%d, %d, %d, %d); Tid, Bid, Aid, delta); if (mysql_query(&m, query)) { fprintf(stderr, "Error in UPD his: %s\n", mysql_error(&m)); } mysql_commit(&m); } mysql_close(&m); exit(0); }