64 bit build fix
[csql.git] / test / sql / StmtCache / stmtTest4.c
bloba4ef6215204bb55ce90d29794e26010bcdb61a77
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, "CREATE TABLE t1 (f1 int, f2 int, f3 char(20), primary key (f1));");
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("AFTER CREATE TABLE operation\n");
22 con->display();
24 // insert into table
25 strcpy(statement,"INSERT INTO t1 VALUES(1234,5,'CSQL');");
26 rv = stmt->prepare(statement);
27 if(rv!=OK) { delete stmt; delete con; return 4; }
28 printf("AFTER INSERT PREPARE operation\n");
29 con->display();
30 int rnd = 0;
31 rv = con->beginTrans();
32 rv = stmt->execute(rows);
33 if (rv != OK) {
34 printError(rv, "Insert failed with ret val %d", rv);
35 con->rollback();
37 else con->commit();
38 printf("AFTER INSERT EXECUTE operation\n");
39 con->display();
40 stmt->free();
41 printf("AFTER STMT FREE operation\n");
42 con->display();
44 strcpy(statement, "UPDATE t1 set f2=10 where f1=1234;");
45 rv = stmt->prepare(statement);
46 if(rv!=OK) { delete stmt; delete con; return 4; }
47 printf("AFTER UPDATE PREPARE operation\n");
48 con->display();
49 rv = con->beginTrans();
50 rv = stmt->execute(rows);
51 if (rv != OK) {
52 printError(rv, "Update failed with ret val %d", rv);
53 con->rollback();
55 else con->commit();
56 stmt->free();
57 printf("AFTER STMT FREE operation\n");
58 con->display();
60 strcpy(statement, "DELETE from t1 where f2=10;");
61 rv = stmt->prepare(statement);
62 if(rv!=OK) { delete stmt; delete con; return 4; }
63 printf("AFTER DELETE PREPARE operation\n");
64 con->display();
65 rv = con->beginTrans();
66 rv = stmt->execute(rows);
67 if (rv != OK) {
68 printError(rv, "Delete failed with ret val %d", rv);
69 con->rollback();
71 else con->commit();
72 stmt->free();
73 printf("AFTER STMT FREE operation\n");
74 con->display();
76 strcpy(statement, "SELECT f1 from t1 where f2=1;");
77 rv = stmt->prepare(statement);
78 if(rv!=OK) { delete stmt; delete con; return 4; }
79 printf("AFTER SELECT PREPARE operation\n");
80 con->display();
81 rv = con->beginTrans();
82 int val =0;
83 stmt->bindField(1, &val);
84 rv = stmt->execute(rows);
85 while (stmt->fetch() != NULL)
87 printf("Tuple value %d\n", val);
89 con->commit();
90 stmt->free();
91 printf("AFTER STMT FREE operation\n");
92 con->display();
94 strcpy(statement, "DROP TABLE t1");
95 rv = stmt->prepare(statement);
96 if (rv != OK) {con->disconnect();delete stmt; delete con; return -1; }
97 stmt->execute(rows);
98 stmt->free();
101 con->disconnect();
102 printf("AFTER disconnect\n");
103 con->display();
104 delete stmt;
105 delete con;