From: Jamey Cribbs Date: 2006-03-05T09:45:40+09:00 Subject: Re: Kirbybase Hacks NilClass angus wrote: >[Jamey Cribbs , 2006-03-04 18.56 CET] > > >>However, the last example does give me an idea. I'm going to take a >>look at the KBTable#select method and see if I can wrap the query >>processing logic in a begin/rescue block. It may be as simple as what >>David shows here, have the rescue return false. The problem I can see >>is when there is an OR condition in the block, i.e.: >> >>#select { |r| r.speed > 300 or r.range < 900 } >> >> >[...] > > >>Now, lets say we are looping through the table records and we get to a >>record where :speed is nil and :range is 800. According to the query >>block, this record should qualify as a valid match. But, if I don't >>override NilClass#method_missing to return fasle, but, instead, try to >>catch it with a begin/rescue block like I show in the code above, the >>record will *not* be added to valid matches. The problem with the code >>above is that I can't get granular enough. There is no way to get >>inside the query block and put a begin/rescue around *each* condition >>within the block. >> >> > >But doesn't NULL always propagate in "database semantics"? I mean, if any >subexpression is NULL, the whole expression becomes NULL. It's the expected >behaviour (but maybe not to the users of KirbyBase). In SQL, normally, one >uses NVL(a, b) (with the meaning 'a.nil? ? b : a') to guard subexpressions >against NULL. > > I'm not so sure about that. Here's a link to a page talking about how the developer of SQLite decided how to treat NULL: http://www.sqlite.org/nulls.html If I read it correctly, he says that all of the major SQL dbms' treat "null OR true" as true. Maybe I'm reading this page wrong, but that seems to go against what you are saying. I'm definitely not a database expert, so anyone with knowledge on this, please chime in. In the meantime, I'm going to start taking a look at adding a Null class (or some such construct) to KirbyBase, to see if I can do away with the NilClass#method_missing issue. Jamey