USER-DEFINED TYPES AND AGGREGATES The SqlMethodAttribute provides SQL

USER-DEFINED TYPES AND AGGREGATES The SqlMethodAttribute provides SQL Server with information about how the method will interact with SQL Server. Some methods marked with SqlMethodwill change the value of the object on which they are called. This is true for the SetValue method. Since the SetValue changes an LDimobject, it must be used with a setsyntax, as shown in the SQL batch in Listing 5-20. Listing 5-20: Using the LDim SetValue Method DECLARE @d AS LDim SET @d.SetValue(2.3, ft ) PRINT CONVERT(CHAR, @d) 2.3 ft If the IsMutator property of the SqlMethod had been set to false, the SQL batch shown in Listing 5-20 would have produced an error when executed. Methods that have IsMutator = false can be used in VIEWS and SELECTstatements but not in UPDATEstatements. The SqlMethod has another property, named OnNullCall, which affects its behavior when a null parameter is passed in. You can think of OnNullCall=true as meaning Call this method even if a null is passed as a parameter. If OnNullCall=false, the method will not be called, and the instance of the user-defined type will be set to null. This property is set to false on the SetValue method. This means that when a null is passed to it, the LDimwill be set to null. That is why the implementation of the SetValue method does not have to check whether any of the input parameters are null. The SQL batch in Listing 5-21 shows that SetValueis not called when a nullis passed in. Listing 5-21: Passing a Null to SetValue DECLARE @d AS LDim SET @d.SetValue(2.3, ft ) PRINT CONVERT(CHAR, @d) 2.3 ft SET @d.SetValue(null, ft ) PRINT CONVERT(CHAR, @d) null The beginning of the SQL batch in Listing 5-21 sets @d to 2.3 ft and then prints it out. It then attempts to set it to null ft. It then prints out @d and shows that it has, in fact, been set to null. In addition, because SqlMethodAttribute derives from SqlFunctionAttribute, any of the

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services

Bookmark the permalink.

Comments are closed.