test cases for trie index
[csql.git] / test / odbc / Connect / odbcconnect4a.c
blobcee72dfe5e1da79e5a519ac307be7efd826aadc9
1 // connect to the DATA SOURCE with the connection string "DSN=mycsql;MODE=csql;SERVER=localhost;PORT=5678;"
2 // close the connction and then call prepare,
3 // it should failed
5 #include<stdio.h>
6 #include<stdlib.h>
7 #include<sql.h>
8 #include<sqlext.h>
9 #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=csql;SERVER=localhost;PORT=5678;", (SQLSMALLINT) strlen ("DSN=mycsql;MODE=csql;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("conenction failed\n");
61 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
62 checkrc(ret,__LINE__);
64 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
65 checkrc(ret,__LINE__);
66 return 1;
69 ret = SQLAllocHandle(SQL_HANDLE_STMT,dbc,&stmt);
70 checkrc(ret,__LINE__);
72 SQLCHAR table[100]="CREATE TABLE EMP(EID INT,SALARY INT)";
75 ret = SQLDisconnect(dbc);
76 checkrc(ret,__LINE__);
78 //AFTER CLOSE THE CONNECTION ,CALL PREPARE
79 ret = SQLPrepare(stmt,table,SQL_NTS);
80 int rettype = ret;
81 if(ret!=SQL_SUCCESS && ret !=SQL_SUCCESS_WITH_INFO)
82 printf("After closing the connection, prepare failed \n");
86 ret = SQLFreeHandle(SQL_HANDLE_DBC,dbc);
87 checkrc(ret,__LINE__);
89 ret = SQLFreeHandle(SQL_HANDLE_ENV,env);
90 checkrc(ret,__LINE__);
91 if(rettype == 0)
93 printf("Test script failed\n");
94 return 1;
97 return 0;