Just another perl hacker somewhere near Disneyland
I have this homenode [perlmonks.org] of little consequence on Perl Monks [perlmonks.org] that you probably have no interest in whatsoever.
I also have some modules [cpan.org] on CPAN [cpan.org] some of which are marginally [cpan.org] more [cpan.org] useful [cpan.org] than others.
my $dsn = <<EOT;
DRIVER={INFORMIX 3.32 32 BIT}
DATABASE=/path/to/database
HOST=hostname
SRVR=Informix
SERV=sqlexec
PR O=sesoctcp
OPT=
EOT
chomp ( $dsn = join(";", split "\n", $dsn));
my $dbh = DBI->connect("dbi:ODBC:$dsn", $username, $passwd, {
PrintError => 0,
RaiseError => 1,
ChopBlanks => 1,
AutoCommit => 1,
});
Of course, there is a certain redundancy in having to create a DSN in order to not use it (but it makes for a good template to substitute other database names into)
my @sql = ( {
STMT => qq{
select *
from table_name
},
ARGS => [],
LIMIT => 0,
},
);
chomp ( $dsn = join(";", split "\n", $dsn));
eval {
my $dbh = DBI->connect("dbi:ODBC:$dsn", $username, $passwd, {
PrintError => 0,
RaiseError => 1,
ChopBlanks => 1,
AutoCommit => 1,
});
open(FH, ">sqltmp.out") or die "Acck: $!";
for my $sql (@sql) {
my $sth = $dbh->prepare($sql->{STMT});
$sth->execute(@{$sql->{ARGS}});
my @names = @{$sth->{NAME}};
my $cnt;
while (my $row = $sth->fetchrow_hashref) {
no warnings 'uninitialized';
print FH "[$_][$row->{$_}]\n" for @names;
print FH "----------\n";
last if $sql->{LIMIT} and ++$cnt >= $sql->{LIMIT};
}
}
close FH;
$dbh->disconnect;
};
if ($@) {
print "Error: $@";
<>;
}
DSN-less tip of the day 0 Comments More | Login | Reply /