File Removed
[csql.git] / test / dbapi / Connection / threadtest2.c
blob6bf69b4bb92a7a7c13612a0e46e95f5fca81daa2
1 #include <stdlib.h>
2 #include <pthread.h>
3 #include <unistd.h>
4 #include <stdio.h>
5 #include <CSql.h>
6 void* print_message_function (void *ptr);
7 int flag=0;
8 int main (int argc, char **argv)
10 Connection conn;
11 DbRetVal rv = conn.open("root","manager");
12 printf ("Main open Returned %d\n", rv);
13 pthread_t thread1, thread2;
14 int message1 =1;
15 int message2 =2;
16 int status;
18 pthread_create (&thread1, NULL,
19 &print_message_function, (void *) &message1);
20 pthread_create (&thread2, NULL,
21 &print_message_function, (void *) &message2);
23 pthread_join(thread1, (void **)&status);
24 pthread_join(thread2, (void **)&status);
27 DatabaseManager *dbMgr = conn.getDatabaseManager();
28 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
29 dbMgr->dropTable("T1");
30 dbMgr->dropTable("T2");
32 rv = conn.close();
33 printf ("Main Returned %d\n", rv);
34 exit (0);
38 void* print_message_function(void *ptr)
40 //if (flag == 0) {flag =1; sleep(2); }
41 char tblname[20];
42 sprintf(tblname, "T%d", *(int*)ptr );
43 Connection conn;
44 DbRetVal rv=conn.open("root","manager");
45 printf("Thread Return value of open %d %d\n", rv, getpid());
46 if(rv!=OK)
48 return NULL;
50 DatabaseManager *dbMgr = conn.getDatabaseManager();
51 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
54 TableDef tabDef;
55 tabDef.addField("f1", typeInt);
56 tabDef.addField("f2", typeInt);
57 rv = dbMgr->createTable(tblname, tabDef);
58 if (rv != OK) { printf("Table creation failed\n"); return NULL; }
59 printf("Table created\n");
61 rv = conn.close();
62 printf("Thread Return value of close %d %d\n", rv, getpid());