string suport <= and >=
[csql.git] / test / dbapi / Connection / isotest14.c
blob78c4eb90234bb2684885c5e3cf094b937ffe0905
1 #include "common.h"
2 //READ_UNCOMMITTED isolation testing
3 //T1 doing select and T2 doing update for same tuple
4 //Both should succeed
6 void* runTest1(void *p);
7 void* runTest2(void *p);
8 int *p1RetVal = NULL;
9 int *p2RetVal = NULL;
11 int main()
14 Connection conn;
15 DbRetVal rv = conn.open("root", "manager");
16 if (rv != OK) { printf("Error during connection %d\n", rv); return 1; }
17 DatabaseManager *dbMgr = conn.getDatabaseManager();
18 int ret = createTable(dbMgr);
19 if (ret != 0) { return 1; }
21 rv = conn.startTransaction();
22 if (rv != OK) {printf ("Unable to start trans\n"); return 1; }
23 rv = insert(dbMgr, 100, false);
24 if (rv != OK) { printf("Unable to insert\n"); return 2; }
25 conn.commit();
26 printf("Tuple inserted\n");
28 pthread_t thr[2];
29 int *status1, *status2;
30 pthread_create (&thr[0], NULL, &runTest1, NULL);
31 pthread_create (&thr[1], NULL, &runTest2, NULL);
32 printf("All threads started\n");
34 pthread_join(thr[0], (void**)&status1);
35 pthread_join(thr[1], (void**)&status2);
36 ret = 0;
37 if (*status1 != 0 || *status2 != 0) ret = 1;
38 dbMgr->dropTable("t1");
39 conn.close();
40 if (p1RetVal) { delete p1RetVal; p1RetVal = NULL; }
41 if (p2RetVal) { delete p2RetVal; p2RetVal = NULL; }
43 return ret;
45 void* runTest1(void *message)
47 Connection conn;
48 DbRetVal rv = conn.open("root", "manager");
49 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
50 DatabaseManager *dbMgr = conn.getDatabaseManager();
51 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
52 rv = conn.startTransaction(READ_UNCOMMITTED);
53 if (rv != OK) return NULL;
54 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
55 p1RetVal = new int();
56 *p1RetVal = 0;
57 rv = select(dbMgr, 100, true);
58 if (rv != OK) { printf("Test Failed:first thread failed to select\n"); *p1RetVal = 1; }
60 conn.commit();
61 rv = conn.close();
62 pthread_exit(p1RetVal);
64 void* runTest2(void *message)
66 Connection conn;
67 DbRetVal rv = conn.open("root", "manager");
68 if (rv != OK) { printf("Error during connection %d\n", rv); return NULL; }
69 DatabaseManager *dbMgr = conn.getDatabaseManager();
70 if (dbMgr == NULL) { printf("Auth failed\n"); return NULL;}
71 rv = conn.startTransaction(READ_UNCOMMITTED);
72 if (rv != OK) return NULL;
73 printf("Thread and pid is %d %lu\n", os::getpid(), os::getthrid());
75 p2RetVal = new int();
76 *p2RetVal = 0;
77 rv = update(dbMgr, 100, false);
78 if (rv != OK) { printf("Test Failed:second thread failed to update\n"); *p2RetVal = 1; }
79 conn.commit();
80 conn.close();
81 pthread_exit(p2RetVal);