adding test scripts
[csql.git] / test / load / SQLAdapterTest.c
blobbff022e0280496a7d830d475fc4fa72d8b263824
1 #include<AbsSqlStatement.h>
2 #include<SqlFactory.h>
3 #include<NanoTimer.h>
4 #define ITERATIONS 10000
5 int main()
7 DbRetVal rv = OK;
8 AbsSqlConnection *con = SqlFactory::createConnection(CSqlGateway);
9 rv = con->connect("root", "manager");
10 if (rv != OK) return 1;
11 AbsSqlStatement *stmt = SqlFactory::createStatement(CSqlGateway);
12 stmt->setConnection(con);
13 char statement[1024];
14 int id1 =10;
15 int newVal = 1000;
16 int count =0, rows=0;
18 strcpy(statement, "INSERT INTO t1 (f1, f2) VALUES (?, ?);");
19 rv = stmt->prepare(statement);
20 if (rv != OK) {delete stmt; delete con; return -1; }
21 for (int i = 0 ; i < ITERATIONS ; i++)
23 rv = con->beginTrans();
24 if (rv != OK) break;
25 id1 = i;
26 stmt->setIntParam(1, id1);
27 stmt->setIntParam(2, id1);
28 rv = stmt->execute(rows);
29 if (rv != OK) break;
30 rv = con->commit();
31 if (rv != OK) break;
32 count++;
34 stmt->free();
37 /*strcpy(statement, "UPDATE t1 set f2=? where f1=?;");
38 rv = stmt->prepare(statement);
39 if (rv != OK) {delete stmt; delete con; return -1; }
40 count =0;
41 for (int i = 0 ; i < ITERATIONS ; i++)
43 rv = con->beginTrans();
44 if (rv != OK) break;
45 stmt->setIntParam(2, i);
46 stmt->setIntParam(1, newVal);
47 rv = stmt->execute(rows);
48 if (rv != OK && rows !=1) break;
49 rv = con->commit();
50 if (rv != OK) break;
51 count++;
53 stmt->free();
56 strcpy(statement, "DELETE FROM t1 where f1=?;");
57 rv = stmt->prepare(statement);
58 if (rv != OK) {delete stmt; delete con; return -1; }
59 stmt->bindField(1, &id1);
60 count =0;
61 for (int i = 0 ; i < ITERATIONS ; i++)
63 rv = con->beginTrans();
64 if (rv != OK) break;
65 stmt->setIntParam(1, i+100000);
66 rv = stmt->execute(rows);
67 if (rv != OK && rows != 1) break;
68 rv = con->commit();
69 if (rv != OK) break;
70 count++;
72 stmt->free();
74 delete stmt;
75 delete con;
76 return 0;