64 bit build fix
[csql.git] / test / performance / SQLTest.c
bloba196d6626c844df717e70f880ed5d090117137c0
1 #include<AbsSqlStatement.h>
2 #include<SqlFactory.h>
3 #include<NanoTimer.h>
4 #define ITERATIONS 100
5 int main()
7 DbRetVal rv = OK;
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);
13 char statement[1024];
14 strcpy(statement, "CREATE TABLE t1 (f1 int, f2 char(196));");
15 int rows =0;
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; }
20 stmt->free();
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; }
28 stmt->free();
29 printf("Index created on t1(f1) \n");
31 strcpy(statement, "INSERT INTO t1 (f1, f2) VALUES (?, ?);");
32 int id1 =10;
33 char name[196];
34 strcpy(name, "Rithish");
35 NanoTimer timer;
36 rv = stmt->prepare(statement);
37 if (rv != OK) {delete stmt; delete con; return -1; }
38 int count =0;
39 for (int i = 0 ; i < ITERATIONS ; i++)
41 timer.start();
42 rv = con->beginTrans();
43 if (rv != OK) break;
44 id1 = i;
45 stmt->setIntParam(1, id1);
46 strcpy(name, "Gopika");
47 stmt->setStringParam(2, name);
48 rv = stmt->execute(rows);
49 if (rv != OK) break;
50 rv = con->commit();
51 if (rv != OK) break;
52 timer.stop();
53 count++;
55 printf("Total Rows Inserted %d %lld %lld %lld\n", count, timer.minc(),
56 timer.maxc(), timer.avg());
57 stmt->free();
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);
64 timer.reset();
65 count =0;
66 for (int i = 0 ; i < ITERATIONS ; i++)
68 timer.start();
69 rv = con->beginTrans();
70 if (rv != OK) break;
71 stmt->setIntParam(1, i);
72 stmt->execute(rows);
73 if (stmt->fetch() == NULL) { printf("unable to read record\n"); break; }
74 stmt->close();
75 rv = con->commit();
76 if (rv != OK) break;
77 timer.stop();
78 count++;
80 stmt->free();
81 printf("Total Rows Selected %d %lld %lld %lld\n", count, timer.minc(),
82 timer.maxc(), 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);
89 timer.reset();
90 count =0;
91 for (int i = 0 ; i < ITERATIONS ; i++)
93 timer.start();
94 rv = con->beginTrans();
95 if (rv != OK) break;
96 stmt->setIntParam(2, i);
97 stmt->setStringParam(1, "ChangedValue");
98 rv = stmt->execute(rows);
99 if (rv != OK && rows !=1) break;
100 rv = con->commit();
101 if (rv != OK) break;
102 timer.stop();
103 count++;
105 stmt->free();
106 printf("Total Rows Updated %d %lld %lld %lld\n", count, timer.minc(),
107 timer.maxc(), 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);
113 timer.reset();
114 count =0;
115 for (int i = 0 ; i < ITERATIONS ; i++)
117 timer.start();
118 rv = con->beginTrans();
119 if (rv != OK) break;
120 stmt->setIntParam(1, i);
121 rv = stmt->execute(rows);
122 if (rv != OK && rows != 1) break;
123 rv = con->commit();
124 if (rv != OK) break;
125 timer.stop();
126 count++;
128 stmt->free();
129 printf("Total Rows Deleted %d %lld %lld %lld\n", count, timer.minc(),
130 timer.maxc(), 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; }
137 stmt->free();
138 printf("Table dropped\n");
141 delete stmt;
142 delete con;
143 return 0;