I level code cleanup
[csql.git] / test / adapter / Connect / conntest5.c
blob3445e8a8fdbb1a59935b3569a50777e2f579dd54
1 // create table t1 ,Insert some records in it.
2 // Close the connection, Fetch should fail.
4 #include"common.h"
5 int main()
7 DbRetVal rv = OK;
8 AbsSqlConnection *con = createConnection();
9 rv = con->connect("root","manager");
10 if(rv !=OK)return 1;
11 printf("Connection opened\n");
13 AbsSqlStatement *stmt = createStatement();
14 stmt->setConnection(con);
15 char statement[200];
16 if(strcmp(getenv("DSN"),"oracle")==0)
17 strcpy(statement,"CREATE TABLE t1(f1 number(9),f2 number(9));");
18 else if(strcmp(getenv("DSN"),"db2")==0)
19 strcpy(statement,"CREATE TABLE t1(f1 INT,f2 INT)");
20 else
21 strcpy(statement,"CREATE TABLE t1(f1 INT,f2 INT);");
23 int rows = 0;
24 rv = stmt->prepare(statement);
25 if(rv!=OK) { delete stmt; delete con; return 2; }
27 rv = stmt->execute(rows);
28 if(rv!=OK) { delete stmt; delete con; return 3; }
29 stmt->free();
30 printf("Table t1 CREATED\n");
31 con->commit();
32 // insert into statement
33 strcpy(statement,"INSERT INTO t1 VALUES(1,1);");
34 if(strcmp(getenv("DSN"),"db2")==0){
35 strcpy(statement,"INSERT INTO t1 VALUES(1,1)");
37 rv = stmt->prepare(statement);
38 if(rv!=OK) { delete stmt; delete con; return 4; }
40 rv = con->beginTrans();
41 if(rv!=OK) { delete stmt; delete con; return 5; }
43 rv = stmt->execute(rows); if(rv!=OK) return 6;
44 rv = con->commit();
45 if(rv!=OK) return 7;
46 stmt->free();
47 printf("One record inserted\n");
49 strcpy(statement,"SELECT f2 FROM t1 ;");
50 if(strcmp(getenv("DSN"),"db2")==0){
51 strcpy(statement,"SELECT f2 FROM t1");
53 rv = stmt->prepare(statement);
54 if(rv!=OK) { delete stmt; delete con; return 8; }
56 int id=10;
57 stmt->bindField(1,&id);
58 rv = con->beginTrans();
59 if(rv!=OK)return 9;
60 stmt->execute(rows);
61 int count=0;
62 stmt->close();
63 stmt->free();
64 rv = con->disconnect(); //close the connection
66 void *rettype;
67 if(rv!=OK)return 10;
68 rettype = (char*)stmt->fetch(rv);
69 if(rettype==NULL && rv == ErrNoConnection) {
70 printf("After closing the connection,fetch failed\n");
71 con->connect("root", "manager");
72 stmt->setConnection(con);
73 strcpy(statement,"DROP TABLE t1;");
74 if(strcmp(getenv("DSN"),"db2")==0){
75 strcpy(statement,"DROP TABLE t1");
77 rv = stmt->prepare(statement);
78 rv = stmt->execute(rows);
79 if(rv==OK){printf("Table Dropped successfully\n");}
80 stmt->free();
81 con->commit();
82 delete stmt;
83 delete con;
84 printf("Test script passed\n");
85 return 0;
88 printf("Test script Failed\n");
89 delete stmt;
90 delete con;
91 return 11;