#!/usr/bin/perl -w
use strict;

use DBI;

# example taken from http://www.easysoft.com/developer/languages/perl/sql_server_unix_tutorial.html
# Replace datasource_name with the name of your data source.
# Replace database_username and database_password
# with the SQL Server database username and password.

my $data_source = q/dbi:ODBC:bqt/;
my $user = q/user/;
my $password = q/user/;

my $dbh = DBI->connect($data_source, $user, $password)
    or die "Can't connect to $data_source: $DBI::errstr";

my $sth = $dbh->prepare ("select * from bqt_db2.hugea where intkey < ?") or die $dbh->errstr;

print "Columns# ".$sth->{NUM_OF_FIELDS}."\n";

print "Should see the column names here\n";
my $i;
for ($i=0;$i<$sth->{NUM_OF_FIELDS};$i++){
   print "$sth->{NAME}->[$i] ($sth->{TYPE}->[$i],$sth->{PRECISION}->[$i],$sth->{SCALE}->[$i],$sth->{NULLABLE}->[$i]) \t";
}
print "executing the query\n";

my $start = time();

$sth->bind_param(1, "50");
$sth->execute()  or die $sth->errstr;

print "# of rows:".$sth->rows."\n";

# Fetch and display the result set value.
while ( my @row = $sth->fetchrow_array ) {
   foreach (@row){
       print defined $_ ? $_."," : "null," ;
   }
   print "\n";
}

print "it took:".(time()-$start)."\n";

$sth->finish();
$dbh->disconnect;

