adding test scripts
[csql.git] / test / sql / StmtCache / stmtTest2.c
blob37677c731f9d43376500bdbb2423ead25f5542e9
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();
21 printf("AFTER CREATE TABLE operation\n");
22 con->display();
24 // insert into table
25 strcpy(statement,"INSERT INTO t1 VALUES(1234,?,'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 int i = 0;
32 if (1) {
33 i++;
34 rv = con->beginTrans();
35 //stmt->setIntParam(1, rnd);
36 stmt->setIntParam(1, i);
37 rv = stmt->execute(rows);
38 if (rv == ErrUnique) {
39 printf("Unique Key Violation Error\n");
40 con->rollback();
41 } else if (rv != OK) {
42 printError(rv, "Insert failed with ret val %d", rv);
43 con->rollback();
45 else con->commit();
47 printf("AFTER INSERT EXECUTE operation\n");
48 con->display();
49 stmt->free();
50 printf("AFTER STMT FREE operation\n");
51 con->display();
53 printf("AFTER DROP TABLE\n");
54 strcpy(statement, "DROP TABLE t1");
55 rv = stmt->prepare(statement);
56 if (rv != OK) {con->disconnect();delete stmt; delete con; return -1; }
57 stmt->execute(rows);
58 con->display();
60 con->disconnect();
61 printf("AFTER disconnect\n");
62 con->display();
63 delete stmt;
64 delete con;