Home arrow SQL Server arrow Page 4 - Executing SQL Server Stored Procedure from Perl
SQL SERVER

Executing SQL Server Stored Procedure from Perl


This article illustrates how to setup a development environment using Perl and SQL Server on the following platforms: Microsoft Windows, Red Hat Linux, and Sun Solaris. Step by step, you can learn, and may choose, the best way that fits into your own requirements.

Author Info:
By: Jack Zhang
Rating: 4 stars4 stars4 stars4 stars4 stars / 99
June 01, 2004
TABLE OF CONTENTS:
  1. · Executing SQL Server Stored Procedure from Perl
  2. · History Lesson: SQL Server(s)
  3. · TDS protocol
  4. · Setup Perl and SQL Server on Windows
  5. · Create A Stored Procedure on Sybase Adaptive Server

print this article
SEARCH DEVARTICLES

Executing SQL Server Stored Procedure from Perl - Setup Perl and SQL Server on Windows
(Page 4 of 5 )

Perl’s running environment is integrated within the *nix system. For Microsoft Windows operating systems, however, you need to download and install it by yourself.

There are a few Windows-based distributions of Perl. ActivePerl from ActiveState.com may be the most popular one. You can download it from:

http://www.activestate.com/Products/ActivePerl/

Choose the latest version of ActivePerl (5.8) (most recent Unix/Linux also uses Perl 5.8).

Installing ActivePerl on Windows is fairly easy. After installation you can use the following command to verify that perl is working:

From command prompt, input:

Perl –v

It will show you something like:

This is perl,  v5.8.0 built for MSWin32-x86-multi-thread
Copyright 1987-2002, Larry Wall

Download Sybase Adaptive Server 12.5 Developer Edition from the Sybase website for free: www.sybase.com/ase_125devel

Installing and configuring Sybase Adaptive Server is also as easy as MS SQL Server.

If you want to use MS SQL Server as a database, install MS SQL Server 7.0 with service pack 2.

Perl uses DBI/DBD architecture to access databases (DBI means Database Interface, DBD means Database Driver). With a specific DBD driver installed, Perl can use the same DBI API to support different database systems.

The DBI module is already installed with the ActivePerl distribution itself.  In order to support SQL Server, we need to download the SQL Server DBD driver from cpan.org: www.cpan.org, search for the DBD-Sybase module, and download the latest version 1.01 source code: DBD-Sybase-1.01.tar.gz

Note: there are a few other DBD Drivers that support both Sybase and Microsoft SQL Server on Windows, such as DBD::ADO; however, they can only be used on a Windows platform.

In order to compile and install the DBD::Sybase source code, we need a C compiler installed on Windows (I use Microsoft Visual C++ 6.0), and make sure nmake.exe is available in the PATH.

Use a decompression utility (ie: Winzip) to extract DBD-Sybase-1.0.1.tar.gz to any available drive such as C:. You should now have the folder c:DBD-Sybase-1.01 that holds all the source code.

Change directory to the above folder, and issue the following command in the command prompt window:

Perl Makefile.PL

You may receive a warning message, such as missing the following library: libtcl.lib, libcomn.lib and libintl.lib.

Because we are using the Sybase CT-Library, libcs.lib and libct.lib are mandatory; others are optional, and we can ignore this warning. Sybase removes these static libraries from its version 12.5 of the Adaptive Server package. The run time libraries still do exist (ie: libtcl.dll, libcomn.dll, linintl.dll)  See the following screenshot:

Executing SQL Server Srored Procedure from Perl

If you receive an error message other than the one above, please check the following environment variable: SYBASE and SYBASE_OCS
%SYBASE%
 should equal the directory root where Sybase Adaptive Server is installed (ie: C:sybase) and %SYBASE_OCS% should equal OCS-12_5 for Sybase Adaptive Server 12.5

Issue the following command to compile the source code:

Nmake

Then install the package by issuing this command:

Nmake install

Using the following code, we can list all the DBD drivers we’ve installed with Perl:

#!/usr/bin/perl

use strict;
use DBI;
my @drivers=DBI->available_drivers();
print join("n",@drivers);
print "n";

Copy and paste the above code in notepad, and save the file as dbi_drivers.pl.

Issue the following command in the command prompt window:

perl dbi_drivers.pl

See following screenshot:

SQL Server & Perl

I recommend you download PerlIDE from open-perl-ide.sourceforge.net, it is a free and open source tool. You can download the precompiled application and install it easily on your Windows operating system. With PerlIDE, you can debug and track variables in your Perl applications.


blog comments powered by Disqus
SQL SERVER ARTICLES

- Executing SQL Server Stored Procedure from P...
- How to Search for Date and Time Values Using...
- Replication: SQL Server 2000 - Part 2
- Replication: SQL Server 2000 - Part 1
- SQL Sever: Storing Code in Binary or Text Fi...
- Execute SQL on Multiple Tables/Columns - New...
- How to Connect to a SQL Server from Visual F...
- SQL Server Hardware Tuning and Performance M...
- Primary Key on Multiple Tables – New RDBMS C...
- Migrating from Sybase to SQL Server
- What's Best for DBAs? GUI or T-SQL Comma...
- How to Perform a SQL Server Performance Audit
- An Introduction To The Bulk Copy Utility
- SQL Server Stored Procedures 101
- Building Your First SQL Server 2000 Database

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials