*** empty log message ***
[csql.git] / test / odbc / Connect / odbcconnect5.c
blob737fdaf2376cdd3af2181fb1c650098de2df39ea
1 /* close the connection and call execute, it should fail.
3 * AUTHOR : Jitendra Lenka
4 */
6 #include<stdio.h>
7 #include<stdlib.h>
8 #include<sql.h>
9 #include<sqlext.h>
10 #include<string.h>
13 //*************************************************************************
15 inline void checkrc(int rc,int line)
17 if(rc)
19 printf("ERROR %d at line %d\n",rc,line);
20 exit(1);
24 //*************************************************************************
25 int main()
27 SQLHENV env;
28 SQLHDBC dbc;
29 SQLHSTMT stmt;
30 SQLRETURN ret;
31 SQLCHAR outstr[1024];
32 SQLSMALLINT outstrlen;
34 // Aloocate an environment handle
35 ret=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&env);
36 checkrc(ret,__LINE__);
38 //we need odbc3 support
39 SQLSetEnvAttr(env,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0);
41 //ALLOCATE A Connection handle
42 ret = SQLAllocHandle(SQL_HANDLE_DBC,env,&dbc);
43 checkrc(ret,__LINE__);
45 // connect to the DSN mydsn
46 ret = SQLConnect (dbc,
47 (SQLCHAR *) "test", (SQLSMALLINT) strlen ("test"),
48 (SQLCHAR *) "root",
49 (SQLSMALLINT) strlen ("root"),
50 (SQLCHAR *) "manager",
51 (SQLSMALLINT) strlen (""));
54 if(SQL_SUCCEEDED(ret))
56 printf("\nConnected to the Data Source..\n");
60 else
62 printf("connection failed\n");
63 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
64 checkrc(ret,__LINE__);
65 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
66 checkrc(ret,__LINE__);
67 return 1;
70 ret = SQLAllocHandle(SQL_HANDLE_STMT,dbc,&stmt);
71 checkrc(ret,__LINE__);
73 SQLCHAR table[100]="CREATE TABLE EMP(EID INT,SALARY INT)";
75 ret = SQLPrepare(stmt,table,SQL_NTS);
76 checkrc(ret,__LINE__);
78 ret = SQLDisconnect(dbc);
79 checkrc(ret,__LINE__);
81 //AFTER CLOSE THE CONNECTION ,CALL execute
83 ret = SQLExecute(stmt);
84 int rettype = ret;
85 if(ret )
86 printf("After closing the connection, Execution failed\n");
89 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
90 checkrc(ret,__LINE__);
92 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
93 checkrc(ret,__LINE__);
95 if(rettype ==0)return 1;
98 return 0;