Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cddf1c0

Browse files
Multiple tables (#35)
Fix for #33 * Added a ArrayPush helper to simplify future code changes * Updated addTable to allow uses to call it multiple times. * Updated addJoin to correctly format multiple "unjoined" tables.
1 parent 4c3a452 commit cddf1c0

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

‎src/ClassModules/SQLSelect.cls‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ End Sub
7575
' Sub: addTable
7676
' Add a table to the query statement
7777
Public Sub addTable(sName As String, Optional sAlias As String = "")
78-
aJoin(0) = Array("", sName, sAlias, "")
78+
aJoin = ArrayPush(aJoin, Array("", sName, sAlias, ""))
7979
End Sub
8080

8181
' Sub: AddHaving
@@ -226,6 +226,8 @@ Private Function JoinString()
226226
Line = ""
227227
If LineArray(0) <> "" Then
228228
Line = LineArray(0) & " JOIN "
229+
ElseIf R > 0 Then
230+
Lines(R - 1) = Lines(R - 1) & ","
229231
End If
230232
Line = Line & LineArray(1)
231233
If LineArray(2) <> "" Then

‎src/Modules/SQLHelperFunctions.bas‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,13 @@ Public Sub QuickSort(vArray As Variant, inLow As Long, inHi As Long)
7474
QuickSort vArray, tmpLow, inHi
7575
End If
7676
End Sub
77+
78+
Public Function ArrayPush(vArray As Variant, newValue As Variant)
79+
ArrLen = UBound(vArray)
80+
If IsEmpty(vArray(0)) Then
81+
ArrLen = -1
82+
End If
83+
ReDim Preserve vArray(0 To ArrLen + 1)
84+
vArray(ArrLen + 1) = newValue
85+
ArrayPush = vArray
86+
End Function

‎testing/ClassModules/SQLlibSelectTests.cls‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,18 @@ Function DistinctTest()
8181
DistinctTest = AssertObjectStringEquals(Interfaced, "SELECT DISTINCT c.country FROM customers c ORDER BY c.country ASC")
8282
End Function
8383

84+
Function MultipleTableTest()
85+
'Distinct
86+
Set MySelect = Create_SQLSelect
87+
With MySelect
88+
.AddTable "countries", "c"
89+
.AddTable "users", "u"
90+
.Fields = Array("u.uname", "c.capital")
91+
End With
92+
Set Interfaced = MySelect
93+
MultipleTableTest = AssertObjectStringEquals(Interfaced, "SELECT u.uname, c.capital FROM countries c, users u")
94+
End Function
95+
8496
' Sub: iTestCase_RunTest
8597
' Run a specific test.
8698
Public Sub iTestCase_RunTest(Test As String, Optional clsObj = Nothing)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /