test cases for trie index
[csql.git] / test / odbc / Adapter / odbcconnect5c.c
blobc73ce5be42cfcfd1e5086937ace3bb9c4c59477a
1 // connect to the DATA SOURCE with the connection string " DSN=mycsql;MODE=ADAPTER;SERVER=localhost;PORT=5678;"
2 // close the connection and call execute, it should fail.
4 #include<stdio.h>
5 #include<stdlib.h>
6 #include<sql.h>
7 #include<sqlext.h>
8 #include<string.h>
11 //*************************************************************************
13 inline void checkrc(int rc,int line)
15 if(rc)
17 printf("ERROR %d at line %d\n",rc,line);
18 exit(1);
22 //*************************************************************************
23 int main()
25 SQLHENV env;
26 SQLHDBC dbc;
27 SQLHSTMT stmt;
28 SQLRETURN ret;
29 SQLCHAR outstr[1024];
30 SQLSMALLINT outstrlen;
32 // Aloocate an environment handle
33 ret=SQLAllocHandle(SQL_HANDLE_ENV,SQL_NULL_HANDLE,&env);
34 checkrc(ret,__LINE__);
36 //we need odbc3 support
37 SQLSetEnvAttr(env,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3,0);
39 //ALLOCATE A Connection handle
40 ret = SQLAllocHandle(SQL_HANDLE_DBC,env,&dbc);
41 checkrc(ret,__LINE__);
43 // connect to the DSN mydsn
44 ret = SQLConnect (dbc,
45 (SQLCHAR *) "DSN=mycsql;MODE=ADAPTER;SERVER=localhost;PORT=5678;", (SQLSMALLINT) strlen ("DSN=mycsql;MODE=ADAPTER;SERVER=localhost;PORT=5678;"),
46 (SQLCHAR *) "root",
47 (SQLSMALLINT) strlen ("root"),
48 (SQLCHAR *) "manager",
49 (SQLSMALLINT) strlen (""));
52 if(SQL_SUCCEEDED(ret))
54 printf("\nConnected to the Data Source..\n");
58 else
60 printf("connection failed\n");
61 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
62 checkrc(ret,__LINE__);
63 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
64 checkrc(ret,__LINE__);
65 return 1;
68 ret = SQLAllocHandle(SQL_HANDLE_STMT,dbc,&stmt);
69 checkrc(ret,__LINE__);
71 SQLCHAR table[100]="CREATE TABLE EMP(EID INT,SALARY INT)";
73 ret = SQLPrepare(stmt,table,SQL_NTS);
74 checkrc(ret,__LINE__);
76 ret = SQLDisconnect(dbc);
77 checkrc(ret,__LINE__);
79 //AFTER CLOSE THE CONNECTION ,CALL execute
81 ret = SQLExecute(stmt);
82 int rettype = ret;
83 if(ret )
84 printf("After closing the connection, Execution failed\n");
87 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
88 checkrc(ret,__LINE__);
90 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
91 checkrc(ret,__LINE__);
93 if(rettype ==0)return 1;
96 return 0;