|
Posted by Ted on April 23, 2008, 10:14 pm
Please log in for more thread options On Apr 23, 9:39=A0pm, xhos...@gmail.com wrote:
> > On Apr 23, 6:18=3DA0pm, xhos...@gmail.com wrote:
>
> > > > > The problem is that there are NULL values, which are undefined in
> > > > > the DBI translation. =3D3DA0So this
>
> > > > > printf("%s%s", $i ? "," : "", $$ref[$i]);
>
> > > > > should be (for example)
>
> > > > > printf("%s%s", $i ? "," : "", $$ref[$i]||'NULL');
>
> > > > This would be a useful tidbit to add to the documentation. =3DA0I
> > > > hadn't expected a mature library like DBI to behave like this.
>
> > > This is not DBI behavior. =3DA0It is Perl behavior when undefined valu=
ed
> > > are encountered. =3DA0It is documented, just not in the DBI docs. =3DA=
0It
> > > is n=3D
> > ot
> > > reasonable to document every non-DBI problem that one may encounter
> > > when using DBI in the DBI docs.
>
> > But null values in SQL are not the same thing as undefined or
> > uninitialized values in any other language I know.
>
> There isn't a built-in map function like Perl's in any other language I
> know, either. =A0If you want to use another language, use it. =A0If you wa=
nt to
> use Perl, use Perl.
>
I use a variety of languages, and I'll include Perl in the mix.
I am aware of the map function. There are, in fact, comparable
utilities in, for example, the standard C++ library. Look especially
at the generic algorithms it includes. And thee are specialized
variants for some of the standard C++ containers. Each seems to have
its own strengths and weaknesses.
> > In any RDBMS I
> > have worked with, null is a legitimate value that can be given to a
> > specific column in a specific row,
>
> No duh. =A0The question is how to represent those values when the data is
> *not* in the RDBMS, but in the language you are using to talk to the RDBMS=
.
>
Precisely, and using undefined is not appropriate since it confounds
two distinctly different ideas.
> > and it has a very specific meaning
> > in a database. =A0Any SQL programmer knows how to handle nulls, what can=
> > and can not be done with them, &c.
>
> There is plenty of empirical evidence that this is not the case.
>
So, as a DB programmer, you have contempt for your peers. But perhaps
I should have been more specific and said that I, and the DB
programmers I know, know how to use them well. My mistake, here I
suppose was to assume that my own observations apply more generally to
a wider population.
> > That is very different from
> > programming errors where a variable has been defined and then used
> > before it has been given a value. =A0So I maintain this IS a DBI issue,
> > and there ought to be functionality provided within DBI to handle the
> > processing of recordsets, including printing them, that can handle
> > null values in a rational manner without generating spurious
> > warnings.
>
> There are. =A0You have failed to use them.
>
Not quite. I failed to find them quickly, having started with DBI
today. The page for "DBD::mysql" says nothing about either this or
the fact that DBI translates nulls into undefined.
> > At a minimum the DBI documentation ought to say somethng
> > about users needing to implement their own processing to handle null
> > values when that is not available.
>
> The DBI docs say, several time, that it translates NULL to undef. =A0It sa=
ys
> what it does, it does what it says.
>
> > The real error here is that, if I
> > am to believe Ted, that nulls are treated as undefined in the DBI
> > translation, and this is plain wrong. =A0On the daatabase side, nulls
> > have a specific meaning (and as you well said, further on, that
> > meaning is different from that of an empty string), and DBI ought to
> > at least provide a means of handling them correctly from the
> > perspective of a database programmer.
>
> I am a database programmer and it handles them correctly from my
> perspective.
>
The meaning null has in SQL is quite different from the meaning given
to undefined in the perl books I use. How, then, do you reconcile the
two?
> > The mistake here is to assume this is a perl issue. =A0Perl, like Java
> > and C++ and FORTRAN and a host of other programming languages, is
> > Turing complete, so anything that can be done in any one of them can
> > in principle be done in any of the others. =A0Surely you know that JDBC
> > is to Java as DBI is to Perl. =A0What we are talking about here is
> > specificlly a database interface issue, and so the relevant aspect of
> > perl programming that applies here is the use of DBI. =A0I know how to
> > deal with nulls when using JDBC.
>
> Kudos to you. =A0Either learn how to handle them in DBI just like you lear=
ned
> to use JDBC, or don't use DBI.
>
> ...
>
That is precisely what I am trying to do. But it would appear I
haven't found all the relevant bits of documentation that would
support such an effort.
>
>
> > > In mysql, a null string and an empty string are two different things.
> > > Should both of them be converted to 'N/A', or just the null?
>
> > No, and I must emphasize that in the occassions where I changed the
> > behaviour, the change was mandated by the meaning of the data and the
> > way it was to be used. =A0In the case in question, the only possible
> > values are real numbers and null. =A0In some instances in this
> > application, the proper way to display the null is to use an empty
> > string. =A0In others, the proper way to display it is to use the string
> > "N/A". =A0But I could make these changes easily because both the JDBC
> > and JSF are well documented, and by examining that documentation to
> > see how the relevant classes/libraries handled nulls in particular and
> > data in general, it became clear almost immediately what code I had to
> > write to obtain the behaviour I required.
>
> So you made the effort to read the JDBC docs, but not the DBI docs. =A0How=
> is this Perl's fault or DBI's fault?
Not quite. I am making the effort to learn DBI, but it would appear I
haven't found all the relevant documentation for it. While I have
been using perl for a variety of things for a while, I started with
DBI only today. I don't think anyone here has attempted to assign
blame. The only criticism I made was to point out the difference in
meaning between the idea of undefined in perl and the meaning of null
in SQL.
>=A0It makes it completely clear how
> NULLs are handled. =A0In fact, it even says how to convert them to empty
> strings:
>
> (From the docs for DBI v1.58):
>
> =A0 =A0 =A0 =A0Here's how to convert fetched NULLs (undefined values) into=
empty
> =A0 =A0 =A0 =A0strings:
>
> =A0 =A0 =A0 =A0 =A0while($row =3D $sth->fetchrow_arrayref) {
> =A0 =A0 =A0 =A0 =A0 =A0# this is a fast and simple way to deal with nulls:=
> =A0 =A0 =A0 =A0 =A0 =A0foreach (@$row) { $_ =3D '' unless defined }
> =A0 =A0 =A0 =A0 =A0 =A0print "@$row\n";
> =A0 =A0 =A0 =A0 =A0}
>
I'll take your word for it, but I haven't found this nugget in the
documentation yet.
Thanks
Ted
>
> --
> --------------------http://NewsReader.Com/--------------------
> The costs of publication of this article were defrayed in part by the
> payment of page charges. This article must therefore be hereby marked
> advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate=
> this fact.- Hide quoted text -
>
> - Show quoted text -
|