Skip to content

Commit 62fe0fd

Browse files
Add support for ! boundary character
This character is used in Microsoft Access in a query when referring directly to a control on a form, and should be treated similar to a period as a separator between elements. #457
1 parent 4328713 commit 62fe0fd

File tree

1 file changed

+70
-6
lines changed

1 file changed

+70
-6
lines changed

Version Control.accda.src/modules/clsSqlFormatter.cls

+70-6
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,8 @@ Public Function FormatSQL(Optional strSql As String, Optional intDialect As eSql
359359
' If the token shouldn't have a space before it
360360
If strTokenValue = "." _
361361
Or strTokenValue = "," _
362-
Or strTokenValue = ";" Then
362+
Or strTokenValue = ";" _
363+
Or (strTokenValue = "!" And m_intDialect = esdAccess) Then
363364
' Trim any whitespace
364365
cReturn.RTrim
365366
End If
@@ -368,7 +369,9 @@ Public Function FormatSQL(Optional strSql As String, Optional intDialect As eSql
368369
cReturn.Add strTokenValue, " "
369370

370371
' If the token shouldn't have a space after it
371-
If strTokenValue = "(" Or strTokenValue = "." Then
372+
If strTokenValue = "(" _
373+
Or strTokenValue = "." _
374+
Or (strTokenValue = "!" And m_intDialect = esdAccess) Then
372375
cReturn.RTrim
373376
End If
374377

@@ -512,7 +515,8 @@ Private Sub Tokenize(strSql As String, intDialect As eSqlDialect)
512515

513516
' A reserved word cannot be preceded by a "."
514517
' This makes it so in "mytable.from", "from" is not considered a reserved word
515-
ElseIf PeekChar(-1, ".") Then
518+
ElseIf PeekChar(-1, ".") _
519+
Or (PeekChar(-1, "!") And m_intDialect = esdAccess) Then
516520

517521
' Likely an object name
518522
If HasMatches("^(.*?)($|\s|[""\'`]|" & RegExBoundaries & ")", strMatch) Then
@@ -1461,9 +1465,69 @@ Public Sub SelfTest()
14611465
If (strActual <> FormatSQL) Then Diff.Strings strActual, FormatSQL
14621466

14631467

1464-
'PrintTokens
1465-
'BuildTestFromTokens
1466-
'Diff.Strings strActual, FormatSQL
1468+
' Test multi-part names
1469+
Tokenize "SELECT [dbo].[field] FROM [server].[schema].[table];", esdMSSQL
1470+
1471+
' Verify tokens
1472+
Debug.Assert m_colTokens.Count = 13
1473+
Debug.Assert VerifyToken(1, ttReservedTopLevel, "SELECT")
1474+
Debug.Assert VerifyToken(2, ttWhitespace, " ")
1475+
Debug.Assert VerifyToken(3, ttQuote, "[dbo]")
1476+
Debug.Assert VerifyToken(4, ttBoundary, ".")
1477+
Debug.Assert VerifyToken(5, ttQuote, "[field]")
1478+
Debug.Assert VerifyToken(6, ttWhitespace, " ")
1479+
Debug.Assert VerifyToken(7, ttReservedTopLevel, "FROM")
1480+
Debug.Assert VerifyToken(8, ttWhitespace, " ")
1481+
Debug.Assert VerifyToken(9, ttQuote, "[server]")
1482+
Debug.Assert VerifyToken(10, ttBoundary, ".")
1483+
Debug.Assert VerifyToken(11, ttQuote, "[schema]")
1484+
Debug.Assert VerifyToken(12, ttBoundary, ".")
1485+
Debug.Assert VerifyToken(13, ttQuote, "[table]")
1486+
1487+
' Verify result
1488+
With New clsConcat
1489+
.AppendOnAdd = vbCrLf
1490+
.Add "SELECT"
1491+
.Add " [dbo].[field]"
1492+
.Add "FROM"
1493+
.Add " [server].[schema].[table]"
1494+
.Remove 2
1495+
strActual = .GetStr
1496+
End With
1497+
Debug.Assert (strActual = FormatSQL)
1498+
If (strActual <> FormatSQL) Then Diff.Strings strActual, FormatSQL
1499+
1500+
1501+
' Test parameter expression
1502+
Tokenize "SELECT [Forms]![frmColors]![Text18];", esdAccess
1503+
1504+
' Verify tokens
1505+
Debug.Assert m_colTokens.Count = 7
1506+
Debug.Assert VerifyToken(1, ttReservedTopLevel, "SELECT")
1507+
Debug.Assert VerifyToken(2, ttWhitespace, " ")
1508+
Debug.Assert VerifyToken(3, ttQuote, "[Forms]")
1509+
Debug.Assert VerifyToken(4, ttBoundary, "!")
1510+
Debug.Assert VerifyToken(5, ttQuote, "[frmColors]")
1511+
Debug.Assert VerifyToken(6, ttBoundary, "!")
1512+
Debug.Assert VerifyToken(7, ttQuote, "[Text18]")
1513+
1514+
' Verify result
1515+
With New clsConcat
1516+
.AppendOnAdd = vbCrLf
1517+
.Add "SELECT"
1518+
.Add " [Forms]![frmColors]![Text18]"
1519+
.Remove 2
1520+
strActual = .GetStr
1521+
End With
1522+
Debug.Assert (strActual = FormatSQL)
1523+
If (strActual <> FormatSQL) Then Diff.Strings strActual, FormatSQL
1524+
1525+
' PrintTokens
1526+
' BuildTestFromTokens
1527+
' Diff.Strings strActual, FormatSQL
1528+
1529+
' Test performance
1530+
TestPerformance
14671531

14681532
End Sub
14691533

0 commit comments

Comments
 (0)