> -----Original Message-----
> From: Rob [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 15, 2002 10:08 AM
> To: [EMAIL PROTECTED]
> Subject: Status of db insert?
>
>
> Hi, I've recently started using PostgreSQL and am trying to
> load a table
> from a file. The file has 4275 records in it but the
> database only ends
> up with 4241 records. When I was using the Pg module I could
> check the
> status of the insert, I imagine I can do the same using the
> DBI module but
> I don't know how. Could someone help me out? Here's the
> script I'm using
> for the insert...
> #!/usr/bin/perl -w
>
> use DBI;
>
> my $database_name = "paging";
> my $database = "dbi:Pg:dbname=$database_name";
> my $db_user = "rob";
> my $DATA_TB = "data";
>
> my $dbh = DBI->connect($database,$db_user,"") or
> die "Can't connect to database\n";
>
> my $sth = $dbh->prepare("INSERT INTO $DATA_TB(CustNo,PIN,CustName,
> Serial,Model) VALUES (?,?,?,?,?");
> open(IN, "data.dat") || die "Can't open input file:$!\n";
> while(<IN>) {
> chomp;
> ($CustNo, $PIN, $CustName, $Serial, $Model) = split(/\|/, $_);
> print "$CustNo, $PIN, $CustName, $Serial, $Model\n";
> $sth->execute($CustNo, $PIN, $CustName, $Serial, $Model);
> #The above line is the one I would like to get the status of.
> }
> close(IN);
>
> $dbh->disconnect;
>From perldoc DBI, execute returns a true value on success and undef on
failure. So, you can do something like this:
$sth->execute($CustNo, $PIN, $CustName, $Serial, $Model)
or warn "insert error: $DBI::errstr\n";
But the database handle's PrintError attribute defaults to "on" (and you
aren't turning it off in this code), which would mean that the error should
be printed anyway. So I'm not sure why you aren't already seeing any errors.
Are you redirecting STDERR somewhere?
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]