adding test scripts
[csql.git] / test / odbc / Gateway / odbcconnect3f.c
blob0e3eaaca50b66674e5039b8925754c110f0232ef
1 // Connect the DATA SOURCE with the connection string "DSN=mycsql;MODE=GATEWAY;SERVER=127.0.0.1;PORT=5678;"
2 // close the connection and then call commit,it should fail.
4 #include<stdio.h>
5 #include<stdlib.h>
6 #include<sql.h>
7 #include<sqlext.h>
8 #include<string.h>
12 //*************************************************************************
14 inline void checkrc(int rc,int line)
16 if(rc)
18 printf("ERROR %d at line %d\n",rc,line);
19 exit(1);
23 //*************************************************************************
24 int main()
26 SQLHENV env;
27 SQLHDBC dbc;
28 SQLHSTMT stmt;
29 SQLRETURN ret;
30 SQLCHAR outstr[1024];
31 SQLSMALLINT outstrlen;
33 // Aloocate an environment handle
34 ret=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&env);
35 checkrc(ret,__LINE__);
37 //we need odbc3 support
38 SQLSetEnvAttr(env,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0);
40 //ALLOCATE A Connection handle
41 ret = SQLAllocHandle(SQL_HANDLE_DBC,env,&dbc);
42 checkrc(ret,__LINE__);
44 // connect to the DSN mydsn
45 ret = SQLConnect (dbc,
46 (SQLCHAR *) "DSN=mycsql;MODE=GATEWAY;SERVER=127.0.0.1;PORT=5678;", (SQLSMALLINT) strlen ("DSN=mycsql;MODE=127.0.0.1;SERVER=localhost;PORT=5678;"),
47 (SQLCHAR *) "root",
48 (SQLSMALLINT) strlen ("root"),
49 (SQLCHAR *) "manager",
50 (SQLSMALLINT) strlen (""));
53 if(SQL_SUCCEEDED(ret))
55 printf("\nConnected to the Data Source successfully..\n");
59 else
61 printf("error in connection\n");
63 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
64 checkrc(ret,__LINE__);
66 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
67 checkrc(ret,__LINE__);
69 return 1;
72 ret = SQLDisconnect(dbc);
73 checkrc(ret,__LINE__);
74 // call to commit
75 ret = SQLTransact(env,dbc,SQL_COMMIT);
77 int rettype = ret;
79 if(ret)
81 printf("After disconnect,commit failed\n");
82 else
83 printf("After disconenct, commit passed\n");
85 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
86 checkrc(ret,__LINE__);
88 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
89 checkrc(ret,__LINE__);
90 if (rettype == 0) return 1;
91 return 0;