Jul 25, 2011 5:27 PM
To use NZ with perl
-
Like (0)
Hello there !
i'm tryin to find out what I need to invoke NZ SQL calls from a perl script..
I read in an old post by frankjustme, where he mentions that DBD::ODBC could be used, and has also put in a line require "/nz/kit/share/perl/nz/SQL.pm"; in his script. Is this something i need to install separately to be able to work with NZ in perl ?
I'm no expert, but you can take a look at the attached document.
Essentially you need Netezza ODBC driver, odbc.ini (configured) and DBD::ODBC perl mod.
If you are new to Perl, you may want to take a serious look at Python instead. Perl is a very useful language, but the excessive use of symbols can make it very hard to read. If you look at the overall usage of the two languages, I think you'll find that Python has been steadily displacing Perl over the last 5 or so years.
So i got unixODBC installed, and try to connect, but i get a file not found error..
-sh-3.00$ /usr/local/unixODBC/bin/isql -v NZSQL
[01000][unixODBC][Driver Manager]Can't open lib '/usr/local/nz/lib/libnzodbc.so' : file not found
[ISQL]ERROR: Could not SQLConnect
Although the file exists :
-sh-3.00$ ls -al /usr/local/nz/lib/libnzodbc.so
-rwxr-xr-x 1 10507 12009 1849631 Apr 7 23:20 /usr/local/nz/lib/libnzodbc.so
Any idea what is causing this ?
I use python to execute queryes with a very simple thin wrapper.
Example:
from pynz import *
nz_conn = getDbConn('twinfin_ip', 'database_name', 'user', 'password')
foreignkeys = query(nz_conn, """ SELECT * FROM _V_ODBC_FOREIGNKEYS1""").fetchall()
Suman,
I copied from the perl scripts on the Netezza server....
#!/usr/bin/perl
use Getopt::Long;
require "/nz/kit/share/perl/nz/SQL.pm";
my $verbose;
my $PROCID=$$;
my $PROCNAME=$0;
my $DBNAME=$ENV{NZ_DATABASE};
$result = GetOptions ("verbose" => \$verbose); # flag
if ( $verbose) {
print " Usage: test.pl ";
exit(0);
}
%myopt = ( KITDIR=> '/nz/kit' );
nz::SQL::config(%myopt);
my $sql;
$sql = (" select 'somecol' as col1, 'col2' as col2 ");
my $qresp = nz::SQL::query($DBNAME, $sql);
my $errstr = nz::SQL::error();
if ($errstr) {
print "Sql Error $errstr sql =$sql\n";
exit(99);
}
foreach my $row (@{$qresp->{data}}) {
($col1) = (@$row);
print "New row Data: $col1\n";
if ( $col1 =~ m/somecol/ ) {
print "do something here\n";
}
}
exit(0);
DBD::ODBC is an option but requires other components to install so go with the KISS method.
Frank
You need to give the path of the libnzodbc driver file in the odbc.ini file:
Eg:
odbc.ini
[ODBC Data Sources]
NZSQL = NetezzaSQL
[NZSQL]
Driver=/root/Desktop/libnzodbc.so
Right now it is not able to find the driver file.
Regards,
Saket Kale.

