test cases for trie index
[csql.git] / test / odbc / Connect / odbcconnect3.c
blob1d1bf45431106c61a034b6b0e1cb0237bcf3465c
1 /* close the connection and then call commit,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>
14 //*************************************************************************
16 inline void checkrc(int rc,int line)
18 if(rc)
20 printf("ERROR %d at line %d\n",rc,line);
21 exit(1);
25 //*************************************************************************
26 int main()
28 SQLHENV env;
29 SQLHDBC dbc;
30 SQLHSTMT stmt;
31 SQLRETURN ret;
32 SQLCHAR outstr[1024];
33 SQLSMALLINT outstrlen;
35 // Aloocate an environment handle
36 ret=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&env);
37 checkrc(ret,__LINE__);
39 //we need odbc3 support
40 SQLSetEnvAttr(env,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0);
42 //ALLOCATE A Connection handle
43 ret = SQLAllocHandle(SQL_HANDLE_DBC,env,&dbc);
44 checkrc(ret,__LINE__);
46 // connect to the DSN mydsn
47 ret = SQLConnect (dbc,
48 (SQLCHAR *) "test", (SQLSMALLINT) strlen ("test"),
49 (SQLCHAR *) "root",
50 (SQLSMALLINT) strlen ("root"),
51 (SQLCHAR *) "manager",
52 (SQLSMALLINT) strlen (""));
55 if(SQL_SUCCEEDED(ret))
57 printf("\nConnected to the Data Source successfully..\n");
61 else
63 printf("error in connection\n");
65 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
66 checkrc(ret,__LINE__);
68 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
69 checkrc(ret,__LINE__);
71 return 1;
74 ret = SQLDisconnect(dbc);
75 checkrc(ret,__LINE__);
76 // call to commit
77 ret = SQLTransact(env,dbc,SQL_COMMIT);
79 int rettype = ret;
81 if(ret)
83 printf("After disconnect,commit failed\n");
84 else
85 printf("After disconenct, commit passed\n");
87 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
88 checkrc(ret,__LINE__);
90 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
91 checkrc(ret,__LINE__);
92 if (rettype == 0) return 1;
93 return 0;