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