Cleaning up wisconsin benchmark files
[csql.git] / test / performance / DMLThreadTest3.c
blob9a3bdc21e526b1cee997a81da69fd03a443fb962
1 /* create t1 table with two fields,
2 * create 3 thredas and each one should insert and update 1000 records .
4 * AUTHOR : Jitendra Lenka
5 */
6 #include<CSql.h>
7 #define THREADS 3
9 void *runInsTest(void *p);
10 void *runSelTest(void *p);
11 int main()
13 Connection conn;
14 DbRetVal rv = conn.open("root","manager");
15 if(rv!=OK)
17 printf("Error during connection %d\n",rv);
18 return -1;
21 DatabaseManager *dbMgr = conn.getDatabaseManager();
22 if(dbMgr ==NULL)
24 printf("Auth failed\n");
25 return -2;
27 TableDef tabDef;
28 tabDef.addField("f11",typeInt,0,NULL,true);
29 tabDef.addField("f12",typeString,1020);
31 rv = dbMgr->createTable("t1",tabDef);
32 if(rv!=OK)
34 printf("Table creation failed\n");
35 return -3;
38 // thread creation
39 pthread_t thr[THREADS];
40 int message[THREADS];
41 int status;
42 for(int i=0;i<THREADS;i++)
44 message[i]=i;
45 pthread_create(&thr[i],NULL,&runInsTest,(void*)&message[i]);
47 for(int i=0;i<THREADS;i++)
49 pthread_join(thr[i],(void**)&status);
51 // **************************************************
53 Table *table = dbMgr->openTable("t1");
54 if(table==NULL)
56 printf("Unable to open table\n");return 1;
59 table->setCondition(NULL);
60 rv = conn.startTransaction();
61 if(rv!=OK)while(rv!=OK)rv = conn.startTransaction();
62 table->execute();
63 int count=0;
64 void *tuple =NULL;
65 while((tuple=(char*)table->fetch()))
67 count++;
69 printf("Tuples found: %d\n",count);
70 table->closeScan();
71 conn.commit();
73 dbMgr->closeTable(table);
75 for(int i=0 ; i<THREADS ;i++)
77 message[i] = i;
78 pthread_create(&thr[i],NULL,&runSelTest,(void*)&message[i]);
81 for(int i=0;i<THREADS;i++)
83 pthread_join(thr[i],(void**)&status);
86 dbMgr->dropTable("t1");
87 conn.close();
88 return 0;
91 void* runInsTest(void *message)
93 Connection conn;
94 DbRetVal rv = conn.open("root","manager");
95 if(rv!=OK)
97 printf("Error during connection %d \n",rv);
98 return NULL;
100 DatabaseManager *dbMgr = conn.getDatabaseManager();
101 if(dbMgr ==NULL)
103 printf("Auth failed\n");
104 return NULL;
106 Table *table = dbMgr->openTable("t1");
107 if(table == NULL)
109 printf("Unable to open table\n");
110 return NULL;
113 int id=0;
114 char name[1020] = "LAKSHYA";
115 table->bindFld("f11",&id);
116 table->bindFld("f12",name);
118 char *tuple;
119 int ret;
120 int i;
121 int count = 0;
122 int val = *(int*)message;
123 for(i=val*1000; i<(val*1000)+1000;i++)
125 rv = conn.startTransaction();
126 //if(rv!=OK)return 1;
127 id = i;
128 strcpy(name,"LAKSHYA SOLUTIONS");
129 ret = table->insertTuple();
130 if(ret !=0)break;
132 count++;
133 conn.commit();
137 printf("Thread :%d Inserted :%d records.\n",val,count);
138 dbMgr->closeTable(table);
139 rv = conn.close();
140 return NULL;
143 void* runSelTest(void* message)
145 Connection conn;
146 DbRetVal rv = conn.open("root","manager");
147 if(rv !=OK)
149 printf("Error during connection %d \n",rv);
150 return NULL;
152 DatabaseManager *dbMgr = conn.getDatabaseManager();
153 if(dbMgr ==NULL)
155 printf("Auth failed\n");
156 return NULL;
159 Table *table = dbMgr->openTable("t1");
160 if(table==NULL)
162 printf("Unable to open table\n");
163 return NULL;
166 int id=0;
167 char name[1020] ="Lakshya";
168 table->bindFld("f11",&id);
169 table->bindFld("f12",name);
171 char *tuple;
172 int i;
173 int count=0;
174 int val = *(int*)message;
176 Condition p1;
177 int valTerm = 0;
178 p1.setTerm("f11",OpEquals,&valTerm);
179 table->setCondition(&p1);
181 for(i = val * 1000; i < (val*1000)+1000;i++)
183 rv = conn.startTransaction();
184 if(rv!=OK)while(rv!=OK) rv = conn.startTransaction();
185 valTerm = i;
186 rv = table->execute();
187 tuple = (char*)table->fetch();
188 if(tuple == NULL)
190 printf("loop break in %d\n",i);
191 table->closeScan();
192 break;
194 strcpy(name,"LAKSHYA SOLUTIONS");
195 table->updateTuple();
196 table->closeScan();
197 conn.commit();
198 count++;
201 printf("UPDATE: Thread %d: Total records :%d\n",val,count);
202 dbMgr->closeTable(table);
203 rv = conn.close();
204 return NULL;