1 #include<AbsSqlStatement.h>
5 //NOTE CREATE TABLE t1 (f1 int, f2 char(196), primary key(f1));
6 //add 1:t1 in csqltable.conf and do csqlserver -c
10 AbsSqlConnection
*con
= SqlFactory::createConnection(CSqlGateway
);
11 rv
= con
->connect("root", "manager");
12 if (rv
!= OK
) return 1;
13 AbsSqlStatement
*stmt
= SqlFactory::createStatement(CSqlGateway
);
14 stmt
->setConnection(con
);
17 strcpy(statement
, "INSERT INTO t1 (f1, f2) VALUES (?, ?);");
20 strcpy(name
, "Rithish");
22 rv
= stmt
->prepare(statement
);
23 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
25 for (int i
= 0 ; i
< ITERATIONS
; i
++)
28 rv
= con
->beginTrans();
31 stmt
->setIntParam(1, id1
);
32 strcpy(name
, "Gopika");
33 stmt
->setStringParam(2, name
);
34 rv
= stmt
->execute(rows
);
41 printf("Total Rows Inserted %d %lld %lld %lld\n", count
, timer
.minc(),
42 timer
.maxc(), timer
.avg());
45 strcpy(statement
, "SELECT * FROM t1 where f1 = ?;");
46 rv
= stmt
->prepare(statement
);
47 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
48 stmt
->bindField(1, &id1
);
49 stmt
->bindField(2, name
);
52 for (int i
= 0 ; i
< ITERATIONS
; i
++)
55 rv
= con
->beginTrans();
57 stmt
->setIntParam(1, i
);
59 if (stmt
->fetch() == NULL
) { printf("unable to read record\n"); break; }
67 printf("Total Rows Selected %d %lld %lld %lld\n", count
, timer
.minc(),
68 timer
.maxc(), timer
.avg());
70 strcpy(statement
, "UPDATE t1 set f2=? where f1=?;");
71 rv
= stmt
->prepare(statement
);
72 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
73 stmt
->bindField(1, &id1
);
74 stmt
->bindField(2, name
);
77 for (int i
= 0 ; i
< ITERATIONS
; i
++)
80 rv
= con
->beginTrans();
82 stmt
->setIntParam(2, i
);
83 stmt
->setStringParam(1, "ChangedValue");
84 rv
= stmt
->execute(rows
);
85 if (rv
!= OK
&& rows
!=1) break;
92 printf("Total Rows Updated %d %lld %lld %lld\n", count
, timer
.minc(),
93 timer
.maxc(), timer
.avg());
95 strcpy(statement
, "DELETE FROM t1 where f1=?;");
96 rv
= stmt
->prepare(statement
);
97 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
98 stmt
->bindField(1, &id1
);
101 for (int i
= 0 ; i
< ITERATIONS
; i
++)
104 rv
= con
->beginTrans();
106 stmt
->setIntParam(1, i
);
107 rv
= stmt
->execute(rows
);
108 if (rv
!= OK
&& rows
!= 1) break;
115 printf("Total Rows Deleted %d %lld %lld %lld\n", count
, timer
.minc(),
116 timer
.maxc(), timer
.avg());