Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- From: Abigail <abigail@xxxxxxxxxx>
- Date: 24 Apr 2008 11:10:05 GMT
_
Ben Bullock (benkasminbullock@xxxxxxxxx) wrote on VCCCL September
MCMXCIII in <URL:news:fuplm6$7nl$1@xxxxxxxxxxxxxxxx>:
%% On Wed, 23 Apr 2008 18:24:31 -0700, Ted wrote:
%%
%% > My understanding of undefined in
%% > Perl was to relate it to uninitialized values in Java or C++. You
%% > declare a variable, but then attempt to use it before you define it
%% > (i.e. give it a value).
%%
%% I don't know Java, but uninitialized values in C++ are completely
%% different from undefined values in Perl. An uninitialized C++ variable
%% just contains random garbage, but Perl's undefined values are something
%% meaningful, i.e. you can test whether a variable is undefined or not.
%%
%% > The idea of NULL in SQL is very different. It
%% > IS a valid value that can be given to variables or to fields in specific
%% > rows, where the table definition allows it.
%%
%% So it sounds just like an undefined value in Perl.
Up to there, yes. But it behaves quite differently. Undefined values in
Perl become 0 or the empty string if the context requires so. But not
so with SQL NULLs (see below).
%% What value would you
%% give a Perl scalar to represent an SQL null, if not the undefined value?
%% A string saying "NULL"? A special "NULL" object? What would their
%% advantage be over just Perl's regular undefined value?
Well, there would be some advantages of using a special NULL object
instead of 'undef'. Because an SQL NULL behaves differently from an
undef. For instance, when doing arithmetic, an 'undef' behaves like
a 0, while an SQL NULL behaves like a NaN:
3 + NULL == NULL (SQL)
3 + undef == 3 (Perl)
3 + NaN == NaN (Perl)
Unfortunally, there's no NaN equivalent for strings, and when you get
something out of a database, DBI cannot know whether it's going to be
used as a string, or as a number.
%% > NULLs in SQL carry a very
%% > specific meaning, and require very specific behaviours when handling
%% > them. To translate this into a language like Java or C+ +, I would
%% > write a class that provides for the same meaning and behaviours that
%% > would be familiar to a SQL programmer. Had I known that the DBI was
%% > broken in terms of translating database nulls into <undefined>
%%
%% I really do not think that it's broken.
I'd say, mapping SQL NULLs to undef was a choice. It's often convenient,
but can be surprising if you're used to SQL NULLs and the wrong choice
if you need the same behaviour. Another choice would have been NaN, but
that makes string handling more cumbersome.
%% > I'd have
%% > considered developeing an extension to DBI; one that included a NULL
%% > class that would serve the needs of database programmers.
%%
%% What would it do, exactly?
If I were to implement is, an object of such a class would have overloaded
all operations and return another NULL object for all operations, except
when comparing it with NULL (in which case it would return a true value).
Abigail
--
$_ = "\nrekcaH lreP rehtona tsuJ"; my $chop; $chop = sub {print chop; $chop};
$chop -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
-> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> () -> ()
.
- Follow-Ups:
- References:
- re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- From: Ted
- Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- From: smallpond
- Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- From: Ted Zlatanov
- Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- From: Ted
- Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- From: Joost Diepenmaat
- Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- From: Ted
- Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- From: Ben Bullock
- re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- Prev by Date: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- Next by Date: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- Previous by thread: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- Next by thread: Re: use of DBI; I am getting multiple error messages mixed in with the correct output.
- Index(es):
Relevant Pages
|