-
Notifications
You must be signed in to change notification settings - Fork 6
/
SQLSelectTableJoin.cls
executable file
·134 lines (92 loc) · 3.22 KB
/
SQLSelectTableJoin.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
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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "SQLSelectTableJoin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
' ___________________________________________________
'
' © Hi-Integrity Systems 2007. All rights reserved.
' www.hisystems.com.au - Toby Wicks
' ___________________________________________________
'
Option Explicit
Private pobjLeftTable As SQLSelectTable
Private pobjRightTable As SQLSelectTable
Private pobjConditions As SQLSelectTableJoinConditions
Private pobjParent As SQLSelectTableJoins
Public TheType As SQLJoinEnum
Friend Property Set Parent(ByVal objParent As SQLSelectTableJoins)
Set pobjParent = objParent
End Property
Public Property Set LeftTable(ByVal objValue As SQLSelectTable)
If objValue Is Nothing Then
RaiseError dboErrorObjectIsNothing
End If
Set pobjLeftTable = objValue
End Property
Public Property Get LeftTable() As SQLSelectTable
Set LeftTable = pobjLeftTable
End Property
Public Property Set RightTable(ByVal objValue As SQLSelectTable)
If objValue Is Nothing Then
RaiseError dboErrorObjectIsNothing
End If
Set pobjRightTable = objValue
End Property
Public Property Get RightTable() As SQLSelectTable
Set RightTable = pobjRightTable
End Property
Public Property Get Where() As SQLSelectTableJoinConditions
Set Where = pobjConditions
End Property
Public Property Set Where(ByVal objValue As SQLSelectTableJoinConditions)
Set pobjConditions = objValue
End Property
Friend Property Get SQL(ByVal eConnectionType As ConnectionTypeEnum) As String
Dim strSQL As String
Dim strJoin As String
Select Case Me.TheType
Case dboInnerJoin
strJoin = "INNER JOIN"
Case dboFullOuterJoin
strJoin = "FULL OUTER JOIN"
Case dboLeftOuterJoin
strJoin = "LEFT OUTER JOIN"
Case dboRightOuterJoin
strJoin = "RIGHT OUTER JOIN"
End Select
If Index = 1 Then
strSQL = pobjLeftTable.SQL(eConnectionType)
Else
strSQL = pobjParent(Index - 1).SQL(eConnectionType)
End If
strSQL = strSQL & " " & strJoin & " " & pobjRightTable.SQL(eConnectionType)
If Not pobjConditions Is Nothing Then
If pobjConditions.SQL(eConnectionType) <> vbNullString Then
strSQL = strSQL & " ON " & pobjConditions.SQL(eConnectionType)
End If
End If
'Surround the join with parentheses - MS Access won't accept is otherwise
SQL = "(" & strSQL & ")"
End Property
Private Function Index() As Integer
Dim intIndex As Integer
For intIndex = 1 To pobjParent.Count
If pobjParent(intIndex) Is Me Then
Exit For
End If
Next
Index = intIndex
End Function
Private Sub Class_Initialize()
Set pobjConditions = New SQLSelectTableJoinConditions
Set pobjConditions.Parent = Me
End Sub