-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySqlColumn.vb
266 lines (228 loc) · 8.38 KB
/
MySqlColumn.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
Public Class MySqlColumn
#Region " Class Constants and Variables "
#Region " Constants "
#End Region
#Region " Enums "
#End Region
#Region " Private Vars "
Private _autoInc As Boolean = False
Private _columnName As String
Private _dataType As MySqlDataType
Private _defaultValue As String
Private _keyField As Boolean = False
Private _isNullable As Boolean = True
Private _length As Integer
Private _onUpdate As String = String.Empty
Private _precision As Integer
#End Region
#End Region
#Region " New "
Public Sub New(columnName As String,
columnType As MySqlDataType,
Optional autoInc As Boolean = False,
Optional keyField As Boolean = False,
Optional defaultValue As String = "",
Optional isNullable As Boolean = True)
' vars passed:
' aColumnName - name for the column
' aColumnType - column type
' aKeyField - is column a key field
' aDefaultValue - columns's default value as a string
Me.ColumnName = columnName
_autoInc = autoInc
Me.DataType = columnType
Me.KeyField = keyField
Me.DefaultValue = defaultValue
Me.IsNullable = isNullable
End Sub
Public Sub New(columnName As String,
columnType As MySqlDataType,
Length As Integer,
Optional keyField As Boolean = False,
Optional defaultValue As String = "",
Optional isNullable As Boolean = True)
' vars passed:
' ColumnName - name for the column
' ColumnType - column type
' Length - length of text in a text column or total digits in decimal column
' aKeyField - is column a key field
' aDefaultValue - columns's default value as a string
Me.New(columnName, columnType, False, keyField, defaultValue, isNullable)
Me.Length = Length
End Sub
Public Sub New(columnName As String,
Length As Integer,
Precision As Integer,
Optional keyField As Boolean = False,
Optional defaultValue As String = "",
Optional isNullable As Boolean = True)
' vars passed:
' ColumnName - name for the column
' Length - total digits in decimal column
' Precision - number of digits right of decimal point
' TextLength - length of text in a text column
' KeyField - is column a key field
' DefaultValue - columns's default value as a string
Me.New(columnName, MySqlDataType.dtDecimal, Length, keyField, defaultValue, isNullable)
Me.Precision = Precision
End Sub
#End Region
#Region " Properties "
Property AutoInc As Boolean
Get
Return _autoInc
End Get
Set(value As Boolean)
Try
_autoInc = value
Catch ex As Exception
_autoInc = False
End Try
End Set
End Property
Property ColumnName() As String
Get
Return _columnName
End Get
Set(ByVal Value As String)
Try
_columnName = Value
Catch ex As Exception
_columnName = String.Empty
End Try
End Set
End Property
Property DataType() As MySqlDataType
Get
Return _dataType
End Get
Set(ByVal Value As MySqlDataType)
Try
If (Value Is MySqlDataType.dtBoolean) OrElse (Value Is MySqlDataType.dtDecimal) OrElse
(Value Is MySqlDataType.dtDate) OrElse (Value Is MySqlDataType.dtDateTime) OrElse
(Value Is MySqlDataType.dtTimeStamp) OrElse (Value Is MySqlDataType.dtFloat) OrElse
(Value Is MySqlDataType.dtDouble) OrElse (Value Is MySqlDataType.dtTinyInt) OrElse
(Value Is MySqlDataType.dtSmallInt) OrElse (Value Is MySqlDataType.dtInteger) OrElse
(Value Is MySqlDataType.dtBigInt) OrElse (Value Is MySqlDataType.dtText) OrElse
(Value Is MySqlDataType.dtVarChar) Then ' if a valid type
_dataType = Value ' then set column type
Else ' else type is none or not valid
_dataType = MySqlDataType.dtNone ' return none
End If
Catch ex As Exception
_dataType = MySqlDataType.dtNone
End Try
End Set
End Property
Property DefaultValue As String
Get
Return _defaultValue
End Get
Set(value As String)
Try
_defaultValue = value
Catch ex As Exception
_defaultValue = ""
End Try
End Set
End Property
Property KeyField() As Boolean
Get
Return _keyField
End Get
Set(ByVal Value As Boolean)
Try
If (_dataType Is MySqlDataType.dtNone) OrElse (_dataType Is MySqlDataType.dtText) Then ' if col type is none or text
_keyField = False ' cannot be key field
Else ' else col can be key field
_keyField = Value ' set key field property
End If
Catch ex As Exception
_keyField = False
End Try
End Set
End Property
Property IsNullable As Boolean
Get
Return _isNullable
End Get
Set(value As Boolean)
Try
_isNullable = value
Catch ex As Exception
_isNullable = True
End Try
End Set
End Property
Property Length() As Integer
Get
Return _length
End Get
Set(ByVal Value As Integer)
Try
' if col type is text or varChar or decimal
If _dataType Is MySqlDataType.dtText OrElse _dataType Is MySqlDataType.dtVarChar OrElse _dataType Is MySqlDataType.dtDecimal Then
_length = Value ' then set text length
Else ' else not a a text or varChar col
_length = -1 ' set text length to -1
End If
Catch ex As Exception
_length = -1
End Try
End Set
End Property
Property OnUpdate As String
Get
Return _onUpdate
End Get
Set(value As String)
Try
_onUpdate = value
Catch ex As Exception
_onUpdate = String.Empty
End Try
End Set
End Property
Property Precision As Integer
Get
Return _precision
End Get
Set(value As Integer)
Try
If _dataType Is MySqlDataType.dtDecimal Then
_precision = value
Else
_precision = -1
End If
Catch ex As Exception
_precision = -1
End Try
End Set
End Property
ReadOnly Property SqlDataType() As String
Get
Return _dataType.ToString
End Get
End Property
#End Region
#Region " Methods "
Public Sub CopyTo(copyToCol As MySqlColumn)
' copies to another mySql column
'
' vars passed:
' CoptToCol - column to copy to
'
Try
copyToCol._autoInc = _autoInc
copyToCol._columnName = _columnName
copyToCol._dataType = _dataType
copyToCol._defaultValue = _defaultValue
copyToCol._isNullable = _isNullable
copyToCol._keyField = _keyField
copyToCol._length = _length
Catch ex As Exception
Return
End Try
End Sub
#End Region
End Class