如何:创建和运行 CLR SQL Server 用户定义的来源: 发布时间:星期二, 2009年2月3日 浏览:27次 评论:0
="t18">通过将“用户定义
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 注意 在默认情况下 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 注意 显示 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 创建用户定义 ![]() 创建 SQL 用户定义 ![]() 打开 ![]() ![]() ![]() ![]() ![]() ![]() ![]() 从“项目”菜单中选择“添加新项” ![]() 在“添加新项”对话框 中选择“用户定义 ![]() ![]() 为新 ![]() ![]() 添加用于定义和创建 UDT ![]() ![]() ![]() ![]() ![]() 注意 C ![]() ![]() 对于 Visual Basic 和 Visual C# ![]() ![]() ![]() ![]() 对于 Visual C ![]() ![]() ![]() ![]() 将代码添加到“Test.sql”(Visual C ![]() ![]() ![]() ![]() 按 F5 生成、部署和调试 UDT ![]() ![]() ![]() ![]() 在“输出”窗口 中查看结果 ![]() ![]() 举例 此举例创建 ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Visual Basic 复制代码 Imports ![]() Imports ![]() Imports Microsoft.SqlServer.Server <Serializable ![]() <SqlUserDefinedType(Format.Native)> _ Public Structure Po ![]() Implements INullable Private m_x As Int32 Private m_y As Int32 Private is_Null As Boolean Public Property X ![]() Get Return (Me.m_x) End Get Set(ByVal Value As Int32) m_x = Value End Set End Property Public Property Y ![]() Get Return (Me.m_y) End Get Set(ByVal Value As Int32) m_y = Value End Set End Property Public ReadOnly Property IsNull ![]() Get Return is_Null End Get End Property Public Shared ReadOnly Property Null ![]() ![]() Get Dim pt As Po ![]() ![]() pt.is_Null = True Return pt End Get End Property Public Overrides Function ![]() ![]() If Me.IsNull ![]() Return Nothing Else Return Me.m_x & ":" & Me.m_y End If End Function Public Shared Function Parse(ByVal s As SqlString) As Po ![]() If s = SqlString.Null Then Return Null End If If s. ![]() ![]() ![]() ![]() Return Null End If If s.IsNull Then Return Null End If 'Parse input ![]() Dim str As String = Convert. ![]() Dim xy ![]() Dim pt As New Po ![]() ![]() pt.X = CType(xy(0), Int32) pt.Y = CType(xy(1), Int32) Return (pt) End Function Public Function Quadrant ![]() If m_x = 0 And m_y = 0 Then Return "centered" End If Dim ![]() Select Case m_x Case 0 ![]() Case Is > 0 ![]() Case Is < 0 ![]() End Select Select Case m_y Case 0 ![]() ![]() Case Is > 0 ![]() ![]() Case Is < 0 ![]() ![]() End Select Return ![]() End Function End Structure C# 复制代码 using ![]() using ![]() using Microsoft.SqlServer.Server; [Serializable ![]() [SqlUserDefinedType(Format.Native)] public struct Po ![]() { private Int32 m_x; private Int32 m_y; private bool is_Null; public Int32 X { get { ![]() } ![]() { m_x = value; } } public Int32 Y { get { ![]() } ![]() { m_y = value; } } public bool IsNull { get { ![]() } } public ![]() ![]() { get { Po ![]() ![]() ![]() ![]() pt.is_Null = true; ![]() } } public override ![]() ![]() ![]() { ![]() { ![]() } ![]() { ![]() } } public ![]() ![]() { ![]() { ![]() } // Parse input ![]() ![]() ![]() ![]() ![]() Po ![]() ![]() ![]() ![]() pt.X = Convert.ToInt32(xy[0]); pt.Y = Convert.ToInt32(xy[1]); ![]() } public SqlString Quadrant ![]() { ![]() ![]() ![]() { ![]() } SqlString ![]() ![]() ![]() { ![]() } ![]() ![]() { ![]() } ![]() ![]() { ![]() } ![]() ![]() { ![]() ![]() } ![]() ![]() { ![]() ![]() } ![]() ![]() { ![]() ![]() } ![]() ![]() } } C ![]() # ![]() #using < ![]() #using < ![]() #using < ![]() using ![]() ![]() using ![]() ![]() using ![]() ![]() using ![]() ![]() using ![]() // In order to debug your User-Defined Types, add the following to your debug.sql file: // // CREATE TABLE test_table (column1 Po ![]() // // INSERT INTO test_table (column1) VALUES ('1:2') // INSERT INTO test_table (column1) VALUES ('-2:3') // INSERT INTO test_table (column1) VALUES ('-3:-4') // // SELECT column1.Quadrant ![]() // // DROP TABLE test_table // [Serializable] [SqlUserDefinedType(Format::Native)] public value struct Po ![]() { private: Int32 m_x; Int32 m_y; bool is_Null; public: property Int32 X { Int32 get ![]() ![]() void ![]() } property Int32 Y { Int32 get ![]() ![]() void ![]() } virtual property bool IsNull { bool get ![]() ![]() } ![]() ![]() { Po ![]() ![]() { Po ![]() pt.is_Null = true; ![]() } } virtual String ^ ![]() ![]() { ![]() { ![]() } ![]() { ![]() } } ![]() ![]() { ![]() { ![]() } // Parse input ![]() String ^str = Convert:: ![]() Po ![]() pt.X = Convert::ToInt32(xy[0]); pt.Y = Convert::ToInt32(xy[1]); ![]() } SqlString Quadrant ![]() { ![]() ![]() ![]() { ![]() } SqlString ![]() ![]() ![]() { ![]() } ![]() ![]() { ![]() } ![]() ![]() { ![]() } ![]() ![]() { ![]() ![]() } ![]() ![]() { ![]() ![]() } ![]() ![]() { ![]() ![]() } ![]() ![]() } }; 将用于执行和测试用户定义类型 (Po ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 复制代码 CREATE TABLE test_table (column1 Po ![]() go INSERT INTO test_table (column1) VALUES ('1:2') INSERT INTO test_table (column1) VALUES ('-2:3') INSERT INTO test_table (column1) VALUES ('-3:-4') select column1.Quadrant ![]() 0
相关文章
读者评论发表评论 |
|