test cases for trie index
[csql.git] / test / soakTest / odbcInsert.c
blob800d5e8dea7b2434e2df97f000cf1d1ae50ca905
1 #include<CSql.h>
2 #include<sql.h>
3 #include<stdio.h>
4 #include<stdlib.h>
5 #include<time.h>
6 #define TS 1000
8 int main(int argc, char **argv)
10 SQLHENV env;
11 SQLHDBC dbc;
12 SQLHSTMT stmt;
13 SQLRETURN ret;
14 SQLCHAR outstr[1024];
15 SQLSMALLINT outstrlen;
17 SQLHDBC adDbc;
18 SQLHSTMT adStmt;
20 struct timeval timeout;
21 struct timeval timeStamp;
22 char msgBuf[25];
24 if (argv[1] == NULL) {
25 fprintf(stderr, "Usage: csqlInsert <o/p file>\n");
26 return 1;
29 FILE *fp = fopen(argv[1], "a");
31 // Aloocate an environment handle
32 ret=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&env);
34 //we need odbc3 support
35 SQLSetEnvAttr(env,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0);
37 //ALLOCATE A Connection handle
38 ret = SQLAllocHandle(SQL_HANDLE_DBC,env,&dbc);
39 ret = SQLAllocHandle(SQL_HANDLE_DBC,env,&adDbc);
41 // connect to the DSN mydsn
42 ret = SQLConnect (dbc,
43 (SQLCHAR *) "test", (SQLSMALLINT) strlen ("test"),
44 (SQLCHAR *) "root",
45 (SQLSMALLINT) strlen ("root"),
46 (SQLCHAR *) "manager",
47 (SQLSMALLINT) strlen (""));
49 if(SQL_SUCCEEDED(ret)) printf("\nConnected to the csql Data Source..\n");
50 else
52 printf("error in conenction\n");
53 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
54 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
55 return 1;
57 ret = SQLConnect (adDbc,
58 (SQLCHAR *) "DSN=mycsql;MODE=ADAPTER;SERVER=localhost;PORT=5678;", (SQLSMALLINT) strlen ("test"),
59 (SQLCHAR *) "root",
60 (SQLSMALLINT) strlen ("root"),
61 (SQLCHAR *) "manager",
62 (SQLSMALLINT) strlen (""));
64 if(SQL_SUCCEEDED(ret)) printf("\nConnected to the msql Data Source..\n");
65 else
67 printf("error in conenction\n");
68 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
69 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
70 return 1;
73 ret = SQLAllocHandle(SQL_HANDLE_STMT,dbc,&stmt);
74 ret = SQLAllocHandle(SQL_HANDLE_STMT,adDbc,&adStmt);
75 int rnd = 0;
76 ret = SQLPrepare(stmt,(unsigned char*)"INSERT INTO soakTable VALUES(1234,?,93333993,'CSQL_LAKSHYA');",SQL_NTS);
77 ret = SQLPrepare(adStmt,(unsigned char*)"INSERT INTO soakTable VALUES(1234,?,93333993,'CSQL_LAKSHYA');",SQL_NTS);
78 ret = SQLBindParameter(stmt,1,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&rnd,0,NULL);
79 ret = SQLBindParameter(adStmt,1,SQL_PARAM_INPUT,SQL_C_SLONG,SQL_INTEGER,0,0,&rnd,0,NULL);
80 int i = 0;
81 while (1) {
82 if (ret == 0) {
83 timeout.tv_sec = 0;
84 timeout.tv_usec = TS;
85 os::select(0, 0, 0, 0, &timeout);
87 srand(time(0));
88 if (i == 0) rnd = rand() % 16645635;
89 else if (i == 1) rnd = (rand() / 17) % 16645635;
90 else if (i == 2) rnd = (rand() / 19) % 16645635;
91 else if (i == 3) rnd = (rand() / 23) % 16645635;
92 else if (i == 4) { i = 0; rnd = (rand() / 29) % 16645635; }
93 i++;
94 ret = SQLExecute(stmt);
95 if (ret == SQL_ERROR) SQLTransact(env, dbc, SQL_ROLLBACK);
96 else ret = SQLTransact(env,dbc,SQL_COMMIT);
97 ret = SQLExecute(adStmt);
98 if (ret == SQL_ERROR) SQLTransact(env, adDbc, SQL_ROLLBACK);
99 else ret = SQLTransact(env,adDbc,SQL_COMMIT);
100 os::gettimeofday(&timeStamp);
101 struct tm *tempTm = os::localtime(&timeStamp.tv_sec);
102 strftime(msgBuf, 25, "%d/%m/%Y %H:%M:%S", tempTm);
103 fprintf(fp, "Inserted PK: %8d %s\n", rnd, msgBuf);
104 fflush(fp);
106 ret = SQLFreeHandle(SQL_HANDLE_STMT,stmt);
107 ret = SQLDisconnect(dbc);
108 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
109 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
110 return 0;