adding test scripts
[csql.git] / test / durability / redologs / stmtTest3.c
blob8773651cf77ceddcc86bfcac5b31f94ef804d9e1
1 #include <SqlFactory.h>
3 int main(int argc, char **argv)
5 DbRetVal rv = OK;
6 struct timeval timeout;
7 struct timeval timeStamp;
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[200];
14 int rows =0;
16 // insert into table
17 strcpy(statement,"INSERT INTO t1 VALUES(1234,?);");
18 rv = stmt->prepare(statement);
19 if(rv!=OK) { delete stmt; delete con; return 4; }
20 int rnd = 0;
21 rv = con->beginTrans();
22 stmt->setIntParam(1, 100);
23 rv = stmt->execute(rows);
24 stmt->setIntParam(1, 200);
25 rv = stmt->execute(rows);
26 if (rv != OK) {
27 printError(rv, "Insert failed with ret val %d", rv);
29 con->commit();
30 stmt->free();
32 strcpy(statement, "UPDATE t1 set f1=? where f2=200;");
33 rv = stmt->prepare(statement);
34 stmt->setIntParam(1, 200);
35 if(rv!=OK) { delete stmt; delete con; return 4; }
36 rv = con->beginTrans();
37 rv = stmt->execute(rows);
38 if (rv != OK) {
39 printError(rv, "Update failed with ret val %d", rv);
41 con->commit();
42 stmt->free();
44 strcpy(statement, "DELETE from t1 where f2=?;");
45 rv = stmt->prepare(statement);
46 stmt->setIntParam(1, 100);
47 if(rv!=OK) { delete stmt; delete con; return 4; }
48 rv = con->beginTrans();
49 rv = stmt->execute(rows);
50 if (rv != OK) {
51 printError(rv, "Delete failed with ret val %d", rv);
53 con->commit();
54 stmt->free();
56 strcpy(statement, "SELECT f1 from t1 where f2=200;");
57 rv = stmt->prepare(statement);
58 if(rv!=OK) { delete stmt; delete con; return 4; }
59 rv = con->beginTrans();
60 int val =0;
61 stmt->bindField(1, &val);
62 rv = stmt->execute(rows);
63 while (stmt->fetch() != NULL)
65 printf("Tuple value %d\n", val);
67 con->commit();
68 stmt->free();
70 con->disconnect();
71 delete stmt;
72 delete con;