DBIx::Simple, fails with no error (not CGI this time!)

J

Justin C

My program connects to a database, and is to insert a row into a table.
It runs with no errors or warnings but the database is not updated.
There is nothing in the Postgresql log either.

Here is the code, it's a small as I can make it:

#!/usr/bin/perl

use warnings ;
use strict ;
use DBIx::Simple ;
use SQL::Abstract ;

my $user = "[user]" ;
my $password = "[passwd]" ;
my $dataSource = DBIx::Simple->connect(
'dbi:pg:database=prospects', $user, $password,
{ RaiseError => 1 , AutoCommit => 0 }
) or die DBI::Simple->error ;

my %input = (
"key" => "4",
"contact" => "john",
"co_name" => "John's Fluff and Grime Ltd",
"ad1" => "1 Some Road",
"town" => "BENJY",
"p_code" => "BN1",
"county" => "Middleshire",
"tel1" => "01234 567234",
);

$dataSource->insert('prospect', \%input);

--- END ---

That last line is taken directly from
<URL: http://search.cpan.org/~juerd/DBIx-...mple/Examples.pod#EXAMPLES_WITH_SQL::Abstract>

(except, on the above page they have $db->insert...)

Any suggestions of where to start looking?

Justin.
 
P

Paul Lalli

My program connects to a database, and is to insert a row into a table.
It runs with no errors or warnings but the database is not updated.
There is nothing in the Postgresql log either.

Here is the code, it's a small as I can make it:

#!/usr/bin/perl

use warnings ;
use strict ;
use DBIx::Simple ;
use SQL::Abstract ;

my $user = "[user]" ;
my $password = "[passwd]" ;
my $dataSource = DBIx::Simple->connect(
'dbi:pg:database=prospects', $user, $password,
{ RaiseError => 1 , AutoCommit => 0 }

You've turned off auto-commit, but never actually comitted your work.
Either turn AutoCommit back on, or explicitly commit your data. I
recommend a block similar to:

END {
if ($?) { # exiting with error
$dataSource->rollback();
} else { # success
$dataSource->commit();
}
}

Paul Lalli
 
J

Justin C

My program connects to a database, and is to insert a row into a table.
It runs with no errors or warnings but the database is not updated.
There is nothing in the Postgresql log either.

Here is the code, it's a small as I can make it:

#!/usr/bin/perl

use warnings ;
use strict ;
use DBIx::Simple ;
use SQL::Abstract ;

my $user = "[user]" ;
my $password = "[passwd]" ;
my $dataSource = DBIx::Simple->connect(
'dbi:pg:database=prospects', $user, $password,
{ RaiseError => 1 , AutoCommit => 0 }

You've turned off auto-commit, but never actually comitted your work.
Either turn AutoCommit back on, or explicitly commit your data. I
recommend a block similar to:

END {
if ($?) { # exiting with error
$dataSource->rollback();
} else { # success
$dataSource->commit();
}
}

Paul Lalli

Hello, again, Paul. I read a lot of documentation for Perl modules that
work with postgresql, so many that when I got to DBIx::Simple I may have
skimped, and skipped straight to the examples... That and I *always* get
confused by boolean 0/1 and which is which... mind you, I should have
been prompted by the RaiseError => 1. The situation isn't helped by the
fact that I've no SQL experience (learning as I'm going along) and I'm
no Perl expert either - but I know more than I do SQL.

Looking at your suggestion, I understand what you're suggesting, but I
don't fully understand your code... no, that's not true, I don't
understand: "END { "

Maybe I'm showing how green I really am. I can see you're testing for
errors, I understand the rollback, and commit. I can't find, in perldoc
-q or -f anything relating to an 'END'. Could you point me at some docs
to explain what is going on there? I know there is a need to trap out
errors if the database throws back an error, at the moment I'm trying to
get to a point of working code, the error trapping would come along
next, honest!

Thanks for the help with the problem.

Justin.
 
T

Tad McClellan

Justin C said:
I can't find, in perldoc
-q or -f anything relating to an 'END'. Could you point me at some docs
to explain what is going on there?


See the "BEGIN, CHECK, INIT and END" section in:

perldoc perlmod
 
P

Paul Lalli

I can't find, in perldoc -q or -f anything relating to an 'END'.

You're not alone.
Could you point me at some docs
to explain what is going on there?

For no real good reason I've ever been able to find, BEGIN{}, INIT{},
CHECK{}, and END{} are all described in `perldoc perlmod`.

Paul Lalli
 
J

Justin C

You're not alone.


For no real good reason I've ever been able to find, BEGIN{}, INIT{},
CHECK{}, and END{} are all described in `perldoc perlmod`.

Thanks Paul, and Tad. I'll read it now...

Ahh! Useful stuff. I'm going to re-read Paul's suggestion for an END{}
code block and drop one in. Thanks again.

Justin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top