Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Perl DBI: problems inserting data to a table

by mje (Curate)
on Nov 21, 2013 at 11:16 UTC ( #1063715=note: print w/ replies, xml ) Need Help??


in reply to Re: Perl DBI: problems inserting data to a table
in thread Perl DBI: problems inserting data to a table

That is, DBI can return a value of 0E0 when an error occurs

Where in the DBI pod does it say when execute returns 0E0 there is an error. execute returns either, rows insert/updated/deleted, -1 (rows altered not known), 0E0 (no rows altered), undef (error)

I think you might be confusing this with the err method which can return '' (empty string) to indicate an informational state and 0 to indicate a warning.


Comment on Re^2: Perl DBI: problems inserting data to a table
Re^3: Perl DBI: problems inserting data to a table
by boftx (Deacon) on Nov 21, 2013 at 11:49 UTC

    From the DBI POD for "execute":

    "For a non-SELECT statement, execute returns the number of rows affected, if known. If no rows were affected, then execute returns "0E0", which Perl will treat as 0 but will regard as true. Note that it is not an error for no rows to be affected by a statement. If the number of rows affected is not known, then execute returns -1."

    A simple text search (ctrl-f) will find it.

    It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

      A simple text search does in deed find what you quoted. I never argued that. The quote however, does not say that when execute returns 0E0 it is an error and that is why I took your comment "That is, DBI can return a value of 0E0 when an error occurs" to be wrong. DBI execute returns undef when an error occurs, 0E0 would mean the execute completed successfully but inserted/updated/deleted no rows.

      For a simple insert statement, execute() should never return '0E0'. It will return undef if there's an error, or '1' if a row was inserted (though I would use RaiseError in which case it would die on error). For a 'insert into ... select ... from' type insert statement, it might return '0E0' if zero rows were selected/inserted (which is not an error), or more if rows were inserted, or (again) undef if there was an error.

        The OP indicates that RaiseError is being set. The only thing I could think of was that a field width constraint was being violated without throwing the exception. At this point, I think I would want to force an insert error and see if RaiseError does in fact fire.

        It helps to remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1063715]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2014-12-18 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (48 votes), past polls