exp changes
[csql.git] / test / performance / ODBCConTest.c
blob0192edecb385c5e94ee3f05827d1c00998726992
1 /* This program has two different aspect
2 * 1. Use ($./ODBCConTest conn) command to get the timer result
3 * which starts from Connection and goes through pprepare, execute, commit
4 * and ends at Disconnect for each iteration.
5 *
6 * 2. Use ($./ODBCConTest prepare) command to get the timer result
7 *
8 * which starts at prepare and ends after commit for each iteration.
10 * Author: Jitendra Lenka
12 #include <iostream>
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <time.h>
17 #include <sql.h>
18 #include <sqlext.h>
19 #include "NanoTimer.h"
20 #define ITERATION 100
21 using namespace std;
22 #define DSN "test"
23 //#define DSN "DSN=mycsql;MODE=CSQL;SERVER=192.168.1.103;PORT=5678;""DSN=mycsql;MODE=CSQL;SERVER=192.168.1.103;PORT=5678;"
25 NanoTimer timer;
27 void extract_error(
28 char *fn,
29 SQLHANDLE handle,
30 SQLSMALLINT type)
32 SQLINTEGER i = 0;
33 SQLINTEGER native;
34 SQLCHAR state[ 7 ];
35 SQLCHAR text[256];
36 SQLSMALLINT len;
37 SQLRETURN ret;
39 fprintf(stderr,
40 "\n"
41 "The driver reported the following diagnostics whilst running "
42 "%s\n\n",
43 fn);
47 ret = SQLGetDiagRec(type, handle, ++i, state, &native, text,
48 sizeof(text), &len );
49 if (SQL_SUCCEEDED(ret))
50 printf("%s:%ld:%ld:%s\n", state, i, native, text);
52 while( ret == SQL_SUCCESS );
55 inline void
56 check_error (SQLSMALLINT handleType, SQLHANDLE handle, int rc, int line)
58 if (rc)
60 cout << "Error " << rc << " at line: " << line << endl;
61 SQLCHAR state[10];
62 SQLINTEGER native;
63 SQLCHAR mesg[300];
64 int i=0;
65 while (SQLGetDiagRec (handleType, handle, i++, state, &native, mesg, 300,
66 NULL) == SQL_SUCCESS)
68 mesg[299] = '\0';
69 cout << "state: " << state << endl;
70 cout << "native: " << native << endl;
71 cout << "mesg: " << mesg << endl;
73 exit (1);
78 inline void
79 checkrc (int rc, int line)
81 if (rc)
83 cout << "Error " << rc << " at line: " << line << endl;
84 exit (1);
88 void
89 readWriteTrans (SQLHDBC hdbc)
91 int rc = SQLSetConnectAttr (hdbc, SQL_ATTR_ACCESS_MODE,
92 (SQLPOINTER) SQL_MODE_READ_WRITE, 0);
93 checkrc (rc, __LINE__);
94 rc = SQLEndTran (SQL_HANDLE_DBC, hdbc, SQL_COMMIT);
95 checkrc (rc, __LINE__);
98 void
99 readOnlyTrans (SQLHDBC hdbc)
101 int rc = SQLSetConnectAttr (hdbc, SQL_ATTR_ACCESS_MODE,
102 (SQLPOINTER) SQL_MODE_READ_ONLY, 0);
103 checkrc (rc, __LINE__);
104 rc = SQLEndTran (SQL_HANDLE_DBC, hdbc, SQL_COMMIT);
105 checkrc (rc, __LINE__);
109 runInsertTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
112 int rc,i;
113 int iHolder;
114 char sHolder[200];
115 char sData[200];
117 timer.reset();
118 for(i=0;i<ITERATION;i++){
119 timer.start();
121 rc = SQLConnect (hdbc,
122 (SQLCHAR *) DSN, SQL_NTS,
123 (SQLCHAR *) "root",
124 (SQLSMALLINT) strlen ("root"),
125 (SQLCHAR *) "manager",
126 (SQLSMALLINT) strlen (""));
128 if (SQL_SUCCEEDED(rc)) {
129 if (rc == SQL_SUCCESS_WITH_INFO) {
130 printf("Driver reported the following diagnostics\n");
131 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
133 }else {
134 fprintf(stderr, "Failed to connect\n");
135 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
138 //check_error (SQL_HANDLE_DBC, hdbc, rc, __LINE__);
139 checkrc (rc, __LINE__);
141 rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
142 checkrc (rc, __LINE__);
143 rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt);
144 checkrc (rc, __LINE__);
146 iHolder = 0;
147 strcpy (sData, "0123456789012345678901234567890123456789");
148 rc = SQLPrepare (hstmt, (unsigned char *) "INSERT INTO t1 VALUES (?, ?)",
149 SQL_NTS);
150 checkrc (rc, __LINE__);
151 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
152 0, 0, &iHolder, 0, NULL);
153 checkrc (rc, __LINE__);
154 SQLINTEGER sLen = SQL_NTS;
155 rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
156 196, 0, (void *) sHolder, 0, &sLen);
157 checkrc (rc, __LINE__);
158 int tCount;
160 iHolder = i ;
161 strcpy (sHolder, sData);
162 rc = SQLExecute (hstmt);
163 checkrc (rc, __LINE__);
164 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
165 checkrc (rc, __LINE__);
166 //timer.stop ();
168 rc = SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
169 checkrc (rc, __LINE__);
170 rc = SQLDisconnect (hdbc);
171 checkrc (rc, __LINE__);
172 timer.stop();
174 printf ("Insert: %lld %lld %lld\n", timer.minc(), timer.maxc(),timer.avg());
175 return 0;
177 //From prepare to Commit (Inserting)
178 int InsertTest(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
181 int rc,i;
182 int iHolder;
183 char sHolder[200];
184 char sData[200];
186 iHolder = 0;
187 strcpy (sData, "0123456789012345678901234567890123456789");
188 timer.reset();
189 for(i=0;i<ITERATION;i++){
190 timer.start();
191 rc = SQLPrepare (hstmt, (unsigned char *) "INSERT INTO t1 VALUES (?, ?)",
192 SQL_NTS);
193 checkrc (rc, __LINE__);
194 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
195 0, 0, &iHolder, 0, NULL);
196 checkrc (rc, __LINE__);
197 SQLINTEGER sLen = SQL_NTS;
198 rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
199 196, 0, (void *) sHolder, 0, &sLen);
200 checkrc (rc, __LINE__);
201 int tCount;
203 iHolder = i ;
204 strcpy (sHolder, sData);
205 rc = SQLExecute (hstmt);
206 checkrc (rc, __LINE__);
207 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
208 checkrc (rc, __LINE__);
209 timer.stop ();
212 printf("Insert: %lld %lld %lld\n", timer.minc(), timer.maxc(),timer.avg());
213 return 0;
216 //From Prepare to commit (Read)
217 int ReadTest(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
219 int iHolder;
220 char sHolder[200];
221 char sData[200];
223 int tempTermVar = 0;
224 int tempTermVal = 0;
225 int rc,i;
227 // Set read-only transaction type
228 readOnlyTrans (hdbc);
229 timer.reset();
230 for(i=0;i<ITERATION;i++){
231 timer.start();
232 rc = SQLPrepare (hstmt, (unsigned char *)
233 "SELECT f1, f2 FROM t1 where f1 = ?", SQL_NTS);
234 checkrc (rc, __LINE__);
235 long sz = 0;
236 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
237 0, 0, &tempTermVar, 0, NULL);
238 checkrc (rc, __LINE__);
239 rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &iHolder, 0, NULL);
240 checkrc (rc, __LINE__);
241 rc = SQLBindCol (hstmt, 2, SQL_C_CHAR, sHolder, sizeof (sHolder), NULL);
242 checkrc (rc, __LINE__);
243 iHolder = 0;
244 strcpy (sData, "0123456789012345678901234567890123456789");
246 int tCount;
248 tempTermVar = i ;
249 rc = SQLExecute (hstmt);
250 checkrc (rc, __LINE__);
251 rc = SQLFetch (hstmt);
252 checkrc (rc, __LINE__);
253 tempTermVal = iHolder;
254 strcpy (sData, sHolder);
255 rc = SQLCloseCursor (hstmt);
256 checkrc (rc, __LINE__);
257 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
258 checkrc (rc, __LINE__);
259 timer.stop();
262 printf("Select: %lld %lld %lld\n", timer.minc(), timer.maxc(),timer.avg());
263 readWriteTrans (hdbc);
264 return rc;
270 runReadTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
273 int iHolder;
274 char sHolder[200];
275 char sData[200];
277 int tempTermVar = 0;
278 int tempTermVal = 0;
279 int rc,i;
281 timer.reset();
282 for(i=0;i<ITERATION;i++){
283 timer.start();
285 rc = SQLConnect (hdbc,
286 (SQLCHAR *) DSN, SQL_NTS,
287 (SQLCHAR *) "root",
288 (SQLSMALLINT) strlen ("root"),
289 (SQLCHAR *) "manager",
290 (SQLSMALLINT) strlen (""));
292 if (SQL_SUCCEEDED(rc)) {
293 if (rc == SQL_SUCCESS_WITH_INFO) {
294 printf("Driver reported the following diagnostics\n");
295 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
297 }else {
298 fprintf(stderr, "Failed to connect\n");
299 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
302 //check_error (SQL_HANDLE_DBC, hdbc, rc, __LINE__);
303 checkrc (rc, __LINE__);
304 rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
305 checkrc (rc, __LINE__);
306 rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt);
307 checkrc (rc, __LINE__);
309 // Set read-only transaction type
310 readOnlyTrans (hdbc);
311 rc = SQLPrepare (hstmt, (unsigned char *)
312 "SELECT f1, f2 FROM t1 where f1 = ?", SQL_NTS);
313 checkrc (rc, __LINE__);
314 long sz = 0;
315 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
316 0, 0, &tempTermVar, 0, NULL);
317 checkrc (rc, __LINE__);
318 rc = SQLBindCol (hstmt, 1, SQL_INTEGER, &iHolder, 0, NULL);
319 checkrc (rc, __LINE__);
320 rc = SQLBindCol (hstmt, 2, SQL_C_CHAR, sHolder, sizeof (sHolder), NULL);
321 checkrc (rc, __LINE__);
322 iHolder = 0;
323 strcpy (sData, "0123456789012345678901234567890123456789");
325 int tCount;
327 tempTermVar = i ;
328 rc = SQLExecute (hstmt);
329 checkrc (rc, __LINE__);
330 rc = SQLFetch (hstmt);
331 checkrc (rc, __LINE__);
332 tempTermVal = iHolder;
333 strcpy (sData, sHolder);
334 rc = SQLCloseCursor (hstmt);
335 checkrc (rc, __LINE__);
336 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
337 checkrc (rc, __LINE__);
339 rc = SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
340 checkrc (rc, __LINE__);
341 rc = SQLDisconnect (hdbc);
342 checkrc (rc, __LINE__);
343 timer.stop();
346 printf("Select: %lld %lld %lld\n", timer.minc(), timer.maxc(),timer.avg());
347 return rc;
351 //From Prepare to Commit(Update
352 int UpdateTest(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
355 int rc,i;
356 int iHolder;
357 char sHolder[200];
358 char sData[200];
360 timer.reset();
361 for(i=0;i<ITERATION;i++){
362 timer.start();
363 rc = SQLPrepare (hstmt,
364 (unsigned char *) "UPDATE t1 SET f2 = ? WHERE f1 = ?",
365 SQL_NTS);
366 checkrc (rc, __LINE__);
367 SQLINTEGER sLen = SQL_NTS;
368 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
369 196, 0, (void *) sHolder, 0, &sLen);
370 checkrc (rc, __LINE__);
371 rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
372 0, 0, &iHolder, 0, NULL);
373 checkrc (rc, __LINE__);
374 iHolder = 0;
375 strcpy (sData, "9876543210987654321098765432109876543210");
377 iHolder = i ;
378 strcpy (sHolder, sData);
379 rc = SQLExecute (hstmt);
380 checkrc (rc, __LINE__);
381 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
382 checkrc (rc, __LINE__);
383 timer.stop ();
385 printf ("Update: %lld %lld %lld\n", timer.minc (), timer.maxc (),timer.avg ());
389 runUpdateTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
391 int rc,i;
392 int iHolder;
393 char sHolder[200];
394 char sData[200];
396 timer.reset();
397 for(i=0;i<ITERATION;i++){
398 timer.start();
400 rc = SQLConnect (hdbc,
401 (SQLCHAR *) DSN, SQL_NTS,
402 (SQLCHAR *) "root",
403 (SQLSMALLINT) strlen ("root"),
404 (SQLCHAR *) "manager",
405 (SQLSMALLINT) strlen (""));
407 if (SQL_SUCCEEDED(rc)) {
408 if (rc == SQL_SUCCESS_WITH_INFO) {
409 printf("Driver reported the following diagnostics\n");
410 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
412 }else {
413 fprintf(stderr, "Failed to connect\n");
414 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
416 checkrc (rc, __LINE__);
417 rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
418 checkrc (rc, __LINE__);
419 rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt);
421 rc = SQLPrepare (hstmt,
422 (unsigned char *) "UPDATE t1 SET f2 = ? WHERE f1 = ?",
423 SQL_NTS);
424 checkrc (rc, __LINE__);
425 SQLINTEGER sLen = SQL_NTS;
426 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR,
427 196, 0, (void *) sHolder, 0, &sLen);
428 checkrc (rc, __LINE__);
429 rc = SQLBindParameter (hstmt, 2, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
430 0, 0, &iHolder, 0, NULL);
431 checkrc (rc, __LINE__);
432 iHolder = 0;
433 strcpy (sData, "9876543210987654321098765432109876543210");
435 int tCount;
437 iHolder = i ;
438 strcpy (sHolder, sData);
439 rc = SQLExecute (hstmt);
440 checkrc (rc, __LINE__);
441 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
442 checkrc (rc, __LINE__);
444 rc = SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
445 checkrc (rc, __LINE__);
446 rc = SQLDisconnect (hdbc);
447 checkrc (rc, __LINE__);
448 timer.stop ();
450 printf ("Update: %lld %lld %lld\n", timer.minc (), timer.maxc (),timer.avg ());
451 return 0;
454 //From prepare to commit(Delete)
455 int DeleteTest(SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
457 int rc,i;
458 int iHolder;
459 timer.reset();
460 for(i=0;i<ITERATION;i++){
461 timer.start();
462 rc = SQLPrepare (hstmt, (unsigned char *)"DELETE FROM t1 WHERE f1 = ?", SQL_NTS);
463 checkrc (rc, __LINE__);
464 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
465 0, 0, &iHolder, 0, NULL);
466 checkrc (rc, __LINE__);
468 iHolder = 0;
469 int tCount;
471 iHolder = i ;
472 rc = SQLExecute (hstmt);
473 checkrc (rc, __LINE__);
474 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
475 checkrc (rc, __LINE__);
477 timer.stop ();
479 printf ("Delete: %lld %lld %lld\n", timer.minc (), timer.maxc (),timer.avg ());
480 return 0;
485 runDeleteTest (SQLHANDLE henv, SQLHANDLE hdbc, SQLHANDLE hstmt)
487 int rc,i;
488 int iHolder;
490 timer.reset();
491 for(i=0;i<ITERATION;i++){
492 timer.start();
494 rc = SQLConnect (hdbc,
495 (SQLCHAR *) DSN, SQL_NTS,
496 (SQLCHAR *) "root",
497 (SQLSMALLINT) strlen ("root"),
498 (SQLCHAR *) "manager",
499 (SQLSMALLINT) strlen (""));
501 if (SQL_SUCCEEDED(rc)) {
502 if (rc == SQL_SUCCESS_WITH_INFO) {
503 printf("Driver reported the following diagnostics\n");
504 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
506 }else {
507 fprintf(stderr, "Failed to connect\n");
508 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
511 //check_error (SQL_HANDLE_DBC, hdbc, rc, __LINE__);
512 checkrc (rc, __LINE__);
513 rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
514 checkrc (rc, __LINE__);
516 rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt);
517 checkrc (rc, __LINE__);
520 rc = SQLPrepare (hstmt, (unsigned char *)"DELETE FROM t1 WHERE f1 = ?", SQL_NTS);
521 checkrc (rc, __LINE__);
522 rc = SQLBindParameter (hstmt, 1, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER,
523 0, 0, &iHolder, 0, NULL);
524 checkrc (rc, __LINE__);
526 iHolder = 0;
527 int tCount;
529 iHolder = i ;
530 rc = SQLExecute (hstmt);
531 checkrc (rc, __LINE__);
532 rc = SQLTransact (henv, hdbc, SQL_COMMIT);
533 checkrc (rc, __LINE__);
535 rc = SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
536 checkrc (rc, __LINE__);
537 rc = SQLDisconnect (hdbc);
538 checkrc (rc, __LINE__);
540 timer.stop ();
542 printf ("Delete: %lld %lld %lld\n", timer.minc (), timer.maxc (),timer.avg ());
543 return 0;
548 main (int ac, char *av[])
550 int flag=1;
552 if(ac==2){
553 if(strcmp(av[1],"conn")==0)flag=1;
554 else if(strcmp(av[1],"prepare")==0)flag=2;
555 else
557 printf("\nValid value: conn or prepare\n");
558 return 1;
562 SQLRETURN rc;
563 SQLHENV henv;
564 SQLHDBC hdbc;
565 SQLHSTMT hstmt;
567 rc = SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
568 checkrc (rc, __LINE__);
569 SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
571 rc = SQLAllocHandle (SQL_HANDLE_DBC, henv, &hdbc);
572 checkrc (rc, __LINE__);
574 rc = SQLConnect (hdbc,
575 (SQLCHAR *) DSN, SQL_NTS,
576 (SQLCHAR *) "root",
577 (SQLSMALLINT) strlen ("root"),
578 (SQLCHAR *) "manager",
579 (SQLSMALLINT) strlen (""));
581 SQLCHAR outstr[1024];
582 SQLSMALLINT outstrlen;
584 if (SQL_SUCCEEDED(rc)) {
585 // printf("Connected\n");
586 if (rc == SQL_SUCCESS_WITH_INFO) {
587 printf("Driver reported the following diagnostics\n");
588 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
590 }else {
591 fprintf(stderr, "Failed to connect\n");
592 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
595 //check_error (SQL_HANDLE_DBC, hdbc, rc, __LINE__);
596 checkrc (rc, __LINE__);
597 rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
598 checkrc (rc, __LINE__);
599 rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt);
600 checkrc (rc, __LINE__);
601 rc = SQLExecDirect(hstmt, (SQLCHAR*) "CREATE TABLE t1 (f1 INTEGER, f2 char(196), primary key (f1));", SQL_NTS );
602 checkrc (rc, __LINE__);
603 printf("Table 't1' Created\n");
606 //Disconnect from the data source
608 printf("-----------------------------------\n");
609 printf("Stmt: | Min | Max | Avg\n");
610 printf("-----------------------------------\n");
612 if(flag==1)
614 rc = SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
615 checkrc (rc, __LINE__);
616 rc = SQLDisconnect (hdbc);
617 checkrc (rc, __LINE__);
619 runInsertTest (henv, hdbc, hstmt);
620 runReadTest (henv, hdbc, hstmt);
621 runUpdateTest (henv, hdbc, hstmt);
622 runDeleteTest (henv, hdbc, hstmt);
623 // Again connect
625 rc = SQLConnect (hdbc,
626 (SQLCHAR *) DSN, SQL_NTS,
627 (SQLCHAR *) "root",
628 (SQLSMALLINT) strlen ("root"),
629 (SQLCHAR *) "manager",
630 (SQLSMALLINT) strlen (""));
632 if (SQL_SUCCEEDED(rc)) {
633 // printf("Connected\n");
634 if (rc == SQL_SUCCESS_WITH_INFO) {
635 printf("Driver reported the following diagnostics\n");
636 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
638 }else {
639 fprintf(stderr, "Failed to connect\n");
640 extract_error("SQLDriverConnect", hdbc, SQL_HANDLE_DBC);
643 check_error (SQL_HANDLE_DBC, hdbc, rc, __LINE__);
644 checkrc (rc, __LINE__);
645 rc = SQLSetConnectOption (hdbc, SQL_AUTOCOMMIT, SQL_AUTOCOMMIT_OFF);
646 checkrc (rc, __LINE__);
647 rc = SQLAllocHandle (SQL_HANDLE_STMT, hdbc, &hstmt);
650 if(flag==2)
653 InsertTest (henv, hdbc, hstmt);
654 ReadTest (henv, hdbc, hstmt);
655 UpdateTest (henv, hdbc, hstmt);
656 DeleteTest (henv, hdbc, hstmt);
660 printf("----------------------------------\n");
661 printf(" |Unit: NanoSec|\n");
662 //For dropping table
664 rc = SQLExecDirect(hstmt, (SQLCHAR*) "DROP TABLE t1;", SQL_NTS );
665 checkrc (rc, __LINE__);
666 printf("Table 't1' Dropped\n");
667 rc = SQLEndTran(SQL_HANDLE_DBC, hdbc, SQL_COMMIT );
668 checkrc (rc, __LINE__);
670 rc = SQLFreeHandle (SQL_HANDLE_STMT, hstmt);
671 checkrc (rc, __LINE__);
672 rc = SQLDisconnect (hdbc);
673 checkrc (rc, __LINE__);
674 rc = SQLFreeHandle (SQL_HANDLE_DBC, hdbc);
675 checkrc (rc, __LINE__);
676 rc = SQLFreeHandle (SQL_HANDLE_ENV, henv);
677 checkrc (rc, __LINE__);
678 exit (0);