IMPLEMENTING LDIM SqlFunctionAttributeproperties (such as DataAccessKind) can be

IMPLEMENTING LDIM SqlFunctionAttributeproperties (such as DataAccessKind) can be used to declare the behavior of UDT methods. Chapter 3 discusses how to create stored procedures, functions, and triggers using a CLR language such as C#. It is sometime useful to create convenience functions for use with user-defined types. This is can be problematic when parametric values must be used to insert an instance of a user-defined type. This is shown in the SQL batch in Listing 5-22. Listing 5-22: Parametric Insertion of an LDim DECLARE @d AS LDim CREATE TABLE Dimensions ( dim LDim ) GO parametric value DECLARE @v AS FLOAT DECLARE @u AS VARCHAR(2) SET @v = 1 SET @u = yd INSERT INTO VALUES (Convert(varchar, @v) + + @u) The SQL batch in Listing 5-22 inserts 1 yd into the Dimensions table. To do this, it had to construct a string that could be inserted into an LDim column. This is an example of a case where a convenience function that can produce an instance of a user-defined type would be very useful. Note that a convenience function is not an instance member of the class that implements the user-defined type and does not use the SqlMethod Attributeattribute; it is a static member of it. In fact, it is only for keeping it together with the user-defined type definition; it could be part of a completely different class. Listing 5-23 shows the implementation of the Make LDimString method. Note also that this method will have to be added to the database that uses it by using the CREATE FUNCTION command, as described in Chapter 3. Listing 5-23: Implementation of the MakeLDimString Method public static LDim MakeLDim(SqlDouble value, SqlString units) { if (value.IsNull || units.IsNull) { return new LDim(); }

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

Bookmark the permalink.

Comments are closed.