I think I agree with Ed - I'd like to see specific error messages rather
than just getting back undef from $sth->{NAME}.
Hardy Merrill
>>> Tim Bunce <[EMAIL PROTECTED]> 01/15/04 11:12AM >>>
On Thu, Jan 15, 2004 at 12:04:47PM -0000, Avis, Ed wrote:
> Tim Bunce wrote:
>
> >>>A statement handle should always have NAME, TYPE, NULLABLE etc
> >>>attributes. It should never be an error to ask for them. But the
> >>>value returned may be undef, for example, if the statement
> >>>has not been executed, the execute failed, or it's not a select
> >>>statement.
> >>
> >>If RaiseError is set, then shouldn't accessing one of these
> >>when it is not available throw an exception rather than giving
undef?
> >
> >I don't think so. It's not an error, it's just unavailable
> >(although you could argue it either way).
>
> You give a long list of possible reasons why the data could be
> unavailable, quoted above. Undef could mean any of those and it's
not
> possible to find out which. An exception can say what the problem
is.
>
> You'd get questions from beginners saying 'I get $sth->{NAME} but it
is
> always undef, what am I doing wrong?'. The answer is probably that
you
> need to execute() first. An error message would make this obvious.
>
> Or consider porting a program from one DBD driver to another. The
> original driver made {NAME} available before executing, but the new
one
> does not. It would be better to see an obvious failure rather than
have
> the program get undef and go wrong later.
>
> You can of course write your code to always check that an attribute
is
> defined after fetching it. But the point of RaiseError is that you
> don't have to type these explicit checks after every DBI operation.
You make some valid points. I'm open to persuasion. Anyone else got
an opinion?
Tim.
p.s. As a related example the DBD::Oracle driver can defer actually
preparing a statement until execute() time in order to reduce round
trips to the database. If $sth->{NAME} (or similar) is used before the
execute() it automatically does the prepare. If that underlying
prepare fails then it croak()s, regardless of RaiseError, because
that's
the only way to reliably convey what's happened.