[Dbix-class] Re: '' != NULL for great sadness

Matt Whipple matt at mattwhipple.com
Fri Jul 10 05:01:00 GMT 2009


fREW Schmidt wrote:
>
> Yeah, I wrote a small filter for DFV that would translate '' to undef 
> because that is not built in behavior (or at least not according to 
> Stosberg :-)  ).  I am using missing_optional_valid, but it turns out 
> that that doesn't matter because of how dbix::class::validation 
> works.  It doesn't validate the params of update or insert, it 
> validates the state of the object just before saving it to the db.
>
> And yes, clearly I'm not using js for EVERYTHING as I said I was using 
> dfv, dbic, and obviously perl.
>
> Anyway, I'm reading up on what another poster said about nulls in the 
> db.  So far I'm not convinced, but give me a while to read up on some 
> of this stuff.  I'd appreciate any other, more complete links relating 
> to nulls in the database.
>
> It just seems to me that it make sense to have undefined values in a 
> field, but I need to think through that some more.
>
To me it appears that the aversion to using NULL is caused because it is 
being used probably more often than not as a result of sloppiness rather 
than design (particularly with the differences with the NULLs), and even 
when properly implemented, there can be a negative impact on the 
performance of some (all?) DBMS's when tables have columns that allow 
NULL values.  With char fields the argument gets foggier with NULL vs an 
empty string (or the myriad of possible values), but with numeric fields 
(as in this case) NULL and 0 (or any other number)  mean very different 
things conceptually and so far any other suggestion to represent an 
unknown value is more complex (quite likely needlessly).  Having to deal 
with NULLs is going to pop up in outside joins anyway, I don't 
understand why intelligent, deliberate use of them elsewhere would be so 
besieged.  I don't recall seeing such strong opposition in database 
systems references...more of just "this probably doesn't work the way 
you think it does, make sure you learn how it does work before you use 
it"...and I'd add a "and document it".

> Thanks guys.
>
>> On Jul 9, 2009 6:59 PM, "Aaron Schrab" <aaron at schrab.com 
>> <mailto:aaron at schrab.com>> wrote:
>>
>> At 17:17 -0500 09 Jul 2009, fREW Schmidt <frioux at gmail.com 
>> <mailto:frioux at gmail.com>> wrote: > > This is all in javascript.  I...
>>
>> It's obviously not all in JavaScript, since you're using DBIC.  And 
>> relying completely on JS for data validation is an extremely bad idea.
>>
>> If you're using Data::FormValidator, it should already handle giving 
>> you undef for fields that were submitted as empty.  Normally, it 
>> won't even include those fields in the hash of valid data that it 
>> returns, so trying to get the value of the field out of that hash 
>> will default to undef.  If you include the missing_optional_valid 
>> option in your call to it, empty fields will be included in the valid 
>> hash, but still with undef as the value.
>>
>> _______________________________________________ List: 
>> http://lists.scsys.co.uk/cgi-bin/mailman/lis...
>>
> ------------------------------------------------------------------------
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk




More information about the DBIx-Class mailing list