Fixing system/config/test002 failed test
[csql.git] / test / performance / DMLThreadTest1.c
blobc69c7a8648c71f5149eb397bb66178f905061dbe
1 /* create 't1' table with two fields f11 int, f12 char,
2 * create 3 threads and each one insert 1000 records in the table.
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);
52 dbMgr->dropTable("t1");
53 conn.close();
54 return 0;
57 void* runInsTest(void *message)
59 Connection conn;
60 DbRetVal rv = conn.open("root","manager");
61 if(rv!=OK)
63 printf("Error during connection %d \n",rv);
64 return NULL;
66 DatabaseManager *dbMgr = conn.getDatabaseManager();
67 if(dbMgr ==NULL)
69 printf("Auth failed\n");
70 return NULL;
72 Table *table = dbMgr->openTable("t1");
73 if(table == NULL)
75 printf("Unable to open table\n");
76 return NULL;
79 int id=0;
80 char name[1020] = "LAKSHYA";
81 table->bindFld("f11",&id);
82 table->bindFld("f12",name);
84 char *tuple;
85 int ret;
86 int i;
87 int count = 0;
88 int val = *(int*)message;
89 for(i=val*1000; i<(val*1000)+1000;i++)
91 rv = conn.startTransaction();
92 //if(rv!=OK)return 1;
93 id = i;
94 strcpy(name,"LAKSHYA SOLUTIONS");
95 ret = table->insertTuple();
96 if(ret !=0)break;
98 count++;
99 conn.commit();
103 printf("Thread :%d Inserted :%d records.\n",val,count);
104 dbMgr->closeTable(table);
105 rv = conn.close();
106 return NULL;