changes for libcsqlstorage and inclusion of libcsqlbase
[csql.git] / test / sqlapi / Csql / Isolation / common.h
blobfc4e2ea929cc62128a859e82ba62d9b63b0305b0
1 #include<SqlFactory.h>
2 #include<SqlNwConnection.h>
3 #include<SqlNwStatement.h>
5 AbsSqlConnection *createConnection()
7 #ifdef NETWORK
8 AbsSqlConnection *con = SqlFactory::createConnection(CSqlNetwork);
9 SqlNwConnection *conn = (SqlNwConnection *) con;
10 conn->setHost("localhost", 5678);
11 #elif defined NETWORKADAPTER
12 AbsSqlConnection *con = SqlFactory::createConnection(CSqlNetworkAdapter);
13 SqlNwConnection *conn = (SqlNwConnection *) con;
14 conn->setHost("localhost", 5678);
15 #elif defined NETWORKGATEWAY
16 AbsSqlConnection *con = SqlFactory::createConnection(CSqlNetworkGateway);
17 SqlNwConnection *conn = (SqlNwConnection *) con;
18 conn->setHost("localhost", 5678);
19 #else
20 AbsSqlConnection *con = SqlFactory::createConnection(CSql);
21 #endif
22 return con;
25 AbsSqlStatement *createStatement()
27 #ifdef NETWORK
28 AbsSqlStatement *stmt = SqlFactory::createStatement(CSqlNetwork);
29 #elif defined NETWORKADAPTER
30 AbsSqlStatement *stmt = SqlFactory::createStatement(CSqlNetworkAdapter);
31 #elif defined NETWORKGATEWAY
32 AbsSqlStatement *stmt = SqlFactory::createStatement(CSqlNetworkGateway);
33 #else
34 AbsSqlStatement *stmt = SqlFactory::createStatement(CSql);
35 #endif
36 return stmt;
39 DbRetVal executeDdlQuery(AbsSqlConnection *conn, AbsSqlStatement *stmt,
40 char *stmtstr)
42 DbRetVal rv = OK;
43 rv = stmt->prepare(stmtstr);
44 if (rv != OK) return rv;
45 int rows = 0;
46 rv = stmt->execute(rows);
47 if (rv != OK) return rv;
48 return OK;
51 DbRetVal insert(AbsSqlStatement *stmt, int val, bool isSleep)
53 char statement[1024] = "insert into t1 values(?, 'PRABAKARAN');";
54 DbRetVal rv = stmt->prepare(statement);
55 if (rv != OK) return rv;
56 stmt->setIntParam(1, val);
57 int rows = 0;
58 rv = stmt->execute(rows);
59 if (rv != OK) { return ErrLockTimeOut; }
60 printf("Inserted tuple : %d %s\n", val, "PRABAKARAN");
61 if (isSleep) ::sleep(5);
62 return OK;
65 DbRetVal select(AbsSqlStatement *stmt, int val, bool isSleep, bool checkUpd=false)
67 char statement[1024] = "select * from t1 where f1 = ?;";
68 int id = 0;
69 char name[196];
70 DbRetVal rv = stmt->prepare(statement);
71 if (rv != OK) return rv;
72 stmt->bindField(1, &id);
73 stmt->bindField(2, name);
74 stmt->setIntParam(1, val);
75 int rows = 0;
76 rv = stmt->execute(rows);
77 if (rv != OK) return rv;
78 void *tuple = stmt->fetch(rv);
79 if (rv != OK) return rv;
80 if (tuple == NULL) {
81 printf("Tuple not found\n");
82 return ErrNotFound;
84 printf("ThreadID: %lu Tuple %d %s\n", os::getthrid(), id, name);
85 if (isSleep) ::sleep(5);
86 if ( checkUpd && strcmp(name, "KANCHANA") != 0) return ErrUnknown;
87 return OK;
90 DbRetVal update(AbsSqlStatement *stmt, int val, bool isSleep, char *updname = NULL)
92 char statement[1024] = "update t1 set f2 = 'KANCHANA' where f1 = ?;";
93 DbRetVal rv = stmt->prepare(statement);
94 if (rv != OK) return rv;
95 stmt->setIntParam(1, val);
96 int rows = 0;
97 rv = stmt->execute(rows);
98 if (rv != OK) { return rv; }
99 printf("ThreadID: %lu Updated Tuple %d %s\n", os::getthrid(), val, "KANCHANA");
100 if (isSleep) ::sleep(2);
101 return OK;
104 DbRetVal remove(AbsSqlStatement *stmt, int val, bool isSleep)
106 char statement[1024] = "delete from t1 where f1 = ?;";
107 DbRetVal rv = stmt->prepare(statement);
108 if (rv != OK) return rv;
109 stmt->setIntParam(1, val);
110 int rows = 0;
111 rv = stmt->execute(rows);
112 if (rv != OK) { return rv; }
113 printf("ThreadID: %lu Deleted Tuple %d %s\n", os::getthrid(), val, "PRABAKARAN");
114 if (isSleep) ::sleep(2);
115 return OK;