Exemple #1
0
/* Clause 4.3.3.1 */
void gen_customers() {
  FILE* output;
  int i, j, k;
  char a_string[1024];
  struct tm* tm1;
  time_t t1;
  char filename[1024] = "\0";

  srand(0);
  printf("Generating customer table data...\n");

  if (strlen(output_path) > 0) {
    strcpy(filename, output_path);
    strcat(filename, "/");
  }
  strcat(filename, CUSTOMER_DATA);
  output = fopen(filename, "w");
  if (output == nullptr) {
    printf("cannot open %s\n", CUSTOMER_DATA);
    return;
  }

  // patched for hyrise - SB270911
  if (mode_string == MODE_HYRISE) {
    gen_table_header(output, "customer");
  }

  for (i = 0; i < warehouses; i++) {
    for (j = 0; j < DISTRICT_CARDINALITY; j++) {
      for (k = 0; k < customers; k++) {
        /* c_id */
        FPRINTF(output, "%d", k + 1);
        METAPRINTF((output, "%c", delimiter));

        /* c_d_id */
        FPRINTF(output, "%d", j + 1);
        METAPRINTF((output, "%c", delimiter));

        /* c_w_id */
        FPRINTF(output, "%d", i + 1);
        METAPRINTF((output, "%c", delimiter));

        /* c_first */
        get_a_string(a_string, 8, 16);
        escape_me(a_string);
        FPRINTF(output, "%s", a_string);
        METAPRINTF((output, "%c", delimiter));

        /* c_middle */
        FPRINTF2(output, "OE");
        METAPRINTF((output, "%c", delimiter));

        /* c_last Clause 4.3.2.7 */
        if (k < 1000) {
          get_c_last(a_string, k);
        } else {
          get_c_last(a_string, get_nurand(255, 0, 999));
        }
        escape_me(a_string);
        FPRINTF(output, "%s", a_string);
        METAPRINTF((output, "%c", delimiter));

        /* c_street_1 */
        get_a_string(a_string, 10, 20);
        escape_me(a_string);
        FPRINTF(output, "%s", a_string);
        METAPRINTF((output, "%c", delimiter));

        /* c_street_2 */
        get_a_string(a_string, 10, 20);
        escape_me(a_string);
        FPRINTF(output, "%s", a_string);
        METAPRINTF((output, "%c", delimiter));

        /* c_city */
        get_a_string(a_string, 10, 20);
        escape_me(a_string);
        FPRINTF(output, "%s", a_string);
        METAPRINTF((output, "%c", delimiter));

        /* c_state */
        get_l_string(a_string, 2, 2);
        FPRINTF(output, "%s", a_string);
        METAPRINTF((output, "%c", delimiter));

        /* c_zip */
        get_n_string(a_string, 4, 4);
        FPRINTF(output, "%s11111", a_string);
        METAPRINTF((output, "%c", delimiter));

        /* c_phone */
        get_n_string(a_string, 16, 16);
        FPRINTF(output, "%s", a_string);
        METAPRINTF((output, "%c", delimiter));

        /* c_since */
        /*
         * Milliseconds are not calculated.  This
         * should also be the time when the data is
         * loaded, I think.
         */
        time(&t1);
        tm1 = localtime(&t1);
        print_timestamp(output, tm1);
        METAPRINTF((output, "%c", delimiter));

        /* c_credit */
        if (get_percentage() < .10) {
          FPRINTF2(output, "BC");
        } else {
          FPRINTF2(output, "GC");
        }
        METAPRINTF((output, "%c", delimiter));

        /* c_credit_lim */
        FPRINTF2(output, "50000.00");
        METAPRINTF((output, "%c", delimiter));

        /* c_discount */
        FPRINTF(output, "0.%04d", get_random(5000));
        METAPRINTF((output, "%c", delimiter));

        /* c_balance */
        FPRINTF2(output, "-10.00");
        METAPRINTF((output, "%c", delimiter));

        /* c_ytd_payment */
        FPRINTF2(output, "10.00");
        METAPRINTF((output, "%c", delimiter));

        /* c_payment_cnt */
        FPRINTF2(output, "1");
        METAPRINTF((output, "%c", delimiter));

        /* c_delivery_cnt */
        FPRINTF2(output, "0");
        METAPRINTF((output, "%c", delimiter));

        /* c_data */
        get_a_string(a_string, 300, 500);
        escape_me(a_string);
        FPRINTF(output, "%s", a_string);

        METAPRINTF((output, "\n"));
      }
    }
  }
  fclose(output);
  printf("Finished customer table data...\n");
  return;
}
Exemple #2
0
/* Clause 4.3.3.1 */
void gen_warehouses() {
  FILE* output;
  int i;
  char a_string[48];
  char filename[1024] = "\0";

  srand(0);
  printf("Generating warehouse table data...\n");

  if (strlen(output_path) > 0) {
    strcpy(filename, output_path);
    strcat(filename, "/");
  }
  strcat(filename, WAREHOUSE_DATA);

  output = fopen(filename, "w");
  if (output == nullptr) {
    printf("cannot open %s\n", WAREHOUSE_DATA);
    return;
  }

  // patched for hyrise - SB270911
  if (mode_string == MODE_HYRISE) {
    gen_table_header(output, "warehouse");
  }

  for (i = 0; i < warehouses; i++) {
    /* w_id */
    FPRINTF(output, "%d", i + 1);
    METAPRINTF((output, "%c", delimiter));

    /* w_name */
    get_a_string(a_string, 6, 10);
    escape_me(a_string);
    FPRINTF(output, "%s", a_string);
    METAPRINTF((output, "%c", delimiter));

    /* w_street_1 */
    get_a_string(a_string, 10, 20);
    escape_me(a_string);
    FPRINTF(output, "%s", a_string);
    METAPRINTF((output, "%c", delimiter));

    /* w_street_2 */
    get_a_string(a_string, 10, 20);
    escape_me(a_string);
    FPRINTF(output, "%s", a_string);
    METAPRINTF((output, "%c", delimiter));

    /* w_city */
    get_a_string(a_string, 10, 20);
    escape_me(a_string);
    FPRINTF(output, "%s", a_string);
    METAPRINTF((output, "%c", delimiter));

    /* w_state */
    get_l_string(a_string, 2, 2);
    FPRINTF(output, "%s", a_string);
    METAPRINTF((output, "%c", delimiter));

    /* w_zip */
    get_n_string(a_string, 4, 4);
    FPRINTF(output, "%s11111", a_string);
    METAPRINTF((output, "%c", delimiter));

    /* w_tax */
    FPRINTF(output, "0.%04d", get_random(2000));
    METAPRINTF((output, "%c", delimiter));

    /* w_ytd */
    FPRINTF2(output, "300000.00");

    METAPRINTF((output, "\n"));
  }
  fclose(output);
  printf("Finished warehouse table data...\n");
  return;
}
Exemple #3
0
/* Clause 4.3.3.1 */
void gen_districts()
{
	FILE *output;
	int i, j;
	char a_string[48];
	char filename[1024] = "\0";

	srand(0);
	printf("Generating district table data...\n");

	if (mode_load == MODE_FLAT) {
		if (strlen(output_path) > 0) {
			strcpy(filename, output_path);
			strcat(filename, "/");
		}
		strcat(filename, DISTRICT_DATA);
		output = fopen(filename, "w");
		if (output == NULL) {
			printf("cannot open %s\n", DISTRICT_DATA);
			return;
		}
	} else if (mode_load == MODE_DIRECT) {
		switch (mode_string) {
		case MODE_PGSQL:
			output = popen("psql", "w");
			if (output == NULL) {
				printf("error cannot open pipe for direct load\n");
				return;
			}
			/* FIXME: Handle properly instead of blindly reading the output. */
			while (fgetc(output) != EOF) ;

			fprintf(output, "BEGIN;\n");
			/* FIXME: Handle properly instead of blindly reading the output. */
			while (fgetc(output) != EOF) ;

			fprintf(output,
					"COPY district FROM STDIN DELIMITER '%c' NULL '%s';\n",
					delimiter, null_str);
			/* FIXME: Handle properly instead of blindly reading the output. */
			while (fgetc(output) != EOF) ;
			break;
		}
	} else {
		printf("error unknown load mode: %d\n", mode_load);
	}

	for (i = 0; i < warehouses; i++) {
		for (j = 0; j < DISTRICT_CARDINALITY; j++) {
			/* d_id */
			FPRINTF(output, "%d", j + 1);
			METAPRINTF((output, "%c", delimiter));

			/* d_w_id */
			FPRINTF(output, "%d", i + 1);
			METAPRINTF((output, "%c", delimiter));

			/* d_name */
			get_a_string(a_string, 6, 10);
			escape_me(a_string);
			FPRINTF(output, "%s", a_string);
			METAPRINTF((output, "%c", delimiter));

			/* d_street_1 */
			get_a_string(a_string, 10, 20);
			escape_me(a_string);
			FPRINTF(output, "%s", a_string);
			METAPRINTF((output, "%c", delimiter));

			/* d_street_2 */
			get_a_string(a_string, 10, 20);
			escape_me(a_string);
			FPRINTF(output, "%s", a_string);
			METAPRINTF((output, "%c", delimiter));

			/* d_city */
			get_a_string(a_string, 10, 20);
			escape_me(a_string);
			FPRINTF(output, "%s", a_string);
			METAPRINTF((output, "%c", delimiter));

			/* d_state */
			get_l_string(a_string, 2, 2);
			FPRINTF(output, "%s", a_string);
			METAPRINTF((output, "%c", delimiter));

			/* d_zip */
			get_n_string(a_string, 4, 4);
			FPRINTF(output, "%s11111", a_string);
			METAPRINTF((output, "%c", delimiter));

			/* d_tax */
			FPRINTF(output, "0.%04d", get_random(2000));
			METAPRINTF((output, "%c", delimiter));

			/* d_ytd */
			FPRINTF2(output, "30000.00");
			METAPRINTF((output, "%c", delimiter));

			/* d_next_o_id */
			FPRINTF2(output, "3001");

			METAPRINTF((output, "\n"));
		}
	}

	if (mode_load == MODE_FLAT) {
		fclose(output);
	} else {
		switch (mode_string) {
		case MODE_PGSQL:
			fprintf(output, "\\.\n");
			/* FIXME: Handle properly instead of blindly reading the output. */
			while (fgetc(output) != EOF) ;

			fprintf(output, "COMMIT;\n");
			/* FIXME: Handle properly instead of blindly reading the output. */
			while (fgetc(output) != EOF) ;

			pclose(output);
			break;
		}
	}

	printf("Finished district table data...\n");
	return;
}
Exemple #4
0
/* Clause 4.3.3.1 */
void gen_customers()
{
	FILE *output;
	int i, j, k;
	char a_string[1024];
	struct tm *tm1;
	time_t t1;
	char filename[1024] = "\0";

	srand(0);
	printf("Generating customer table data...\n");

	if (mode_load == MODE_FLAT) {
		if (strlen(output_path) > 0) {
			strcpy(filename, output_path);
			strcat(filename, "/");
		}
		strcat(filename, CUSTOMER_DATA);
		output = fopen(filename, "w");
		if (output == NULL) {
			printf("cannot open %s\n", CUSTOMER_DATA);
			return;
		}
	} else if (mode_load == MODE_DIRECT) {
		switch (mode_string) {
		case MODE_PGSQL:
			output = popen("psql", "w");
			if (output == NULL) {
				printf("error cannot open pipe for direct load\n");
				return;
			}
			/* FIXME: Handle properly instead of blindly reading the output. */
			while (fgetc(output) != EOF) ;

			fprintf(output, "BEGIN;\n");
			/* FIXME: Handle properly instead of blindly reading the output. */
			while (fgetc(output) != EOF) ;

			fprintf(output,
					"COPY customer FROM STDIN DELIMITER '%c' NULL '%s';\n",
					delimiter, null_str);
			/* FIXME: Handle properly instead of blindly reading the output. */
			while (fgetc(output) != EOF) ;
			break;
		}
	} else {
		printf("error unknown load mode: %d\n", mode_load);
	}

	for (i = 0; i < warehouses; i++) {
		for (j = 0; j < DISTRICT_CARDINALITY; j++) {
			for (k = 0; k < customers; k++) {
				/* c_id */
				FPRINTF(output, "%d", k + 1);
				METAPRINTF((output, "%c", delimiter));

				/* c_d_id */
				FPRINTF(output, "%d", j + 1);
				METAPRINTF((output, "%c", delimiter));

				/* c_w_id */
				FPRINTF(output, "%d", i + 1);
				METAPRINTF((output, "%c", delimiter));

				/* c_first */
				get_a_string(a_string, 8, 16);
				escape_me(a_string);
				FPRINTF(output, "%s", a_string);
				METAPRINTF((output, "%c", delimiter));

				/* c_middle */
				FPRINTF2(output, "OE");
				METAPRINTF((output, "%c", delimiter));

				/* c_last Clause 4.3.2.7 */
				if (k < 1000) {
					get_c_last(a_string, k);
				} else {
					get_c_last(a_string, get_nurand(255, 0, 999));
				}
				escape_me(a_string);
				FPRINTF(output, "%s", a_string);
				METAPRINTF((output, "%c", delimiter));

				/* c_street_1 */
				get_a_string(a_string, 10, 20);
				escape_me(a_string);
				FPRINTF(output, "%s", a_string);
				METAPRINTF((output, "%c", delimiter));

				/* c_street_2 */
				get_a_string(a_string, 10, 20);
				escape_me(a_string);
				FPRINTF(output, "%s", a_string);
				METAPRINTF((output, "%c", delimiter));

				/* c_city */
				get_a_string(a_string, 10, 20);
				escape_me(a_string);
				FPRINTF(output, "%s", a_string);
				METAPRINTF((output, "%c", delimiter));

				/* c_state */
				get_l_string(a_string, 2, 2);
				FPRINTF(output, "%s", a_string);
				METAPRINTF((output, "%c", delimiter));

				/* c_zip */
				get_n_string(a_string, 4, 4);
				FPRINTF(output, "%s11111", a_string);
				METAPRINTF((output, "%c", delimiter));

				/* c_phone */
				get_n_string(a_string, 16, 16);
				FPRINTF(output, "%s", a_string);
				METAPRINTF((output, "%c", delimiter));

				/* c_since */
				/*
				 * Milliseconds are not calculated.  This
				 * should also be the time when the data is
				 * loaded, I think.
				 */
				time(&t1);
				tm1 = localtime(&t1);
				print_timestamp(output, tm1);
				METAPRINTF((output, "%c", delimiter));

				/* c_credit */
				if (get_percentage() < .10) {
					FPRINTF2(output, "BC");
				} else {
					FPRINTF2(output, "GC");
				}
				METAPRINTF((output, "%c", delimiter));

				/* c_credit_lim */
				FPRINTF2(output, "50000.00");
				METAPRINTF((output, "%c", delimiter));

				/* c_discount */
				FPRINTF(output, "0.%04d", get_random(5000));
				METAPRINTF((output, "%c", delimiter));

				/* c_balance */
				FPRINTF2(output, "-10.00");
				METAPRINTF((output, "%c", delimiter));

				/* c_ytd_payment */
				FPRINTF2(output, "10.00");
				METAPRINTF((output, "%c", delimiter));

				/* c_payment_cnt */
				FPRINTF2(output, "1");
				METAPRINTF((output, "%c", delimiter));

				/* c_delivery_cnt */
				FPRINTF2(output, "0");
				METAPRINTF((output, "%c", delimiter));

				/* c_data */
				get_a_string(a_string, 300, 500);
				escape_me(a_string);
				FPRINTF(output, "%s", a_string);

				METAPRINTF((output, "\n"));
			}
		}
	}

	if (mode_load == MODE_FLAT) {
		fclose(output);
	} else {
		switch (mode_string) {
		case MODE_PGSQL:
			fprintf(output, "\\.\n");
			/* FIXME: Handle properly instead of blindly reading the output. */
			while (fgetc(output) != EOF) ;

			fprintf(output, "COMMIT;\n");
			/* FIXME: Handle properly instead of blindly reading the output. */
			while (fgetc(output) != EOF) ;

			pclose(output);
			break;
		}
	}

	printf("Finished customer table data...\n");
	return;
}
Exemple #5
0
/* Clause 4.3.3.1 */
void gen_districts()
{
	FILE *output;
	int i, j;
	char a_string[48];
	char filename[1024] = "\0";

	srand(0);
	printf("Generating district table data...\n");

	if (strlen(output_path) > 0) {
		strcpy(filename, output_path);
		strcat(filename, "/");
	}
	strcat(filename, DISTRICT_DATA);
	output = fopen(filename, "w");
	if (output == NULL) {
		printf("cannot open %s\n", DISTRICT_DATA);
		return;
	}

	for (i = 0; i < warehouses; i++) {
		for (j = 0; j < DISTRICT_CARDINALITY; j++) {
			/* d_id */
			FPRINTF(output, "%d", j + 1);
			METAPRINTF((output, "%c", delimiter));

			/* d_w_id */
			FPRINTF(output, "%d", i + 1);
			METAPRINTF((output, "%c", delimiter));

			/* d_name */
			get_a_string(a_string, 6, 10);
			escape_me(a_string);
			FPRINTF(output, "%s", a_string);
			METAPRINTF((output, "%c", delimiter));

			/* d_street_1 */
			get_a_string(a_string, 10, 20);
			escape_me(a_string);
			FPRINTF(output, "%s", a_string);
			METAPRINTF((output, "%c", delimiter));

			/* d_street_2 */
			get_a_string(a_string, 10, 20);
			escape_me(a_string);
			FPRINTF(output, "%s", a_string);
			METAPRINTF((output, "%c", delimiter));

			/* d_city */
			get_a_string(a_string, 10, 20);
			escape_me(a_string);
			FPRINTF(output, "%s", a_string);
			METAPRINTF((output, "%c", delimiter));

			/* d_state */
			get_l_string(a_string, 2, 2);
			FPRINTF(output, "%s", a_string);
			METAPRINTF((output, "%c", delimiter));

			/* d_zip */
			get_n_string(a_string, 4, 4);
			FPRINTF(output, "%s11111", a_string);
			METAPRINTF((output, "%c", delimiter));

			/* d_tax */
			FPRINTF(output, "0.%04d", get_random(2000));
			METAPRINTF((output, "%c", delimiter));

			/* d_ytd */
			FPRINTF2(output, "30000.00");
			METAPRINTF((output, "%c", delimiter));

			/* d_next_o_id */
			FPRINTF2(output, "3001");

			METAPRINTF((output, "\n"));
		}
	}
	fclose(output);
	printf("Finished district table data...\n");
	return;
}
/* Clause 4.7.1 */
void gen_orders()
{
	int i, j;
	FILE *orders_file = stdout;
	FILE *order_line_file = stdout;
	FILE *cc_xacts_file = stdout;
	char a_string[1024];
	int customers, orders;
	double o_sub_total, o_tax, o_total;
	struct tm *tm1, *tm2;
	time_t t1, t2;
	int order_line_count;
	char filename1[256];
	char filename2[256];
	char filename3[256];

	sprintf(filename1, "%s/orders.data", path);
	orders_file = fopen(filename1, "w");
	if (orders_file == NULL)
	{
		fprintf(stderr, "cannot open orders.data\n");
		return;
	}

	sprintf(filename2, "%s/order_line.data", path);
	order_line_file = fopen(filename2, "w");
	if (order_line_file == NULL)
	{
		fprintf(stderr, "cannot open order_line.data\n");
		return;
	}

	sprintf(filename3, "%s/cc_xacts.data", path);
	cc_xacts_file = fopen(filename3, "w");
	if (cc_xacts_file == NULL)
	{
		fprintf(stderr, "cannot open cc_xacts.data\n");
		return;
	}

	srand(0);
	printf("Generating order, order_line, and cc_xacts table data...\n");

	customers = ebs * 2880;
	orders = (int) (customers * 0.9);

	for (i = 0; i < orders; i++)
	{

		/* Order Line */

		order_line_count = get_random_int(5) + 1;
		for (j = 0; j < order_line_count; j++)
		{
			/* ol_id */
			fprintf(order_line_file, "%s%d%s", 
				field_deco, j + 1, field_deco);
			fprintf(order_line_file, "%c", delimiter);

			/* ol_o_id */
			fprintf(order_line_file, "%s%d%s", 
				field_deco, i + 1, field_deco);
			fprintf(order_line_file, "%c", delimiter);

			/* ol_i_id */
			fprintf(order_line_file, "%s%d%s",
				field_deco, 
				get_random_int(items) + 1, field_deco);
			fprintf(order_line_file, "%c", delimiter);

			/* ol_qty */
			fprintf(order_line_file, "%s%d%s",
				field_deco, 
				get_random_int(300) + 1, field_deco);
			fprintf(order_line_file, "%c", delimiter);

			/* ol_discount */
			fprintf(order_line_file, "%s%0.2f%s",
				field_deco, 
				(double) get_random_int(4) / 100.0, field_deco);
			fprintf(order_line_file, "%c", delimiter);

			/* ol_comments */
			get_a_string(a_string, 20, OL_COMMENT_LEN);
			fprintf(order_line_file, "%s%s%s", 
				field_deco, a_string, field_deco);

			fprintf(order_line_file, "\n");
		}

		/* Orders */

		/* o_id */
		fprintf(orders_file, "%s%d%s", field_deco, i + 1, field_deco);
		fprintf(orders_file, "%c", delimiter);

		/* o_c_id */
		fprintf(orders_file, "%s%d%s",  
			field_deco, get_random_int(customers) + 1, field_deco);
		fprintf(orders_file, "%c", delimiter);

		/* o_date */
		/* Note that the milliseconds are not calculated. */
		time(&t2);
		t1 = t2 - (86400 + get_random_int(5184000));
		tm1 = localtime(&t1);
		print_timestamp(orders_file, tm1);
		/*fprintf(orders_file, "%s%04d%02d%02d%02d%02d%02d000000%s",
			field_deco, 
			tm1->tm_year + 1900, tm1->tm_mon + 1, tm1->tm_mday,
			tm1->tm_hour, tm1->tm_min, tm1->tm_sec, field_deco);
		*/
		fprintf(orders_file, "%c", delimiter);

		/* o_sub_total */
		o_sub_total = (double) (get_random_int(999990) + 10) / 100.0;
		fprintf(orders_file, "%s%0.2f%s", 
			field_deco, o_sub_total, field_deco);
		fprintf(orders_file, "%c", delimiter);

		/* o_tax */
		o_tax = o_sub_total * 0.0825;
		fprintf(orders_file, "%s%0.2f%s", 
			field_deco, o_tax, field_deco);
		fprintf(orders_file, "%c", delimiter);

		/* o_total */
		o_total = o_sub_total + o_tax + order_line_count;
		fprintf(orders_file, "%s%0.2f%s", 
			field_deco, o_total, field_deco);
		fprintf(orders_file, "%c", delimiter);

		/* o_ship_type */
		fprintf(orders_file, "%s%s%s",
			field_deco, 
			o_ship_type[get_random_int(O_SHIP_TYPE_MAX)], 
			field_deco);
		fprintf(orders_file, "%c", delimiter);

		/* o_ship_date */
		/* Note that the milliseconds are not calculated. */
		t1 += get_random_int(691200);
		print_timestamp(orders_file, tm1);
		/*
		fprintf(orders_file, "%s%04d%02d%02d%02d%02d%02d000000%s",
			field_deco, 
			tm1->tm_year + 1900, tm1->tm_mon + 1, tm1->tm_mday,
			tm1->tm_hour, tm1->tm_min, tm1->tm_sec, field_deco);
		*/
		fprintf(orders_file, "%c", delimiter);

		/* o_bill_addr_id */
		fprintf(orders_file, "%s%d%s",
			field_deco, 
			get_random_int(2 * customers) + 1, field_deco);
		fprintf(orders_file, "%c", delimiter);

		/* o_ship_addr_id */
		fprintf(orders_file, "%s%d%s",
			field_deco, 
			get_random_int(2 * customers) + 1, field_deco);
		fprintf(orders_file, "%c", delimiter);

		/* o_status */
		fprintf(orders_file, "%s%s%s",
			field_deco, 
			o_status[get_random_int(O_STATUS_MAX)], field_deco);

		fprintf(orders_file, "\n");


		/* CC Xacts */

		/* cx_o_id */
		fprintf(cc_xacts_file, "%s%d%s", field_deco, i + 1, field_deco);
		fprintf(cc_xacts_file, "%c", delimiter);

		/* cx_type */
		fprintf(cc_xacts_file, "%s%s%s",
			field_deco, 
			cx_type[get_random_int(CX_TYPE_MAX)], field_deco);
		fprintf(cc_xacts_file, "%c", delimiter);

		/* cx_num */
		get_n_string(a_string, 16, 16);
		fprintf(cc_xacts_file, "%s%s%s", 
			field_deco, a_string, field_deco);
		fprintf(cc_xacts_file, "%c", delimiter);

		/* cx_name */
		/* Clause 4.7.1 says this should be an a_string[14..30] but the
		 * column definition in Clause 1.4.7 says it is at least 31. */
		get_a_string(a_string, 14, 30);
		fprintf(cc_xacts_file, "%s%s%s", 
			field_deco, a_string, field_deco);
		fprintf(cc_xacts_file, "%c", delimiter);

		/* cx_expiry */
		t2 += 864000 + get_random_int(62294400);
		tm2 = localtime(&t2);
		fprintf(cc_xacts_file, "%s%04d%02d%02d%s", 
			field_deco, tm2->tm_year + 1900,
			tm2->tm_mon + 1, tm2->tm_mday, field_deco);
		fprintf(cc_xacts_file, "%c", delimiter);

		/* cx_auth_id */
		get_a_string(a_string, CX_AUTH_ID_LEN, CX_AUTH_ID_LEN);
		fprintf(cc_xacts_file, "%s%s%s", 
			field_deco, a_string, field_deco);
		fprintf(cc_xacts_file, "%c", delimiter);

		/* cx_xact_amt */
		fprintf(cc_xacts_file, "%s%0.2f%s", 
			field_deco, o_total, field_deco);
		fprintf(cc_xacts_file, "%c", delimiter);

		/* cx_xact_date */
		/* Note that the milliseconds are not calculated. */
		print_timestamp(cc_xacts_file, tm1);
		/*
		fprintf(cc_xacts_file, "%s%04d%02d%02d%02d%02d%02d000000%s",
			field_deco, tm1->tm_year + 1900, tm1->tm_mon + 1, 
			tm1->tm_mday, tm1->tm_hour,
			tm1->tm_min, tm1->tm_sec, field_deco);
		*/
		fprintf(cc_xacts_file, "%c", delimiter);

		/* cx_co_id */
		fprintf(cc_xacts_file, "%s%d%s", 
			field_deco, get_random_int(92) + 1, field_deco);

		fprintf(cc_xacts_file, "\n");
	}

	fflush(orders_file);
	fflush(order_line_file);
	fflush(cc_xacts_file);
	fclose(orders_file);
	fclose(order_line_file);
	fclose(cc_xacts_file);
	printf("Finished order, order_line, and cc_xacts table data.\n");
	return;
}
/* Clause 4.7.1 */
void gen_customers()
{
	int i, j;
	int customers;
	FILE *output = stdout;
	char a_string[1024];
	char c_uname[C_UNAME_LEN + 1];
	int max;
	struct tm *tm1, *tm2, *tm3;
	time_t t1, t2, t3;
	char filename[256];

	sprintf(filename, "%s/customer.data", path);
	output = fopen(filename, "w");
	if (output == NULL)
	{
		fprintf(stderr, "cannot open customer.data\n");
		return;
	}

	srand(0);
	printf("Generating customer table data...\n");

	customers = 2880 * ebs;

	for (i = 0; i < customers; i++)
	{

		/* c_id */
		fprintf(output, "%s%d%s", field_deco, i + 1, field_deco);
		fprintf(output, "%c", delimiter);

		/* c_uname */
		/* Clause 4.6.2.10 */
		digsyl2(c_uname, i + 1, 0);
		fprintf(output, "%s%s%s", field_deco, c_uname, field_deco);
		fprintf(output, "%c", delimiter);

		/* c_passwd */
		/* Clause 4.6.2.11 */
		max = strlen(c_uname);
		fprintf(output, "%s", field_deco);
		for (j = 0; j < max; j++)
		{
			fprintf(output, "%c", (char) tolower(c_uname[j]));
		}
		fprintf(output, "%s%c", field_deco, delimiter);

		/* c_lname */
		get_a_string(a_string, 8, C_LNAME_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* c_fname */
		get_a_string(a_string, 8, C_FNAME_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* c_addr_id */
		fprintf(output, "%s%d%s", field_deco, get_random_int(2 * customers) + 1, field_deco);
		fprintf(output, "%c", delimiter);

		/* c_phone */
		get_n_string(a_string, 9, C_PHONE_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* c_email */
		/* Clause 6.4.2.14 */
		get_a_string(a_string, 2, 9);
		fprintf(output, "%s%s@%s%s", 
			field_deco, c_uname, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* c_since */
		time(&t2);
		t1 = t2 - (86400 + get_random_int(63072000));
		tm1 = localtime(&t1);
		fprintf(output, "%s%04d%02d%02d%s", 
			field_deco, tm1->tm_year + 1900,
			tm1->tm_mon + 1, tm1->tm_mday, field_deco);
		fprintf(output, "%c", delimiter);

		/* c_last_visit */
		t3 = t1 + get_random_int(5270400);
		if (t3 > t2)
		{
			t3 = t2;
		}
		tm3 = localtime(&t3);
		fprintf(output, "%s%04d%02d%02d%s", 
			field_deco, tm3->tm_year + 1900,
			tm3->tm_mon + 1, tm3->tm_mday, field_deco);
		fprintf(output, "%c", delimiter);

		/* c_login */
		/* This should be changed to the date and time the table is
		 * populated. Note that the milliseconds are not calculated. */
		tm2 = localtime(&t2);
		print_timestamp(output, tm2);
		/*
		fprintf(output, "%s%04d%02d%02d%02d%02d%02d000000%s",
			field_deco, 
			tm2->tm_year + 1900, tm2->tm_mon + 1, tm2->tm_mday,
			tm2->tm_hour, tm2->tm_min, tm2->tm_sec, field_deco);
		*/
		fprintf(output, "%c", delimiter);

		/* c_expiration */
		t2 += 7200;
		tm2 = localtime(&t2);
		print_timestamp(output, tm2);
		/*
		fprintf(output, "%s%04d%02d%02d%02d%02d%02d000000%s",
			field_deco, 
			tm2->tm_year + 1900, tm2->tm_mon + 1, tm2->tm_mday,
			tm2->tm_hour, tm2->tm_min, tm2->tm_sec, field_deco);
		*/
		fprintf(output, "%c", delimiter);

		/* c_discount */
		fprintf(output, "%s%0.2f%s",
			field_deco, (double) get_random_int(51) / 100.0, 
			field_deco);
		fprintf(output, "%c", delimiter);

		/* c_balance */
		fprintf(output, "%s0.0%s", field_deco, field_deco);
		fprintf(output, "%c", delimiter);

		/* c_ytd_pmt */
		fprintf(output, "%s%0.2f%s", field_deco, 
			(double) get_random_int(100000) / 100.0, field_deco);
		fprintf(output, "%c", delimiter);

		/* c_birthdate */
		/* The date is being calculated from 1900 instead of 1880. */
		tm1->tm_year = 0;
		tm1->tm_mon = 0;
		tm1->tm_mday = 1;
		tm1->tm_sec = 0;
		tm1->tm_min = 0;
		tm1->tm_hour = 0;
		t1 = mktime(tm1);
		time(&t2);
		tm2 = localtime(&t2);
		t3 = (time_t) (get_percentage() * (double) ((long long) t2 - (long long) t1 + (long long) 86400)) + t1;
		tm3 = localtime(&t3);
		fprintf(output, "%s%04d%02d%02d%s", 
			field_deco, tm3->tm_year + 1900,
			tm3->tm_mon + 1, tm3->tm_mday, field_deco);
		fprintf(output, "%c", delimiter);

		/* c_data */
		get_a_string(a_string, 100, C_DATA_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);

		fprintf(output, "\n");
	}

	fflush(output);
	fclose(output);
	printf("Finished customer table data.\n");
	return;
}