*** empty log message ***
[csql.git] / test / performance / wisc / odbcBench.c
blob5c099de490d332be2be61666e9bce3826f4ceced
2 #include <iostream>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <time.h>
7 #include <sql.h>
8 #include <sqlext.h>
9 #include "NanoTimer.h"
10 #define ITERATION 100
11 using namespace std;
12 bool mysql;
14 NanoTimer timer;
15 long long int timevalues[30]={0};
16 void extract_error(
17 char *fn,
18 SQLHANDLE handle,
19 SQLSMALLINT type)
21 SQLINTEGER i = 0;
22 SQLINTEGER native;
23 SQLCHAR state[ 7 ];
24 SQLCHAR text[256];
25 SQLSMALLINT len;
26 SQLRETURN ret;
28 fprintf(stderr,
29 "\n"
30 "The driver reported the following diagnostics whilst running "
31 "%s\n\n",
32 fn);
36 ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,
37 sizeof(text), &len );
38 if (SQL_SUCCEEDED(ret))
39 printf("%s:%ld:%ld:%s\n", state, i, native, text);
41 while( ret == SQL_SUCCESS );
44 inline void
45 check_error (SQLSMALLINT handleType, SQLHANDLE handle, int rc, int line)
47 if (rc)
49 cout << "Error " << rc << " at line: " << line << endl;
50 SQLCHAR state[10];
51 SQLINTEGER native;
52 SQLCHAR mesg[300];
53 int i=0;
54 while (SQLGetDiagRec (handleType, handle, i++, state, &native, mesg, 300,
55 NULL) == SQL_SUCCESS)
57 mesg[299] = '\0';
58 cout << "state: " << state << endl;
59 cout << "native: " << native << endl;
60 cout << "mesg: " << mesg << endl;
62 exit (1);
67 inline void checkrc (int rc, int line)
69 if (rc)
71 cout << "Error " << rc << " at line: " << line << endl;
72 exit (1);
76 void readWriteTrans (SQLHDBC hdbc)
78 int rc = SQLSetConnectAttr (hdbc, SQL_ATTR_ACCESS_MODE,
79 (SQLPOINTER) SQL_MODE_READ_WRITE, 0);
80 checkrc (rc, __LINE__);
81 rc = SQLEndTran (SQL_HANDLE_DBC, hdbc, SQL_COMMIT);
82 checkrc (rc, __LINE__);
85 void readOnlyTrans (SQLHDBC hdbc)
87 int rc = SQLSetConnectAttr (hdbc, SQL_ATTR_ACCESS_MODE,
88 (SQLPOINTER) SQL_MODE_READ_ONLY, 0);
89 checkrc (rc, __LINE__);
90 rc = SQLEndTran (SQL_HANDLE_DBC, hdbc, SQL_COMMIT);
91 checkrc (rc, __LINE__);
94 void createHashIndex(SQLHANDLE hstmt,bool flag)
96 int rc;
97 if (mysql) {
98 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx1 USING HASH ON big1(unique1);", SQL_NTS );
99 checkrc (rc, __LINE__);
100 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx2 USING HASH ON big2(unique1);", SQL_NTS );
101 checkrc (rc, __LINE__);
102 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx3 USING HASH ON small(unique1)", SQL_NTS );
103 checkrc (rc, __LINE__);
104 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx4 USING HASH ON big1(stringu1)", SQL_NTS );
105 checkrc (rc, __LINE__);
106 } else {
107 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx1 ON big1(unique1) HASH;", SQL_NTS );
108 checkrc (rc, __LINE__);
109 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx2 ON big2(unique1) HASH;", SQL_NTS );
110 checkrc (rc, __LINE__);
111 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx3 ON small(unique1) HASH", SQL_NTS );
112 checkrc (rc, __LINE__);
113 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx4 ON big1(stringu1) HASH", SQL_NTS );
114 checkrc (rc, __LINE__);
117 void createTreeIndex(SQLHANDLE hstmt,bool flag)
119 int rc;
120 if (mysql)
122 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx5 USING BTREE ON big1(unique1);", SQL_NTS );
123 checkrc (rc, __LINE__);
124 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx6 USING BTREE ON big2(unique1);", SQL_NTS );
125 checkrc (rc, __LINE__);
126 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx7 USING BTREE ON small(unique1);", SQL_NTS );
127 checkrc (rc, __LINE__);
128 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx8 USING BTREE ON big1(stringu1);", SQL_NTS );
129 checkrc (rc, __LINE__);
130 }else {
131 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx5 ON big1(unique1) TREE;", SQL_NTS );
132 checkrc (rc, __LINE__);
133 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx6 ON big2(unique1) TREE;", SQL_NTS );
134 checkrc (rc, __LINE__);
135 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx7 ON small(unique1) TREE;", SQL_NTS );
136 checkrc (rc, __LINE__);
137 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE INDEX idx8 ON big1(stringu1) TREE;", SQL_NTS );
138 checkrc (rc, __LINE__);
142 void dropHashIndex(SQLHANDLE hstmt,bool flag)
144 int rc;
145 if (mysql) {
146 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx1 on big1 ;", SQL_NTS );
147 checkrc (rc, __LINE__);
148 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx2 on big2;", SQL_NTS );
149 checkrc (rc, __LINE__);
150 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx3 on small", SQL_NTS );
151 checkrc (rc, __LINE__);
152 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx4 on big1;", SQL_NTS );
153 checkrc (rc, __LINE__);
154 } else {
155 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx1 ;", SQL_NTS );
156 checkrc (rc, __LINE__);
157 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx2 ;", SQL_NTS );
158 checkrc (rc, __LINE__);
159 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx3 ;", SQL_NTS );
160 checkrc (rc, __LINE__);
161 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx4 ;", SQL_NTS );
162 checkrc (rc, __LINE__);
165 void dropTreeIndex(SQLHANDLE hstmt,bool flag)
167 int rc;
168 if (mysql)
170 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx5 on big1 ;", SQL_NTS );
171 checkrc (rc, __LINE__);
172 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx6 on big2;", SQL_NTS );
173 checkrc (rc, __LINE__);
174 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx7 on small;", SQL_NTS );
175 checkrc (rc, __LINE__);
176 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx8 on big1;", SQL_NTS );
177 checkrc (rc, __LINE__);
178 }else {
179 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx5 ;", SQL_NTS );
180 checkrc (rc, __LINE__);
181 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx6 ;", SQL_NTS );
182 checkrc (rc, __LINE__);
183 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx7 ;", SQL_NTS );
184 checkrc (rc, __LINE__);
185 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP INDEX idx8 ;", SQL_NTS );
186 checkrc (rc, __LINE__);
191 long long int onePerSel(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
193 int uni1;
194 int uni2;
195 char str1[200];
196 char str2[200];
197 int val[] = {1, 5, 10, 50, 100, 500, 1000, 5000 ,7500, 9900};;
198 int tempTermVar=0;
199 int tempTermVar2=0;
200 char tempval[124]="Value";
201 int rc;
202 readOnlyTrans (hdbc);
203 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT unique1, unique2, stringu1 from big1 where unique1 between ? and ?;", SQL_NTS);
204 checkrc (rc, __LINE__);
205 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL);
206 checkrc (rc, __LINE__);
207 rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar2, 0, NULL);
208 checkrc (rc, __LINE__);
210 rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &uni1, 0, NULL);
211 checkrc (rc, __LINE__);
212 rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &uni2, 0, NULL);
213 checkrc (rc, __LINE__);
214 rc = SQLBindCol (hstmt, 3, SQL_C_CHAR, str1, sizeof (str1), NULL);
215 checkrc (rc, __LINE__);
216 //rc = SQLBindCol (hstmt, 4, SQL_C_CHAR, str2, sizeof (str2), NULL);
217 //checkrc (rc, __LINE__);
219 int i, j, k;
220 int Count;
222 timer.reset ();
224 /* Run 1per Test */
225 for (i = 0; i < 10; i++)
227 Count=0;
228 strcpy(tempval,"Value");
229 tempTermVar = val[i] ;
230 tempTermVar2 = val[i]+99 ;
231 timer.start ();
232 rc = SQLExecute (hstmt);
233 checkrc (rc, __LINE__);
234 while(SQL_SUCCEEDED(rc = SQLFetch(hstmt)))
236 Count++;
238 // printf("Count=%d\n",Count);
239 rc = SQLCloseCursor (hstmt);
240 checkrc (rc, __LINE__);
241 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
242 checkrc (rc, __LINE__);
243 timer.stop ();
245 readWriteTrans (hdbc);
246 //printf ("Read: 1 %lld\n", timer.avg ());
247 return timer.avg()/1000;
250 long long int runReadTest (SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt,bool flag)
252 int uni1;
253 int uni2;
254 char str1[200];
255 char str2[200];
257 int val[] = {1, 10, 100, 500, 1000, 5000 ,7500, 8000, 9000, 9999};
258 int tempTermVar=0;
259 char tempval[124]="Value";
260 int rc;
262 /* Set read-only transaction type */
263 readOnlyTrans (hdbc);
264 if(flag){
265 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT unique1, unique2, stringu1, stringu2 from big1 where unique1=?;", SQL_NTS);
267 else {
268 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT unique1, unique2, stringu1, stringu2 from big1 where stringu1=?;", SQL_NTS);
270 checkrc (rc, __LINE__);
271 long sz = 0;
272 if(flag){
273 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL);
274 checkrc (rc, __LINE__);
276 else{
277 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_C_CHAR, 196, 0, tempval, 0, NULL);
278 checkrc (rc, __LINE__);
281 rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &uni1, 0, NULL);
282 checkrc (rc, __LINE__);
283 rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &uni2, 0, NULL);
284 checkrc (rc, __LINE__);
285 rc = SQLBindCol (hstmt, 3, SQL_C_CHAR, str1, sizeof (str1), NULL);
286 checkrc (rc, __LINE__);
287 rc = SQLBindCol (hstmt, 4, SQL_C_CHAR, str2, sizeof (str2), NULL);
288 checkrc (rc, __LINE__);
290 int i, j, k;
291 int Count;
293 timer.reset ();
295 /* Run 1per Test */
296 for (i = 0; i < 10; i++)
298 strcpy(tempval,"Value");
299 if(flag){
300 tempTermVar = val[i] ;}
301 else{
302 char buf[10];
303 sprintf(buf,"%d",val[i]);
304 strcat(tempval,buf);
306 timer.start ();
307 rc = SQLExecute (hstmt);
308 checkrc (rc, __LINE__);
309 rc = SQLFetch (hstmt);
310 checkrc (rc, __LINE__);
311 Count++;
312 rc = SQLCloseCursor (hstmt);
313 checkrc (rc, __LINE__);
314 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
315 checkrc (rc, __LINE__);
316 timer.stop ();
318 //printf ("Read: 1 %lld\n", timer.avg ());
319 /* Set read-write transaction type */
320 readWriteTrans (hdbc);
321 return timer.avg()/1000;
325 //aggregate
326 long long int aggregate(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt,bool flag)
328 int summin;
329 int rc;
330 /* Set read-only transaction type */
331 readOnlyTrans (hdbc);
332 if(flag){
333 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT MIN(unique1) from big1;", SQL_NTS);
335 else {
336 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT SUM(unique1) from big1;", SQL_NTS);
338 checkrc (rc, __LINE__);
339 rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &summin, 0, NULL);
340 checkrc (rc, __LINE__);
342 int i, j, k;
343 int Count;
345 timer.reset ();
346 for (i = 0; i < 10; i++)
348 timer.start ();
349 rc = SQLExecute (hstmt);
350 checkrc (rc, __LINE__);
351 rc = SQLFetch (hstmt);
352 checkrc (rc, __LINE__);
353 Count++;
354 // printf("value=%d",summin);
355 rc = SQLCloseCursor (hstmt);
356 checkrc (rc, __LINE__);
357 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
358 checkrc (rc, __LINE__);
359 timer.stop ();
361 //printf ("Read: 1 %lld\n", timer.avg ());
362 /* Set read-write transaction type */
363 readWriteTrans (hdbc);
364 return timer.avg()/1000;
368 long long int dmlstatement(SQLHANDLE henv, SQLHANDLE hdbc,SQLHANDLE hstmt,int val)
370 int tempTermVar=10000,tempTermVar2=10000;
371 int rc;
372 /* Set read-only transaction type */
373 readOnlyTrans (hdbc);
374 if(val==1){
375 rc = SQLPrepare (hstmt, (unsigned char *) "insert into big1 values(?,?,0,2,0,10,50,688,1950,4950,9950,1,100,'MXXXXXXXXXXXXXXXXXXXXXXXXXGXXXXXXXXXXXXXXXXXXXXXXXXC','GXXXXXXXXXXXXXXXXXXXXXXXXXCXXXXXXXXXXXXXXXXXXXXXXXXA','OXXXXXXXXXXXXXXXXXXXXXXXXXOXXXXXXXXXXXXXXXXXXXXXXXXO');", SQL_NTS);
377 else if(val==2){
378 rc = SQLPrepare (hstmt, (unsigned char *) "UPDATE big1 SET two=1 WHERE unique1=?;", SQL_NTS);
379 }else
381 rc = SQLPrepare (hstmt, (unsigned char *) "DELETE FROM big1 WHERE unique1=?;", SQL_NTS);
383 checkrc (rc, __LINE__);
385 int i, j, k;
386 int Count;
388 timer.reset ();
389 for (i = 0; i < 100; i++)
390 { tempTermVar+=i;
391 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL);
392 checkrc (rc, __LINE__);
393 if(val==1)
395 tempTermVar2+=i;
396 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar2, 0, NULL);
397 checkrc (rc, __LINE__);
399 timer.start ();
400 rc = SQLExecute (hstmt);
401 checkrc (rc, __LINE__);
402 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
403 checkrc (rc, __LINE__);
404 timer.stop ();
405 tempTermVar=10000;tempTermVar2=10000;
407 //printf ("Read: 1 %lld\n", timer.avg ());
408 /* Set read-write transaction type */
409 readWriteTrans (hdbc);
410 return timer.avg()/1000;
414 //Joining
415 long long int joining(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt,int flag)
417 int uni1;
418 int uni2,uni3,uni4,uni5;
419 char str1[200];
420 char str2[200];
422 int val[] = {1, 5, 10, 50, 100, 250, 500, 750, 900, 999};
423 int tempTermVar=0;
424 char tempval[124]="Value";
425 int rc;
427 /* Set read-only transaction type */
428 readOnlyTrans (hdbc);
429 if(flag==1){
430 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT big1.unique1, big1.unique2, small.unique1, small.stringu1 FROM small,big1 WHERE big1.unique1=small.unique1 AND small.unique1=?;", SQL_NTS);
432 else {
433 rc = SQLPrepare (hstmt, (unsigned char *) "SELECT small.unique1, big1.unique1, big2.unique1, small.stringu1, big1.unique2, big2.unique2 FROM big1, big2, small WHERE small.unique1=big1.unique1 AND big1.unique1=big2.unique1 AND big1.unique1 = ?;", SQL_NTS);
435 checkrc (rc, __LINE__);
436 long sz = 0;
437 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &tempTermVar, 0, NULL);
438 checkrc (rc, __LINE__);
439 rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &uni1, 0, NULL);
440 checkrc (rc, __LINE__);
441 rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &uni2, 0, NULL);
442 checkrc (rc, __LINE__);
443 rc = SQLBindCol (hstmt, 2, SQL_INTEGER, &uni3, 0, NULL);
444 checkrc (rc, __LINE__);
445 rc = SQLBindCol (hstmt, 4, SQL_C_CHAR, str1, sizeof (str1), NULL);
446 checkrc (rc, __LINE__);
447 if(flag==2){
448 rc = SQLBindCol (hstmt, 5, SQL_INTEGER, &uni4, 0, NULL);
449 checkrc (rc, __LINE__);
450 rc = SQLBindCol (hstmt, 6, SQL_INTEGER, &uni5, 0, NULL);
451 checkrc (rc, __LINE__);
453 int i, j, k;
454 int Count;
456 timer.reset ();
458 /* Run 1per Test */
459 for (i = 0; i < 10; i++)
461 tempTermVar = val[i] ;
462 timer.start ();
463 rc = SQLExecute (hstmt);
464 checkrc (rc, __LINE__);
465 rc = SQLFetch(hstmt);
466 Count++;
467 // printf("%d,%d\n",uni1,uni3);
468 rc = SQLCloseCursor (hstmt);
469 checkrc (rc, __LINE__);
470 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
471 checkrc (rc, __LINE__);
472 timer.stop ();
474 //printf ("Read: 1 %lld\n", timer.avg ());
475 /* Set read-write transaction type */
476 readWriteTrans (hdbc);
477 return timer.avg()/1000;
481 void printTime()
483 printf("Wisconsin Benchmark Report:\n");
484 printf("*******************************************************\n");
485 printf(" Statement \t NoIndex Hash\t Tree\n");
486 printf("*******************************************************\n");
487 printf(" SelectInt 1 \t %lld\t %lld \t %lld\n",timevalues[0],timevalues[1],timevalues[2]);
488 printf(" SelectStr 1 \t %lld\t %lld \t %lld\n",timevalues[3],timevalues[4],timevalues[5]);
489 printf(" 1Per Sel \t %lld\t %lld \t %lld\n\n",timevalues[6],timevalues[7],timevalues[8]);
490 printf(" Min All \t %lld\t %lld \t %lld\n",timevalues[9],timevalues[10],timevalues[11]);
491 printf(" Sum All \t %lld\t %lld \t %lld\n\n",timevalues[12],timevalues[13],timevalues[14]);
492 printf(" Insert 1 \t %lld\t %lld \t %lld\n",timevalues[15],timevalues[16],timevalues[17]);
493 printf(" Update 1 \t %lld\t %lld \t %lld\n",timevalues[18],timevalues[19],timevalues[20]);
494 printf(" Delete 1 \t %lld\t %lld \t %lld\n\n",timevalues[21],timevalues[22],timevalues[23]);
495 printf(" Join(10K*1K)1 \t %lld\t %lld \t %lld\n",timevalues[24],timevalues[25],timevalues[26]);
496 printf(" Join(10K*10K*1K)1 \t %lld\t %lld \t %lld\n",timevalues[27],timevalues[28],timevalues[29]);
497 printf("*******************************************************\n");
501 int main (int ac, char **av)
503 int rc;
504 SQLHENV henv;
505 SQLHDBC hdbc;
506 SQLHSTMT hstmt;
507 mysql=false;
508 if (ac ==2) mysql = true;
509 //printf("Mysql Set %d \n", ac); return 0;
510 rc = SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
511 checkrc (rc, __LINE__);
512 SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
514 rc = SQLAllocHandle (SQL_HANDLE_DBC, henv, &hdbc);
515 checkrc (rc, __LINE__);
516 if (!mysql) {
517 rc = SQLConnect (hdbc,
518 (SQLCHAR *) "test", (SQLSMALLINT) strlen ("test"),
519 (SQLCHAR *) "root",
520 (SQLSMALLINT) strlen ("root"),
521 (SQLCHAR *) "manager",
522 (SQLSMALLINT) strlen (""));
523 }else {
525 SQLCHAR outstr[1024];
526 SQLSMALLINT outstrlen;
527 rc = SQLDriverConnect(hdbc, NULL, (SQLCHAR*)"DSN=myodbc3;", SQL_NTS,
528 outstr, sizeof(outstr), &outstrlen,
529 SQL_DRIVER_NOPROMPT);
533 if (SQL_SUCCEEDED(rc)) {
534 printf("Connected\n");
535 //printf("Returned connection string was:\n\t%s\n", outstr);
536 if (rc == SQL_SUCCESS_WITH_INFO) {
537 printf("Driver reported the following diagnostics\n");
538 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
540 } else {
541 fprintf(stderr, "Failed to connect\n");
542 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
545 //check_error (SQL_HANDLE_DBC, hdbc, rc, __LINE__);
546 checkrc (rc, __LINE__);
547 rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
548 checkrc (rc, __LINE__);
549 rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt);
550 checkrc (rc, __LINE__);
551 int ins=1,upd=2,del=3;
552 //Query 1
553 timevalues[0] = runReadTest (henv, hdbc, hstmt,true);
554 timevalues[3] = runReadTest (henv, hdbc, hstmt,false);
555 timevalues[6] = onePerSel(henv, hdbc, hstmt);
556 timevalues[9] = aggregate(henv, hdbc, hstmt,true);
557 timevalues[12] = aggregate(henv, hdbc, hstmt,false);
558 timevalues[15] = dmlstatement(henv, hdbc, hstmt,ins);
559 timevalues[18] = dmlstatement(henv, hdbc, hstmt,upd);
560 timevalues[21] = dmlstatement(henv, hdbc, hstmt,del);
561 timevalues[24] = joining(henv, hdbc, hstmt,1);
562 timevalues[27] = joining(henv, hdbc, hstmt,2);
563 printf("NON INDEX OVER\n");
565 //Hash
566 createHashIndex( hstmt,true);
567 timevalues[1] = runReadTest (henv, hdbc, hstmt,true);
568 timevalues[4] = runReadTest (henv, hdbc, hstmt,false);
569 timevalues[7] = onePerSel(henv, hdbc, hstmt);
570 timevalues[10] = aggregate(henv, hdbc, hstmt,true);
571 timevalues[13] = aggregate(henv, hdbc, hstmt,false);
572 timevalues[16] = dmlstatement(henv, hdbc, hstmt,ins);
573 timevalues[19] = dmlstatement(henv, hdbc, hstmt,upd);
574 timevalues[22] = dmlstatement(henv, hdbc, hstmt,del);
575 timevalues[25] = joining(henv, hdbc, hstmt,1);
576 timevalues[28] = joining(henv, hdbc, hstmt,2);
577 dropHashIndex(hstmt,true);
578 printf("HASH INDEX OVER\n");
579 //printTime();
581 //TREE
582 createTreeIndex(hstmt,true);
583 timevalues[2] = runReadTest (henv, hdbc, hstmt,true);
584 timevalues[5] = runReadTest (henv, hdbc, hstmt,false);
585 timevalues[8] = onePerSel(henv, hdbc, hstmt);
586 timevalues[11] = aggregate(henv, hdbc, hstmt,true);
587 timevalues[14] = aggregate(henv, hdbc, hstmt,false);
588 timevalues[17] = dmlstatement(henv, hdbc, hstmt,ins);
589 timevalues[20] = dmlstatement(henv, hdbc, hstmt,upd);
590 timevalues[23] = dmlstatement(henv, hdbc, hstmt,del);
591 timevalues[26] = joining(henv, hdbc,hstmt,1);
592 timevalues[29] = joining(henv, hdbc,hstmt,2);
593 dropTreeIndex(hstmt,true);
594 printf("TREE INDEX OVER\n");
596 printTime();
597 rc = SQLEndTran(SQL_HANDLE_DBC, hdbc, SQL_COMMIT );
598 checkrc (rc, __LINE__);
600 rc = SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
601 checkrc (rc, __LINE__);
602 rc = SQLDisconnect (hdbc);
603 checkrc (rc, __LINE__);
604 rc = SQLFreeHandle (SQL_HANDLE_DBC, hdbc);
605 checkrc (rc, __LINE__);
606 rc = SQLFreeHandle (SQL_HANDLE_ENV, henv);
607 checkrc (rc, __LINE__);
608 exit (0);