int main(int argc, char* argv[]) { struct stat st; /* For getoptlong(). */ int c; init_common(); if (argc < 2) { printf("Usage: %s -w # [-c #] [-i #] [-o #] [-s #] [-n #] [-d <str>]\n", argv[0]); printf("\n"); printf("-w #\n"); printf("\twarehouse cardinality\n"); printf("-c #\n"); printf("\tcustomer cardinality, default %d\n", CUSTOMER_CARDINALITY); printf("-i #\n"); printf("\titem cardinality, default %d\n", ITEM_CARDINALITY); printf("-o #\n"); printf("\torder cardinality, default %d\n", ORDER_CARDINALITY); printf("-n #\n"); printf("\tnew-order cardinality, default %d\n", NEW_ORDER_CARDINALITY); printf("-d <path>\n"); printf("\toutput path of data files\n"); printf("--sapdb\n"); printf("\tformat data for SAP DB\n"); printf("--pgsql\n"); printf("\tformat data for PostgreSQL\n"); printf("--mysql\n"); printf("\tformat data for MySQL\n"); printf("--hyrise\n"); // patched for hyrise printf("\tformat data for HYRISE\n"); // SB270911 return 1; } /* Parse command line arguments. */ while (1) { int option_index = 0; static struct option long_options[] = { {"pgsql", no_argument, &mode_string, MODE_PGSQL}, {"sapdb", no_argument, &mode_string, MODE_SAPDB}, {"mysql", no_argument, &mode_string, MODE_MYSQL}, {"hyrise", no_argument, &mode_string, MODE_HYRISE}, // patched for hyrise, SB270911 {0, 0, 0, 0}}; c = getopt_long(argc, argv, "c:d:i:n:o:w:", long_options, &option_index); if (c == -1) { break; } switch (c) { case 0: break; case 'c': customers = atoi(optarg); break; case 'd': strcpy(output_path, optarg); break; case 'i': items = atoi(optarg); break; case 'n': new_orders = atoi(optarg); break; case 'o': orders = atoi(optarg); break; case 'w': warehouses = atoi(optarg); break; default: printf("?? getopt returned character code 0%o ??\n", c); return 2; } } if (warehouses == 0) { printf("-w must be used\n"); return 3; } if (strlen(output_path) > 0 && ((stat(output_path, &st) < 0) || (st.st_mode & S_IFMT) != S_IFDIR)) { printf("Output directory of data files '%s' not exists\n", output_path); return 3; } /* Set the correct delimiter. */ if (mode_string == MODE_SAPDB) { delimiter = ','; strcpy(null_str, "\"nullptr\""); } else if (mode_string == MODE_PGSQL || mode_string == MODE_MYSQL) { delimiter = '\t'; strcpy(null_str, ""); } else if (mode_string == MODE_HYRISE) { // patched for hyrise delimiter = '|'; // strcpy(null_str, ""); // loadHyriseLayouts(); // SB270911 } printf("warehouses = %d\n", warehouses); printf("districts = %d\n", DISTRICT_CARDINALITY); printf("customers = %d\n", customers); printf("items = %d\n", items); printf("orders = %d\n", orders); printf("stock = %d\n", items); printf("new_orders = %d\n", new_orders); printf("\n"); if (strlen(output_path) > 0) { printf("Output directory of data files: %s\n", output_path); } else { printf("Output directory of data files: current directory\n"); } printf("\n"); printf("Generating data files for %d warehouse(s)...\n", warehouses); gen_items(); gen_warehouses(); gen_stock(); gen_districts(); gen_customers(); gen_history(); gen_orders(); gen_new_orders(); return 0; }
int main(int argc, char *argv[]) { struct stat st; /* For getoptlong(). */ int c; init_common(); if (argc < 2) { printf("Usage: %s -w # [-c #] [-i #] [-o #] [-s #] [-n #] [-d <str>]\n", argv[0]); printf("\n"); printf("-w #\n"); printf("\twarehouse cardinality\n"); printf("-c #\n"); printf("\tcustomer cardinality, default %d\n", CUSTOMER_CARDINALITY); printf("-i #\n"); printf("\titem cardinality, default %d\n", ITEM_CARDINALITY); printf("-o #\n"); printf("\torder cardinality, default %d\n", ORDER_CARDINALITY); printf("-n #\n"); printf("\tnew-order cardinality, default %d\n", NEW_ORDER_CARDINALITY); printf("-d <path>\n"); printf("\toutput path of data files\n"); printf("--drizzle\n"); printf("\tformat data for Drizzle\n"); printf("--mysql\n"); printf("--nuodb\n"); printf("\tformat data for NuoDB\n"); printf("\tformat data for MySQL\n"); printf("--pgsql\n"); printf("\tformat data for PostgreSQL\n"); printf("--sapdb\n"); printf("\tformat data for SAP DB\n"); printf("--direct\n"); printf("\tdon't generate flat files, load directly into database\n"); return 1; } /* Parse command line arguments. */ while (1) { int option_index = 0; static struct option long_options[] = { { "direct", no_argument, &mode_load, MODE_DIRECT }, { "pgsql", no_argument, &mode_string, MODE_PGSQL }, { "sapdb", no_argument, &mode_string, MODE_SAPDB }, { "mysql", no_argument, &mode_string, MODE_MYSQL }, { "nuodb", no_argument, &mode_string, MODE_NUODB }, { "drizzle", no_argument, &mode_string, MODE_DRIZZLE }, { 0, 0, 0, 0 } }; c = getopt_long(argc, argv, "c:d:i:n:o:w:", long_options, &option_index); if (c == -1) { break; } switch (c) { case 0: break; case 'c': customers = atoi(optarg); break; case 'd': strcpy(output_path, optarg); break; case 'i': items = atoi(optarg); break; case 'n': new_orders = atoi(optarg); break; case 'o': orders = atoi(optarg); break; case 'w': warehouses = atoi(optarg); break; default: printf("?? getopt returned character code 0%o ??\n", c); return 2; } } if (warehouses == 0) { printf("-w must be used\n"); return 3; } if (strlen(output_path) > 0 && ((stat(output_path, &st) < 0) || (st.st_mode & S_IFMT) != S_IFDIR)) { printf("Output directory of data files '%s' not exists\n", output_path); return 3; } /* Verify that datagen supports a direct load for the selected database. */ if (mode_load == MODE_DIRECT) { switch (mode_string) { case MODE_SAPDB: case MODE_MYSQL: case MODE_NUODB: case MODE_DRIZZLE: printf("the rdbms select does not support direct loading\n"); return 4; } } /* Set the correct delimiter. */ if (mode_string == MODE_SAPDB) { delimiter = ','; strcpy(null_str, "\"NULL\""); } else if (mode_string == MODE_PGSQL || mode_string == MODE_MYSQL || mode_string == MODE_DRIZZLE || mode_string == MODE_NUODB) { delimiter = '\t'; strcpy(null_str, ""); } printf("warehouses = %d\n", warehouses); printf("districts = %d\n", DISTRICT_CARDINALITY); printf("customers = %d\n", customers); printf("items = %d\n", items); printf("orders = %d\n", orders); printf("stock = %d\n", items); printf("new_orders = %d\n", new_orders); printf("\n"); if (strlen(output_path) > 0) { printf("Output directory of data files: %s\n",output_path); } else { printf("Output directory of data files: current directory\n"); } printf("\n"); printf("Generating data files for %d warehouse(s)...\n", warehouses); gen_items(); gen_warehouses(); gen_stock(); gen_districts(); gen_customers(); gen_history(); gen_orders(); gen_new_orders(); return 0; }