Skip to Content
author's profile photo Former Member
Former Member

c++ app using ODBC w/MaxDB

I'm trying to build a c++ application to use ODBC with MaxDB and I'm finding the ODBC Manual for MaxDB a little difficult to follow. Is it possible to get a code snipet for a simple connection.

I have been trying to use:

#include "/opt/sapdb/indep_prog/incl/WINDOWS.H"

#include "/opt/sapdb/indep_prog/incl/sql.h"

#include "/opt/sapdb/indep_prog/incl/sqlext.h"

#include <iostream>

class ODBC_Class;

/**********************************************/

ODBC_Class::ODBC_Class(){

ReturnCode = SQL_SUCCESS;

ReturnCode = SQLAllocHandle(SQL_HANDLE_ENV,

SQL_NULL_HANDLE,

&EnvHandle);

if(ReturnCode == SQL_SUCCESS){

ReturnCode = SQLSetEnvAttr(EnvHandle,

SQL_ATTR_ODBC_VERSION,

(SQLPOINTER) SQL_OV_ODBC3,

SQL_IS_UINTEGER);

}//if

if(ReturnCode == SQL_SUCCESS){

ReturnCode = SQLAllocHandle(SQL_HANDLE_DBC,

EnvHandle,

&ConnHandle);

}//if

}//ODBC_Class

/----


/

ODBC_Class::~ODBC_Class(){

if(ConnHandle != NULL){

SQLFreeHandle(SQL_HANDLE_DBC, ConnHandle);

}//if

if(EnvHandle != NULL){

SQLFreeHandle(SQL_HANDLE_ENV, EnvHandle);

}//if

}//~ODBC_Class

/----


/

int main(){

SQLRETURN ReturnCode = SQL_SUCCESS;

//ODBC_Class Example;

return(ReturnCode);

}//main

and when I g++ -o odbctest odbctest.cpp

I get:

/tmp/cc4SE4V9.o(.text+0x1f): In function `ODBC_Class::ODBC_Class[not-in-charge]()':

: undefined reference to `SQLAllocHandle'

/tmp/cc4SE4V9.o(.text+0x46): In function `ODBC_Class::ODBC_Class[not-in-charge]()':

: undefined reference to `SQLSetEnvAttr'

/tmp/cc4SE4V9.o(.text+0x70): In function `ODBC_Class::ODBC_Class[not-in-charge]()':

: undefined reference to `SQLAllocHandle'

/tmp/cc4SE4V9.o(.text+0x9f): In function `ODBC_Class::ODBC_Class[in-charge]()':

: undefined reference to `SQLAllocHandle'

/tmp/cc4SE4V9.o(.text+0xc6): In function `ODBC_Class::ODBC_Class[in-charge]()':

: undefined reference to `SQLSetEnvAttr'

/tmp/cc4SE4V9.o(.text+0xf0): In function `ODBC_Class::ODBC_Class[in-charge]()':

: undefined reference to `SQLAllocHandle'

/tmp/cc4SE4V9.o(.text+0x11b): In function `ODBC_Class::~ODBC_Class [not-in-charge]()':

: undefined reference to `SQLFreeHandle'

/tmp/cc4SE4V9.o(.text+0x135): In function `ODBC_Class::~ODBC_Class [not-in-charge]()':

: undefined reference to `SQLFreeHandle'

/tmp/cc4SE4V9.o(.text+0x159): In function `ODBC_Class::~ODBC_Class [in-charge]()':

: undefined reference to `SQLFreeHandle'

/tmp/cc4SE4V9.o(.text+0x173): In function `ODBC_Class::~ODBC_Class [in-charge]()':

: undefined reference to `SQLFreeHandle'

collect2: ld returned 1 exit status

So apparantly this methods are not part of the Core, Level1 and Level2 conformance of the MaxDB ODBC calls.

Im still trying to learn all the in's and out's of ODBC so plz don't flame me, I'm just looking for a little help understanding what I need to do.

Thank you for you precious time, I hope to learn this well enough to help others in the future.

Steve

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

2 Answers

  • Best Answer
    Posted on Nov 17, 2004 at 12:13 PM

    > and when I: g++ -o odbctest odbctest.cpp

    Where do you specify the ODBC-library?

    Something like <ODBC_installdir>/lib/libsqlod.a

    is missing.

    HTH Thomas

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Nov 17, 2004 at 02:51 PM

    I have them hard coded:

    #include "/opt/sapdb/indep_prog/incl/WINDOWS.H"

    #include "/opt/sapdb/indep_prog/incl/sql.h"

    #include "/opt/sapdb/indep_prog/incl/sqlext.h"

    Add a comment
    10|10000 characters needed characters exceeded

    • Hm, you specify the include files in your programs. That's ok and the compiler is happy. But when linking the program to an executable, the linker has to know how to link the ODBC-driver. Therefore you have something like this:

      <compile>

      g++ -c myprog.cpp

      <static linking>

      g++ -o myexe myprog.o <path where the driver is>/libsqlod.a

      HTH Thomas

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.