Perl DBI does not print error.

Discussion in 'Perl Misc' started by sam, Mar 10, 2005.

  1. sam

    sam Guest

    Hi,

    The perl DBI does not prints error message:
    $sth = $dbh->prepare($insert_sql)
    || print ERRFILE_OUT "prepare: $insert_sql: $DBI::errstr";

    The out of this error only does not print why the error was occurred.
    eg.
    Unable to execute query: DBI::db=HASH(0x8647df0)->errstr:

    Dan anyone please tell me how to prints how a description of the error
    from DBI when sql executed failed?

    Thanks
    Sam
     
    sam, Mar 10, 2005
    #1
    1. Advertising

  2. sam

    Guest

    sam <> wrote:
    > Hi,
    >
    > The perl DBI does not prints error message:
    > $sth = $dbh->prepare($insert_sql)
    > || print ERRFILE_OUT "prepare: $insert_sql: $DBI::errstr";
    >
    > The out of this error only does not print why the error was occurred.
    > eg.
    > Unable to execute query: DBI::db=HASH(0x8647df0)->errstr:


    It is not clear whether this is what you want but for some reason you
    aren't getting it, or if this is what you get and it is for some reason not
    suitable.

    It is hard to believe it is really either of those, as the error message
    you give does not seem to be generated by the code snippet you give and
    there is no reason to expect that it would be.

    > Dan anyone please tell me how to prints how a description of the error
    > from DBI when sql executed failed?


    I'm not sure why you would expect an *execution* failure to occur in a
    *prepare* method.

    In my hands, I turn on RaiseError and it just works. No magic incantations
    are necessary.

    Given the almost complete absense of context you provide, it is hard to be
    more helpful than that.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Mar 10, 2005
    #2
    1. Advertising

  3. sam

    sam Guest

    wrote:

    > sam <> wrote:
    >
    >>Hi,
    >>
    >>The perl DBI does not prints error message:
    >>$sth = $dbh->prepare($insert_sql)
    >> || print ERRFILE_OUT "prepare: $insert_sql: $DBI::errstr";
    >>
    >>The out of this error only does not print why the error was occurred.
    >>eg.
    >>Unable to execute query: DBI::db=HASH(0x8647df0)->errstr:

    >
    >
    > It is not clear whether this is what you want but for some reason you
    > aren't getting it, or if this is what you get and it is for some reason not
    > suitable.
    >
    > It is hard to believe it is really either of those, as the error message
    > you give does not seem to be generated by the code snippet you give and
    > there is no reason to expect that it would be.
    >
    >
    >>Dan anyone please tell me how to prints how a description of the error
    >>from DBI when sql executed failed?

    >
    >
    > I'm not sure why you would expect an *execution* failure to occur in a
    > *prepare* method.
    >
    > In my hands, I turn on RaiseError and it just works. No magic incantations
    > are necessary.
    >
    > Given the almost complete absense of context you provide, it is hard to be
    > more helpful than that.
    >

    Hi,
    Do you have any example?
    The following is a copy of the sample code that does not print out DBI
    error:

    #!/usr/bin/perl

    use DBI;

    # connect using to the database named $database using given
    # username and password, return a database handle
    $database = "mydb";
    $username = "me";
    $pw = "mypass";
    $dbh = DBI->connect("DBI:mysql:$database",$username,$pw);
    die "Unable to connect: $DBI::errstr\n" unless (defined $dbh);

    $sth = $dbh->prepare(q{SELECT * from customer}) or die "Unable to prep
    our query:".$dbh->errstr."\n";
    $rc = $sth->execute or die "Unable to execute our query:".$dbh->errstr."\n";

    while ($aref = $sth->fetchrow_arrayref){
    for ($i=0; $i < $sth->{NUM_OF_FIELDS};$i++){
    print $sth->{NAME}->[$i].": " . $aref->[$i] . "\n";
    }
    }

    # tells server you will not need more data from statement handle
    # (optional, since we're just about to disconnect)
    $sth->finish;
    # disconnects handle from database
    $dbh->disconnect;

    Thanks
    sam

    > Xho
    >
     
    sam, Mar 10, 2005
    #3
    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. ulloa
    Replies:
    1
    Views:
    544
    Juha Laiho
    Jul 22, 2004
  2. Jerome Hauss
    Replies:
    0
    Views:
    184
    Jerome Hauss
    Oct 13, 2004
  3. Asby

    Mason, DBI, and DBI::Pg

    Asby, Jul 24, 2003, in forum: Perl Misc
    Replies:
    0
    Views:
    189
  4. Tim Haynes
    Replies:
    3
    Views:
    153
    Ron Reidy
    Sep 13, 2003
  5. Replies:
    2
    Views:
    158
Loading...

Share This Page