[Qt-interest] Comparing two NULL QVariants returns true
Israel Brewster
israel at frontierflying.com
Mon May 30 19:16:05 CEST 2011
On May 29, 2011, at 5:08 AM, Robert Hairgrove wrote:
> On Sun, 2011-05-29 at 14:33 +0200, Thiago Macieira wrote:
>> On Sunday, 29 de May de 2011 13:18:44 Robert Hairgrove wrote:
>>> In the internal "compare()" function in file qvariant.cpp, the case
>>> where two null variants are compared is at the very bottom:
>>>
>>> if (a->is_null && b->is_null)
>>> return true;
>>>
>>> I was wondering why this is implemented as such, whereas most databases
>>> will return false when two NULL values are compared. What was the
>>> rationale behind this?
>>
>> You're saying that for databases, this happens:
>>
>> Type a = null;
>> Type b = a;
>> then
>> a != b;
>> ?
>>
>> Sounds very counter-intuitive. I've only seen that for NaNs.
I want to say that I've seen it for a number of databases. It does sound somewhat counterintuitive on the face of things, but it starts making sense when you take database restrictions into account. Say, for example, that you have a database of office workers with a phone number column. No two people can have the same phone number (we're assuming people don't share phones), but some people may not have a phone number at all. If null was considered equal, and you put a unique constraint on the phone column, then only one person would be allowed to have no phone. With null not being equal, the unique constraint works as expected- you can have any number of people without phone numbers, but no two people can have the SAME phone number. So from that perspective it makes sense for comparing two null values to return false.
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
-----------------------------------------------
Israel Brewster
Computer Support Technician II
Era Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x7293
-----------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Israel Brewster.vcf
Type: text/directory
Size: 417 bytes
Desc: not available
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110530/1b2a4711/attachment.bin
-------------- next part --------------
More information about the Qt-interest-old
mailing list