windows fixes for test directory
[csql.git] / test / sql / StmtCache / stmtTest9.c
blob1ef060d077b2a6e2880252e4256fc069a5b2df1c
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 AbsSqlStatement *dropstmt = SqlFactory::createStatement(CSql);
14 dropstmt->setConnection(con);
15 char statement[200];
16 int rows =0;
17 // insert into table
18 strcpy(statement,"INSERT INTO t1 VALUES(?, ?, 'CSQL');");
19 rv = stmt->prepare(statement);
20 if(rv!=OK) { delete stmt; delete con; return 4; }
21 rv = con->beginTrans();
22 stmt->setIntParam(1, 100);
23 stmt->setIntParam(2, 100);
24 rv = stmt->execute(rows);
25 if (rv != OK) {
26 printError(rv, "Insert failed with ret val %d", rv);
27 con->rollback();
29 else con->commit();
30 con->display();
31 printf("creating index\n");
32 strcpy(statement, "create index idx1 on t1(f2);");
33 rv = dropstmt->prepare(statement);
34 if (rv != OK) {
35 printf("create index on table failed\n");
36 con->disconnect();delete stmt; delete con; return -1;
38 dropstmt->execute(rows);
39 dropstmt->free();
40 printf("After create index \n");
41 con->display();
43 rv = con->beginTrans();
44 stmt->setIntParam(1, 200);
45 stmt->setIntParam(2, 200);
46 rv = stmt->execute(rows);
47 if (rv != OK) {
48 printError(rv, "Insert failed with ret val %d", rv);
49 con->rollback();
51 else con->commit();
52 stmt->free();
53 printf("After reusing cached insert stmt\n");
54 con->display();
55 strcpy(statement,"INSERT INTO t1 VALUES(?, ?, 'CSQL');");
56 rv = stmt->prepare(statement);
57 if(rv!=OK) { delete stmt; delete con; return 4; }
58 rv = con->beginTrans();
59 stmt->setIntParam(1, 300);
60 stmt->setIntParam(2, 300);
61 rv = stmt->execute(rows);
62 if (rv != OK) {
63 printError(rv, "Insert failed with ret val %d", rv);
64 con->rollback();
66 else con->commit();
68 con->disconnect();
69 delete stmt;
70 delete con;