in reply to Re: Using DBI for the first time...
in thread Using Oraperl for the first time... (was: Using DBI for the first time...)

Just to illustrate I have rewritten your script to use DBI.
Note that I don't have access to Oracle so I haven't tested it.

The rewrite is quite simple:

#!/usr/bin/perl -w use strict; use DBI; use Env; my $DB = "DBNAME"; my $UN = "USERNAME"; my $PW = "PASSWORD"; my ($dbh,$sth,$clli,$c); $dbh = DBI->connect("dbi:Oravel:$DB",$UN,$PW, {AutoCommit => 0, RaiseError => 1) or die("Oracle login FAILED, $DBI::errstr"); $sth = $dbh->prepare("select distinct(clli) from gvc_traffic30"); $sth->execute; $sth->bind_col(1, \$clli); while ($sth->fetchrow_arrayref ) { $c++; if ($clli =~ /\W/ ) { print "Found bad character in line $c."; } else { print "This clli appears to be OK."; } print " : $clli\n"; }
Note that I don't do any error checking. This is because I set $dbh->{RaiseError} in the connect call, so the DBI will do all neccessary errorchecking for me!

Check the DBI documentation to see what this does.

Happy DBI'ing

Replies are listed 'Best First'.
Re: Re: Re: Using DBI for the first time...
by snafu (Chaplain) on Aug 21, 2001 at 18:01 UTC
    Aside from a couple of typos your code worked great. I appreciate it. Now I shall sit back and study it.

    NOTE: Typos were on lines 12 & 13.

    Im not sure if Oravel is what you wanted since I have not checked the DBI docs yet but I changed it to Oracle (knowing that that is a proper driver for DBI) and it worked
    Original
    $dbh = DBI->connect("dbi:Oravel:$DB",$UN,$PW,
    Changed
    $dbh = DBI->connect("dbi:Oracle:$DB",$UN,$PW,

    This next one was simply a case of a missing bracket.
    Original
    (...{AutoCommit => 0, RaiseError => 1) or
    Changed
    (...{AutoCommit => 0, RaiseError => 1}) or

    This is really great! Thanks for the example work.

    ----------
    - Jim