Tuesday, June 17, 2008

Compiling DBD::ODBC on Vista and XP

Background
On my machine(s), I need to use the Unicode-enabled version (specifically, the UTF-16 enabled version) of DBD::ODBC that is distributed on CPAN. However, the default packages distributed and installed by ActiveState Perl is not unicode enabled (tested up to v1.15).

Previously, I have successfully installed my own copy after Googling the web intensively for a day or two and compiling / testing / tweaking the information found on the articles online.

I have decided to post the steps here to "keep a copy" in case I need it again and I can't find it on my harddisk. I was lucky I made notes the previous time, otherwise I would have spent another day or two going through the same stuff again.


Systems / Setups tested against
  1. Windows Vista Business Edition x86, ActiveState Perl v5.8.8
  2. Windows 2003 Server x64, ActiveState Perl v5.8.8 (v5.10 is too buggy for me, esp the x64 edition)

Prerequisites
  1. Make sure you have VS.Net 2005/2008 installed and working. If not, I guess the Windows SDK with the VC++ compiler and headers is a viable alternative (not 100% tested on using Win SDK only).
  2. Make sure your SQL Server 2005 (Express or otherwise) is installed, working, and is patched (ODBC v1.16 fails with unpatched version of MSSQL 2005 due to the "old" SQL client driver provided).
  3. Create an ODBC connection with proper user credentials and permissions on the database for testing (as part of the ODBC installation procedure).
  4. Make sure the PERL modules (eg, DBI) are installed and updated using the PPM (perl package manager).

Procedure

  1. Download and unpack DBD::ODBC from http://search.cpan.org/~mjevans/DBD-ODBC-1.16/
  2. Start the Visual Studio 200X command prompt, navigate to the directory where the module sources are unpacked in Step 1.
  3. Set the ODBC connection parameters with valid information:
    1. set DBI_DSN=dbi:ODBC:test_db
    2. set DBI_USER=user
    3. set DBI_PASS=pass
  4. Run "perl Makefile.PL"
  5. Run "nmake"
  6. Run "nmake manifest"
  7. Run the following command as a single line:
    mt -manifest blib\arch\auto\DBD\ODBC\ODBC.dll.manifest -outputresource:blib\arch\auto\DBD\ODBC\ODBC.dll;#2
  8. Run "nmake test"*, check for errors or problems at this step.
  9. If nothing goes wrong, run "nmake install"**

* Note: The outpuyt from my "nmake test" step looks like this:
D:\tmp\DBD-ODBC-1.16\DBD-ODBC-1.16>nmake test

Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.

D:\Perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harness(0, 'bl
ib\lib', 'blib\arch')" t/*.t
t/01base................ok
t/02simple..............ok 1/62#
# Using DBMS_NAME 'Microsoft SQL Server'
# Using DBMS_VER '09.00.3042'
# Using DRIVER_NAME 'SQLNCLI.DLL'
# Using DRIVER_VER '09.00.3042'
t/02simple..............ok
t/03dbatt...............ok 3/26#
# N.B. Some drivers (postgres/cache) may return ODBC 2.0 column names for the SQ
LTables result-set e.g. TABLE_QUALIFIER instead of TABLE_CAT
t/03dbatt...............ok
t/05meth................ok
t/07bind................ok
t/08bind2...............ok
t/09multi...............ok
t/10handler.............ok
t/20SqlServer...........ok
t/30Oracle..............ok
2/4 skipped: Oracle tests not supported using Microsoft SQL Server
t/40UnicodeRoundTrip....ok
t/41Unicode.............ok
All tests successful, 2 subtests skipped.
Files=12, Tests=299, 24 wallclock secs ( 0.00 cusr + 0.00 csys = 0.00 CPU)




** Note: The output from my "nmake install" step looks like this:

D:\tmp\DBD-ODBC-1.16\DBD-ODBC-1.16>nmake install

Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
Copyright (C) Microsoft Corporation. All rights reserved.

Installing D:\Perl\site\lib\auto\DBD\ODBC\ODBC.bs
Installing D:\Perl\site\lib\auto\DBD\ODBC\ODBC.dll
Installing D:\Perl\site\lib\auto\DBD\ODBC\ODBC.dll.manifest
Installing D:\Perl\site\lib\auto\DBD\ODBC\ODBC.exp
Installing D:\Perl\site\lib\auto\DBD\ODBC\ODBC.lib
Installing D:\Perl\site\lib\auto\DBD\ODBC\ODBC.pdb
Installing D:\Perl\html\site\lib\DBD\ODBC.html
Installing D:\Perl\html\site\lib\DBD\ODBC\Changes.html
Installing D:\Perl\html\site\lib\DBD\ODBC\FAQ.html
Files found in blib\arch: installing files in blib\lib into architecture dependent library tree
Installing D:\Perl\site\lib\DBD\ODBC.pm
Installing D:\Perl\site\lib\DBD\ODBC\Changes.pm
Installing D:\Perl\site\lib\DBD\ODBC\FAQ.pm
Appending installation info to D:\Perl\lib/perllocal.pod