2 #include<SqlNwConnection.h>
3 #include<SqlNwStatement.h>
5 AbsSqlConnection
*createConnection()
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);
20 AbsSqlConnection
*con
= SqlFactory::createConnection(CSql
);
25 AbsSqlStatement
*createStatement()
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
);
34 AbsSqlStatement
*stmt
= SqlFactory::createStatement(CSql
);
39 DbRetVal
executeDdlQuery(AbsSqlConnection
*conn
, AbsSqlStatement
*stmt
,
43 rv
= stmt
->prepare(stmtstr
);
44 if (rv
!= OK
) return rv
;
46 rv
= stmt
->execute(rows
);
47 if (rv
!= OK
) return rv
;
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
);
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);
65 DbRetVal
select(AbsSqlStatement
*stmt
, int val
, bool isSleep
, bool checkUpd
=false)
67 char statement
[1024] = "select * from t1 where f1 = ?;";
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
);
76 rv
= stmt
->execute(rows
);
77 if (rv
!= OK
) return rv
;
78 void *tuple
= stmt
->fetch(rv
);
79 if (rv
!= OK
) return rv
;
81 printf("Tuple not found\n");
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
;
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
);
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);
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
);
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);