1 #include<AbsSqlStatement.h>
8 AbsSqlConnection
*con
= SqlFactory::createConnection(CSql
);
9 rv
= con
->connect("root", "manager");
10 if (rv
!= OK
) return 1;
11 AbsSqlStatement
*stmt
= SqlFactory::createStatement(CSql
);
12 stmt
->setConnection(con
);
14 strcpy(statement
, "CREATE TABLE t1 (f1 int, f2 char(196));");
16 rv
= stmt
->prepare(statement
);
17 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
18 rv
= stmt
->execute(rows
);
19 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
21 printf("Table t1 created\n");
23 strcpy(statement
, "CREATE INDEX t1idx on t1 (f1);");
24 rv
= stmt
->prepare(statement
);
25 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
26 rv
= stmt
->execute(rows
);
27 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
29 printf("Index created on t1(f1) \n");
31 strcpy(statement
, "INSERT INTO t1 (f1, f2) VALUES (?, ?);");
34 strcpy(name
, "Rithish");
36 rv
= stmt
->prepare(statement
);
37 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
39 for (int i
= 0 ; i
< ITERATIONS
; i
++)
42 rv
= con
->beginTrans();
45 stmt
->setIntParam(1, id1
);
46 strcpy(name
, "Gopika");
47 stmt
->setStringParam(2, name
);
48 rv
= stmt
->execute(rows
);
55 printf("Total Rows Inserted %d %lld %lld %lld\n", count
, timer
.min(),
56 timer
.max(), timer
.avg());
59 strcpy(statement
, "SELECT * FROM t1 where f1 = ?;");
60 rv
= stmt
->prepare(statement
);
61 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
62 stmt
->bindField(1, &id1
);
63 stmt
->bindField(2, name
);
66 for (int i
= 0 ; i
< ITERATIONS
; i
++)
69 rv
= con
->beginTrans();
71 stmt
->setIntParam(1, i
);
73 if (stmt
->fetch() == NULL
) { printf("unable to read record\n"); break; }
81 printf("Total Rows Selected %d %lld %lld %lld\n", count
, timer
.min(),
82 timer
.max(), timer
.avg());
84 strcpy(statement
, "UPDATE t1 set f2=? where f1=?;");
85 rv
= stmt
->prepare(statement
);
86 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
87 stmt
->bindField(1, &id1
);
88 stmt
->bindField(2, name
);
91 for (int i
= 0 ; i
< ITERATIONS
; i
++)
94 rv
= con
->beginTrans();
96 stmt
->setIntParam(2, i
);
97 stmt
->setStringParam(1, "ChangedValue");
98 rv
= stmt
->execute(rows
);
99 if (rv
!= OK
&& rows
!=1) break;
106 printf("Total Rows Updated %d %lld %lld %lld\n", count
, timer
.min(),
107 timer
.max(), timer
.avg());
109 strcpy(statement
, "DELETE FROM t1 where f1=?;");
110 rv
= stmt
->prepare(statement
);
111 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
112 stmt
->bindField(1, &id1
);
115 for (int i
= 0 ; i
< ITERATIONS
; i
++)
118 rv
= con
->beginTrans();
120 stmt
->setIntParam(1, i
);
121 rv
= stmt
->execute(rows
);
122 if (rv
!= OK
&& rows
!= 1) break;
129 printf("Total Rows Deleted %d %lld %lld %lld\n", count
, timer
.min(),
130 timer
.max(), timer
.avg());
132 strcpy(statement
, "DROP TABLE t1;");
133 rv
= stmt
->prepare(statement
);
134 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
135 rv
= stmt
->execute(rows
);
136 if (rv
!= OK
) {delete stmt
; delete con
; return -1; }
138 printf("Table dropped\n");