1 // create table t1 ,Insert some records in it.
2 // Close the connection, Fetch should fail.
8 AbsSqlConnection
*con
= createConnection();
9 rv
= con
->connect("root","manager");
11 printf("Connection opened\n");
13 AbsSqlStatement
*stmt
= createStatement();
14 stmt
->setConnection(con
);
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)");
21 strcpy(statement
,"CREATE TABLE t1(f1 INT,f2 INT);");
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; }
30 printf("Table t1 CREATED\n");
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;
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; }
57 stmt
->bindField(1,&id
);
58 rv
= con
->beginTrans();
64 rv
= con
->disconnect(); //close the connection
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");}
84 printf("Test script passed\n");
88 printf("Test script Failed\n");