Queries from Ruby via ODBC

Posted by etjgalvez on 08-Apr-2014 09:54

I am trying to query a Progress OpenEdge Database from a ruby application.

I am unable to get ruby-odbc to compile against the Progress ODBC driver include files.

Perls DBD::ODBC compiled just fine and I can query from perl.

Any suggestions?

I've tried both DataDirect Connect64 drivers and the Progress OpenEdge SQL Client Access drivers.

I get the same error with both libraries.

47501odbc:~ # gem install ruby-odbc -- --with-odbc-dir=/usr/dlc/odbc
Building native extensions with: '--with-odbc-dir=/usr/dlc/odbc'
This could take a while...
/usr/local/rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/rubygems/ext/builder.rb:73: warning: Insecure world writable dir /usr/dlc in PATH, mode 040777
ERROR:  Error installing ruby-odbc:
        ERROR: Failed to build gem native extension.
 
    /usr/local/rvm/rubies/ruby-2.1.1/bin/ruby extconf.rb --with-odbc-dir=/usr/dlc/odbc
checking for version.h... no
checking for sql.h... yes
checking for sqlext.h... yes
checking for SQLTCHAR in sqltypes.h... no
checking for SQLLEN in sqltypes.h... no
checking for SQLULEN in sqltypes.h... no
checking for odbcinst.h... yes
checking for SQLAllocConnect() in -lodbc... yes
checking for SQLConfigDataSource() in -lodbcinst... no
checking for SQLConfigDataSource() in -liodbcinst... no
checking for SQLInstallerError() in odbcinst.h... yes
checking for SQLBIGINT in sqltypes.h with -DHAVE_LONG_LONG... no
creating Makefile
 
make "DESTDIR=" clean
 
make "DESTDIR="
compiling init.c
compiling odbc.c
odbc.c:47: error: redefinition of typedef ‘SQLTCHAR’
/usr/dlc/odbc/include/sqltypes.h:329: error: previous declaration of ‘SQLTCHAR’ was here
odbc.c:2404: error: ‘SQL_DTC_TRANSITION_COST’ undeclared here (not in a function)
odbc.c:2709: error: ‘SQL_DTC_ENLIST_EXPENSIVE’ undeclared here (not in a function)
odbc.c:2709: error: initializer element is not constant
odbc.c:2709: error: (near initialization for ‘get_info_bitmap[201].bits’)
odbc.c:2710: error: ‘SQL_DTC_UNENLIST_EXPENSIVE’ undeclared here (not in a function)
odbc.c:2710: error: initializer element is not constant
odbc.c:2710: error: (near initialization for ‘get_info_bitmap[202].bits’)
odbc.c:7993: error: ‘SQL_CP_OFF’ undeclared here (not in a function)
odbc.c:7993: error: initializer element is not constant
odbc.c:7993: error: (near initialization for ‘o_const[44].value’)
odbc.c:7994: error: ‘SQL_CP_ONE_PER_DRIVER’ undeclared here (not in a function)
odbc.c:7994: error: initializer element is not constant
odbc.c:7994: error: (near initialization for ‘o_const[45].value’)
odbc.c:7995: error: ‘SQL_CP_ONE_PER_HENV’ undeclared here (not in a function)
odbc.c:7995: error: initializer element is not constant
odbc.c:7995: error: (near initialization for ‘o_const[46].value’)
odbc.c:7996: error: ‘SQL_CP_DEFAULT’ undeclared here (not in a function)
odbc.c:7996: error: initializer element is not constant
odbc.c:7996: error: (near initialization for ‘o_const[47].value’)
make: *** [odbc.o] Error 1
 
make failed, exit code 2
 
Gem files will remain installed in /usr/local/rvm/gems/ruby-2.1.1/gems/ruby-odbc-0.99995 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.1.1/extensions/x86_64-linux/2.1.0/ruby-odbc-0.99995/gem_make.out

I'm cross posting this from here on a suggestion from the folks over there: https://community.progress.com/technicalusers/f/19/t/9394.aspx

All Replies

Posted by jhobson on 09-Apr-2014 08:13

The problem is that odbc.c is defining SQLTCHAR, which is already defined in sqltypes.h.

typedef SQLCHAR         SQLTCHAR;

Perhaps this happened because the parser that examines files is not working properly.

/usr/local/rvm/rubies/ruby-2.1.1/bin/ruby extconf.rb --with-odbc-dir=/usr/dlc/odbc

...

checking for SQLTCHAR in sqltypes.h... no

checking for SQLLEN in sqltypes.h... no

checking for SQLULEN in sqltypes.h... no

Does ruby create odbc.c? What's at line 47 of odbc.c?

Posted by etjgalvez on 09-Apr-2014 09:49

The source tarball is here: www.ch-werner.de/.../ruby-odbc-0.99995.tar.gz

Or some slightly modified source in a git repo here: github.com/.../odbc.c

Line 43-49

#ifndef HAVE_TYPE_SQLTCHAR
#ifdef UNICODE
typedef SQLWCHAR SQLTCHAR;
#else
typedef SQLCHAR SQLTCHAR;
#endif
#endif


Posted by jhobson on 10-Apr-2014 07:40

Because Ruby reported that SQLTCHAR was not in sqltypes.h, I suspect that HAVE_TYPE_SQLTCHAR is not defined. I don't know why Ruby didn't find SQLTCHAR in our sqltypes.h file.

Are the resulting files somewhere so I can look at them? Perhaps one of the resulting files can be modified to work-around this problem.

Posted by etjgalvez on 06-May-2014 14:58

Sure.

I really appreciate the help.

dl.dropboxusercontent.com/.../ruby-odbc-0.99995.tgz

The build files are in the 'ext' directory.

My make output is in make.log

Posted by jhobson on 07-May-2014 15:27

I was able to get odbc.c to compile by changing:

DEFS     =

To:

DEFS2    = -DHAVE_TYPE_SQLTCHAR -DSQL_DTC_TRANSITION_COST=1750 -DSQL_DTC_ENLIST_EXPENSIVE=0x00000001L -DSQL_DTC_UNENLIST_EXPENSIVE=0x00000002L

DEFS     = $(DEFS2) -DSQL_CP_OFF=0UL -DSQL_CP_ONE_PER_DRIVER=1UL -DSQL_CP_ONE_PER_HENV=2UL -DSQL_CP_DEFAULT=SQL_CP_OFF

Hopefully this will work for you as well. Good luck.

Posted by jhobson on 07-May-2014 15:28

Oops...I forgot to mention I made this change in the ext/Makefile.

Posted by etjgalvez on 07-May-2014 16:13

Thank you!  That appears to work great!

Posted by jhobson on 08-May-2014 08:08

You're welcome. I'm glad that fixed the problem.

This thread is closed