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

Just a quick note to everyone. I have been chatting with some folks in the PM and it looks like there maybe some information I left out (purposefully) that maybe needed. Therefore, here it is...the whole script:

#!/usr/bin/perl -w use strict; use DBI; use Oraperl; use Env; my $DB = "DBNAME"; my $UN = "USERNAME"; my $PW = "PASSWORD"; my ($dbh,$sql,$c,$cursor,@MYARRAY,$numElements); $dbh = &ora_login($DB,$UN,$PW) or die("Oracle login FAILED."); $sql = "select distinct(clli) from gvc_traffic30"; $cursor = &ora_open($dbh,$sql) or die("Failed query (bad query?). $!\n +"); @MYARRAY= &ora_fetch($cursor) or die("Failed to get return from query. + $!\n"); foreach my $clli ( @MYARRAY ) { chomp($clli); sleep(5); $c++; if ( /\W/ ) { print "Found bad character in line $c."; } else { print "This clli appears to be OK."; } print " : $clli\n"; }

Perhaps the Oraperl.pm is not widely used?

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

Replies are listed 'Best First'.
Re: Re: Using DBI for the first time...
by htoug (Deacon) on Aug 21, 2001 at 10:50 UTC
    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

      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