Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[HOWTO] Access Sybase using perl
View unanswered posts
View posts from last 24 hours

Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks
View previous topic :: View next topic  
Author Message

Joined: 02 Nov 2003
Posts: 512
Location: Utah County, UT

PostPosted: Sat Aug 27, 2005 3:50 am    Post subject: [HOWTO] Access Sybase using perl Reply with quote

HOWTO: Access Sybase using perl
The following will show you how to access a Sybase DB with perl using freeTDS(or Sybase), DBI, and DBD::Sybase.
What prompted this was days of searching for this stuff. I couldn't find all the parts in one place for
someone needing to connect to the DB on ports other than the default, and wanted to save someone else
days of googling.

prerequisites: perl

Install freeTDS
If you don't have the Sybase libraries then you'll need freeTDS. If you have the Sybase libraries installed you need to skip this step.
Portage method
If your DB only runs on the default port then you just need to emerge the package:

sudo emerge freetds

Alternate method
It's important to use this method to get the dev version(daily snapshot) if you need to access your DB on non-default ports.

tar -zxf freetds-current.tgz
cd freetds-*
./configure --with-tdsver=7.0
make -j2
sudo make install

notes: 8.0 should also work in the configure, but I haven't tried it.
Adjust make to -j3 if you have a dual-(processor|core) rig.
You can also use your own CFLAGS, but I'd advise against if you're
connecting to a live DB since it will net little to no performance gain.

Install DBI

sudo emerge dev-perl/DBI

Set environment variable
This is an important step. The DBD::Sybase perl modules need to know where the libraries are to compile.
If using the freeTDS libraries:

export SYBASE="/usr/local/"

If using Sybase libraries:

export SYBASE="/usr/local/sybase/"

Install DBD::Sybase
Since there is no ebuild for the Sybase module you'll have to install it by hand or use CPAN.
If you've never used CPAN you'll have to go through the setup process which is very simple.
When CPAN asks about the DB setup while installing DBD::Sybase you can input your DB info,
or just hit enter for the default. Letting the tests fail won't hurt since we're force installing.

sudo perl -MCPAN -e shell
force install DBD::Sybase

Finishing up
You should now have a fully working Sybase for perl using DBI, and DBD::Sybase.
You'll also need to set the SYBASE environment variable in /etc/profile, or do like I do and start all your Sybase scripts like this:

  $ENV{'SYBASE'} = '/usr/local/';
  use DBI;
  use DBD::Sybase;

The only problem I've seen to date using the snapshot tds is memory errors when issuing the disconnect.
The workaround I use is to set the variables I use to access the db to "" before I disconnect.
You can also use CTlibs, but that is overkill for the simple stuff I usually do.
This has worked successfully on every machine I've tried it on including:
Athlon-XP Running Gentoo
G3 Running Panther
G4 Running Gentoo
G4 Running Tiger
G5 Running Tiger
Ultra-5 Running Gentoo
Gentoo systems.
X2 4200+@2.6 - Athy
X2 3600+ - Myth
UltraSparc5 440 - sparcy
Back to top
View user's profile Send private message

Joined: 26 Apr 2007
Posts: 10
Location: Lansing, MI, US

PostPosted: Tue Aug 28, 2007 7:48 pm    Post subject: Doesn't work w/ current ebuild Reply with quote

I'm trying to compile DBD-Sybase-1.08 after emerging dev-db/freetds-0.62.3, and I get the following error during compilation of dbdimp.c:


dbdimp.c: In function `clientmsg_cb':
dbdimp.c:328: error: `CS_LOGIN_STATUS' undeclared (first use in this function)
dbdimp.c:328: error: (Each undeclared identifier is reported only once
dbdimp.c:328: error: for each function it appears in.)
make: *** [dbdimp.o] Error 1

Any idea what's going wrong? I set SYBASE=/usr because the freetds stuff got installed in /usr/lib and /usr/include .
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Documentation, Tips & Tricks All times are GMT
Page 1 of 1

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum