Skip to content

Commit

Permalink
Add option to format query SQL
Browse files Browse the repository at this point in the history
Formatting of queries is now available as an option in the add-in. #426
  • Loading branch information
joyfullservice committed Aug 18, 2023
1 parent b4b6d03 commit 2e79ba0
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 34 deletions.
88 changes: 59 additions & 29 deletions Version Control.accda.src/forms/frmVCSOptions.bas
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Begin Form
GridY =24
Width =10080
DatasheetFontHeight =11
ItemSuffix =248
Left =20761
Top =2250
Right =-29055
Bottom =13995
ItemSuffix =250
Left =-25575
Top =1500
Right =-5310
Bottom =14085
RecSrcDt = Begin
0x79e78b777268e540
End
Expand Down Expand Up @@ -397,7 +397,7 @@ Begin Form
Left =540
Top =1500
Width =9000
Height =4740
Height =4755
TabIndex =2
Name ="tabOptions"
HorizontalAnchor =2
Expand All @@ -406,7 +406,7 @@ Begin Form
LayoutCachedLeft =540
LayoutCachedTop =1500
LayoutCachedWidth =9540
LayoutCachedHeight =6240
LayoutCachedHeight =6255
ThemeFontIndex =1
Shape =1
Gradient =12
Expand All @@ -426,13 +426,13 @@ Begin Form
Left =615
Top =1980
Width =8850
Height =4185
Height =4200
Name ="pgeGeneral"
Caption ="General"
LayoutCachedLeft =615
LayoutCachedTop =1980
LayoutCachedWidth =9465
LayoutCachedHeight =6165
LayoutCachedHeight =6180
Begin
Begin CheckBox
OverlapFlags =215
Expand Down Expand Up @@ -719,13 +719,13 @@ Begin Form
Left =615
Top =1980
Width =8850
Height =4185
Height =4205
Name ="pgeExport"
Caption ="Export"
LayoutCachedLeft =615
LayoutCachedTop =1980
LayoutCachedWidth =9465
LayoutCachedHeight =6165
LayoutCachedHeight =6185
Begin
Begin TextBox
OverlapFlags =247
Expand Down Expand Up @@ -990,28 +990,28 @@ Begin Form
Begin CheckBox
OverlapFlags =247
Left =5340
Top =4200
Top =4620
TabIndex =8
Name ="chkExtractThemeFiles"

LayoutCachedLeft =5340
LayoutCachedTop =4200
LayoutCachedTop =4620
LayoutCachedWidth =5600
LayoutCachedHeight =4440
LayoutCachedHeight =4860
Begin
Begin Label
OverlapFlags =247
Left =5640
Top =4140
Top =4560
Width =2340
Height =315
ForeColor =5324600
Name ="Label112"
Caption ="Extract Theme Files"
LayoutCachedLeft =5640
LayoutCachedTop =4140
LayoutCachedTop =4560
LayoutCachedWidth =7980
LayoutCachedHeight =4455
LayoutCachedHeight =4875
ForeThemeColorIndex =-1
ForeTint =100.0
End
Expand Down Expand Up @@ -1212,6 +1212,36 @@ Begin Form
PressedForeThemeColorIndex =10
PressedForeTint =100.0
End
Begin CheckBox
OverlapFlags =247
Left =5340
Top =4200
TabIndex =13
Name ="chkFormatSQL"

LayoutCachedLeft =5340
LayoutCachedTop =4200
LayoutCachedWidth =5600
LayoutCachedHeight =4440
Begin
Begin Label
OverlapFlags =247
Left =5640
Top =4140
Width =2340
Height =315
ForeColor =5324600
Name ="Label249"
Caption ="Format SQL"
LayoutCachedLeft =5640
LayoutCachedTop =4140
LayoutCachedWidth =7980
LayoutCachedHeight =4455
ForeThemeColorIndex =-1
ForeTint =100.0
End
End
End
End
End
Begin Page
Expand All @@ -1220,13 +1250,13 @@ Begin Form
Left =615
Top =1980
Width =8850
Height =4185
Height =4200
Name ="pgePrinterSettings"
Caption ="Printer Settings"
LayoutCachedLeft =615
LayoutCachedTop =1980
LayoutCachedWidth =9465
LayoutCachedHeight =6165
LayoutCachedHeight =6180
Begin
Begin CheckBox
OverlapFlags =247
Expand Down Expand Up @@ -1868,13 +1898,13 @@ Begin Form
Left =615
Top =1980
Width =8850
Height =4185
Height =4200
Name ="pgeDatabases"
Caption ="Databases"
LayoutCachedLeft =615
LayoutCachedTop =1980
LayoutCachedWidth =9465
LayoutCachedHeight =6165
LayoutCachedHeight =6180
Begin
Begin ListBox
ColumnHeads = NotDefault
Expand Down Expand Up @@ -2152,13 +2182,13 @@ Begin Form
Left =615
Top =1980
Width =8850
Height =4185
Height =4200
Name ="pgeTable"
Caption ="Table Data"
LayoutCachedLeft =615
LayoutCachedTop =1980
LayoutCachedWidth =9465
LayoutCachedHeight =6165
LayoutCachedHeight =6180
Begin
Begin CheckBox
OverlapFlags =247
Expand Down Expand Up @@ -2461,13 +2491,13 @@ Begin Form
Left =615
Top =1980
Width =8850
Height =4185
Height =4200
Name ="pgeBuild"
Caption ="Build"
LayoutCachedLeft =615
LayoutCachedTop =1980
LayoutCachedWidth =9465
LayoutCachedHeight =6165
LayoutCachedHeight =6180
Begin
Begin CheckBox
OverlapFlags =247
Expand Down Expand Up @@ -2638,13 +2668,13 @@ Begin Form
Left =615
Top =1980
Width =8850
Height =4185
Height =4200
Name ="pgeGitIntegration"
Caption ="Git Integration"
LayoutCachedLeft =615
LayoutCachedTop =1980
LayoutCachedWidth =9465
LayoutCachedHeight =6165
LayoutCachedHeight =6180
Begin
Begin CheckBox
OverlapFlags =247
Expand Down Expand Up @@ -2955,13 +2985,13 @@ Begin Form
Left =615
Top =1980
Width =8850
Height =4185
Height =4200
Name ="pgeSettings"
Caption ="Settings"
LayoutCachedLeft =615
LayoutCachedTop =1980
LayoutCachedWidth =9465
LayoutCachedHeight =6165
LayoutCachedHeight =6180
Begin
Begin OptionGroup
OverlapFlags =255
Expand Down
15 changes: 14 additions & 1 deletion Version Control.accda.src/modules/clsDbQuery.cls
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Private Sub IDbComponent_Export(Optional strAlternatePath As String)

Dim strFile As String
Dim strHash As String
Dim strSql As String
Dim dbs As DAO.Database

' Save and sanitize file
Expand All @@ -52,13 +53,25 @@ Private Sub IDbComponent_Export(Optional strAlternatePath As String)
Set dbs = CurrentDb
strFile = IDbComponent_BaseFolder & GetSafeFileName(m_Query.Name) & ".sql"
On Error Resume Next
WriteFile dbs.QueryDefs(m_Query.Name).SQL, strFile
strSql = dbs.QueryDefs(m_Query.Name).SQL
If Catch(3258) Then
Log.Error eelWarning, "Unable to access SQL property of query '" & m_Query.Name & "'. SQL view may not be available for this query.", ModuleName(Me) & ".Export"
ElseIf Err.Number Then
Log.Error eelError, "Unexpected error accessing SQL property of query '" & m_Query.Name & "'. Error " & Err.Number & ": " & Err.Description, ModuleName(Me) & ".Export"
End If
On Error GoTo 0
If strSql <> vbNullString Then
' Pass-through queries should not be formatted, since they support formatting and comments.
If Options.SaveQuerySQL And dbs.QueryDefs(m_Query.Name).Type <> dbQSQLPassThrough Then
With New clsSqlFormatter
Perf.OperationStart "Format SQL"
WriteFile .FormatSQL(strSql), strFile
Perf.OperationEnd
End With
Else
WriteFile strSql, strFile
End If
End If
Perf.OperationEnd
Log.Add " " & m_Query.Name & " (SQL)", Options.ShowDebug
End If
Expand Down
3 changes: 3 additions & 0 deletions Version Control.accda.src/modules/clsOptions.cls
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Public GitSettings As Dictionary
Public SavePrintVars As Boolean
Public ExportPrintSettings As Dictionary
Public SaveQuerySQL As Boolean
Public FormatSQL As Boolean
Public ForceImportOriginalQuerySQL As Boolean
Public SaveTableSQL As Boolean
Public StripPublishOption As Boolean
Expand Down Expand Up @@ -74,6 +75,7 @@ Public Sub LoadDefaults()
.UseGitIntegration = False
.SavePrintVars = True
.SaveQuerySQL = True
.FormatSQL = True
.ForceImportOriginalQuerySQL = False
.SaveTableSQL = True
.StripPublishOption = True
Expand Down Expand Up @@ -582,6 +584,7 @@ Private Sub Class_Initialize()
.Add "SavePrintVars"
.Add "ExportPrintSettings"
.Add "SaveQuerySQL"
.Add "FormatSQL"
.Add "ForceImportOriginalQuerySQL"
.Add "SaveTableSQL"
.Add "StripPublishOption"
Expand Down
45 changes: 41 additions & 4 deletions Version Control.accda.src/queries/qryNavPaneGroups.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,41 @@
SELECT MSysNavPaneGroupCategories.Name AS CategoryName, MSysNavPaneGroupCategories.Position AS CategoryPosition, MSysNavPaneGroupCategories.Flags AS CategoryFlags, MSysNavPaneGroups.Name AS GroupName, MSysNavPaneGroups.Flags AS GroupFlags, MSysNavPaneGroups.Position AS GroupPosition, MSysObjects.Type AS ObjectType, MSysObjects.Name AS ObjectName, MSysNavPaneGroupToObjects.Flags AS ObjectFlags, MSysNavPaneGroupToObjects.Icon AS ObjectIcon, MSysNavPaneGroupToObjects.Position AS ObjectPosition, MSysNavPaneGroupToObjects.Name AS NameInGroup, MSysNavPaneGroupCategories.Id AS CategoryID, MSysNavPaneGroups.Id AS GroupID, MSysNavPaneGroupToObjects.Id AS LinkID
FROM (MSysNavPaneGroupCategories INNER JOIN MSysNavPaneGroups ON MSysNavPaneGroupCategories.Id = MSysNavPaneGroups.GroupCategoryID) LEFT JOIN (MSysNavPaneGroupToObjects LEFT JOIN MSysObjects ON MSysNavPaneGroupToObjects.ObjectID = MSysObjects.Id) ON MSysNavPaneGroups.Id = MSysNavPaneGroupToObjects.GroupID
WHERE (((MSysNavPaneGroups.Name) Is Not Null) AND ((MSysNavPaneGroupCategories.Type)=4))
ORDER BY MSysNavPaneGroupCategories.Name, MSysNavPaneGroups.Name, MSysObjects.Type, MSysObjects.Name;
SELECT
MSysNavPaneGroupCategories.Name AS CategoryName,
MSysNavPaneGroupCategories.Position AS CategoryPosition,
MSysNavPaneGroupCategories.Flags AS CategoryFlags,
MSysNavPaneGroups.Name AS GroupName,
MSysNavPaneGroups.Flags AS GroupFlags,
MSysNavPaneGroups.Position AS GroupPosition,
MSysObjects.Type AS ObjectType,
MSysObjects.Name AS ObjectName,
MSysNavPaneGroupToObjects.Flags AS ObjectFlags,
MSysNavPaneGroupToObjects.Icon AS ObjectIcon,
MSysNavPaneGroupToObjects.Position AS ObjectPosition,
MSysNavPaneGroupToObjects.Name AS NameInGroup,
MSysNavPaneGroupCategories.Id AS CategoryID,
MSysNavPaneGroups.Id AS GroupID,
MSysNavPaneGroupToObjects.Id AS LinkID
FROM
(
MSysNavPaneGroupCategories
INNER JOIN MSysNavPaneGroups ON MSysNavPaneGroupCategories.Id = MSysNavPaneGroups.GroupCategoryID
)
LEFT JOIN (
MSysNavPaneGroupToObjects
LEFT JOIN MSysObjects ON MSysNavPaneGroupToObjects.ObjectID = MSysObjects.Id
) ON MSysNavPaneGroups.Id = MSysNavPaneGroupToObjects.GroupID
WHERE
(
(
(MSysNavPaneGroups.Name) Is Not Null
)
AND (
(
MSysNavPaneGroupCategories.Type
)= 4
)
)
ORDER BY
MSysNavPaneGroupCategories.Name,
MSysNavPaneGroups.Name,
MSysObjects.Type,
MSysObjects.Name;
1 change: 1 addition & 0 deletions Version Control.accda.src/vcs-options.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"TTOption": false
},
"SaveQuerySQL": true,
"FormatSQL": true,
"ForceImportOriginalQuerySQL": false,
"SaveTableSQL": true,
"StripPublishOption": true,
Expand Down

0 comments on commit 2e79ba0

Please sign in to comment.