adding test scripts
[csql.git] / test / sqlapi / Csql / Connect / fetchafterclose.c
blob5dafb7e99926f5c42006a58d1ab93b6cc866da0f
1 /*
2 create table T1 ,Insert some records in it.
3 Close the connection, Fetch should fail.
4 */
6 #include"common.h"
8 int main()
10 DbRetVal rv = OK;
11 AbsSqlConnection *con = createConnection();
12 rv = con->connect("root","manager");
13 if(rv !=OK) {
14 delete con;
15 return 1;
17 printf("Connection opened\n");
19 AbsSqlStatement *stmt = createStatement();
20 stmt->setConnection(con);
21 char statement[200];
22 strcpy(statement,"CREATE TABLE T1(F1 INT,F2 INT);");
23 int rows = 0;
24 rv = stmt->prepare(statement);
25 if(rv!=OK) {
26 con->disconnect();
27 delete stmt;
28 delete con;
29 return 2;
31 printf("Statement Prepared\n");
33 rv = stmt->execute(rows);
34 if(rv!=OK) {
35 con->disconnect();
36 delete stmt;
37 delete con;
38 return 3;
40 stmt->free();
41 printf("Table T1 CREATED\n");
43 // insert into statement
44 strcpy(statement,"INSERT INTO T1 VALUES(1,1);");
45 rv = stmt->prepare(statement);
46 if(rv!=OK) { con->disconnect(); delete stmt; delete con; return 4; }
47 rv = con->beginTrans();
48 if(rv!=OK) { con->disconnect(); delete stmt; delete con; return 5; }
49 rv = stmt->execute(rows); if(rv!=OK) return 6;
50 rv = con->commit();
51 if(rv!=OK) {
52 return 7;
54 stmt->free();
55 printf("One record inserted\n");
57 strcpy(statement,"SELECT F2 FROM T1 ;");
58 rv = stmt->prepare(statement);
59 if(rv!=OK) { con->disconnect(); delete stmt; delete con; return 10; }
60 int id=10;
61 stmt->bindField(1,&id);
62 rv = con->beginTrans();
63 if(rv!=OK)return 11;
64 stmt->execute(rows);
65 int count=0;
66 stmt->close(); stmt->free();
67 rv = con->disconnect(); //close the connection
68 void *rettype;
69 if(rv!=OK)return 8;
70 rettype = (char*)stmt->fetch();
71 if(rettype==NULL && rv == OK) {
72 printf("Fetch Failed After closing Connection,\n");
73 con->connect("root", "manager");
74 stmt->setConnection(con);
75 strcpy(statement,"DROP TABLE T1;");
76 rv = stmt->prepare(statement);
77 rv = stmt->execute(rows);
78 if(rv==OK) { printf("Table Dropped successfully\n"); }
79 stmt->free(); delete stmt; delete con;
80 printf("Test script passed\n");
81 return 0;
83 printf("Test script Failed\n");
85 delete stmt; delete con;
86 return 7;