-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStatement.vb
108 lines (90 loc) · 3.45 KB
/
Statement.vb
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
Imports System.ComponentModel
Imports System.Data.Common
Imports System.Data.SQLite
Imports SQLite.Data.SQLiteClient
Public Class Statement
Inherits Databasic.Statement
''' <summary>
''' Currently prepared and executed MySQL/MariaDB 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 SQLiteCommand
''' <summary>
''' Currently executed MySQL/MariaDB data reader from MySQL/MariaDB 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 SQLiteDataReader
''' <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 SQLiteConnection)
MyBase.New(sql, connection)
Me._cmd = New SQLiteCommand(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 SQLiteTransaction)
MyBase.New(sql, transaction)
Me._cmd = New SQLiteCommand(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 MySQL/MariaDB statement params without any '@' chars in object keys.</param>
Protected Overrides Sub addParamsWithValue(sqlParams As Object)
Dim sqlParamValue As Object
If (Not sqlParams Is Nothing) Then
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 MySQL/MariaDB 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