Removing large file for data load. Modified README to generate mysql and psql input...
[csql.git] / test / performance / wisc / support.c
blob48e82743d54c4df09c50ed7f160998178174fba1
2 #include <stdio.h>
3 #include <string.h>
4 #include "support.h"
6 void
7 convert(int unique, char* buf)
9 int i;
10 int rem;
12 for (i=0; i<7; i++) buf[i] = 'A';
14 i = 6;
15 while ( unique > 0 ) {
16 rem = unique % 26;
17 buf[i] = 'A' + rem;
18 unique = unique / 26;
19 i--;
23 int
24 randNum(int seed, int limit, int generator, int prime)
26 do {
27 seed = (generator * seed) % prime;
28 } while (seed>limit);
30 return seed;
33 static unsigned long initSelection = 0xFFFFFFFFL;
34 static unsigned long querySelection = 0xFFFFFFFFL;
36 int
37 isQuery(int queryNum)
39 /* Check the (queryNum-1)th bit of the querySpec */
41 if ((1 << (queryNum - 1)) & querySelection)
42 return 1;
43 else
44 return 0;
47 #define MAX_TOKENS 40
49 int
50 setQueries(char* queryString)
52 /* If never called then querySelection = all,
53 if called, set query to none. and start processing
55 if (querySelection == initSelection)
56 querySelection = 0;
58 /* Parse the string into comma separated tokens */
60 char* tokens[MAX_TOKENS];
61 int numTokens;
62 int tokenPtr = 0;
63 char* dash;
64 int start;
65 int end;
66 int i;
67 int tokenValue;
69 numTokens = 0;
70 tokens[numTokens] = strtok(queryString, ",");
71 while (tokens[numTokens] != NULL) {
72 if (numTokens < MAX_TOKENS) {
73 tokens[++numTokens] = strtok(NULL, ",");
75 else {
76 fprintf (stderr, "Too many queries specified.\n");
77 return -1;
81 /* Check to see if you got any tokens (return if not) */
83 if (numTokens == 0) {
84 return 0;
87 /* Process each token, expanding ranges if present,
88 * and adding the query numbers to the return value */
90 for (tokenPtr = 0; tokenPtr < numTokens; tokenPtr++) {
92 /* Check for a range '-' of tokens */
94 dash = strchr(tokens[tokenPtr], '-');
96 if (dash) {
97 /* Get the start and end range specifiers (set the dash to null) */
98 *dash = 0;
99 if (sscanf(tokens[tokenPtr], "%d", &start) == -1 ||
100 sscanf(dash+1, "%d", &end) == -1) {
101 fprintf (stderr, "Invalid query range specified (%s-%s).\n",
102 tokens[tokenPtr], dash+1);
103 return -1;
106 /* Make sure that the start and end values are in range
107 * (return -1 to signal error in caller) */
108 if ((start < 1) || (start > 32) || (end < 1) || (end > 32) || (start >= end)) {
109 fprintf (stderr, "Invalid query range specified (%d-%d).\n", start, end);
110 return -1;
113 /* From start to end, set the bit in the querySpec */
114 for (i = start; i < (end+1); i++) {
115 querySelection = querySelection | (1 << (i - 1));
118 else {
119 /* Set the (tokenPtr) bit in the querySpec */
120 if (sscanf(tokens[tokenPtr], "%d", &tokenValue) == -1) {
121 fprintf (stderr, "Invalid query specified (%s).\n", tokens[tokenPtr]);
122 return -1;
124 if (tokenValue < 1 || tokenValue > 32) {
125 fprintf (stderr, "Invalid query specified (%d).\n", tokenValue);
126 return -1;
128 querySelection = querySelection | (1 << (tokenValue - 1));
131 return 0;