/
Misc.vb
executable file
·798 lines (667 loc) · 36.7 KB
/
Misc.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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
' ___________________________________________________
'
' © Hi-Integrity Systems 2010. All rights reserved.
' www.hisystems.com.au - Toby Wicks
' ___________________________________________________
'
Option Strict On
Option Explicit On
Namespace SQL
Module Misc
Public Function SQLConvertIdentifierName( _
ByVal strIdentifierName As String, _
ByVal eConnectionType As Database.ConnectionType) As String
'This function places tags around a field name or table name to ensure it doesn't
'conflict with a reserved word or if it contains spaces it is not misinterpreted
Select Case eConnectionType
Case Database.ConnectionType.MicrosoftAccess, _
Database.ConnectionType.SQLServer, _
Database.ConnectionType.SQLServerCompactEdition
Return "[" & strIdentifierName.Trim & "]"
Case Database.ConnectionType.MySQL
Return "`" & strIdentifierName.Trim & "`"
Case Database.ConnectionType.Pervasive
Return """" & strIdentifierName.Trim & """"
Case Database.ConnectionType.HyperSQL
Return """" & strIdentifierName.Trim & """"
Case Else
Throw New NotImplementedException(eConnectionType.ToString)
End Select
End Function
Public Function SQLConvertValue( _
ByVal objValue As Object, _
ByVal eConnectionType As Database.ConnectionType) As String
If SQLValueIsNull(objValue) Then
Return "NULL"
ElseIf TypeOf objValue Is Boolean Then
Dim bBoolean As Boolean = DirectCast(objValue, Boolean)
If bBoolean Then
Return "1"
Else
Return "0"
End If
ElseIf TypeOf objValue Is Char Then
Dim chChar As Char = DirectCast(objValue, Char)
If chChar.Equals("'") Then
Select Case eConnectionType
Case Database.ConnectionType.MicrosoftAccess, _
Database.ConnectionType.SQLServer, _
Database.ConnectionType.SQLServerCompactEdition, _
Database.ConnectionType.Pervasive, _
Database.ConnectionType.HyperSQL
Return "''''"
Case Database.ConnectionType.MySQL
Return "'\''"
Case Else
Throw New NotImplementedException(eConnectionType.ToString)
End Select
ElseIf chChar.Equals("\") Then
Select Case eConnectionType
Case Database.ConnectionType.MicrosoftAccess, _
Database.ConnectionType.SQLServer, _
Database.ConnectionType.SQLServerCompactEdition, _
Database.ConnectionType.Pervasive, _
Database.ConnectionType.HyperSQL
Return "\"
Case Database.ConnectionType.MySQL
Return "\\"
Case Else
Throw New NotImplementedException(eConnectionType.ToString)
End Select
Else
Return "'" & chChar & "'"
End If
ElseIf TypeOf objValue Is DateTime Then
Dim dtDate As Date = DirectCast(objValue, DateTime)
Dim strDate As String
'If the date hasn't been set then set to the 1899-12-30 so that
'the date isn't set to 2001-01-01
If dtDate.Day = 1 And dtDate.Month = 1 And dtDate.Year = 1 Then
strDate = "1899-12-30"
Else
strDate = dtDate.Year & "-" & dtDate.Month & "-" & dtDate.Day
End If
If dtDate.Hour <> 0 Or dtDate.Minute <> 0 Or dtDate.Second <> 0 Then
strDate &= " " & dtDate.Hour & ":" & dtDate.Minute & ":" & dtDate.Second & "." & dtDate.Millisecond
End If
Select Case eConnectionType
Case Database.ConnectionType.MicrosoftAccess
Return "#" & strDate & "#"
Case Database.ConnectionType.MySQL, _
Database.ConnectionType.SQLServer, _
Database.ConnectionType.SQLServerCompactEdition, _
Database.ConnectionType.Pervasive, _
Database.ConnectionType.HyperSQL
Return "'" & strDate & "'"
Case Else
Throw New NotImplementedException(eConnectionType.ToString)
End Select
ElseIf TypeOf objValue Is String Then
Select Case eConnectionType
Case Database.ConnectionType.MicrosoftAccess, _
Database.ConnectionType.SQLServer, _
Database.ConnectionType.SQLServerCompactEdition, _
Database.ConnectionType.Pervasive, _
Database.ConnectionType.HyperSQL
Return "'" & DirectCast(objValue, String).Replace("'"c, "''") & "'"
Case Database.ConnectionType.MySQL
'Replace the \ escape character with \\ and replace single quotes with two single quotes
Return "'" & DirectCast(objValue, String).Replace("\"c, "\\").Replace("'"c, "\'") & "'"
Case Else
Throw New NotImplementedException(eConnectionType.ToString)
End Select
ElseIf TypeOf objValue Is Byte() Then
Select Case eConnectionType
Case Database.ConnectionType.MicrosoftAccess, _
Database.ConnectionType.SQLServer, _
Database.ConnectionType.SQLServerCompactEdition, _
Database.ConnectionType.Pervasive, _
Database.ConnectionType.MySQL
Return SQLConvertBinaryArray("0x", CType(objValue, Byte()), String.Empty)
Case Database.ConnectionType.HyperSQL
Return SQLConvertBinaryArray("x'", CType(objValue, Byte()), "'")
Case Else
Throw New NotImplementedException(eConnectionType.ToString)
End Select
ElseIf TypeOf objValue Is System.Guid Then
Return "'" & DirectCast(objValue, System.Guid).ToString("D") & "'"
Else
Return CType(objValue, String)
End If
End Function
Private Function SQLConvertBinaryArray(ByVal strHexPrefix As String, ByVal bytData As Byte(), ByVal strHexSuffix As String) As String
Dim objHexData As New System.Text.StringBuilder(strHexPrefix, (bytData.Length * 2) + strHexPrefix.Length + strHexSuffix.Length)
For Each bytByte As Byte In bytData
objHexData.Append(String.Format("{0:X2}", bytByte))
Next
objHexData.Append(strHexSuffix)
Return objHexData.ToString
End Function
Public Function SQLValueIsNull(ByVal objValue As Object) As Boolean
If objValue Is Nothing Then
Return True
ElseIf objValue Is DBNull.Value Then
Return True
Else
Return False
End If
End Function
Public Function SQLConvertAggregate(ByVal eAggregate As SQL.AggregateFunction) As String
Dim strAggregate As String
Select Case eAggregate
Case SQL.AggregateFunction.Average
strAggregate = "AVG"
Case AggregateFunction.Count
strAggregate = "COUNT"
Case AggregateFunction.Maximum
strAggregate = "MAX"
Case AggregateFunction.Minimum
strAggregate = "MIN"
Case AggregateFunction.StandardDeviation
strAggregate = "STDEV"
Case AggregateFunction.Sum
strAggregate = "SUM"
Case AggregateFunction.Variance
strAggregate = "VAR"
Case Else
Throw New NotSupportedException
End Select
Return strAggregate
End Function
Public Function SQLConvertCompare(ByVal eCompare As SQL.ComparisonOperator) As String
Dim strCompare As String
Select Case eCompare
Case ComparisonOperator.EqualTo
strCompare = "="
Case ComparisonOperator.GreaterThan
strCompare = ">"
Case ComparisonOperator.GreaterThanOrEqualTo
strCompare = ">="
Case ComparisonOperator.LessThan
strCompare = "<"
Case ComparisonOperator.LessThanOrEqualTo
strCompare = "<="
Case ComparisonOperator.Like
strCompare = "LIKE"
Case ComparisonOperator.NotLike
strCompare = "NOT LIKE"
Case ComparisonOperator.NotEqualTo
strCompare = "<>"
Case Else
Throw New NotSupportedException
End Select
Return strCompare
End Function
Public Function SQLConvertLogicalOperator(ByVal eLogicalOperator As SQL.LogicalOperator) As String
Dim strLogicalOperator As String
Select Case eLogicalOperator
Case LogicalOperator.And
strLogicalOperator = "AND"
Case LogicalOperator.Or
strLogicalOperator = "OR"
Case Else
Throw New NotSupportedException
End Select
Return strLogicalOperator
End Function
Public Function SQLFieldNameAndTablePrefix( _
ByVal objTable As SQLSelectTable, _
ByVal strFieldName As String, _
ByVal eConnectionType As Database.ConnectionType) As String
Dim strTablePrefix As String = String.Empty
If objTable IsNot Nothing Then
strTablePrefix = SQLTablePrefix(objTable, eConnectionType) & "."
End If
Return strTablePrefix & SQLConvertIdentifierName(strFieldName, eConnectionType)
End Function
''' <summary>
''' Returns the table alias or if the alias is not set the table's name.
''' </summary>
Public Function SQLTablePrefix( _
ByVal objTable As SQLSelectTable, _
ByVal eConnectionType As Database.ConnectionType) As String
If objTable.Alias <> String.Empty Then
Return SQLConvertIdentifierName(objTable.Alias, eConnectionType)
Else
Return SQLConvertIdentifierName(objTable.Name, eConnectionType)
End If
End Function
Public Function SQLConditionValue(ByVal objValue As Object) As Object
If TypeOf objValue Is SQLFieldValue Then
Dim objSQLFieldValue As SQLFieldValue = DirectCast(objValue, SQLFieldValue)
Return objSQLFieldValue.Value
Else
Return objValue
End If
End Function
Public Sub CompareValuePairAssertValid( _
ByVal eCompare As SQL.ComparisonOperator, _
ByVal objValue As Object)
If Not TypeOf objValue Is String And (eCompare = ComparisonOperator.Like Or eCompare = ComparisonOperator.NotLike) Then
Throw New Exceptions.DatabaseObjectsException("The LIKE operator cannot be used in conjunction with a non-string data type")
ElseIf TypeOf objValue Is Boolean And Not (eCompare = ComparisonOperator.EqualTo Or eCompare = ComparisonOperator.NotEqualTo) Then
Throw New Exceptions.DatabaseObjectsException("A boolean value can only be used in conjunction with the " & ComparisonOperator.EqualTo.ToString & " or " & ComparisonOperator.NotEqualTo.ToString & " operators")
End If
End Sub
Public Sub SQLConvertBooleanValue( _
ByRef objValue As Object, _
ByRef eCompare As SQL.ComparisonOperator)
'If a boolean variable set to true then use the NOT
'operator and compare it to 0. ie. if the condition is 'field = true' then
'SQL code should be 'field <> 0'
'-1 is true in MSAccess and 1 is true in SQLServer.
If TypeOf objValue Is Boolean Then
If DirectCast(objValue, Boolean) = True Then
If eCompare = ComparisonOperator.EqualTo Then
eCompare = ComparisonOperator.NotEqualTo
Else
eCompare = ComparisonOperator.EqualTo
End If
objValue = False
End If
End If
End Sub
Public Function SQLConvertCondition( _
ByVal eCompare As ComparisonOperator, _
ByVal objValue As Object, _
ByVal eConnectionType As Database.ConnectionType) As String
Dim strSQL As String = String.Empty
SQLConvertBooleanValue(objValue, eCompare)
'Return 'IS NULL' rather than '= NULL'
If SQLValueIsNull(objValue) Then
If eCompare = ComparisonOperator.EqualTo Then
strSQL &= "IS " & SQLConvertValue(objValue, eConnectionType)
ElseIf eCompare = ComparisonOperator.NotEqualTo Then
strSQL &= "IS NOT " & SQLConvertValue(objValue, eConnectionType)
Else
Throw New Exceptions.DatabaseObjectsException("DBNull or Nothing/null specified as an SQLCondition value using the " & eCompare.ToString & " operator")
End If
Else
strSQL &= _
SQLConvertCompare(eCompare) & " " & _
SQLConvertValue(objValue, eConnectionType)
End If
Return strSQL
End Function
Public Function SQLConvertDataTypeString( _
ByVal eConnection As Database.ConnectionType, _
ByVal eDataType As DataType, _
ByVal intSize As Integer, _
ByVal intPrecision As Integer, _
ByVal intScale As Integer) As String
Dim strDataType As String = String.Empty
Select Case eDataType
Case DataType.TinyInteger
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "BYTE"
Case Database.ConnectionType.MySQL
strDataType = "TINYINT UNSIGNED"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "TINYINT"
Case Database.ConnectionType.Pervasive
strDataType = "TINYINT"
Case Database.ConnectionType.HyperSQL
strDataType = "TINYINT"
End Select
Case DataType.SmallInteger
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "SMALLINT"
Case Database.ConnectionType.MySQL
strDataType = "SMALLINT"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "SMALLINT"
Case Database.ConnectionType.Pervasive
strDataType = "SMALLINT"
Case Database.ConnectionType.HyperSQL
strDataType = "SMALLINT"
End Select
Case DataType.Integer
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "INTEGER"
Case Database.ConnectionType.MySQL
strDataType = "INT"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "INTEGER"
Case Database.ConnectionType.Pervasive
strDataType = "INTEGER"
Case Database.ConnectionType.HyperSQL
strDataType = "INT"
End Select
Case DataType.BigInteger
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "NUMERIC(19,0)"
Case Database.ConnectionType.MySQL
strDataType = "BIGINT"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "BIGINT"
Case Database.ConnectionType.Pervasive
strDataType = "BIGINT"
Case Database.ConnectionType.HyperSQL
strDataType = "BIGINT"
End Select
Case DataType.Character
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "TEXT(" & intSize & ")"
Case Database.ConnectionType.MySQL
strDataType = "CHAR(" & intSize & ")"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "CHAR(" & intSize & ")"
Case Database.ConnectionType.Pervasive
strDataType = "CHAR(" & intSize & ")"
Case Database.ConnectionType.HyperSQL
strDataType = "CHAR(" & intSize & ")"
End Select
Case DataType.UnicodeCharacter
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
'Unicode is only supported in Microsoft Access 2000+
strDataType = "TEXT(" & intSize & ")"
Case Database.ConnectionType.MySQL
strDataType = "NCHAR(" & intSize & ")"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "NCHAR(" & intSize & ")"
Case Database.ConnectionType.Pervasive
'Unable to verify this is correct.
strDataType = "CHAR(" & intSize & ")"
Case Database.ConnectionType.HyperSQL
strDataType = "CHAR(" & intSize & ")"
End Select
Case DataType.VariableCharacter
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "TEXT(" & intSize & ")"
Case Database.ConnectionType.MySQL
strDataType = "VARCHAR(" & intSize & ")"
Case Database.ConnectionType.SQLServer
strDataType = "VARCHAR(" & intSize & ")"
Case Database.ConnectionType.Pervasive
strDataType = "VARCHAR(" & intSize & ")"
Case Database.ConnectionType.SQLServerCompactEdition
strDataType = "VARCHAR(" & intSize & ")"
Case Database.ConnectionType.HyperSQL
strDataType = "VARCHAR(" & intSize & ")"
End Select
Case DataType.UnicodeVariableCharacter
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
'Unicode is only supported in Microsoft Access 2000+
strDataType = "TEXT(" & intSize & ")"
Case Database.ConnectionType.MySQL
strDataType = "NVARCHAR(" & intSize & ")"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "NVARCHAR(" & intSize & ")"
Case Database.ConnectionType.Pervasive
'Unable to verify this is correct.
strDataType = "VARCHAR(" & intSize & ")"
Case Database.ConnectionType.HyperSQL
strDataType = "VARCHAR(" & intSize & ")"
End Select
Case DataType.Decimal
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "NUMERIC(" & intPrecision & "," & intScale & ")"
Case Database.ConnectionType.MySQL
strDataType = "DECIMAL(" & intPrecision & "," & intScale & ")"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "NUMERIC(" & intPrecision & "," & intScale & ")"
Case Database.ConnectionType.Pervasive
strDataType = "NUMERIC(" & intPrecision & "," & intScale & ")"
Case Database.ConnectionType.HyperSQL
strDataType = "NUMBER(" & intPrecision & "," & intScale & ")"
End Select
Case DataType.Real
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "REAL"
Case Database.ConnectionType.MySQL
strDataType = "FLOAT"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "REAL"
Case Database.ConnectionType.Pervasive
strDataType = "REAL"
Case Database.ConnectionType.HyperSQL
strDataType = "DOUBLE"
End Select
Case DataType.Float
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "FLOAT"
Case Database.ConnectionType.MySQL
strDataType = "DOUBLE"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "FLOAT"
Case Database.ConnectionType.Pervasive
strDataType = "FLOAT"
Case Database.ConnectionType.HyperSQL
strDataType = "DOUBLE"
End Select
Case DataType.SmallMoney
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "NUMERIC(10,4)"
Case Database.ConnectionType.MySQL
strDataType = "DECIMAL(10,4)"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "SMALLMONEY"
Case Database.ConnectionType.Pervasive
strDataType = "DECIMAL(10,4)"
Case Database.ConnectionType.SQLServerCompactEdition
strDataType = "MONEY"
Case Database.ConnectionType.HyperSQL
strDataType = "NUMBER(10,4)"
End Select
Case DataType.Money
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "NUMERIC(19,4)"
Case Database.ConnectionType.MySQL
strDataType = "DECIMAL(19,4)"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "MONEY"
Case Database.ConnectionType.Pervasive
strDataType = "DECIMAL(19,4)"
Case Database.ConnectionType.HyperSQL
strDataType = "NUMBER(19,4)"
End Select
Case DataType.Boolean
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "YESNO"
Case Database.ConnectionType.MySQL
strDataType = "BOOLEAN"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "BIT"
Case Database.ConnectionType.Pervasive
strDataType = "BIT"
Case Database.ConnectionType.HyperSQL
strDataType = "BOOLEAN"
End Select
Case DataType.SmallDateTime
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "DATETIME"
Case Database.ConnectionType.MySQL
strDataType = "DATETIME"
Case Database.ConnectionType.SQLServer
strDataType = "SMALLDATETIME"
Case Database.ConnectionType.Pervasive
strDataType = "DATETIME"
Case Database.ConnectionType.SQLServerCompactEdition
strDataType = "DATETIME"
Case Database.ConnectionType.HyperSQL
strDataType = "DATE"
End Select
Case DataType.DateTime
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "DATETIME"
Case Database.ConnectionType.MySQL
strDataType = "DATETIME"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "DATETIME"
Case Database.ConnectionType.Pervasive
strDataType = "DATETIME"
Case Database.ConnectionType.HyperSQL
strDataType = "DATE"
End Select
Case DataType.TimeStamp
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
Throw New NotSupportedException("TIMESTAMP")
Case Database.ConnectionType.MySQL
strDataType = "TIMESTAMP"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "TIMESTAMP"
Case Database.ConnectionType.Pervasive
strDataType = "TIMESTAMP"
Case Database.ConnectionType.HyperSQL
strDataType = "TIMESTAMP"
End Select
Case DataType.Text
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "MEMO"
Case Database.ConnectionType.MySQL
strDataType = "LONGTEXT"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "TEXT"
Case Database.ConnectionType.Pervasive
strDataType = "LONGVARCHAR"
Case Database.ConnectionType.HyperSQL
strDataType = "CLOB(2G)"
End Select
Case DataType.UnicodeText
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
'Unicode is only supported in Microsoft Access 2000+
strDataType = "MEMO"
Case Database.ConnectionType.MySQL
strDataType = "LONGTEXT CHARACTER SET UTF8"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "NTEXT"
Case Database.ConnectionType.Pervasive
strDataType = "LONGVARCHAR"
Case Database.ConnectionType.HyperSQL
strDataType = "CLOB(2G)"
End Select
Case DataType.Binary
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "OLEOBJECT"
Case Database.ConnectionType.MySQL
strDataType = "BLOB"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "BINARY"
Case Database.ConnectionType.Pervasive
strDataType = "BINARY"
Case Database.ConnectionType.HyperSQL
strDataType = "BINARY(8000)"
End Select
Case DataType.VariableBinary
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "OLEOBJECT"
Case Database.ConnectionType.MySQL
strDataType = "BLOB"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "VARBINARY"
Case Database.ConnectionType.Pervasive
strDataType = "LONGVARBINARY"
Case Database.ConnectionType.HyperSQL
strDataType = "VARBINARY(8000)"
End Select
Case DataType.Image
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "IMAGE"
Case Database.ConnectionType.MySQL
strDataType = "LONGBLOB"
Case Database.ConnectionType.SQLServer, Database.ConnectionType.SQLServerCompactEdition
strDataType = "IMAGE"
Case Database.ConnectionType.Pervasive
strDataType = "LONGVARBINARY"
Case Database.ConnectionType.HyperSQL
strDataType = "BLOB(2G)"
End Select
Case DataType.UniqueIdentifier
Select Case eConnection
Case Database.ConnectionType.MicrosoftAccess
strDataType = "UNIQUEIDENTIFIER"
Case Database.ConnectionType.MySQL
strDataType = "UNIQUEIDENTIFIER"
Case Database.ConnectionType.Pervasive
strDataType = "UNIQUEIDENTIFIER"
Case Database.ConnectionType.SQLServer
strDataType = "UNIQUEIDENTIFIER"
Case Database.ConnectionType.SQLServerCompactEdition
strDataType = "UNIQUEIDENTIFIER"
Case Database.ConnectionType.HyperSQL
strDataType = "UNIQUEIDENTIFIER"
End Select
Case Else
Throw New NotImplementedException("Data type " & eDataType.ToString)
End Select
If strDataType = String.Empty Then
Throw New NotImplementedException("Data type " & eDataType.ToString & " is not implemented for connection type " & eConnection.ToString)
End If
Return strDataType
End Function
Public Sub DataTypeEnsureIsDecimal(ByVal eDataType As DataType)
If eDataType <> DataType.Decimal Then
Throw New Exceptions.MethodLockedException("First set Type to " & DataType.Decimal.ToString)
End If
End Sub
Public Sub DataTypeEnsureIsCharacter(ByVal eDataType As SQL.DataType)
If Not DataTypeIsCharacter(eDataType) Then
Throw New Exceptions.MethodLockedException("Data type is not character based")
End If
End Sub
Public Sub DataTypeEnsureIsInteger(ByVal eDataType As SQL.DataType)
If Not DataTypeIsInteger(eDataType) Then
Throw New Exceptions.MethodLockedException
End If
End Sub
Public Function DataTypeIsInteger(ByVal eDataType As SQL.DataType) As Boolean
Select Case eDataType
Case DataType.BigInteger, DataType.Integer, DataType.SmallInteger, DataType.TinyInteger
Return True
Case Else
Return False
End Select
End Function
Public Function DataTypeIsCharacter(ByVal eDataType As DataType) As Boolean
Select Case eDataType
Case _
DataType.Character, DataType.UnicodeCharacter, _
DataType.VariableCharacter, DataType.UnicodeVariableCharacter
Return True
Case Else
Return False
End Select
End Function
''' <summary>
''' All keys are returned in lower case.
''' </summary>
''' <exception cref="FormatException">If the connection string is in an invalid format.</exception>
Friend Function GetDictionaryFromConnectionString(ByVal strConnectionString As String) As System.Collections.Generic.IDictionary(Of String, String)
Dim objDictionary As New System.Collections.Generic.Dictionary(Of String, String)
Dim strPropertyValueArray() As String
For Each strPropertyValue As String In strConnectionString.Split(";"c)
If Not String.IsNullOrEmpty(strPropertyValue) Then
strPropertyValueArray = strPropertyValue.Split("="c)
If strPropertyValueArray.Length = 2 Then
objDictionary.Add(strPropertyValueArray(0).Trim.ToLower, strPropertyValueArray(1).Trim)
Else
Throw New FormatException("Invalid key property definition for '" & strPropertyValue & "' from '" & strConnectionString & "'")
End If
End If
Next
Return objDictionary
End Function
End Module
End Namespace