-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSqlResultRow.cls
97 lines (68 loc) · 2.39 KB
/
SqlResultRow.cls
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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "SqlResultRow"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Private Type tRow
ParentResult As SqlResult
Values() As Variant
IsEmpty As Boolean
End Type
Private this As tRow
Option Explicit
Private Sub Class_Initialize()
ReDim this.Values(0 To 0)
this.IsEmpty = True
End Sub
Public Property Set ParentResult(value As SqlResult)
Set this.ParentResult = value
End Property
Friend Sub AddValue(ByVal value As Variant)
If Not this.IsEmpty Then ReDim Preserve this.Values(0 To UBound(this.Values) + 1)
this.Values(UBound(this.Values)) = value
this.IsEmpty = False
End Sub
Public Property Get Item(nameOrIndex As Variant) As Variant
Attribute Item.VB_UserMemId = 0
If TypeName(nameOrIndex) = "String" Then
Item = GetFieldValueByName(nameOrIndex)
ElseIf IsNumeric(nameOrIndex) Then
Item = GetFieldValueByIndex(nameOrIndex)
Else
'return empty variant
End If
End Property
Private Function GetFieldValueByName(ByVal name As String) As Variant
If Not this.IsEmpty Then GetFieldValueByName = this.Values(this.ParentResult.FieldNameIndex(name))
End Function
Private Function GetFieldValueByIndex(ByVal index As Integer) As Variant
If Not this.IsEmpty Then GetFieldValueByIndex = this.Values(index)
End Function
Public Function Create(parent As SqlResult, fields As ADODB.fields) As SqlResultRow
Dim result As New SqlResultRow
Set result.ParentResult = parent
Dim field As ADODB.field
Dim value As Variant
For Each field In fields
If TypeName(field.value) = "String" Then
value = LTrim(RTrim(StringType.Coalesce(field.value, vbNullString)))
Else
value = StringType.Coalesce(field.value, vbEmpty)
End If
result.AddValue value
Next
Set Create = result
End Function
Public Function ToString() As String
If this.IsEmpty Then
ToString = TypeName(Me)
Exit Function
End If
Dim result As String
result = Join(this.Values, this.ParentResult.ValueSeparator)
ToString = result
End Function