Previous Thread:   SqlMethodAttribute

1/22/2006 10:07:39 AM    Re: IsNull property on UDTs
Hi Leila,  
  
Long answer:  
  
SQL Server keeps the semantic equivalent of a bitswitch to determine whether  
  
a value is database NULL. If you write a UDT, you keep the semantic  
  
equivalent of a bitswitch (determined by the implementor, you) and answer  
  
correctly to IsNull (a read-only) property. SQL Server can optimize by  
  
reading its bitswitch and not having to instanciate one of your UDTs just to  
  
find out that its NULL. It will do this on (instance) method calls if the  
  
method is not marked InvokeIfReceiverIsNull=true. SQL Server does not set  
  
your "nullability bit" directly, there is no set method on IsNull.  
  
In your statement:  
  
set @p = '1:1'  
  
SQL Server calls Parse (to convert from string) and you make a non-null  
  
instance, "setting it to non-null as far as your IsNull implementation is  
  
concerned" in your code. SQL Server calls your IsNull property as part of  
  
this statement, setting its internal bitswitch.  
  
In your statement:  
  
if @p IS NULL...  
  
SQL Server does not necesarily have to call your IsNull at all, if it  
  
"knows" (through its bitswitch) the value is NULL. Be careful with this, as  
  
this T-SQL statement:  
  
SELECT @p.IsNull  
  
returns false or NULL unless InvokeIfReceiverIsNull=true is specified on the  
  
IsNull accessor. Then, it would return false or true. I've written a few  
  
blog entries about this too. ;-)  
  
Cheers,  
  
Bob Beauchemin  
  
http://www.SQLskills.com/blogs/bobb  
  
"Leila" <Leilas@hotpop.com> wrote in message  
  
news:epZ6SM3HGHA.216@TK2MSFTNGP15.phx.gbl...



1/22/2006 11:44:29 AM    Re: IsNull property on UDTs
InvokeIfReceiverIsNull=true says that, if the UDT instance is NULL, the  
  
method will be called, rather than just return NULL. OnNullCall=true says  
  
that if the input parameter to the method (static or instance method) is a  
  
NULL value than the method will be called.  
  
Cheers,  
  
Bob Beauchemin  
  
http://www.SQLskills.com/blogs/bobb  
  
"Leila" <Leilas@hotpop.com> wrote in message  
  
news:eZ1Kpr4HGHA.2900@TK2MSFTNGP14.phx.gbl...

1/22/2006 8:12:18 PM    IsNull property on UDTs
Hi,  
  
I'm examining the Point UDT with the definition in MSDN:  
  
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.SQL.v2005.en/denet9/html/1e5b43b3-4971-45ee-a591-3f535e2ac722.htm  
  
When I try this batch, I get NULL as expected:  
  
declare @a point  
  
if @a is null  
  
print 'Null'  
  
else  
  
print 'Not Null'  
  
But if I initialize @a with some value, the batch returns NOT NULL:  
  
declare @a point  
  
set @a='1:1'  
  
if @a is null  
  
print 'Null'  
  
else  
  
print 'Not Null'  
  
In the CLR implementation of UDT, there's no clue of changing is_Null to  
  
FALSE, so how does SQL Server determine that @a is not null?  
  
Thanks in advance,  
  
Leila

1/22/2006 10:47:28 PM    Re: IsNull property on UDTs
Thanks for the great explanation Bob!  
  
What's the difference between InvokeIfReceiverIsNull and OnNullCall?  
  
Leila  
  
"Bob Beauchemin" <no_bobb_spam@sqlskills.com> wrote in message  
  
news:OuHWM63HGHA.604@TK2MSFTNGP14.phx.gbl...