64 bit build fix
[csql.git] / test / sql / StmtCache / stmtTest12.c
blob11ea0a444f1db6ef122ce78a4c5bdd4ef48b0736
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 (f2));");
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();
22 // insert into table
23 strcpy(statement,"INSERT INTO t1 VALUES(1234,?,'CSQL');");
24 rv = stmt->prepare(statement);
25 if(rv!=OK) { delete stmt; delete con; return 4; }
26 printf("AFTER INSERT PREPARE operation\n");
27 int rnd = 0;
28 int i = 0;
29 if (1) {
30 i++;
31 rv = con->beginTrans();
32 stmt->setIntParam(1, i);
33 rv = stmt->execute(rows);
34 if (rv == ErrUnique) {
35 printf("Unique Key Violation Error\n");
36 con->rollback();
37 } else if (rv != OK) {
38 printError(rv, "Insert failed with ret val %d", rv);
39 con->rollback();
41 else con->commit();
43 stmt->free();
45 printf("TRUNCATE TABLE\n");
46 strcpy(statement, "TRUNCATE TABLE t1");
47 rv = stmt->prepare(statement);
48 if (rv != OK) {con->disconnect();delete stmt; delete con; return -1; }
49 rv = con->beginTrans();
50 stmt->execute(rows);
51 con->commit();
52 con->display();
53 stmt->free();
55 strcpy(statement, "DROP TABLE t1");
56 rv = stmt->prepare(statement);
57 if (rv != OK) {con->disconnect();delete stmt; delete con; return -1; }
58 stmt->execute(rows);
59 stmt->free();
61 con->disconnect();
62 delete stmt;
63 delete con;