-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStatement.vb
More file actions
114 lines (89 loc) · 3.41 KB
/
Statement.vb
File metadata and controls
114 lines (89 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
Imports System.ComponentModel
Imports System.Data.Common
Imports System.Data.SqlClient
Public Class Statement
Inherits Databasic.Statement
''' <summary>
''' Currently prepared and executed Microsoft SQL command.
''' </summary>
Public Overrides Property Command As DbCommand
Get
Return Me._cmd
End Get
Set(value As DbCommand)
Me._cmd = value
End Set
End Property
Private _cmd As SqlCommand
''' <summary>
''' Currently executed Microsoft SQL data reader from Microsoft SQL command.
''' </summary>
Public Overrides Property Reader As DbDataReader
Get
Return Me._reader
End Get
Set(value As DbDataReader)
Me._reader = value
End Set
End Property
Private _reader As SqlDataReader
''' <summary>
''' Empty SQL statement constructor.
''' </summary>
''' <param name="sql">SQL statement code.</param>
''' <param name="connection">Connection instance.</param>
Public Sub New(sql As String, connection As SqlConnection)
MyBase.New(sql, connection)
Me._cmd = New SqlCommand(sql, connection)
Me._cmd.Prepare()
End Sub
''' <summary>
''' Empty SQL statement constructor.
''' </summary>
''' <param name="sql">SQL statement code.</param>
''' <param name="transaction">SQL transaction instance with connection instance inside.</param>
Public Sub New(sql As String, transaction As SqlTransaction)
MyBase.New(sql, transaction)
Me._cmd = New SqlCommand(sql, transaction.Connection, transaction)
Me._cmd.Prepare()
End Sub
''' <summary>
''' Set up all sql params into internal Command instance.
''' </summary>
''' <param name="sqlParams">Anonymous object with named keys as Microsoft SQL statement params without any '@' chars in object keys.</param>
Protected Overrides Sub addParamsWithValue(sqlParams As Object)
If (Not sqlParams Is Nothing) Then
Dim sqlParamValue As Object
For Each prop As PropertyDescriptor In TypeDescriptor.GetProperties(sqlParams)
sqlParamValue = prop.GetValue(sqlParams)
If (sqlParamValue Is Nothing) Then
sqlParamValue = DBNull.Value
Else
sqlParamValue = Me.getPossibleUnderlyingEnumValue(sqlParamValue)
End If
Me._cmd.Parameters.AddWithValue(
prop.Name, sqlParamValue
)
Next
End If
End Sub
''' <summary>
''' Set up all sql params into internal Command instance.
''' </summary>
''' <param name="sqlParams">Dictionary with named keys as Microsoft SQL statement params without any '@' chars in dictionary keys.</param>
Protected Overrides Sub addParamsWithValue(sqlParams As Dictionary(Of String, Object))
Dim sqlParamValue As Object
If (Not sqlParams Is Nothing) Then
For Each pair As KeyValuePair(Of String, Object) In sqlParams
If (pair.Value Is Nothing) Then
sqlParamValue = DBNull.Value
Else
sqlParamValue = Me.getPossibleUnderlyingEnumValue(pair.Value)
End If
Me._cmd.Parameters.AddWithValue(
pair.Key, sqlParamValue
)
Next
End If
End Sub
End Class