Quispiam

power computing

First install FreetDS from source, do not install from MacPorts, MacPorts do not seem to contain the regular libraries, just the ODBC ones.

cd ~
mkdir src
cd src
wget ftp://mirrors.ibiblio.org/freetds/stable/freetds-stable.tgz
tar xvzf freetds-stable.tgz
cd freetds-0.91
./configure --prefix=/opt/local/freetds --with-tdsver=8.0
make; make install

Now edit the freetds.conf file

cd /opt/local/freetds/etc
sudo vi freetds.conf

And add a server at the bottom

[SERVER]
    host = some.host
    port = 1433
    tds version = 8.0

I was able to connect to SQLServer 2005 with these settings.

Now, test the connection works

cd /opt/local/freetds/bin
./tsql -S SERVER -U some_user

Type the password when prompted

use DATABASE;
go
select * from SOMETABLE;
go

You should get data back at this point.

Next install DBD::Sybase.  This is slightly harder and normally I use the cpan shell until it bombs out.

sudo cpan DBD::Sybase

cpan will download and try and build DBD::Sybase, but it should fail, so exit cpan and

cd ~/.cpan/build
cd DBD-Sybase-1.12
sudo su
export SYBASE=/opt/local/freetds
perl Makefile.pl

Answer what ever you like for the tests.

make
make install

Then run a basic script that uses DBD::Sybase to connect to SERVER and pulls out some data, similar to what we did previously with tds

#!/usr/bin/env perl
use common::sense;
use DBI;
use DBD::Sybase;

my $dbh = DBI->connect(
    'DBI:Sybase:server=SERVER;database=ParticipantDatabase',
    'some_user',
    'some_password'
) || die "Unable to connect to server $DBI::errstr";
my $sth = $dbh->prepare (
    "SELECT TOP 10 * FROM SOME_TABLE"
) || die "Prepare failed $DBI::errstr";
$sth->execute( ) || die "Select failed: $DBI::errstr";
print "Displaying " . $sth->rows . "n";
print '-' x 72 . "n";

while(my $row = $sth->fetchrow_hashref ) {
    while (my ($field, $value) = each(%$row)){
        print "$field : t $value n";
    }
}

Thanks go to the following posts

http://www.perlmonks.org/?node_id=392385
http://blog.qaevangelist.com/?p=140
http://rasterweb.net/raster/code/freetdsnotes.html

Matt

Share