15 static SQLHSTMT hstmt
;
18 "insert into %s values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
23 extern int verboseOut
;
26 static int longerRun
= 1;
29 int odbcDB::connect (char *dsn
)
34 rc
= SQLAllocHandle(SQL_HANDLE_ENV
,SQL_NULL_HANDLE
,&henv
);
36 printf ("Unable to allocate an environment handle.\n");
38 SQLSetEnvAttr(henv
,SQL_ATTR_ODBC_VERSION
,(void*)SQL_OV_ODBC3
,0);
39 rc
= SQLAllocHandle(SQL_HANDLE_DBC
,henv
,&hdbc
);
41 printf ("Unable to allocate connection handle.\n");
46 unsigned char outbuf
[256];
48 rc
= SQLConnect (hdbc
,
49 (SQLCHAR
*) "test", (SQLSMALLINT
) strlen ("test"),
51 (SQLSMALLINT
) strlen ("root"),
52 (SQLCHAR
*) "manager",
53 (SQLSMALLINT
) strlen (""));
57 SQLSMALLINT outstrlen;
58 //SQLSMALLINT SQL_DRIVER_NOPROMPT;
59 SQLSMALLINT slen = SQL_NTS;
61 SQLDriverConnect(hdbc,NULL,(SQLCHAR*)"DSN=myodbc3;",SQL_NTS,outstr,sizeof(outstr),&outstrlen,SQL_DRIVER_NOPROMPT);*/
63 if(!SQL_SUCCEEDED(rc
)){
64 printf("Unable to connect to driver\n");
68 rc
= SQLSetConnectOption(hdbc
, SQL_AUTOCOMMIT
, SQL_AUTOCOMMIT_OFF
);
69 if (rc
!= SQL_SUCCESS
&& rc
!= SQL_SUCCESS_WITH_INFO
)
70 printf ("Unable to set connection option autocommit %d.\n", rc
);
71 /* allocate statement handle for use with table creation and population */
73 rc
= SQLAllocHandle(SQL_HANDLE_STMT
,hdbc
,&hstmt
);
75 printf ("Unable to allocate statement handle.\n");
82 odbcDB::populateTable(char* tblName
, int numTups
, int valRange
)
90 static SQLINTEGER intVal1
, intVal2
, intVal3
, intVal4
, intVal5
, intVal6
,
91 intVal7
, intVal8
, intVal9
, intVal10
, intVal11
, intVal12
,
93 static SQLINTEGER cbintVal
=4;
94 static char s4Val
[64];
95 static char charVal1
[64], charVal2
[64];
98 SQLRETURN rc
= SQL_SUCCESS
;
99 static SQLINTEGER cValLen
=0,cValLen2
=0,cValLen4
=0;
103 printf ("Populating table %s with %d rows...\n", tblName
, numTups
);
105 /* create a prepared statement */
106 sprintf(buf
, InsertTmplt
, tblName
);
108 rc
= SQLPrepare(hstmt
,(SQLCHAR
*)buf
, SQL_NTS
);
110 printf ("Unable to prepare statement.\n");
114 /* set generator and prime values based upon value range */
116 if ( valRange
<=1000 ) {
120 else if ( valRange
<=10000 ) {
124 else if ( valRange
<=100000 ) {
128 else if ( valRange
<=1000000 ) {
132 else if ( valRange
<=10000000 ) {
136 else if ( valRange
<=100000000 ) {
141 printf ("Too many rows in table.\n");
146 /* bind the input parameters */
148 sprintf(charVal1
, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
150 sprintf(charVal2
, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
156 printf ("Binding parameters for table load...\n");
161 rc
+= SQLBindParameter( hstmt
, 1, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
162 SQL_INTEGER
, 10, 0, &intVal1
,4 , &cbintVal
) ;
163 rc
+= SQLBindParameter( hstmt
, 2, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
164 SQL_INTEGER
, 10, 0, &intVal2
,4 , &cbintVal
) ;
165 rc
+= SQLBindParameter( hstmt
, 3, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
166 SQL_INTEGER
, 10, 0, &intVal3
,4 , &cbintVal
) ;
167 rc
+= SQLBindParameter( hstmt
, 4, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
168 SQL_INTEGER
, 10, 0, &intVal4
,4 , &cbintVal
) ;
169 rc
+= SQLBindParameter( hstmt
, 5, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
170 SQL_INTEGER
, 10, 0, &intVal5
,4 , &cbintVal
) ;
171 rc
+= SQLBindParameter( hstmt
, 6, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
172 SQL_INTEGER
, 10, 0, &intVal6
,4 , &cbintVal
) ;
173 rc
+= SQLBindParameter( hstmt
, 7, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
174 SQL_INTEGER
, 10, 0, &intVal7
,4 , &cbintVal
) ;
175 rc
+= SQLBindParameter( hstmt
, 8, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
176 SQL_INTEGER
, 10, 0, &intVal8
,4 , &cbintVal
) ;
177 rc
+= SQLBindParameter( hstmt
, 9, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
178 SQL_INTEGER
, 10, 0, &intVal9
,4 , &cbintVal
) ;
179 rc
+= SQLBindParameter( hstmt
, 10, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
180 SQL_INTEGER
, 10, 0, &intVal10
,4 , &cbintVal
) ;
181 rc
+= SQLBindParameter( hstmt
, 11, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
182 SQL_INTEGER
, 10, 0, &intVal11
,4 , &cbintVal
) ;
183 rc
+= SQLBindParameter( hstmt
, 12, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
184 SQL_INTEGER
, 10, 0, &intVal12
,4 , &cbintVal
) ;
185 rc
+= SQLBindParameter( hstmt
, 13, SQL_PARAM_INPUT
, SQL_C_SLONG
,\
186 SQL_INTEGER
, 38, 0, &intVal13
,4 , &cbintVal
) ;
189 rc
+= SQLBindParameter( hstmt
, 14, SQL_PARAM_INPUT
, SQL_C_CHAR
,\
190 SQL_CHAR
, 52,0, charVal1
, 52, &cValLen
) ;
192 rc
+= SQLBindParameter( hstmt
, 15, SQL_PARAM_INPUT
, SQL_C_CHAR
,\
193 SQL_CHAR
, 52,0, charVal2
, 52, &cValLen2
) ;
195 rc
+= SQLBindParameter( hstmt
, 16, SQL_PARAM_INPUT
, SQL_C_CHAR
,\
196 SQL_CHAR
, 52,0, s4Val
, 52, &cValLen4
) ;
199 printf ("Bind Parameters failed.\n");
202 printf ("Completed\n");
204 } /* End BindColumns */
206 /* insert the numTups rows */
208 for (i
=0; i
<numTups
; i
++) {
209 seed
= randNum(seed
, valRange
, generator
, prime
);
210 randInt
= (int) seed
- 1;
212 /* unique1: range is 0 - valRange-1; order is random */
214 /* unique2: range is 0 - valRange-1; order is sequential */
216 /* two: range is 0 - 1; order is random */
217 intVal3
= randInt
% 2;
218 /* four: range is 0 - 3; order is random */
219 intVal4
= randInt
% 4;
220 /* ten: range is 0 - 9; order is random */
221 intVal5
= randInt
% 10;
222 /* twenty: range is 0 - 19; order is random */
223 intVal6
= randInt
% 20;
224 /* onepercent: range is 0 - 99; order is random */
225 intVal7
= randInt
% 100;
226 /* tenpercent: range is 0 - 9; order is random */
227 intVal8
= randInt
% 10;
228 /* twentypercent: range is 0 - 4; order is random */
229 intVal9
= randInt
% 5;
230 /* fiftypercent: range is 0 - 1; order is random */
231 intVal10
= randInt
% 2;
232 /* unique3: range is 0 - valRange-1; order is random */
234 /* evenonepercent: range is 0 - 198; order is random */
235 intVal12
= (randInt
%100) * 2;
236 /* oddonepercent: range is 0 - 199; order is random */
237 intVal13
= (randInt
%100) * 2 + 1;
238 /* stringu1: order is random */
239 convert(randInt
, charVal1
);
240 cValLen
= (int) strlen(charVal1
);
241 /* stringu2: order is sequential */
242 convert(i
, charVal2
);
243 cValLen2
= (int) strlen(charVal2
);
244 /* string4: order is cyclic */
248 strcpy(s4Val
,"AAAAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
251 strcpy(s4Val
,"HHHHxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
254 strcpy(s4Val
,"OOOOxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
257 strcpy(s4Val
,"VVVVxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
260 cValLen4
= (int) strlen(s4Val
);
262 /* ODBC Execute prepared statement */
264 rc
= SQLExecute(hstmt
);
269 SQLCHAR sqlstate
[6], msg
[300];
273 while ( SQLGetDiagRec(SQL_HANDLE_STMT
, hstmt
, i
, sqlstate
, &native
, msg
, 290, &len
)
280 printf ("SQLExecute failed. (%d)\n", i
);
285 rc
= SQLTransact(henv
,hdbc
,SQL_COMMIT
);
287 printf ("Commit failed\n");
291 /* commit the transaction */
293 rc
= SQLTransact(henv
,hdbc
,SQL_COMMIT
);
295 printf ("Commit failed\n");
297 /* close the statement (but do not drop) and return */
299 rc
= SQLFreeStmt(hstmt
, SQL_DROP
);
301 printf ("Unable to SQL_DROP statement handle.\n");
303 rc
= SQLAllocStmt(hdbc
, &hstmt
);
305 printf ("Unable to Alloc statement handle.\n");
311 fetchSelect(int queryNum
, class wiscTimer
*wT
, SQLHENV henv
, SQLHDBC hdbc
, SQLHSTMT hstmtI
, int verify
,
312 int resCard
, int uniq
)
317 SQLSMALLINT bindtype
;
319 SQLSMALLINT colnamelen
;
320 SQLSMALLINT nullable
;
321 SQLUINTEGER collen
[MAXCOLS
];
323 SQLINTEGER outlen
[MAXCOLS
];
324 SQLCHAR
* data
[MAXCOLS
];
325 SQLSMALLINT nresultcols
= 0, dispcols
= 0;
326 SQLRETURN rc
= SQL_SUCCESS
;
329 // SQLRETURN rc1 = SQL_SUCCESS;
331 for ( i
= 0; i
< MAXCOLS
; i
++ )
334 /* Instantiate the result set */
336 rc
= SQLNumResultCols(hstmtI
, &nresultcols
);
338 printf ("SQLNumresult columns failed.\n");
340 /* bind each column */
342 for (i
= 0; i
< nresultcols
; i
++) {
344 rc
= SQLDescribeCol(hstmtI
,
347 (SQLSMALLINT
) sizeof(colname
),
355 printf ("Unable to describe the column %d.\n", i
+1);
357 /* Select a binding type based on the column type */
362 bindtype
= SQL_C_CHAR
;
363 bindsize
= collen
[i
] + 1;
367 bindtype
= SQL_C_SLONG
;
368 bindsize
= sizeof (int);
372 bindtype
= SQL_C_SHORT
;
373 bindsize
= sizeof (short);
377 bindtype
= SQL_C_TINYINT
;
378 bindsize
= sizeof (char);
382 bindtype
= SQL_C_FLOAT
;
383 bindsize
= sizeof (float);
387 bindtype
= SQL_C_DOUBLE
;
388 bindsize
= sizeof (double);
392 // The schema used for wisconsin benchmark queries does not
393 // involve this datatype.
395 bindtype
= SQL_C_NUMERIC
;
396 bindsize
= collen
[i
] + 1;
401 printf ("Unknown col type %d\n", coltype
);
402 bindtype
= SQL_C_CHAR
;
407 data
[i
] = (unsigned char *) ::malloc(bindsize
);
409 rc
= SQLBindCol( hstmtI
,
412 (SQLPOINTER
)(data
[i
]),
417 printf ("Unable to bind the column %d.\n", i
+1);
419 //if (print) printf ("%*.*s ",collen[i], collen[i], colname);
420 } /* end for each column */
422 dispcols
= nresultcols
;
424 /* commit the transaction */
426 /* execute the query */
429 rc
= SQLExecute(hstmtI
);
431 if (rc
!= SQL_SUCCESS
)
433 printf ("Execute failed. (query=%d hstmt=%p rc=%d)\n",
434 queryNum
, hstmtI
, rc
);
438 /* if specified, verify that the number of actual result
439 * rows are the expected number of result rows
444 rc
= SQLFetch(hstmtI
);
452 for (i
= 0; i
< dispcols
; i
++) {
453 if (outlen
[i
] == SQL_NULL_DATA
) {
454 strcpy((char *)data
[i
], "NULL");
456 printf ("%*.*s ", collen
[i
], collen
[i
], data
[i
]);
462 //printf ("rc = %d\n", rc);
463 //printf("PRABA::Total tuples fetched %d\n", cnt);
465 rc
= SQLTransact(henv
, hdbc
, SQL_COMMIT
);
467 printf ("Unable to commit transaction");
470 rc
= SQLCloseCursor(hstmtI
);
471 if (rc
!= SQL_SUCCESS
)
473 printf ("Close Cursor failed. (query=%d hstmt=%p rc=%d)\n",
474 queryNum
, hstmtI
, rc
);
479 if (uniq
&& cnt
!= 1) {
480 printf ("Error: Query %d: uniq specified and cnt = %d\n", queryNum
, cnt
);
482 if ( cnt
!= resCard
) {
483 printf ("Error: Query %d: expected %d results, got %d\n", queryNum
, resCard
, cnt
);
487 /* free locally allocated memory */
489 for ( i
= 0 ; i
< MAXCOLS
; i
++ ) {
498 odbcDB::selectionQuery (int queryNum
, class wiscTimer
*wT
, char *form1
, char *form2
, int tblCard
,
499 int resCard
, int uniq
, int verify
, int repeatCnt
,
502 int range
= tblCard
- resCard
;
504 char buf
[MAXHSTMT
][192];
507 SQLHSTMT hstmtA
[MAXHSTMT
];
508 SQLRETURN rc
= SQL_SUCCESS
;
510 /* do not perform the operation if the query is not specified by the
513 if (!isQuery(queryNum
)) {
517 bzero((char *)buf
,sizeof(buf
));
519 /* print the query number */
522 printf ("Query %d:\n", queryNum
);
524 /* limit the repeat count */
526 if ( repeatCnt
> 256 ) {
528 printf ("selectionQuery: repeatCnt too high");
532 /* create array[repeatCnt*2] of statement handles */
534 totalNumQueries
= repeatCnt
* 2;
535 times
= longerRun
* RPTS
;
537 printf ("Query %d - total %d times %d\n", queryNum
, totalNumQueries
, times
);
539 for (i
= 0; i
< totalNumQueries
; i
++) {
540 rc
= SQLAllocStmt(hdbc
, &hstmtA
[i
]);
542 printf ("Unable to allocate statement handle.\n");
546 * Build and compile queries that select desired number of
547 * rows (alternating between the two forms). A total of
548 * ten queries are constructed, with column ranges selected
552 for (i
= 0; i
< repeatCnt
; i
++) {
554 val
= (int) (drand48() * range
);
558 sprintf(buf
[2*i
], form1
);
561 sprintf(buf
[2*i
], form1
, val
);
564 sprintf(buf
[2*i
], form1
, val
, val
+resCard
-1);
567 printf ("selectionQuery: unexpected numParams value\n");
571 /* ODBC prepared statement 2 different statements prepared, each
572 * executed repeatCnt number of times with the parameters changed
573 * for each iteration */
575 rc
= SQLPrepare(hstmtA
[2*i
],(SQLCHAR
*) buf
[2*i
], SQL_NTS
);
577 printf ("Unable to prepare statement.\n");
578 printf("hstmtA[%d]=%p, buf[%d]=%s\n", 2*i
, hstmtA
[2*i
], 2*i
, buf
[2*i
]);
580 val
= (int) (drand48() * range
);
582 switch ( numParams
) {
584 sprintf(buf
[2*i
+1], form2
);
587 sprintf(buf
[2*i
+1], form2
, val
);
590 sprintf(buf
[2*i
+1], form2
, val
, val
+resCard
-1);
593 printf ("selectionQuery: unexpected numParams value\n");
597 /* ODBC prepared statement #2 */
599 rc
= SQLPrepare(hstmtA
[2*i
+1],(SQLCHAR
*) buf
[2*i
+1], SQL_NTS
);
601 printf ("Unable to prepare statement.\n");
606 /* commit the transaction */
608 /* execute and time queries. */
610 /* ODBC version of fetchSelect call, handle freed in fetchSelect */
612 for (i
= 0; i
< totalNumQueries
; i
++) {
614 /* execute each query many a time */
616 for (j
= 0; j
< times
; j
++) {
618 rc
= fetchSelect(queryNum
, wT
, henv
, hdbc
, hstmtA
[i
], verify
, resCard
, uniq
);
621 printf ("fetchSelect failed.\n");
631 odbcDB::runUpdate(int queryNum
, class wiscTimer
*wT
, char* col
,
632 int numBigTblTups
, char *Big1TblName
, char *Big2TblName
)
634 char* upd
= "update %s set %s = %d where %s = %d";
636 int val1
= numBigTblTups
+ 1;
637 int val2
= numBigTblTups
/2;
639 SQLHSTMT hstmtA
[MAXHSTMT
];
640 SQLRETURN rc
= SQL_SUCCESS
;
642 if (!isQuery(queryNum
))
645 /* print the query number */
648 printf ("Query %d:\n", queryNum
);
650 /* prepare the update statements */
652 for (i
= 0; i
< ((10*RPTS
)/4); i
++, val1
++, val2
++) {
655 /* allocate and prepare statement #1 */
657 sprintf(buf
, upd
, Big1TblName
, col
, val1
, col
, val2
);
659 rc
+= SQLAllocStmt(hdbc
, &hstmtA
[i
*4]);
660 rc
+= SQLPrepare(hstmtA
[i
*4],(SQLCHAR
*)buf
, SQL_NTS
);
662 /* allocate and prepare statement #2 */
664 sprintf(buf
, upd
, Big2TblName
, col
, val1
, col
, val2
);
666 rc
+= SQLAllocStmt(hdbc
, &hstmtA
[i
*4+1]);
667 rc
+= SQLPrepare(hstmtA
[i
*4+1],(SQLCHAR
*)buf
, SQL_NTS
);
669 /* allocate and prepare statement #3 */
671 sprintf(buf
, upd
, Big1TblName
, col
, val2
, col
, val1
);
673 rc
+= SQLAllocStmt(hdbc
, &hstmtA
[i
*4+2]);
674 rc
+= SQLPrepare(hstmtA
[i
*4+2],(SQLCHAR
*)buf
, SQL_NTS
);
676 /* allocate and prepare statement #4 */
678 sprintf(buf
, upd
, Big2TblName
, col
, val2
, col
, val1
);
680 rc
+= SQLAllocStmt(hdbc
, &hstmtA
[i
*4+3]);
681 rc
+= SQLPrepare(hstmtA
[i
*4+3],(SQLCHAR
*)buf
, SQL_NTS
);
684 printf ("Prepare failed\n");
687 /* commit the transaction */
689 rc
= SQLTransact(henv
, hdbc
, SQL_COMMIT
);
691 printf ("Unable to commit transaction");
693 /* Execute and time updates. */
695 for (i
= 0; i
< 10*RPTS
; i
++) {
699 rc
= SQLExecute(hstmtA
[i
]);
701 printf ("Execute failed (handle[%d]=%p)\n", i
, hstmtA
[i
]);
703 rc
= SQLTransact(henv
,hdbc
,SQL_COMMIT
);
708 printf ("commit failed\n");
712 /* Delete compiled commands. */
714 for (i
=0; i
<10*RPTS
; i
++) {
715 rc
= SQLFreeStmt(hstmtA
[i
], SQL_DROP
);
717 printf ("Free Stmt failed\n");
720 /* commit the transaction and return */
722 rc
= SQLTransact(henv
,hdbc
,SQL_COMMIT
);
724 printf ("Unable to commit transaction.\n");
730 odbcDB::runDelete(int queryNum
, class wiscTimer
*wT
, int numBigTblTups
,
731 char *Big1TblName
, char *Big2TblName
)
733 char* ins
= "delete from %s where unique1=%d";
735 int val
= numBigTblTups
+ 1;
738 SQLHSTMT hstmtA
[MAXHSTMT
];
739 SQLRETURN rc
= SQL_SUCCESS
;
741 /* perform this operation whether specified by user or not, in case
742 * it affects subsequent queries; however, do not record it if not
743 * specified by user */
745 if (!isQuery(queryNum
))
748 /* print the query number */
751 printf ("Query %d:\n", queryNum
);
753 /* prepare delete statements */
755 for (i
= 0; i
< 5*RPTS
; i
++, val
++) {
759 sprintf(buf
, ins
, Big1TblName
, val
);
761 rc
+= SQLAllocStmt(hdbc
, &hstmtA
[i
*2]);
763 rc
+= SQLPrepare(hstmtA
[i
*2],(SQLCHAR
*)buf
, SQL_NTS
);
765 sprintf(buf
, ins
, Big2TblName
, val
);
767 rc
+= SQLAllocStmt(hdbc
, &hstmtA
[i
*2+1]);
769 rc
+= SQLPrepare(hstmtA
[i
*2+1],(SQLCHAR
*)buf
, SQL_NTS
);
772 printf ("Allocation and Prepare failed\n");
776 /* commit the transaction */
778 rc
= SQLTransact(henv
, hdbc
, SQL_COMMIT
);
781 printf ("Commit failed\n");
783 /* execute and time deletes. */
785 for (i
= 0; i
< 10*RPTS
; i
++) {
787 val
+= i
% 2; // incr every other value.
790 rc
= SQLExecute(hstmtA
[i
]);
792 printf ("Execute failed\n");
794 /* commit the transaction */
796 rc
= SQLTransact(henv
, hdbc
, SQL_COMMIT
);
801 printf ("Unable to commit transaction\n");
805 for (i
= 0; i
< 10*RPTS
; i
++) {
807 rc
= SQLFreeStmt(hstmtA
[i
], SQL_DROP
);
810 printf ("Free Stmt failed.\n");
814 /* commit the transaction and return */
816 rc
= SQLTransact(henv
, hdbc
, SQL_COMMIT
);
818 printf ("Unable to commit transaction");
825 odbcDB::runInsert(int queryNum
, class wiscTimer
*wT
, int numBigTblTups
,
826 char *Big1TblName
, char *Big2TblName
)
828 char* ins
= "insert into %s values (%d, %d, 0, 2, 0, 10, 50,\
829 688, 1950, 4950, 9950, 1, 100,\
830 'MxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxC',\
831 'GxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxA',\
832 'OxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxO')";
834 int val
= numBigTblTups
+ 1;
837 SQLHSTMT hstmtA
[MAXHSTMT
];
838 SQLRETURN rc
= SQL_SUCCESS
;
840 /* perform this operation whether specified by user or not, in case
841 * it affects subsequent queries; however, do not record it if not
842 * specified by user */
844 if (!isQuery(queryNum
))
847 /* print the query number */
850 printf ("Query %d:\n", queryNum
);
852 /* Alloc statement handles, compile insert statements and bind
855 for (i
= 0; i
< 5*RPTS
; i
++, val
++) {
858 sprintf(buf
, ins
, Big1TblName
, val
, val
);
860 rc
+= SQLAllocStmt(hdbc
, &hstmtA
[i
*2]);
862 rc
+= SQLPrepare(hstmtA
[i
*2],(SQLCHAR
*)buf
, SQL_NTS
);
864 sprintf(buf
, ins
, Big2TblName
, val
, val
);
866 rc
+= SQLAllocStmt(hdbc
, &hstmtA
[i
*2+1]);
868 rc
+= SQLPrepare(hstmtA
[i
*2+1],(SQLCHAR
*)buf
, SQL_NTS
);
871 printf ("Alloc and prepare failed\n");
875 /* commit the transaction */
877 rc
= SQLTransact(henv
, hdbc
, SQL_COMMIT
);
879 printf ("Commit failed\n");
881 /* execute the insert statement 10*RPT times */
883 for (i
= 0; i
< 10*RPTS
; i
++) {
887 rc
= SQLExecute(hstmtA
[i
]);
889 printf ("Execute now\n");
891 rc
= SQLTransact(henv
,hdbc
,SQL_COMMIT
);
896 printf ("Commit failed\n");
900 for (i
=0; i
<10*RPTS
; i
++) {
902 rc
= SQLFreeStmt(hstmtA
[i
], SQL_DROP
);
904 printf ("Free Stmt failed\n");
907 rc
= SQLTransact(henv
, hdbc
, SQL_COMMIT
);
909 printf ("Unable to commit transaction\n");
916 int odbcDB::disconnect()
921 printf ("Disconnecting from the data source...\n");
923 rc
= SQLTransact(henv
,hdbc
,SQL_COMMIT
);
925 printf ("Unable to commit transaction\n");
927 rc
= SQLDisconnect(hdbc
);
929 printf ("Unable to disconnect\n");
931 rc
= SQLFreeConnect(hdbc
);
933 printf ("Unable to free connection handle");
935 rc
= SQLFreeEnv(henv
);
937 printf ("Unable to free environment handle");
942 static int immedExecute (char* cmd
)
946 rc
= SQLAllocHandle(SQL_HANDLE_STMT
, hdbc
, &hstmt
);
947 if (rc
!= SQL_SUCCESS
)
948 printf ("immedExecute: SQLAllocHandle failed with retCode=%d %s:%d\n", rc
, __FILE__
, __LINE__
);
950 /* Execute the command */
951 rc
= SQLPrepare(hstmt
, (SQLCHAR
*) cmd
, SQL_NTS
);
953 printf ("Prepare of (%s) failed\n", cmd
);
954 rc
= SQLExecute(hstmt
);
956 printf ("Execute of (%s) failed\n", cmd
);
958 /* Commit the transaction */
960 //rc = SQLTransact(henv, hdbc, SQL_COMMIT);
962 printf ("Unable to commit transaction");
964 /* Close associated cusssor and drop pending results */
965 printf("SQL Statement executed %s\n", (char*)cmd
);
966 //rc = SQLFreeStmt(hstmt, SQL_CLOSE);
968 printf ("Unable to SQL_CLOSE statement handle.\n");
974 odbcDB::emptyTable (char *tblName
)
978 sprintf (buf
, "delete from %s", tblName
);
980 return immedExecute (buf
);
984 odbcDB::createTable (char *tblName
)
988 sprintf (buf
, "create table %s "
989 "(unique1 integer not null, unique2 integer not null, "
990 "two integer not null, four integer not null, "
991 "ten integer not null, twenty integer not null, "
992 "onepercent integer not null, tenpercent integer not null, "
993 "twentypercent integer not null, fiftypercent integer not null, "
994 "unique3 integer not null, evenonepercent integer not null, "
995 "oddonepercent integer not null, stringu1 char(52) not null, "
996 "stringu2 char(52) not null, string4 char(52) not null)",
999 return immedExecute (buf
);
1003 odbcDB::dropTable (char *tblName
)
1007 sprintf (buf
, "drop table %s", tblName
);
1009 return immedExecute (buf
);
1013 odbcDB::createIndex (char *idx
, char *tblName
, char *fld
)
1016 if (strcmp(fld
, "unique2") == 0) {
1017 sprintf (buf
, "create index %s on %s (%s)",
1020 sprintf (buf
, "create index %s on %s (%s) tree",
1025 return immedExecute (buf
);
1029 odbcDB::dropIndex (char *idx
, char *tblName
)
1033 sprintf (buf
, "drop index %s", idx
);
1035 return immedExecute (buf
);