For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > June 2007 > DBIx::Simple, fails with no error (not CGI this time!)









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

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

2007-06-28, 7:04 pm


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-...H_SQL::Abstract>

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

Any suggestions of where to start looking?

Justin.

--
Justin Catterall www.masonsmusic.co.uk
Director T: +44 (0)1424 427562
Masons Music Ltd F: +44 (0)1424 434362
For full company details see our web site
Paul Lalli

2007-06-28, 7:05 pm

On Jun 28, 10:15 am, Justin C <justin.0...@purestblue.com> wrote:
> 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


Justin C

2007-06-28, 7:05 pm

In article <1183050172.985662.257880@g4g2000hsf.googlegroups.com>, Paul Lalli wrote:
> On Jun 28, 10:15 am, Justin C <justin.0...@purestblue.com> wrote:
>
> 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
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.

--
Justin C, by the sea.
Tad McClellan

2007-06-28, 10:03 pm

Justin C <justin.0706@purestblue.com> wrote:

> 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


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
Paul Lalli

2007-06-28, 10:03 pm

On Jun 28, 7:21 pm, Justin C <justin.0...@purestblue.com> wrote:

> 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

Justin C

2007-06-29, 8:03 am

On 2007-06-29, Paul Lalli <mritty@gmail.com> wrote:
> On Jun 28, 7:21 pm, Justin C <justin.0...@purestblue.com> wrote:
>
>
> 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.

--
Justin Catterall www.masonsmusic.co.uk
Director T: +44 (0)1424 427562
Masons Music Ltd F: +44 (0)1424 434362
For full company details see our web site
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com