rwitmer has asked for the wisdom of the Perl Monks concerning the following question:

Okay, so here's the deal. I am using a Mac. This is not my fault. My work is making me. It runs OSX which I am informed is sort of like BSD. I want to connect to a MS SQL database and run a query. That's ALL, just one tiny little query. This server belongs to the client though, so can't just ssh there and run a query. And it's MSFT, so I can't use a client program and run a query. But apparently there is a way to do this with Perl.

To do this you need to download and install this thing called FreeTDS. I did this. It worked. I tested it and made a query to the DB. That worked. FreeTDS is supposed to work from within Perl though... That didn't work. You have to install either DBD::ODBC or DBD::Sybase, Sybase preferably. Sybase won't install on my machine. ODBC installs successfully! But it wants some sort of ODBC driver, which I don't understand because the driver must be there if FreeTDS is capable of running a query. So here are my two questions:

QUESTION 1

I am trying to install DBD::Sybase. I got FreeTDS running and can do queries with it from the command line, so I know that's working fine. But now I want to do queries from Perl. So I am trying to install the DBD::Sybase module. perl Makefile.pl works fine, but running make doesn't work. I am running OSX and I am having basically the same problem the guys are here:

http://www.cpanforum.com/posts/9843 http://www.cpanforum.com/posts/9851

I get this output:

rwitmers-macbook-pro-15:DBD-Sybase-1.09 rwitmer$ make cc -c -I/opt/freetds/include -DSYB_LP64 -DNO_BLK=1 -I/System/Library/Perl/Extras/5.8.8/darwin-thread-multi-2level/auto/DB +I -arch i386 -arch ppc -g -pipe -fno-common -DPERL_DARWIN -no-cpp-precom +p -fno-strict-aliasing -Wdeclaration-after-statement -I/usr/local/includ +e -O3 -DVERSION=\"1.09\" -DXS_VERSION=\"1.09\" "-I/System/Library/Perl/5.8.8/darwin-thread-multi-2level/CORE" Sybas +e.c cc -c -I/opt/freetds/include -DSYB_LP64 -DNO_BLK=1 -I/System/Library/Perl/Extras/5.8.8/darwin-thread-multi-2level/auto/DB +I -arch i386 -arch ppc -g -pipe -fno-common -DPERL_DARWIN -no-cpp-precom +p -fno-strict-aliasing -Wdeclaration-after-statement -I/usr/local/includ +e -O3 -DVERSION=\"1.09\" -DXS_VERSION=\"1.09\" "-I/System/Library/Perl/5.8.8/darwin-thread-multi-2level/CORE" dbdim +p.c dbdimp.c: In function ‘syb_init’: dbdimp.c:777: error: ‘BLK_VERSION_150’ undeclared (first use in this function) dbdimp.c:777: error: (Each undeclared identifier is reported only once dbdimp.c:777: error: for each function it appears in.) dbdimp.c:781: error: ‘BLK_VERSION_125’ undeclared (first use in this f +unction) dbdimp.c:785: error: ‘BLK_VERSION_120’ undeclared (first use in this f +unction) dbdimp.c: In function ‘syb_init’: dbdimp.c:777: error: ‘BLK_VERSION_150’ undeclared (first use in this f +unction) dbdimp.c:777: error: (Each undeclared identifier is reported only once dbdimp.c:777: error: for each function it appears in.) dbdimp.c:781: error: ‘BLK_VERSION_125’ undeclared (first use in this f +unction) dbdimp.c:785: error: ‘BLK_VERSION_120’ undeclared (first use in this f +unction) lipo: can't open input file: /var/folders/5j/5jvD0zy7GiaxVDHIL7Uk-++++TI/-Tmp-//ccad658l.out (No su +ch file or directory) make: *** [dbdimp.o] Error 1

QUESTION 2

So that's option #1, fix the Sybase module and get it to install. Option #2 is to use DBD::ODBC. I got that to install and perl seems to recognize that the module exists. Only, when I try to connect to the database it tell me that it needs a driver, like this:

rwitmers-macbook-pro-15:Documents rwitmer$ perl testFreetds.pl Unable for connect to server [iODBC][Driver Manager]Data source name n +ot found and no default driver specified. Driver could not be loaded (SQL-IM002) at testFreetds.pl line 20.

What kind of driver is it looking for and where do I find it?

The readme says to define these:

DBI_DSN The dbi data source, e.g. 'dbi:ODBC:YOUR_DSN_HERE' DBI_USER The username to use to connect to the database DBI_PASS The username to use to connect to the database ODBCHOME (Unix only) The dir your driver manager is installed in + or specify this via -o argument to Makefile.PL

I don't have ODBCHOME defined because I have no idea what a driver manager is, or whether I have it.

