1 /* create t1 table with two fields f11 int, f12 char.
2 * create 3 thredas and each one should insert and fetch 1000 records.
4 * AUTHOR : Jitendra Lenka
9 void *runInsTest(void *p
);
10 void *runSelTest(void *p
);
14 DbRetVal rv
= conn
.open("root","manager");
17 printf("Error during connection %d\n",rv
);
21 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
24 printf("Auth failed\n");
28 tabDef
.addField("f11",typeInt
,0,NULL
,true);
29 tabDef
.addField("f12",typeString
,1020);
31 rv
= dbMgr
->createTable("t1",tabDef
);
34 printf("Table creation failed\n");
39 pthread_t thr
[THREADS
];
42 for(int i
=0;i
<THREADS
;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");
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();
65 while((tuple
=(char*)table
->fetch()))
69 printf("Tuples found: %d\n",count
);
73 dbMgr
->closeTable(table
);
75 for(int i
=0 ; i
<THREADS
;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");
91 void* runInsTest(void *message
)
94 DbRetVal rv
= conn
.open("root","manager");
97 printf("Error during connection %d \n",rv
);
100 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
103 printf("Auth failed\n");
106 Table
*table
= dbMgr
->openTable("t1");
109 printf("Unable to open table\n");
114 char name
[1020] = "LAKSHYA";
115 table
->bindFld("f11",&id
);
116 table
->bindFld("f12",name
);
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;
128 strcpy(name
,"LAKSHYA SOLUTIONS");
129 ret
= table
->insertTuple();
137 printf("Thread :%d Inserted :%d records.\n",val
,count
);
138 dbMgr
->closeTable(table
);
143 void* runSelTest(void* message
)
146 DbRetVal rv
= conn
.open("root","manager");
149 printf("Error during connection %d \n",rv
);
152 DatabaseManager
*dbMgr
= conn
.getDatabaseManager();
155 printf("Auth failed\n");
159 Table
*table
= dbMgr
->openTable("t1");
162 printf("Unable to open table\n");
167 char name
[1020] ="Lakshya";
168 table
->bindFld("f11",&id
);
169 table
->bindFld("f12",name
);
174 int val
= *(int*)message
;
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();
186 rv
= table
->execute();
187 tuple
= (char*)table
->fetch();
188 if(tuple
!= NULL
)count
++;
193 printf("Select: Thread %d: Total records :%d\n",val
,count
);
194 dbMgr
->closeTable(table
);