adding test scripts
[csql.git] / test / sql / StmtCache / stmtTest13b.c
blob501b333c6ed96f14e0797e8723e89c4d2d210a98
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(f1, f2, f3) 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("alter TABLE\n");
46 strcpy(statement, "alter table t1 drop column f3");
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();
54 strcpy(statement,"INSERT INTO t1(f1, f2, f3) VALUES(1234,?,'CSQL');");
55 rv = stmt->prepare(statement);
56 if(rv!=OK) { delete stmt; delete con; return 4; }
57 printf("AFTER INSERT PREPARE operation\n");
58 i = 1000;
59 if (1) {
60 i++;
61 rv = con->beginTrans();
62 stmt->setIntParam(1, i);
63 rv = stmt->execute(rows);
64 if (rv == ErrUnique) {
65 printf("Unique Key Violation Error\n");
66 con->rollback();
67 } else if (rv != OK) {
68 printError(rv, "Insert failed with ret val %d", rv);
69 con->rollback();
71 else con->commit();
73 stmt->free();
74 system("csqldump");
75 strcpy(statement, "drop TABLE t2");
76 rv = stmt->prepare(statement);
77 if (rv != OK) {con->disconnect();delete stmt; delete con; return -1; }
78 stmt->execute(rows);
79 stmt->free();
81 con->disconnect();
82 delete stmt;
83 delete con;