64 bit build fix
[csql.git] / test / sql / StmtCache / stmtTest3.c
blobf4a8177e77a99338ac68f81ea15990fab72c130b
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 strcpy(statement, "UPDATE t1 set f2=? where f1=?;");
15 rv = stmt->prepare(statement);
16 if(rv!=OK) { delete stmt; delete con; return 4; }
17 printf("AFTER UPDATE PREPARE operation\n");
18 con->display();
19 int i = 1;
20 int rows=0;
21 rv = con->beginTrans();
22 stmt->setIntParam(1, 100);
23 stmt->setIntParam(2, i);
24 rv = stmt->execute(rows);
25 if (rv != OK) {
26 printError(rv, "Update failed with ret val %d", rv);
27 con->rollback();
29 else con->commit();
30 stmt->free();
31 printf("AFTER STMT FREE operation\n");
32 con->display();
34 strcpy(statement, "DELETE from t1 where f2=?;");
35 rv = stmt->prepare(statement);
36 if(rv!=OK) { delete stmt; delete con; return 4; }
37 printf("AFTER DELETE PREPARE operation\n");
38 con->display();
39 rv = con->beginTrans();
40 stmt->setIntParam(1, 100);
41 rv = stmt->execute(rows);
42 if (rv != OK) {
43 printError(rv, "Update failed with ret val %d", rv);
44 con->rollback();
46 else con->commit();
47 stmt->free();
48 printf("AFTER STMT FREE operation\n");
49 con->display();
52 strcpy(statement, "SELECT f1 from t1 where f2=?;");
53 rv = stmt->prepare(statement);
54 if(rv!=OK) { delete stmt; delete con; return 4; }
55 printf("AFTER SELECT PREPARE operation\n");
56 con->display();
57 rv = con->beginTrans();
58 int val =0;
59 stmt->bindField(1, &val);
60 stmt->setIntParam(1, 1);
61 rv = stmt->execute(rows);
62 while (stmt->fetch()!= NULL)
64 printf("Tuple value %d\n", val);
66 con->commit();
67 stmt->free();
68 printf("AFTER STMT FREE operation\n");
69 con->display();
72 con->disconnect();
73 printf("AFTER disconnect\n");
74 con->display();
75 delete stmt;
76 delete con;