What is your advice on solving either of these two problems?

Thanks!
Rebecca

Replies are listed 'Best First'.
Re: Problems with DBD::ODBC and DBD::Sybase
by Narveson (Chaplain) on May 27, 2009 at 22:14 UTC
    What kind of driver is it looking for?

    It's looking for an ODBC driver. Basically ODBC was an attempt to do what DBI does, namely talk to various databases in a uniform way. The success of this attempt may be judged by the popularity of DBD::ODBC, which uses DBI to talk to ODBC which is then supposed to use an ODBC driver to talk to your database.

Re: Problems with DBD::ODBC and DBD::Sybase
by derby (Abbot) on May 27, 2009 at 23:32 UTC

    Do a google search for BLK_VERSION_150 dbdimp.c ... there's an issue with FreeTDS not defining the symbols dbdimp.c wants. Also, if you just want a client, I would recommend installing sqsh ... it's an isql replacement (and much better IMHO).

    -derby
      This worked somewhat! I did what it said here:

      http://www.mail-archive.com/dbi-users@perl.org/msg31071.html

      and it worked! Now Sybase installs. Unfortunately, when I run FreeTDS's test script

      http://www.freetds.org/userguide/perl.htm#DBD.SYBASE

      it dies. It's not much more specific than that though. I guess it has to do with the driver stuff the next poster said?

        Do you have your freetds.conf file configured correctly?

        -derby
Re: Problems with DBD::ODBC and DBD::Sybase
by mje (Curate) on May 28, 2009 at 12:37 UTC

    I don't use DBD::Sybase so cannot comment on #1 but I do know about DBD::ODBC and a little about FreeTDS. For a background on ODBC in unix see http://www.easysoft.com/developer/interfaces/odbc/linux.html - I know it says Linux/UNIX but most of it applies to OSX too.

    OSX comes with a modified iODBC driver manager and from the looks of things you are already using that - or DBD::ODBC would not have built. You need to add your FreeTDS ODBC driver with the ODBCAdmin GUI program then create a datasource. I don't own a MAC so I'm not sure if FreeTDS includes the libraries to add a driver with ODBCAdmin but if it does not then you can hand edit the odbcinst.ini file. Use iodbc-config --odbcinstini to find where the odbcinst.ini file is and and add a driver something like this:

    [ODBC Drivers] FreeTDS = Installed [FreeTDS] Driver = /path/to/libtdsodbc.so

    Then fire up ODBCAdmin and create your data source. You'll need to add attributes to say where your sql server is, what protocol to use, username, password etc - best to consult the FreeTDS home page for that. Here again, you can just run iodbc-config --odbcini and it will tell you which files to use to define your user and system data sources in. I've included a very simply data source definition I used some time ago with FreeTDS and MS SQL Server below.

    [freetds] Driver = FreeTDS Description = connection to RS machine Trace = No Server = 192.168.250.71 #Database = pubs TDS_Version = 7.0

    ODBC is pretty much the same across unix-like platforms but typically OSX has it differences e.g., you get the iODBC driver manager by default whereas most of the rest of the unix world use the unixODBC driver manager. Also, it may be possible FreeTDS cannot get its settings from the odbc.ini file directly - it needs special parts of the ODBC driver manager (SQLPrivateProfileString etc to do that). If that is the case, you can put the settings in your freetds.conf file but the freetds page is the best place to start researching that. I don't own or have a MAC to hand right now but I got DBD::ODBC working on OSX in the past.

      Okay, I read the background info you posted. Thanks, that made it a lot clearer. Then I ran the command you suggested to find odbcinst.ini. It worked, see:

      rebecca-witmers-macbook-pro-15:jtds-1.2.2-dist rwitmer$ iodbc-config --odbcinstini
      /Library/ODBC/odbcinst.ini

      The trouble is, when I go there, nothing is there. Really:

      But that's in the directory for OSX 10.4. My machine has 10.5. What's the deal here? Do I have this driver manager thing or what? I am confused.

        I see you have also posted to the FreeTDS list - that is a good idea. The fact that you can run iodbc-config shows you do have the iODBC driver manager installed. The --odbcinstini argument is telling you which file to add your drivers to. If the file does not exist, create it. Similarly with the odbc.ini file.

        iodbctest is the command line app you can use to test your dsns are working. iodbctestw is a unicode aware version of the same app.

        You need to go ahead and create your odbcinst.ini and odbc.ini files based on my previous comments and the help on the freetds web site detailing what to put in them. But bare in mind the freetds site instructions are probably for the unixODBC driver manager and iODBC (the driver manager you are using) is slightly different in the way you name driver and data sources - see my previous reply.

        I'm no expert OSX person but if you get no joy from the freetds list I might be able to help further.