ODBC Connection in Eclipse for C++ and Vertica
Is there any way to connect Eclipse with ODBC ?
I installed unixODBC. Then i used the following program to connect Vertica with ODBC.
#include <stdlib.h> #include <iostream> #include <assert.h> #include <sql.h> #include <sqlext.h> #include <sqltypes.h> using namespace std; int main() { SQLRETURN ret; // Stores return value from ODBC API calls SQLHENV hdlEnv; // Handle for the SQL environment object // Allocate an a SQL environment object ret = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hdlEnv); assert(SQL_SUCCEEDED(ret)); // Set the ODBC version we are going to use to // 3. ret = SQLSetEnvAttr(hdlEnv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER) SQL_OV_ODBC3, SQL_IS_UINTEGER); assert(SQL_SUCCEEDED(ret)); // Allocate a database handle. SQLHDBC hdlDbc; ret = SQLAllocHandle(SQL_HANDLE_DBC, hdlEnv, &hdlDbc); assert(SQL_SUCCEEDED(ret)); // Connect four times. If load balancing is on, client should // connect to different nodes. for (int x=1; x <= 4; x++) { // Connect to the database using SQLDriverConnect. Set // ConnectionLoadBalance to 1 (true) to enable load // balancing. cout << endl << "Connection attempt #" << x << "... "; const char *connStr = "DSN=mydsn;ConnectionLoadBalance=0;" "UID=dbadmin;PWD=1"; ret = SQLDriverConnect(hdlDbc, NULL, (SQLCHAR*)connStr, SQL_NTS, NULL, 0, NULL, SQL_DRIVER_NOPROMPT ); if(!SQL_SUCCEEDED(ret)) { cout << "failed. Exiting." << endl; exit(EXIT_FAILURE); } else { cout << "succeeded" << endl; } // We're connected. Query the v_monitor.current_session table to // find the name of the node we've connected to. // Set up a statement handle SQLHSTMT hdlStmt; SQLAllocHandle(SQL_HANDLE_STMT, hdlDbc, &hdlStmt); assert(SQL_SUCCEEDED(ret)); ret = SQLExecDirect( hdlStmt, (SQLCHAR*)"SELECT node_name FROM " "V_MONITOR.CURRENT_SESSION;", SQL_NTS ); if(SQL_SUCCEEDED(ret)) { // Bind varible to column in result set. SQLTCHAR node_name[256]; ret = SQLBindCol(hdlStmt, 1, SQL_C_TCHAR, (SQLPOINTER)node_name, sizeof(node_name), NULL); while(SQL_SUCCEEDED(ret = SQLFetchScroll(hdlStmt, SQL_FETCH_NEXT,1))) { // Print the bound variables, which now contain the values from the // fetched row. cout << "Connected to node " << node_name << endl; } } // Free statement handle SQLFreeHandle(SQL_HANDLE_STMT,hdlStmt); cout << "Disconnecting." << endl; ret = SQLDisconnect( hdlDbc ); assert(SQL_SUCCEEDED(ret)); } // When done, free all of the handles to close them // in an orderly fashion. cout << endl << "Freeing handles..." << endl; SQLFreeHandle(SQL_HANDLE_DBC, hdlDbc); SQLFreeHandle(SQL_HANDLE_ENV, hdlEnv); cout << "Done!" << endl; exit(EXIT_SUCCESS); }
However, I am getting the following errors:
undefined reference to
SQLAllocHandle' undefined reference to
SQLSetEnvAttr'
undefined reference toSQLAllocHandle' undefined reference to
SQLDriverConnect'
.......
undefined reference toSQLFreeHandle' undefined reference to
SQLFreeHandle'
collect2: error: ld returned 1 exit status
I think it has something to do with the library. Does anybody know where is the default library for unixodbc ? I tried /usr/lib/x86_64-linux-gnu/libodbcinst.so , but it still shows errors.
Invoking: GCC C++ Linker
g++ -L/usr/lib/x86_64-linux-gnu -o "hello2" ./src/hello2.o -l/usr/lib/x86_64-linux-gnu/libodbcinst.so
/usr/bin/ld: cannot find -l/usr/lib/x86_64-linux-gnu/libodbcinst.so
collect2: error: ld returned 1 exit status
What I am doing wrong here ? Does anybody have any idea?