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

Discussion in 'Perl Misc' started by Justin C, Jun 28, 2007.

  1. Justin C

    Justin C Guest

    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-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
     
    Justin C, Jun 28, 2007
    #1
    1. Advertising

  2. Justin C

    Paul Lalli Guest

    On Jun 28, 10:15 am, Justin C <> 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
     
    Paul Lalli, Jun 28, 2007
    #2
    1. Advertising

  3. Justin C

    Justin C Guest

    In article <>, Paul Lalli wrote:
    > On Jun 28, 10:15 am, Justin C <> 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


    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.
     
    Justin C, Jun 29, 2007
    #3
  4. Justin C <> 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/"
     
    Tad McClellan, Jun 29, 2007
    #4
  5. Justin C

    Paul Lalli Guest

    On Jun 28, 7:21 pm, Justin C <> 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
     
    Paul Lalli, Jun 29, 2007
    #5
  6. Justin C

    Justin C Guest

    On 2007-06-29, Paul Lalli <> wrote:
    > On Jun 28, 7:21 pm, Justin C <> 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
     
    Justin C, Jun 29, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Al Tobey
    Replies:
    0
    Views:
    541
    Al Tobey
    Oct 24, 2003
  2. I & L Fogg
    Replies:
    1
    Views:
    220
    Ben Morrow
    Jun 21, 2004
  3. shankar
    Replies:
    1
    Views:
    127
    J. Gleixner
    Mar 14, 2006
  4. Justin Catterall

    DBIx::Simple, authentication fails

    Justin Catterall, Jun 27, 2007, in forum: Perl Misc
    Replies:
    2
    Views:
    100
    Justin C
    Jun 27, 2007
  5. Justin C
    Replies:
    3
    Views:
    159
    Paul Lalli
    Jul 7, 2007
Loading...

Share This Page