Exemple #1
0
/* Clause 4.3.3.1 */
void gen_items() {
  FILE* output;
  int i;
  char a_string[128];
  int j;
  char filename[1024] = "\0";

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

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

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

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

    /* i_im_id */
    FPRINTF(output, "%d", get_random(9999) + 1);
    METAPRINTF((output, "%c", delimiter));

    /* i_name */
    get_a_string(a_string, 14, 24);
    escape_me(a_string);
    FPRINTF(output, "%s", a_string);
    METAPRINTF((output, "%c", delimiter));

    /* i_price */
    FPRINTF(output, "%0.2f", ((double)get_random(9900) + 100.0) / 100.0);
    METAPRINTF((output, "%c", delimiter));

    /* i_data */
    get_a_string(a_string, 26, 50);
    if (get_percentage() < .10) {
      j = get_random(strlen(a_string) - 8);
      strncpy(a_string + j, "ORIGINAL", 8);
    }
    escape_me(a_string);
    FPRINTF(output, "%s", a_string);

    METAPRINTF((output, "\n"));
  }
  fclose(output);
  printf("Finished item table data...\n");
  return;
}
Exemple #2
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 #3
0
/* Clause 4.3.3.1 */
void gen_history() {
  FILE* output;
  int i, j, k;
  char a_string[64];
  struct tm* tm1;
  time_t t1;
  char filename[1024] = "\0";

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

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

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

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

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

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

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

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

        /* h_date */
        /*
         * 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));

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

        /* h_data */
        get_a_string(a_string, 12, 24);
        escape_me(a_string);
        FPRINTF(output, "%s", a_string);

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

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

	if (mode_load == MODE_FLAT) {
		if (strlen(output_path) > 0) {
			strcpy(filename, output_path);
			strcat(filename, "/");
		}
		strcat(filename, ITEM_DATA);
		output = fopen(filename, "w");
		if (output == NULL) {
			printf("cannot open %s\n", ITEM_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 item 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 < items; i++) {
		/* i_id */
		FPRINTF(output, "%d", i + 1);
		METAPRINTF((output, "%c", delimiter));

		/* i_im_id */
		FPRINTF(output, "%d", get_random(9999) + 1);
		METAPRINTF((output, "%c", delimiter));

		/* i_name */
		get_a_string(a_string, 14, 24);
		escape_me(a_string);
		FPRINTF(output, "%s", a_string);
		METAPRINTF((output, "%c", delimiter));

		/* i_price */
		FPRINTF(output, "%0.2f", ((double) get_random(9900) + 100.0) / 100.0);
		METAPRINTF((output, "%c", delimiter));

		/* i_data */
		get_a_string(a_string, 26, 50);
		if (get_percentage() < .10) {
			j = get_random(strlen(a_string) - 8);
			strncpy(a_string + j, "ORIGINAL", 8);
		}
		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 item table data...\n");
	return;
}
int execute_buy_confirm(	struct db_context_t *odbcc,
						struct buy_confirm_t *data)
{

	SQLRETURN rc;
	short int ship_day = 0;
	char ol_comment[OL_COMMENT_LEN + 1];
	char cx_auth_id[CX_AUTH_ID_LEN + 1];
	char sql_cmd[2048];
	long long  c_addr_id = 0;
	char c_fname[C_FNAME_LEN+1];
	char c_lname[C_LNAME_LEN+1];
	short co_id = 0;
	long long  ship_addr_id = 0;
	long long scl_i_id[SHOPPING_CART_ITEMS_MAX];
	short scl_qty[SHOPPING_CART_ITEMS_MAX];
	double scl_cost[SHOPPING_CART_ITEMS_MAX];
	int   ol_id = 0;
	int i_stock = 0;
	int ix,iy;        /* Loop Counter */

	for ( ix =0 ; ix < SHOPPING_CART_ITEMS_MAX ; ix++ ) {
		scl_i_id[ix] = 0;
		scl_qty[ix] = 0;
		scl_cost[ix] = 0;
	}
	ix = 0;

	bzero(ol_comment,sizeof(ol_comment));
	bzero(cx_auth_id,sizeof(cx_auth_id));
	bzero(sql_cmd,sizeof(sql_cmd));
	bzero(c_fname,sizeof(c_fname));
	bzero(c_lname,sizeof(c_lname));
	
	/* Generate random day between 1 to 7 for ship_date. */
	ship_day = get_random_int(7) + 1;
	/* get authentication id from PGE */
	strcpy(cx_auth_id, "012345678912345");
	/* generate a_string[20..100] as order_line comment */
	get_a_string(ol_comment, 20, 100);
	
	
	/* SELECT shopping_cart Info */
	/* Create SQL Command */
	if( data->sc_id != 0 ){
	
		// if data->sc_id not Zero, Select data from Shopping_Cart Table
		/* Create SQL Command */
		sprintf(sql_cmd,STMT_BUYCONF_selSC,data->sc_id);

		/* Execute SQL Command */
		rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
		if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
			LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
			SQLCloseCursor(odbcc->hstmt);
			return W_ERROR;
		}

		/* Get data */
		SQLBindCol(odbcc->hstmt,1,SQL_DOUBLE,&data->sc_sub_total,0,NULL);
		SQLBindCol(odbcc->hstmt,2,SQL_DOUBLE,&data->sc_tax,0,NULL);
		SQLBindCol(odbcc->hstmt,3,SQL_DOUBLE,&data->sc_ship_cost,0,NULL);
		SQLBindCol(odbcc->hstmt,4,SQL_DOUBLE,&data->sc_total,0,NULL);
		rc = SQLFetch(odbcc->hstmt);
		if( rc != SQL_NO_DATA_FOUND ) {
				if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
				LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
				SQLCloseCursor(odbcc->hstmt);
				return W_ERROR;
			}
		}
		SQLCloseCursor(odbcc->hstmt);

	}else{

		// if data-> sc_id is Zero, Get Shopping_Cart iD from Shopping_Cart Table
		/* Create SQL Command */
		sprintf(sql_cmd,STMT_BUYCONF_selInsVal);

		/* Execute SQL Command */
		rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
		if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
			LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
			SQLCloseCursor(odbcc->hstmt);
			return W_ERROR;
		}

		/* Get data */
		SQLBindCol(odbcc->hstmt,1,SQL_C_SBIGINT,&data->sc_id,0,NULL);
		rc = SQLFetch(odbcc->hstmt);
		if( rc != SQL_NO_DATA_FOUND ) {
				if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
				LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
				SQLCloseCursor(odbcc->hstmt);
				return W_ERROR;
			}
		}
		SQLCloseCursor(odbcc->hstmt);
		
		//insert data is all Zero
		data->sc_sub_total =0 ;
		data->sc_tax = 0 ;
		data->sc_ship_cost = 0 ;
		data->sc_total =0 ;
		
	}

	/* SELECT customer Info */
	/* Create SQL command */
	memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
	sprintf(sql_cmd,STMT_BUYCONF_selCS,data->c_id);

	/* Execute SQL Command */
	rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
	if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
		LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
		SQLCloseCursor(odbcc->hstmt);
		return W_ERROR;
	}

	/* Get data */
	SQLBindCol(odbcc->hstmt,1,SQL_CHAR,c_fname,sizeof(c_fname),NULL);
	SQLBindCol(odbcc->hstmt,2,SQL_CHAR,c_lname,sizeof(c_lname),NULL);
	SQLBindCol(odbcc->hstmt,3,SQL_DOUBLE,&data->c_discount,0,NULL);
	SQLBindCol(odbcc->hstmt,4,SQL_C_SBIGINT,&c_addr_id,0,NULL);
	rc = SQLFetch(odbcc->hstmt);
	if( rc != SQL_NO_DATA_FOUND ) {
		if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
			LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
			SQLCloseCursor(odbcc->hstmt);
			return W_ERROR;
		}
	}
	SQLCloseCursor(odbcc->hstmt);

	if (data->shipping.addr_street1[0] != 0x00) {
		
		/* SELECT ADDRESS  */
		/* Create SQL command */
		memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
		sprintf(	sql_cmd,STMT_BUYCONF_selADRCNT,
				data->shipping.co_name,
				data->shipping.addr_zip,
				data->shipping.addr_state,
				data->shipping.addr_city,
				data->shipping.addr_street1,
				data->shipping.addr_street2);

		/* Execute SQL Command */
		rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
		if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
			LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
			SQLCloseCursor(odbcc->hstmt);
			return W_ERROR;
		}

		/* Get data */
		SQLBindCol(odbcc->hstmt,1,SQL_C_SBIGINT,&ship_addr_id,0,NULL);
		SQLBindCol(odbcc->hstmt,2,SQL_C_SHORT,&co_id,0,NULL);
		rc = SQLFetch(odbcc->hstmt);
		SQLCloseCursor(odbcc->hstmt);

		if( rc != SQL_NO_DATA_FOUND ) {
			if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
				LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
				return W_ERROR;
			}
		} else {

			/* Create SQL command */
			memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
			sprintf(sql_cmd,STMT_BUYCONF_getCountry, data->shipping.co_name);

			/* Execute SQL Command */
			rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
			if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
				LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
				return W_ERROR;
			}

			/* Get data */
			SQLBindCol(odbcc->hstmt,1,SQL_SMALLINT,&co_id,0,NULL);
			rc = SQLFetch(odbcc->hstmt);
			if( rc != SQL_NO_DATA_FOUND ) {
				if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
					LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
					return W_ERROR;
				}
			}
			SQLCloseCursor(odbcc->hstmt);
				
			//select id from sequense
			/* Create SQL command */
			memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
			sprintf(sql_cmd,STMT_BUYCONF_selADRID);

			/* Execute SQL Command */
			rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
			if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
				LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
				SQLCloseCursor(odbcc->hstmt);
				return W_ERROR;
			}

			/* Get data */
			SQLBindCol(odbcc->hstmt,1,SQL_C_UBIGINT,&ship_addr_id,0,NULL);
			rc = SQLFetch(odbcc->hstmt);
			SQLCloseCursor(odbcc->hstmt);
			if( rc != SQL_NO_DATA_FOUND ) {
				if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
					LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
					return W_ERROR;
				}
			}	
			
			/* INSERT ADDRESS  */
			/* Create SQL command */
			memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
			sprintf(	sql_cmd,STMT_BUYCONF_insADR,
					ship_addr_id ,
					data->shipping.addr_street1,
					data->shipping.addr_street2,
					data->shipping.addr_city,
					data->shipping.addr_state,
					data->shipping.addr_zip,
					co_id);

			/* Execute SQL Command */
			rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
			if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
				LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
				SQLCloseCursor(odbcc->hstmt);
				return W_ERROR;
			}
			SQLCloseCursor(odbcc->hstmt);
		}
		
	} else {
		
		/* SELECT ADDRESS  */
		/* Create SQL command */
		ship_addr_id = c_addr_id;
		memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
		sprintf(sql_cmd,STMT_BUYCONF_selADR,ship_addr_id);

		/* Execute SQL Command */
		rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
		if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
			LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
			SQLCloseCursor(odbcc->hstmt);
			return W_ERROR;
		}

		/* Get data */
		SQLBindCol(odbcc->hstmt,1,SQL_SMALLINT,&co_id,0,NULL);
		rc = SQLFetch(odbcc->hstmt);
		if( rc != SQL_NO_DATA_FOUND ) {
			if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
				LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
				SQLCloseCursor(odbcc->hstmt);
				return W_ERROR;
			}
		}
		SQLCloseCursor(odbcc->hstmt);
	}
	
	/* INSERT ORDERS  */
	/* Create SQL command */
	memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
	sprintf(sql_cmd,STMT_BUYCONF_insODR,
			data->sc_id,
			data->c_id,
			data->sc_sub_total,
			data->sc_tax,
			data->sc_total,
			ship_day,
			c_addr_id,
 			ship_addr_id);

	/* Execute SQL Command */
	rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
	if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
		LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
		SQLCloseCursor(odbcc->hstmt);
		return W_ERROR;
	}
	SQLCloseCursor(odbcc->hstmt);
	
	/* SELECT Shopping Cart Line  */
	/* Create SQL command */
	memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
	sprintf(sql_cmd,STMT_BUYCONF_selSCL,data->sc_id);

	/* Execute SQL Command */
	rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
	if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
		LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
		SQLCloseCursor(odbcc->hstmt);
		return W_ERROR;
	}

	/* Get data */
	for (ix=0;ix<SHOPPING_CART_ITEMS_MAX;ix++) {
		SQLBindCol(odbcc->hstmt,1,SQL_C_UBIGINT, &scl_i_id[ix],0,NULL);
		SQLBindCol(odbcc->hstmt,2,SQL_DOUBLE,  &scl_cost[ix],0,NULL);
		SQLBindCol(odbcc->hstmt,3,SQL_C_SHORT,&scl_qty[ix], 0,NULL);
		rc = SQLFetch(odbcc->hstmt);
		if( rc == SQL_NO_DATA_FOUND ) {
			break;
		}
		if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
			LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
			SQLCloseCursor(odbcc->hstmt);
			return W_ERROR;
		}
	}
	SQLCloseCursor(odbcc->hstmt);

	for (iy=0;iy<ix;iy++) {
		
		/* INSERT ORDER Line  */
		/* Create SQL command */
		memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
		sprintf( sql_cmd,STMT_BUYCONF_insODRL,
					++ol_id,
					data->sc_id,
					scl_i_id[iy],
					scl_qty[iy],
					data->c_discount,
 					ol_comment);

		/* Execute SQL Command */
		rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
		if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
			LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
			SQLCloseCursor(odbcc->hstmt);
			return W_ERROR;
		}
		SQLCloseCursor(odbcc->hstmt);

		/* SELECT Item  */
		/* Create SQL command */
		memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
		sprintf(sql_cmd,STMT_BUYCONF_selITM, scl_i_id[iy]);

		/* Execute SQL Command */
		rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
		if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
			LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
			SQLCloseCursor(odbcc->hstmt);
			return W_ERROR;
		}

		/* Get data */
		SQLBindCol(odbcc->hstmt,1,SQL_C_SHORT,&co_id,0,NULL);
		rc = SQLFetch(odbcc->hstmt);
		if( rc != SQL_NO_DATA_FOUND ) {
			if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO) {
				LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
				SQLCloseCursor(odbcc->hstmt);
				return W_ERROR;
			}
		}
		SQLCloseCursor(odbcc->hstmt);

		if (i_stock - 10 > scl_qty[iy]) {
			i_stock -= scl_qty[iy];
		} else {
			i_stock = i_stock - scl_qty[iy] + 21;
		}

		/* UPDATE Item  */
		/* Create SQL command */
		memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
		sprintf(sql_cmd,STMT_BUYCONF_updITM, i_stock,scl_i_id[iy]);

		/* Execute SQL Command */
		rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
		if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
			LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
			SQLCloseCursor(odbcc->hstmt);
			return W_ERROR;
		}
		SQLCloseCursor(odbcc->hstmt);
	}

	/* INSERT cc_xacts  */
	/* Create SQL command */
	memset( sql_cmd , 0x00 , sizeof( sql_cmd ) ) ;
	sprintf(sql_cmd,STMT_BUYCONF_insXACT,
					data->sc_id,
					data->cx_type,
					data->cx_num,
					data->cx_name,
					data->cx_expiry,
					cx_auth_id,
					data->sc_total,
					co_id);

	/* Execute SQL Command */
	rc = SQLExecDirect(odbcc->hstmt,sql_cmd,SQL_NTS);
	if (rc != SQL_SUCCESS && rc != SQL_SUCCESS_WITH_INFO){
		LOG_ODBC_ERROR(SQL_HANDLE_STMT, odbcc->hstmt);
		SQLCloseCursor(odbcc->hstmt);
		return W_ERROR;
	}
	SQLCloseCursor(odbcc->hstmt);

	rc = getSCDetail(	odbcc,
					data->scl_data,
					data->sc_id,
					&data->sc_size);
	
	if (rc == W_ERROR) {
		return W_ERROR;
	}

	return OK;
}
/* Clause 4.7.1 */
void gen_addresses()
{
	int i;
	FILE *output = stdout;
	char a_string[1024];
	int addresses;
	char filename[256];

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

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

	addresses = ebs * 2880 * 2;
	for (i = 0; i < addresses; i++)
	{
		/* addr_id */
		fprintf(output, "%s%d%s", field_deco, i + 1, field_deco);
		fprintf(output, "%c", delimiter);

		/* addr_street1 */
		get_a_string(a_string, 15, ADDR_STREET1_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* addr_street2 */
		get_a_string(a_string, 15, ADDR_STREET1_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* addr_city */
		get_a_string(a_string, 4, ADDR_CITY_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* addr_state */
		get_a_string(a_string, 2, ADDR_STATE_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* addr_zip */
		get_a_string(a_string, 5, ADDR_ZIP_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* addr_co_id */
		fprintf(output, "%s%d%s", field_deco, get_random_int(CO_ID_MAX) + 1, field_deco);

		fprintf(output, "\n");
	}

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

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

	if (mode_load == MODE_FLAT) {
		if (strlen(output_path) > 0) {
			strcpy(filename, output_path);
			strcat(filename, "/");
		}
		strcat(filename, HISTORY_DATA);
		output = fopen(filename, "w");
		if (output == NULL) {
			printf("cannot open %s\n", HISTORY_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 history 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++) {
				/* h_c_id */
				FPRINTF(output, "%d", k + 1);
				METAPRINTF((output, "%c", delimiter));

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

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

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

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

				/* h_date */
				/*
				 * 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));

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

				/* h_data */
				get_a_string(a_string, 12, 24);
				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 history table data...\n");
	return;
}
Exemple #8
0
/* Clause 4.3.3.1 */
void gen_stock()
{
	FILE *output;
	int i, j, k;
	char a_string[128];
	char filename[1024] = "\0";

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

	if (mode_load == MODE_FLAT) {
		if (strlen(output_path) > 0) {
			strcpy(filename, output_path);
			strcat(filename, "/");
		}
		strcat(filename, STOCK_DATA);
		output = fopen(filename, "w");
		if (output == NULL) {
			printf("cannot open %s\n", STOCK_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 stock 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 < items; j++) {
			/* s_i_id */
			FPRINTF(output, "%d", j + 1);
			METAPRINTF((output, "%c", delimiter));

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

			/* s_quantity */
			FPRINTF(output, "%d", get_random(90) + 10);
			METAPRINTF((output, "%c", delimiter));

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

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

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

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

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

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

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

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

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

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

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

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

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

			/* s_data */
			get_a_string(a_string, 26, 50);
			if (get_percentage() < .10) {
				k = get_random(strlen(a_string) - 8);
				strncpy(a_string + k, "ORIGINAL", 8);
			}
			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 stock table data...\n");
	return;
}
Exemple #9
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;
}
/* 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;
}
Exemple #11
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_items()
{
	int i;
	FILE *output = stdout;
	char a_string[1024];
	int i1, i2, i3, i4, i5;
	double srp;
	struct tm tm1, *tm2, *tm3;
	time_t t1, t2, t3;
	char filename[256];

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

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

	item_count = items;

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

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

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

		/* i_a_id */
		if (i < items / 4)
		{
			fprintf(output, "%s%d%s", field_deco, i + 1, field_deco);
		}
		else
		{
			fprintf(output, "%s%d%s",
				field_deco, 
				get_random_int(items / 4) + 1, field_deco);
		}
		fprintf(output, "%c", delimiter);

		/* i_pub_date */
		tm1.tm_year = 30;
		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);

		/* i_publisher */
		get_a_string(a_string, 14, I_PUBLISHER_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* i_subject */
		fprintf(output, "%s%s%s",
			field_deco, 
			i_subject[get_random_int(I_SUBJECT_MAX)], field_deco);
		fprintf(output, "%c", delimiter);

		/* i_desc */
		get_a_string(a_string, 100, I_DESC_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* i_related1 */
		i1 = get_random_int(items) + 1;
		fprintf(output, "%s%d%s", field_deco, i1, field_deco);
		fprintf(output, "%c", delimiter);

		/* i_related2 */
		do
		{
			i2 = get_random_int(items) + 1;
		}
		while (i2 == i1);
		fprintf(output, "%s%d%s", field_deco, i2, field_deco);
		fprintf(output, "%c", delimiter);

		/* i_related3 */
		do
		{
			i3 = get_random_int(items) + 1;
		}
		while (i3 == i1 || i3 == i2);
		fprintf(output, "%s%d%s", field_deco, i3, field_deco);
		fprintf(output, "%c", delimiter);

		/* i_related4 */
		do
		{
			i4 = get_random_int(items) + 1;
		}
		while (i4 == i1 || i4 == i2 || i4 == i3);
		fprintf(output, "%s%d%s", field_deco, i4, field_deco);
		fprintf(output, "%c", delimiter);

		/* i_related5 */
		do
		{
			i5 = get_random_int(items) + 1;
		}
		while (i5 == i1 || i5 == i2 || i5 == i3 || i5 == i4);
		fprintf(output, "%s%d%s", field_deco, i5, field_deco);
		fprintf(output, "%c", delimiter);

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

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

		/* i_srp */
		srp = (get_random_int(999900) + 100.0) / 100;
		fprintf(output, "%s%0.2f%s", field_deco, srp, field_deco);
		fprintf(output, "%c", delimiter);

		/* i_cost */
		fprintf(output, "%s%0.2f%s",
			field_deco, 
			(1.0 - ((double) get_random_int(6) / 10.0)) * srp, 
			field_deco);
		fprintf(output, "%c", delimiter);

		/* i_avail */
		/*
		 * 86400 is the number of seconds in a day, and 2505600 is the
		 * number ofseconds in 29 days.
		 */
		t3 += 86400 + (time_t) get_random_int(2505601);
		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);

		/* i_stock */
		fprintf(output, "%s%d%s", 
			field_deco, get_random_int(21) + 10, field_deco);
		fprintf(output, "%c", delimiter);

		/* i_isbn */
		get_a_string(a_string, 13, I_ISBN_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* i_page */
		fprintf(output, "%s%d%s", 
			field_deco, get_random_int(9980) + 20, field_deco);
		fprintf(output, "%c", delimiter);

		/* i_backing */
		fprintf(output, "%s%s%s",
			field_deco, 
			i_backing[get_random_int(I_BACKING_MAX)], field_deco);
		fprintf(output, "%c", delimiter);

		/* i_dimensions */
		/* Clause 4.6.2.17 */
		fprintf(output, "%s%0.2fx%0.2fx%0.2f%s",
			field_deco, 
			(double) (get_random_int(9999) + 1) / 100.0, (double) (get_random_int(9999) + 1) / 100.0, (double) (get_random_int(9999) + 1) / 100.0, field_deco);

		fprintf(output, "\n");
	}

	fflush(output);
	fclose(output);
	printf("Finished item 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;
}
/* Clause 4.7.1 */
void gen_authors()
{
	int i;
	FILE *output = stdout;
	char a_string[1024];
	struct tm tm1, *tm2, *tm3;
	time_t t1, t2, t3;
	char filename[256];

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

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

	author_count = items / 4;

	for (i = 0; i < author_count; i++)
	{
		/* a_id */
		fprintf(output, "%s%d%s", field_deco, i + 1, field_deco);
		fprintf(output, "%c", delimiter);

		/* a_fname */
		get_a_string(a_string, 3, A_FNAME_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

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

		/* a_mname */
		get_a_string(a_string, 1, A_MNAME_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);
		fprintf(output, "%c", delimiter);

		/* a_dob */
		/* The date is being calculated from 1900 instead of 1800. */
		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);

		/* a_bio */
		get_a_string(a_string, 125, A_BIO_LEN);
		fprintf(output, "%s%s%s", field_deco, a_string, field_deco);

		fprintf(output, "\n");
	}

	fflush(output);
	fclose(output);
	printf("Finished author table data.\n");
	return;
}
Exemple #15
0
/* Clause 4.3.3.1 */
void gen_stock() {
  FILE* output;
  int i, j, k;
  char a_string[128];
  char filename[1024] = "\0";

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

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

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

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

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

      /* s_quantity */
      FPRINTF(output, "%d", get_random(90) + 10);
      METAPRINTF((output, "%c", delimiter));

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

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

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

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

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

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

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

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

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

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

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

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

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

      /* s_data */
      get_a_string(a_string, 26, 50);
      if (get_percentage() < .10) {
        k = get_random(strlen(a_string) - 8);
        strncpy(a_string + k, "ORIGINAL", 8);
      }
      escape_me(a_string);
      FPRINTF(output, "%s", a_string);

      METAPRINTF((output, "\n"));
    }
  }
  fclose(output);
  printf("Finished stock table data...\n");
  return;
}
Exemple #16
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 #17
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;
}
int execute_buy_confirm(struct db_context_t *dbc,
	struct buy_confirm_t *data)
{
	short int ship_day = 0;
	char ol_comment[OL_COMMENT_LEN + 1];
	char cx_auth_id[CX_AUTH_ID_LEN + 1];
	char sql_cmd[2048];
	long long  c_addr_id = 0;
	char c_fname[C_FNAME_LEN+1];
	char c_lname[C_LNAME_LEN+1];
	short co_id = 0;
	long long  ship_addr_id = 0;
	long long scl_i_id[SHOPPING_CART_ITEMS_MAX];
	short scl_qty[SHOPPING_CART_ITEMS_MAX];
	double scl_cost[SHOPPING_CART_ITEMS_MAX];
	int	ol_id = 0;
	int st_stock = 0;
	int ix,iy;        /* Loop Counter */

	PGresult *res;
	int j;

	for ( ix =0 ; ix < SHOPPING_CART_ITEMS_MAX ; ix++ )
	{
		scl_i_id[ix] = 0;
		scl_qty[ix] = 0;
		scl_cost[ix] = 0;
	}
	ix = 0;

	bzero(ol_comment,sizeof(ol_comment));
	bzero(cx_auth_id,sizeof(cx_auth_id));
	bzero(sql_cmd,sizeof(sql_cmd));
	bzero(c_fname,sizeof(c_fname));
	bzero(c_lname,sizeof(c_lname));

	/* Generate random day between 1 to 7 for ship_date. */
	ship_day = get_random_int(7) + 1;
	/* get authentication id from PGE */
	strcpy(cx_auth_id, "012345678912345");
	/* generate a_string[20..100] as order_line comment */
	get_a_string(ol_comment, 20, 100);


	/* SELECT shopping_cart Info */
	if( data->sc_id != 0 )
	{

		// if data->sc_id not Zero, Select data from Shopping_Cart Table
		/* Create SQL Command */
		sprintf(sql_cmd,STMT_BUYCONF_selSC2,data->sc_id); 

		/* **MOBILE CODE** SQL Command */
		res = PQexec(dbc->conn, sql_cmd);
		if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
		{
			LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
			PQclear(res);
			return ERROR;
		}

		if (PQntuples(res) != 0)
		{
			/* Get data */
			j = 0;
			data->sc_sub_total = strtod(PQgetvalue(res, 0, j++), NULL);
			data->sc_tax = strtod(PQgetvalue(res, 0, j++), NULL);
			data->sc_ship_cost = strtod(PQgetvalue(res, 0, j++), NULL);
			data->sc_total = strtod(PQgetvalue(res, 0, j++), NULL);
			PQclear(res);
		}
		else
		{
			LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
			LOG_ERROR_MESSAGE("Could not obtain shopping_cart info for sc_id = %d\n", data->sc_id); /* pgxc modif: addition of c_id */
			PQclear(res);
			return ERROR;
		}
	}
	else
	{
		// if data-> sc_id is Zero, Get Shopping_Cart iD from Shopping_Cart Table
		/* Create SQL Command */
		sprintf(sql_cmd,STMT_BUYCONF_selInsVal);

		/* **MOBILE CODE** SQL Command */
		res = PQexec(dbc->conn, sql_cmd);
		if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
		{
			LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
			PQclear(res);
			return ERROR;
		}

		/* Get data */
		if (PQntuples(res) != 0)
		{
			j = 0;
			data->sc_id = atoll(PQgetvalue(res, 0, j++));
			PQclear(res);
		}
		else
		{
			LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
			LOG_ERROR_MESSAGE("Could not obtain shopping_cart_id\n"); /* pgxc modif: addition of c_id */
			PQclear(res);
			return ERROR;
		}
 
		//insert data is all Zero
		data->sc_sub_total = 0;
		data->sc_tax = 0;
		data->sc_ship_cost = 0;
		data->sc_total = 0;
	}

	/* SELECT customer Info */
	/* Create SQL command */
	memset(sql_cmd, 0x00, sizeof(sql_cmd));
	sprintf(sql_cmd,STMT_BUYCONF_selCS,data->c_id);

	/* **MOBILE CODE** SQL Command */
	res = PQexec(dbc->conn, sql_cmd);
	if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
	{
		LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
		PQclear(res);
		return ERROR;
	}

	if (PQntuples(res) != 0)
	{
		/* Get data */
		j = 0;
		strcpy(c_fname, PQgetvalue(res, 0, j++));
		strcpy(c_lname, PQgetvalue(res, 0, j++));
		data->c_discount = strtod(PQgetvalue(res, 0, j++), NULL);
		c_addr_id = atoll(PQgetvalue(res, 0, j++));
		PQclear(res);
	}
	else
	{
		LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
		LOG_ERROR_MESSAGE("Could not select customer = %d\n", data->c_id); /* pgxc modif: addition of c_id */
		PQclear(res);
		return ERROR;
	}

	if (data->shipping.addr_street1[0] != 0x00)
	{
		/* SELECT ADDRESS  */
		/* Create SQL command */
		memset(sql_cmd, 0x00, sizeof(sql_cmd));
		sprintf(sql_cmd, STMT_BUYCONF_selADRCNT,
			data->shipping.co_name,
			data->shipping.addr_zip,
			data->shipping.addr_state,
			data->shipping.addr_city,
			data->shipping.addr_street1,
			data->shipping.addr_street2,
			data->c_id); /* pgxc additional */

		/* **MOBILE CODE** SQL Command */
		res = PQexec(dbc->conn, sql_cmd);
		if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
		{
			LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
			PQclear(res);
			return ERROR;
		}

		/* Get data */
		j = 0;
		if (PQntuples(res) != 0)
		{
			ship_addr_id = atoll(PQgetvalue(res, 0, j++));
			co_id = atoi(PQgetvalue(res, 0, j++));
		}

		if(PQntuples(res) == 0)
		{
			PQclear(res);

			/* Create SQL command */
			memset(sql_cmd, 0x00, sizeof(sql_cmd));
			sprintf(sql_cmd,STMT_BUYCONF_getCountry, data->shipping.co_name);

			/* **MOBILE CODE** SQL Command */
			res = PQexec(dbc->conn, sql_cmd);
			if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
			{
				LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
				PQclear(res);
				return ERROR;
			}

			/* Get data */
			if (PQntuples(res) != 0)
			{
				j = 0;
				co_id = atoi(PQgetvalue(res, 0, j++));
			}
			else
			{
				LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
			    LOG_ERROR_MESSAGE("Could not obtain country for %s", data->shipping.co_name);
			    PQclear(res);
			    return ERROR;
			}
			PQclear(res);

			//select id from sequense
			/* Create SQL command */
			memset(sql_cmd, 0x00, sizeof(sql_cmd));
			sprintf(sql_cmd,STMT_BUYCONF_selADRID);

			/* **MOBILE CODE** SQL Command */
			res = PQexec(dbc->conn, sql_cmd);
			if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
			{
				LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
				PQclear(res);
				return ERROR;
			}

/* Get data */
			if (PQntuples(res) != 0)
			{
				j = 0;
				ship_addr_id = atoll(PQgetvalue(res, 0, j++));
				PQclear(res);
			}
			else
			{
				LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
				LOG_ERROR_MESSAGE("Could not obtain addr_id");
				PQclear(res);
				return ERROR;
			}

			/* INSERT ADDRESS  */
			/* Create SQL command */
			memset(sql_cmd, 0x00, sizeof(sql_cmd));
			sprintf(sql_cmd,STMT_BUYCONF_insADR,
				ship_addr_id,
				data->shipping.addr_street1,
				data->shipping.addr_street2,
				data->shipping.addr_city,
				data->shipping.addr_state,
				data->shipping.addr_zip,
				co_id,
				data->c_id);

			/* **MOBILE CODE** SQL Command */
			res = PQexec(dbc->conn, sql_cmd);
			if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
			{
				LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
				PQclear(res);
				return ERROR;
			}
			PQclear(res);
		}
		else
		{
			PQclear(res);
		}

	}
	else
	{

		/* SELECT ADDRESS  */
		/* Create SQL command */
		ship_addr_id = c_addr_id;
		memset(sql_cmd, 0x00, sizeof(sql_cmd));

		if (data->c_id > 0) 
			sprintf(sql_cmd,STMT_BUYCONF_selADR,ship_addr_id,data->c_id); /* pgxc modif: addition of c_id */
		else
			sprintf(sql_cmd,STMT_BUYCONF_selADR_nocust,ship_addr_id); /* pgxc modif */

		/* **MOBILE CODE** SQL Command */
		res = PQexec(dbc->conn, sql_cmd);
		if (!res || PQresultStatus(res) != PGRES_TUPLES_OK )
		{
			LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
			PQclear(res);
			return ERROR;
		}

		/* Get data */
		if (PQntuples(res) != 0)
		{
			j = 0;
			co_id = atoi(PQgetvalue(res, 0, j++));
			PQclear(res);
		}
		else
		{
			LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
			LOG_ERROR_MESSAGE("Could not obtain address for addr_id = %d, c_id = %lld\n", ship_addr_id, data->c_id); /* pgxc modif: addition of c_id */
			PQclear(res);
			return ERROR;
		}
	}

	/* INSERT ORDERS  */
	/* Create SQL command */
	memset(sql_cmd, 0x00, sizeof(sql_cmd));
		sprintf(sql_cmd,STMT_BUYCONF_insODR,
		data->sc_id,
		data->c_id,
		data->sc_sub_total,
		data->sc_tax,
		data->sc_total,
		ship_day,
		c_addr_id,
		ship_addr_id);

	/* **MOBILE CODE** SQL Command */
	res = PQexec(dbc->conn, sql_cmd);
	if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
	{
		LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
		PQclear(res);
		return ERROR;
	}
	PQclear(res);

	/* seems to block here in case scl was created with a c_id null if the customer made the shopping cart before being registered */
	/* SELECT Shopping Cart Line  */
	/* Create SQL command */
	memset( sql_cmd , 0x00 , sizeof( sql_cmd ) );
	sprintf(sql_cmd,STMT_BUYCONF_selSCL,data->sc_id); /*,data->c_id);*/

	/* **MOBILE CODE** SQL Command */
	res = PQexec(dbc->conn, sql_cmd);
	if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
	{
		LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
		PQclear(res);
		return ERROR;
	}

	if (PQntuples(res) != 0)
	{
		/* Get data */
		for (ix=0;ix<SHOPPING_CART_ITEMS_MAX && ix < PQntuples(res);ix++)
		{
			j = 0;
			scl_i_id[ix] = atoll(PQgetvalue(res, ix, j++));
			scl_cost[ix] = strtod(PQgetvalue(res, ix, j++), NULL);
			scl_qty[ix] = atoi(PQgetvalue(res, ix, j++));
		}
		PQclear(res);
	}
	else
	{
		LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
		LOG_ERROR_MESSAGE("Could not select shopping_cart for sc_id = %d\n", data->sc_id); /* pgxc modif: addition of c_id */
		PQclear(res);
		return ERROR;
	}

	for (iy=0;iy<ix;iy++)
	{

		/* INSERT ORDER Line  */
		/* Create SQL command */
		memset(sql_cmd, 0x00, sizeof(sql_cmd));
		sprintf(sql_cmd,STMT_BUYCONF_insODRL,
			++ol_id,
			data->sc_id,
			scl_i_id[iy],
			scl_qty[iy],
			data->c_discount,
			ol_comment,
			data->c_id); /* pgxc additional */

		/* **MOBILE CODE** SQL Command */
		res = PQexec(dbc->conn, sql_cmd);
		if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
		{
			LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
			PQclear(res);
			return ERROR;
		}
		PQclear(res);
  
		/* SELECT Item  */
		/* Create SQL command */
		memset(sql_cmd, 0x00, sizeof(sql_cmd));
		sprintf(sql_cmd,STMT_BUYCONF_selITM, scl_i_id[iy]); /* for pgxc nothing changed here, not necessary as stock is a partition of item just depending on it */

		/* **MOBILE CODE** SQL Command */
		res = PQexec(dbc->conn, sql_cmd);
		if (!res || PQresultStatus(res) != PGRES_TUPLES_OK)
		{
			LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
			PQclear(res);
			return ERROR;
		}

		/* Get data */
		if (PQntuples(res) != 0)
		{
			j = 0;
			co_id = atoi(PQgetvalue(res, 0, j++));
			PQclear(res);
		}
		else
		{
			LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
			LOG_ERROR_MESSAGE("Could not obtain item = %d\n", scl_i_id[iy]); /* pgxc modif: addition of c_id */
			PQclear(res);
			return ERROR;
		}

		if (st_stock - 10 > scl_qty[iy])
		{
			st_stock -= scl_qty[iy];
		}
		else
		{
			st_stock = st_stock - scl_qty[iy] + 21;
		}

		/* UPDATE Item  */
		/* Create SQL command */
		memset(sql_cmd, 0x00, sizeof(sql_cmd));
		sprintf(sql_cmd,STMT_BUYCONF_updITM, st_stock,scl_i_id[iy]); /* pgxc modif: name of stock variable changed to st_stock */

		/* **MOBILE CODE** SQL Command */
		res = PQexec(dbc->conn, sql_cmd);
		if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
		{
			LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
			PQclear(res);
			return ERROR;
		}
	PQclear(res);
	}
 
	/* INSERT cc_xacts  */
	/* Create SQL command */
	memset(sql_cmd, 0x00, sizeof(sql_cmd));
	sprintf(sql_cmd,STMT_BUYCONF_insXACT,
		data->sc_id,
		data->cx_type,
		data->cx_num,
		data->cx_name,
		data->cx_expiry,
		cx_auth_id,
		data->sc_total,
		co_id,
		data->c_id); /* pgxc additional */

	/* **MOBILE CODE** SQL Command */
	res = PQexec(dbc->conn, sql_cmd);
	if (!res || PQresultStatus(res) != PGRES_COMMAND_OK)
	{
		LOG_ERROR_MESSAGE("%s\nPQbackendPID[%d]\nPQstatus[%d]\nPQtransactionStatus[%d]\nPQsocket[%d]\nPQprotocolVersion[%d]\n", PQerrorMessage(dbc->conn), PQbackendPID(dbc->conn), (int)PQstatus(dbc->conn), (int)PQtransactionStatus(dbc->conn), PQsocket(dbc->conn), PQprotocolVersion(dbc->conn));
		PQclear(res);
		return ERROR;
	}
	PQclear(res);

	if (getSCDetail(dbc, data->scl_data, data->sc_id, data->c_id, &data->sc_size) == W_ERROR)
	{
		return W_ERROR;
	}

	return OK;
}