At 11:54 PM +0200 5/14/01, Nico van Leeuwen wrote:
>Good evening,
>
>I have been struggeling with oracle selects all day am getting some strange
>results.
>
>I can't seem to find out what is wrong with the following script:
>
>#!/usr/bin/perl -w
>
>use strict;
>use DBI;
>
># Connect to the database
>
>my $dbh = DBI->connect( 'dbi:Oracle:mercury.systime',
>                        'systime',
>                        'systime',
>                        {
>                          RaiseError => 1,
>                          AutoCommit => 0
>                        }
>                      ) || die "Database connection not made: $DBI::errstr";
>
>       print "connected\n";
>
># Insert a new row
>
>       $dbh->do("INSERT INTO t_user ( name, adresse, plz, land, ort, vorname )
>VALUES( 'van Leeuwen' , 'Emmi-Welter Str 22', 52064, '0049', 'Aachen',
>'Nico' )");

You must do a commit here.

        $dbh->commit;


>       # Get the row back
>
>       my $sth = $dbh->prepare("SELECT name, adresse, plz, ort, land, vorname
>FROM t_user");
>
>       $sth->execute();
>
>       my( $name, $adresse, $plz, $ort, $land, $vorname );
>
>       $sth->bind_columns( undef, \$name, \$adresse, \$plz, \$ort, \$land,
>\$vorname );
>
>       while( $sth->fetch() ) {
>
>               print "$name, $adresse, $plz, $ort, $land, $vorname\n";
>               print "-------------------------------\n";
>
>       }
>
>
>$sth->finish();
>$dbh->disconnect();
>
>exit;
>

I generally leave autocommit on so that I don't have to remember to 
call commit.  Otherwise, you could end up with abended records when 
you die without disconnect on the select statement.  For instance, 
the select statement would most likely hang do to the uncommitted 
insert, which might cause someone to ^C the script resulting in an 
abended record.

Hope that fixes your problem.

Rob

--
As soon as you make something foolproof, someone will create a better fool.

Reply via email to