FreeTDS on FreeBSD 7
Connect to a Microsoft SQL Server via Perl from UNIX

Prerequisites:

FreeBSD (Base + Autoconf, Automake, Bash and GCC)
Perl Modules (DBI)

Overview:
 Step #1 - Download, Unzip, Untar, Configure, Compile and Install FreeTDS
 Step #2 - Download, Unzip, Untar, Configure, Compile and Install DBD::Sybase
 Step #3 - unixODBC (Not required for FreeTDS, but logical to install it now)

Step #1

FreeTDS - Free "Tabular Data Stream"

Home:

 http://www.freetds.org

# Change to your desired "source" storage directory
cd /usr/src

# Download (Notes: Users behind a Proxy Server should read this and users without Internet but have a CDRom read this.)

fetch http://ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
 
# Unzip and Untar

tar xvf freetds-stable.tgz


# Configure
cd freetds-?.??/
./configure --enable-msdblib --with-tdsver=8.0

#
 Compile & Install
make install clean

# PHP tests for a FreeTDS installation by looking for files that FreeTDS no longer installs
touch /usr/local/include/tds.h
touch /usr/local/lib/libtds.a


Step #2

DBD::Sybase

Home:

 http://www.peppler.org/freeware/dbd-sybase.html

# Change to your desired "source" storage directory
cd /usr/src


# Download

fetch http://www.peppler.org/downloads/DBD-Sybase-1.08.tar.gz

# Ungzip and Untar
tar xvf DBD-Sybase-?.??.tar.gz


# Change to the source directory
cd DBD-Sybase-?.??

# Set a few shell variables temporarily
SYBASE=/usr/local/
export SYBASE
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$SYBASE/lib
export LD_LIBRARY_PATH

#
 Add the needed environment variables (so it they survive reboots) to /etc/rc.local
vi /etc/rc.local

 

 

# Fix dbdimp.c before compiling or you will get an error:
> dbdimp.c:800: error: 'BLK_VERSION_150' undeclared (first use in this function)
> dbdimp.c:800: error: (Each undeclared identifier is reported only once
> dbdimp.c:800: error: for each function it appears in.)

# This is really a FreeTDS bug - they define the CS_VERSION_1xx symbols, but not the corresponding BLK_VERSION_xxx symbols.

Edit dbdimp.c and add

vi /usr/src/DBD-Sybase-1.08/dbdimp.c
#define BLK_VERSION_150 BLK_VERSION_100
#define BLK_VERSION_125 BLK_VERSION_100
#define BLK_VERSION_120 BLK_VERSION_100

somewhere near the top (but after the #include section).

Michael
Michael Peppler - Peppler Consulting SaRL
mpeppler@peppler.org -
http://www.peppler.org

 

 

# Create the Makefile - press "Enter" on any questions to accept default settings
perl Makefile.PL

#
 Compile
make
# make test

#
 Install
make install clean

 

# Optional test script - safe to ignore / skip this
# Test a connection to a Microsoft SQL Server

# (You should already have a database called "test" a table "authors" a field "Name")

# Create a scripts directory if one does not already exist
cd /opt
mkdir scripts
cd /opt/scripts

# Create a script for testing
vi /opt/scripts/my.pl

# Make the script executable
chmod +x /opt/scripts/my.pl

# Run the script
/opt/scripts/my.pl

 


#
 Note: Edit freetds.conf to suit your needs
vi /usr/local/etc/freetds.conf


Step #3

unixODBC

Home:

http://www.unixodbc.org

# Install unixODBC from ports
cd /usr/ports/databases/unixODBC/
make install clean