1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
SQLHANDLE handle;
//SQLSMALLINT type;
SQLHENV env;
SQLHDBC dbc;
SQLHSTMT stmt;
SQLRETURN ret;
SQLCHAR conn[256] =
"DSN=MY_DSN;UID=user;PWD=pwd;";
//Allocate and environment handle
SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &env);
//ODBC 3 support
SQLSetEnvAttr (env, SQL_ATTR_ODBC_VERSION, (void *) SQL_OV_ODBC3, 0);
//Allocate a connection handle
SQLAllocHandle (SQL_HANDLE_DBC, env, &dbc);
//Connect to the DSN
ret = SQLDriverConnect(dbc, NULL, conn, SQL_NTS, outstr, sizeof (outstr), &outstrlen, SQL_DRIVER_NOPROMPT);
if (SQL_SUCCEEDED(ret)){
outfile1<<"SQLDriverConnect succeded"<<endl;
//Allocate Statement handle
ret = SQLAllocHandle (SQL_HANDLE_STMT, dbc, &stmt);
if (SQL_SUCCEEDED(ret)){
outfile1<<"Statement handle allocated"<<endl;
//Execute Query
ret = SQLExecDirect(stmt, (unsigned char*)"SELECT * FROM SCHEMA.USER_TABLE", SQL_NTS);
if (SQL_SUCCEEDED(ret)){
outfile1<<"Execute query succeded"<<endl;
outfile1.close();
return (SecurityErrOK);
} else{
outfile1<<"Execute query failed"<<endl;
outfile1.close();
return (SecurityErrNoSuchUser);
}
} else{
outfile1<<"Handle allocation failed"<<endl;
outfile1.close();
return (SecurityErrNoSuchUser);
}
} else{
outfile1<<"SQLDriverConnect failed"<<endl;
outfile1.close();
return (SecurityErrNoSuchUser);
}
|