Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > DBIx::Simple, fails with no error (not CGI this time!)

Reply
Thread Tools

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

 
 
Justin C
Guest
Posts: n/a
 
      06-28-2007

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(
'dbig: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-Simple-1.30/lib/DBIx/Simple/Examples.pod#EXAMPLES_WITH_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
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      06-28-2007
On Jun 28, 10:15 am, Justin C <(E-Mail Removed)> 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(
> 'dbig: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


 
Reply With Quote
 
 
 
 
Justin C
Guest
Posts: n/a
 
      06-28-2007
In article <(E-Mail Removed). com>, Paul Lalli wrote:
> On Jun 28, 10:15 am, Justin C <(E-Mail Removed)> 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(
>> 'dbig: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.

--
Justin C, by the sea.
 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      06-29-2007
Justin C <(E-Mail Removed)> 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/"
 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      06-29-2007
On Jun 28, 7:21 pm, Justin C <(E-Mail Removed)> 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

 
Reply With Quote
 
Justin C
Guest
Posts: n/a
 
      06-29-2007
On 2007-06-29, Paul Lalli <(E-Mail Removed)> wrote:
> On Jun 28, 7:21 pm, Justin C <(E-Mail Removed)> 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`.


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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CGI (read multipart form): Accept-Charset encoding error (CGI::InvalidEncoding) Stefan Fischer Ruby 2 02-23-2010 08:17 AM
Constant.t fails 240 of 272 tests and recurs.t fails 1 of 25 tests on HPUX using perl 5.8.7 dayo Perl Misc 11 12-16-2005 09:09 PM
slideshow fails, Firefox debugger also fails lkrubner@geocities.com Javascript 2 12-23-2004 06:22 PM
Forms Authentication Fails Between ASP.NET 1.0 and 1.1 Applications (Cookie Decryption Fails) John Saunders ASP .Net 1 11-18-2003 03:25 PM
Importing WMI module into Python CGI script fails MK Python 4 07-20-2003 08:24 PM



Advertisments