| 1 | /* |
| 2 | * Legal Notice |
| 3 | * |
| 4 | * This document and associated source code (the "Work") is a part of a |
| 5 | * benchmark specification maintained by the TPC. |
| 6 | * |
| 7 | * The TPC reserves all right, title, and interest to the Work as provided |
| 8 | * under U.S. and international laws, including without limitation all patent |
| 9 | * and trademark rights therein. |
| 10 | * |
| 11 | * No Warranty |
| 12 | * |
| 13 | * 1.1 TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THE INFORMATION |
| 14 | * CONTAINED HEREIN IS PROVIDED "AS IS" AND WITH ALL FAULTS, AND THE |
| 15 | * AUTHORS AND DEVELOPERS OF THE WORK HEREBY DISCLAIM ALL OTHER |
| 16 | * WARRANTIES AND CONDITIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, |
| 17 | * INCLUDING, BUT NOT LIMITED TO, ANY (IF ANY) IMPLIED WARRANTIES, |
| 18 | * DUTIES OR CONDITIONS OF MERCHANTABILITY, OF FITNESS FOR A PARTICULAR |
| 19 | * PURPOSE, OF ACCURACY OR COMPLETENESS OF RESPONSES, OF RESULTS, OF |
| 20 | * WORKMANLIKE EFFORT, OF LACK OF VIRUSES, AND OF LACK OF NEGLIGENCE. |
| 21 | * ALSO, THERE IS NO WARRANTY OR CONDITION OF TITLE, QUIET ENJOYMENT, |
| 22 | * QUIET POSSESSION, CORRESPONDENCE TO DESCRIPTION OR NON-INFRINGEMENT |
| 23 | * WITH REGARD TO THE WORK. |
| 24 | * 1.2 IN NO EVENT WILL ANY AUTHOR OR DEVELOPER OF THE WORK BE LIABLE TO |
| 25 | * ANY OTHER PARTY FOR ANY DAMAGES, INCLUDING BUT NOT LIMITED TO THE |
| 26 | * COST OF PROCURING SUBSTITUTE GOODS OR SERVICES, LOST PROFITS, LOSS |
| 27 | * OF USE, LOSS OF DATA, OR ANY INCIDENTAL, CONSEQUENTIAL, DIRECT, |
| 28 | * INDIRECT, OR SPECIAL DAMAGES WHETHER UNDER CONTRACT, TORT, WARRANTY, |
| 29 | * OR OTHERWISE, ARISING IN ANY WAY OUT OF THIS OR ANY OTHER AGREEMENT |
| 30 | * RELATING TO THE WORK, WHETHER OR NOT SUCH AUTHOR OR DEVELOPER HAD |
| 31 | * ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. |
| 32 | * |
| 33 | * Contributors: |
| 34 | * Gradient Systems |
| 35 | */ |
| 36 | #include "config.h" |
| 37 | #include "porting.h" |
| 38 | #include <stdio.h> |
| 39 | #include "constants.h" |
| 40 | #include "w_catalog_page.h" |
| 41 | #include "date.h" |
| 42 | #include "decimal.h" |
| 43 | #include "genrand.h" |
| 44 | #include "build_support.h" |
| 45 | #include "misc.h" |
| 46 | #include "tables.h" |
| 47 | #include "scaling.h" |
| 48 | #include "nulls.h" |
| 49 | #include "tdefs.h" |
| 50 | |
| 51 | #include "append_info.h" |
| 52 | |
| 53 | struct CATALOG_PAGE_TBL g_w_catalog_page; |
| 54 | |
| 55 | /* |
| 56 | * Routine: mk_catalog_page() |
| 57 | * Purpose: populate the catalog_page table |
| 58 | * Algorithm: |
| 59 | * catalogs are issued either monthly, quarterly or bi-annually (cp_type) |
| 60 | * there is 1 of each type circulating at all times |
| 61 | * Data tdefsures: |
| 62 | * |
| 63 | * Params: |
| 64 | * Returns: |
| 65 | * Called By: |
| 66 | * Calls: |
| 67 | * Assumptions: |
| 68 | * Side Effects: |
| 69 | * TODO: |
| 70 | * 20020903 jms cp_department needs to be randomized |
| 71 | * 20020903 jms cp_description needs to be randomized |
| 72 | */ |
| 73 | int mk_w_catalog_page(void *info_arr, ds_key_t index) { |
| 74 | static date_t dStartDateStorage; |
| 75 | static date_t *dStartDate = &dStartDateStorage; |
| 76 | static int nCatalogPageMax; |
| 77 | int nDuration, nOffset, nType; |
| 78 | static int bInit = 0; |
| 79 | struct CATALOG_PAGE_TBL *r; |
| 80 | int nCatalogInterval; |
| 81 | tdef *pTdef = getSimpleTdefsByNumber(CATALOG_PAGE); |
| 82 | |
| 83 | r = &g_w_catalog_page; |
| 84 | |
| 85 | if (!bInit) { |
| 86 | nCatalogPageMax = ((int)get_rowcount(CATALOG_PAGE) / CP_CATALOGS_PER_YEAR) / (YEAR_MAXIMUM - YEAR_MINIMUM + 2); |
| 87 | |
| 88 | strtodt(dStartDate, DATA_START_DATE); |
| 89 | |
| 90 | /* columns that still need to be populated */ |
| 91 | strcpy(r->cp_department, "DEPARTMENT" ); |
| 92 | |
| 93 | bInit = 1; |
| 94 | } |
| 95 | |
| 96 | nullSet(&pTdef->kNullBitMap, CP_NULLS); |
| 97 | r->cp_catalog_page_sk = index; |
| 98 | mk_bkey(&r->cp_catalog_page_id[0], index, CP_CATALOG_PAGE_ID); |
| 99 | r->cp_catalog_number = (long)(index - 1) / nCatalogPageMax + 1; |
| 100 | r->cp_catalog_page_number = (long)(index - 1) % nCatalogPageMax + 1; |
| 101 | switch (nCatalogInterval = ((r->cp_catalog_number - 1) % CP_CATALOGS_PER_YEAR)) { |
| 102 | case 0: /* bi-annual */ |
| 103 | case 1: |
| 104 | nType = 1; |
| 105 | nDuration = 182; |
| 106 | nOffset = nCatalogInterval * nDuration; |
| 107 | break; |
| 108 | case 2: |
| 109 | case 3: /* Q2 */ |
| 110 | case 4: /* Q3 */ |
| 111 | case 5: /* Q4 */ |
| 112 | nDuration = 91; |
| 113 | nOffset = (nCatalogInterval - 2) * nDuration; |
| 114 | nType = 2; |
| 115 | break; |
| 116 | default: |
| 117 | nDuration = 30; |
| 118 | nOffset = (nCatalogInterval - 6) * nDuration; |
| 119 | nType = 3; /* monthly */ |
| 120 | } |
| 121 | r->cp_start_date_id = dStartDate->julian + nOffset; |
| 122 | r->cp_start_date_id += ((r->cp_catalog_number - 1) / CP_CATALOGS_PER_YEAR) * 365; |
| 123 | r->cp_end_date_id = r->cp_start_date_id + nDuration - 1; |
| 124 | dist_member(&r->cp_type, "catalog_page_type" , nType, 1); |
| 125 | gen_text(&r->cp_description[0], RS_CP_DESCRIPTION / 2, RS_CP_DESCRIPTION - 1, CP_DESCRIPTION); |
| 126 | |
| 127 | void *info = append_info_get(info_arr, CATALOG_PAGE); |
| 128 | |
| 129 | append_row_start(info); |
| 130 | |
| 131 | append_key(info, r->cp_catalog_page_sk); |
| 132 | append_varchar(info, r->cp_catalog_page_id); |
| 133 | append_key(info, r->cp_start_date_id); |
| 134 | append_key(info, r->cp_end_date_id); |
| 135 | append_varchar(info, &r->cp_department[0]); |
| 136 | append_integer(info, r->cp_catalog_number); |
| 137 | append_integer(info, r->cp_catalog_page_number); |
| 138 | append_varchar(info, &r->cp_description[0]); |
| 139 | append_varchar(info, r->cp_type); |
| 140 | |
| 141 | append_row_end(info); |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |