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 "tables.h" |
40 | #include "columns.h" |
41 | #include "genrand.h" |
42 | #include "tdefs.h" |
43 | #include "scaling.h" |
44 | #include "w_tdefs.h" |
45 | #include "s_tdefs.h" |
46 | #include "tdef_functions.h" |
47 | #include "r_params.h" |
48 | |
49 | extern tdef w_tdefs[]; |
50 | extern tdef s_tdefs[]; |
51 | extern table_func_t s_tdef_funcs[]; |
52 | extern table_func_t w_tdef_funcs[]; |
53 | |
54 | /* |
55 | * Routine: get_rowcount(int table) |
56 | * Purpose: |
57 | * Algorithm: |
58 | * Data Structures: |
59 | * |
60 | * Params: |
61 | * Returns: |
62 | * Called By: |
63 | * Calls: |
64 | * Assumptions: |
65 | * Side Effects: |
66 | * TODO: None |
67 | */ |
68 | ds_key_t GetRowcountByName(char *szName) { |
69 | int nTable = -1; |
70 | |
71 | nTable = GetTableNumber(szName); |
72 | if (nTable >= 0) |
73 | return (get_rowcount(nTable - 1)); |
74 | |
75 | nTable = distsize(szName); |
76 | return (nTable); |
77 | } |
78 | |
79 | /* |
80 | * Routine: GetTableNumber(char *szName) |
81 | * Purpose: Return size of table, pseudo table or distribution |
82 | * Algorithm: Need to use rowcount distribution, since argument could be a |
83 | * pseudo table Data Structures: |
84 | * |
85 | * Params: |
86 | * Returns: |
87 | * Called By: |
88 | * Calls: |
89 | * Assumptions: |
90 | * Side Effects: |
91 | * TODO: None |
92 | */ |
93 | int GetTableNumber(char *szName) { |
94 | int i; |
95 | char *szTable; |
96 | |
97 | for (i = 1; i <= distsize("rowcounts" ); i++) { |
98 | dist_member(&szTable, "rowcounts" , i, 1); |
99 | if (strcasecmp(szTable, szName) == 0) |
100 | return (i - 1); |
101 | } |
102 | |
103 | return (-1); |
104 | } |
105 | |
106 | /* |
107 | * Routine: |
108 | * Purpose: |
109 | * Algorithm: |
110 | * Data Structures: |
111 | * |
112 | * Params: |
113 | * Returns: |
114 | * Called By: |
115 | * Calls: |
116 | * Assumptions: |
117 | * Side Effects: |
118 | * TODO: None |
119 | */ |
120 | /* |
121 | tdef * |
122 | getTdefsByNumber(int nTable) |
123 | { |
124 | if (is_set("UPDATE")) |
125 | { |
126 | if (s_tdefs[nTable].flags & FL_PASSTHRU) |
127 | { |
128 | switch(nTable + S_BRAND) |
129 | { |
130 | case S_CATALOG_PAGE: nTable = CATALOG_PAGE; break; |
131 | case S_CUSTOMER_ADDRESS: nTable = CUSTOMER_ADDRESS; break; |
132 | case S_PROMOTION: nTable = PROMOTION; break; |
133 | } |
134 | return(&w_tdefs[nTable]); |
135 | } |
136 | else |
137 | return(&s_tdefs[nTable]); |
138 | } |
139 | else |
140 | return(&w_tdefs[nTable]); |
141 | } |
142 | */ |
143 | tdef *getSimpleTdefsByNumber(nTable) { |
144 | if (nTable >= S_BRAND) |
145 | return (&s_tdefs[nTable - S_BRAND]); |
146 | return (&w_tdefs[nTable]); |
147 | } |
148 | |
149 | tdef *getTdefsByNumber(int nTable) { |
150 | if (is_set("UPDATE" ) && is_set("VALIDATE" )) { |
151 | if (s_tdefs[nTable].flags & FL_PASSTHRU) { |
152 | switch (nTable + S_BRAND) { |
153 | case S_CATALOG_PAGE: |
154 | nTable = CATALOG_PAGE; |
155 | break; |
156 | case S_CUSTOMER_ADDRESS: |
157 | nTable = CUSTOMER_ADDRESS; |
158 | break; |
159 | case S_PROMOTION: |
160 | nTable = PROMOTION; |
161 | break; |
162 | } |
163 | return (&w_tdefs[nTable]); |
164 | } else |
165 | return (&s_tdefs[nTable]); |
166 | } |
167 | |
168 | return (getSimpleTdefsByNumber(nTable)); |
169 | } |
170 | |
171 | /* |
172 | * Routine: |
173 | * Purpose: |
174 | * Algorithm: |
175 | * Data Structures: |
176 | * |
177 | * Params: |
178 | * Returns: |
179 | * Called By: |
180 | * Calls: |
181 | * Assumptions: |
182 | * Side Effects: |
183 | * TODO: None |
184 | */ |
185 | char *getTableNameByID(int i) { |
186 | tdef *pT = getSimpleTdefsByNumber(i); |
187 | |
188 | return (pT->name); |
189 | } |
190 | |
191 | /* |
192 | * Routine: |
193 | * Purpose: |
194 | * Algorithm: |
195 | * Data Structures: |
196 | * |
197 | * Params: |
198 | * Returns: |
199 | * Called By: |
200 | * Calls: |
201 | * Assumptions: |
202 | * Side Effects: |
203 | * TODO: None |
204 | */ |
205 | int getTableFromColumn(int nColumn) { |
206 | int i; |
207 | tdef *pT; |
208 | |
209 | for (i = 0; i <= MAX_TABLE; i++) { |
210 | pT = getSimpleTdefsByNumber(i); |
211 | if ((nColumn >= pT->nFirstColumn) && (nColumn <= pT->nLastColumn)) |
212 | return (i); |
213 | } |
214 | return (-1); |
215 | } |
216 | |