├── .gitattributes ├── .gitignore ├── BaiSqlFormat.sln ├── BaiSqlFormatForm ├── AboutBox.Designer.cs ├── AboutBox.cs ├── AboutBox.resx ├── App.config ├── BaiSqlFormatForm.csproj ├── FrameworkClassReplacements │ ├── CustomContentWebBrowser.cs │ └── SelectableTextBox.cs ├── MainForm.Designer.cs ├── MainForm.cs ├── MainForm.resx ├── Others │ ├── HTMLHelp.cs │ └── WriteLog.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── SingleAssemblyResourceManager.cs └── sql_bai_icon.ico ├── BaiSqlFormatForm2 ├── AboutBox.Designer.cs ├── AboutBox.cs ├── AboutBox.resx ├── App.config ├── BaiSqlFormatForm2.csproj ├── FrameworkClassReplacements │ ├── CustomContentWebBrowser.cs │ └── SelectableTextBox.cs ├── MainForm.Designer.cs ├── MainForm.cs ├── MainForm.resx ├── Others │ └── WriteLog.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ ├── Settings.settings │ └── licenses.licx └── sql_bai_icon.ico ├── BaiSqlFormatLib ├── BaiSqlFormatLib.csproj ├── BaseFormatterState.cs ├── Formatters │ ├── HtmlPageWrapper.cs │ ├── TSqlIdentityFormatter.cs │ ├── TSqlObfuscatingFormatter.cs │ ├── TSqlStandardFormatter.cs │ └── TSqlStandardFormatterOptions.cs ├── Interfaces │ ├── IParseTree.cs │ ├── ISqlTokenFormatter.cs │ ├── ISqlTokenParser.cs │ ├── ISqlTokenizer.cs │ ├── ISqlTreeFormatter.cs │ ├── IToken.cs │ ├── ITokenList.cs │ ├── MessagingConstants.cs │ ├── SqlHtmlConstants.cs │ ├── SqlStructureConstants.cs │ ├── SqlTokenType.cs │ └── SqlXmlConstants.cs ├── Key.snk ├── NetUtils.cs ├── ObfuscatingKeywordMapping.cs ├── ParseStructure │ ├── Node.cs │ ├── NodeExtensions.cs │ ├── NodeFactory.cs │ └── NodeImpl.cs ├── ParseTree.cs ├── Parsers │ └── TSqlStandardParser.cs ├── Properties │ └── AssemblyInfo.cs ├── References │ └── LinqBridge │ │ ├── COPYING.txt │ │ └── LinqBridge.dll ├── SimplifiedStringReader.cs ├── SqlFormattingManager.cs ├── StandardKeywordRemapping.cs ├── TSqlStandardTokenizer.cs ├── Token.cs ├── TokenList.cs ├── Tokenizers │ ├── SimplifiedStringReader.cs │ └── TSqlStandardTokenizer.cs └── Utils.cs └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | [Ss]tyle[Cc]op.* 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # LightSwitch generated files 235 | GeneratedArtifacts/ 236 | ModelManifest.xml 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ 243 | -------------------------------------------------------------------------------- /BaiSqlFormat.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BaiSqlFormatLib", "BaiSqlFormatLib\BaiSqlFormatLib.csproj", "{ADBDFDCA-CAB6-4569-9151-0BD42E65B400}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BaiSqlFormatForm", "BaiSqlFormatForm\BaiSqlFormatForm.csproj", "{949039DF-CB5D-4214-B5C6-470EAC4460A9}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BaiSqlFormatForm2", "BaiSqlFormatForm2\BaiSqlFormatForm2.csproj", "{D78DC06C-52B1-4877-9A3E-12DA3C36DBC2}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {ADBDFDCA-CAB6-4569-9151-0BD42E65B400}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {ADBDFDCA-CAB6-4569-9151-0BD42E65B400}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {ADBDFDCA-CAB6-4569-9151-0BD42E65B400}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {ADBDFDCA-CAB6-4569-9151-0BD42E65B400}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {949039DF-CB5D-4214-B5C6-470EAC4460A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {949039DF-CB5D-4214-B5C6-470EAC4460A9}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {949039DF-CB5D-4214-B5C6-470EAC4460A9}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {949039DF-CB5D-4214-B5C6-470EAC4460A9}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {D78DC06C-52B1-4877-9A3E-12DA3C36DBC2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {D78DC06C-52B1-4877-9A3E-12DA3C36DBC2}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {D78DC06C-52B1-4877-9A3E-12DA3C36DBC2}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {D78DC06C-52B1-4877-9A3E-12DA3C36DBC2}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | EndGlobal 35 | -------------------------------------------------------------------------------- /BaiSqlFormatForm/AboutBox.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace BaiSqlFormatForm 2 | { 3 | partial class AboutBox 4 | { 5 | /// 6 | /// 必需的设计器变量。 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// 清理所有正在使用的资源。 12 | /// 13 | protected override void Dispose(bool disposing) 14 | { 15 | if (disposing && (components != null)) 16 | { 17 | components.Dispose(); 18 | } 19 | base.Dispose(disposing); 20 | } 21 | 22 | #region Windows 窗体设计器生成的代码 23 | 24 | /// 25 | /// 设计器支持所需的方法 - 不要修改 26 | /// 使用代码编辑器修改此方法的内容。 27 | /// 28 | private void InitializeComponent() 29 | { 30 | System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AboutBox)); 31 | this.okButton = new System.Windows.Forms.Button(); 32 | this.textBoxDescription = new System.Windows.Forms.TextBox(); 33 | this.labelCopyright = new System.Windows.Forms.Label(); 34 | this.labelVersion = new System.Windows.Forms.Label(); 35 | this.labelProductName = new System.Windows.Forms.Label(); 36 | this.logoPictureBox = new System.Windows.Forms.PictureBox(); 37 | this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); 38 | this.labelCompanyName = new System.Windows.Forms.Label(); 39 | ((System.ComponentModel.ISupportInitialize)(this.logoPictureBox)).BeginInit(); 40 | this.tableLayoutPanel.SuspendLayout(); 41 | this.SuspendLayout(); 42 | // 43 | // okButton 44 | // 45 | this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 46 | this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; 47 | this.okButton.Location = new System.Drawing.Point(423, 238); 48 | this.okButton.Name = "okButton"; 49 | this.okButton.Size = new System.Drawing.Size(75, 21); 50 | this.okButton.TabIndex = 24; 51 | this.okButton.Text = "确定(&O)"; 52 | // 53 | // textBoxDescription 54 | // 55 | this.textBoxDescription.Dock = System.Windows.Forms.DockStyle.Fill; 56 | this.textBoxDescription.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 57 | this.textBoxDescription.Location = new System.Drawing.Point(146, 107); 58 | this.textBoxDescription.Margin = new System.Windows.Forms.Padding(6, 3, 3, 3); 59 | this.textBoxDescription.Multiline = true; 60 | this.textBoxDescription.Name = "textBoxDescription"; 61 | this.textBoxDescription.ReadOnly = true; 62 | this.textBoxDescription.ScrollBars = System.Windows.Forms.ScrollBars.Both; 63 | this.textBoxDescription.Size = new System.Drawing.Size(352, 125); 64 | this.textBoxDescription.TabIndex = 23; 65 | this.textBoxDescription.TabStop = false; 66 | this.textBoxDescription.Text = "说明"; 67 | // 68 | // labelCopyright 69 | // 70 | this.labelCopyright.Dock = System.Windows.Forms.DockStyle.Fill; 71 | this.labelCopyright.Location = new System.Drawing.Point(146, 52); 72 | this.labelCopyright.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0); 73 | this.labelCopyright.MaximumSize = new System.Drawing.Size(0, 16); 74 | this.labelCopyright.Name = "labelCopyright"; 75 | this.labelCopyright.Size = new System.Drawing.Size(352, 16); 76 | this.labelCopyright.TabIndex = 21; 77 | this.labelCopyright.Text = "作 者:Bai"; 78 | this.labelCopyright.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 79 | // 80 | // labelVersion 81 | // 82 | this.labelVersion.Dock = System.Windows.Forms.DockStyle.Fill; 83 | this.labelVersion.Location = new System.Drawing.Point(146, 26); 84 | this.labelVersion.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0); 85 | this.labelVersion.MaximumSize = new System.Drawing.Size(0, 16); 86 | this.labelVersion.Name = "labelVersion"; 87 | this.labelVersion.Size = new System.Drawing.Size(352, 16); 88 | this.labelVersion.TabIndex = 0; 89 | this.labelVersion.Text = "版 本:v1.0"; 90 | this.labelVersion.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 91 | // 92 | // labelProductName 93 | // 94 | this.labelProductName.Dock = System.Windows.Forms.DockStyle.Fill; 95 | this.labelProductName.Location = new System.Drawing.Point(146, 0); 96 | this.labelProductName.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0); 97 | this.labelProductName.MaximumSize = new System.Drawing.Size(0, 16); 98 | this.labelProductName.Name = "labelProductName"; 99 | this.labelProductName.Size = new System.Drawing.Size(352, 16); 100 | this.labelProductName.TabIndex = 19; 101 | this.labelProductName.Text = "产品名称:SQL代码格式调整工具"; 102 | this.labelProductName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 103 | // 104 | // logoPictureBox 105 | // 106 | this.logoPictureBox.Dock = System.Windows.Forms.DockStyle.Fill; 107 | this.logoPictureBox.Image = ((System.Drawing.Image)(resources.GetObject("logoPictureBox.Image"))); 108 | this.logoPictureBox.Location = new System.Drawing.Point(3, 3); 109 | this.logoPictureBox.Name = "logoPictureBox"; 110 | this.tableLayoutPanel.SetRowSpan(this.logoPictureBox, 6); 111 | this.logoPictureBox.Size = new System.Drawing.Size(134, 256); 112 | this.logoPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 113 | this.logoPictureBox.TabIndex = 12; 114 | this.logoPictureBox.TabStop = false; 115 | // 116 | // tableLayoutPanel 117 | // 118 | this.tableLayoutPanel.ColumnCount = 2; 119 | this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 28.14371F)); 120 | this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 71.85629F)); 121 | this.tableLayoutPanel.Controls.Add(this.logoPictureBox, 0, 0); 122 | this.tableLayoutPanel.Controls.Add(this.labelProductName, 1, 0); 123 | this.tableLayoutPanel.Controls.Add(this.labelVersion, 1, 1); 124 | this.tableLayoutPanel.Controls.Add(this.labelCopyright, 1, 2); 125 | this.tableLayoutPanel.Controls.Add(this.labelCompanyName, 1, 3); 126 | this.tableLayoutPanel.Controls.Add(this.textBoxDescription, 1, 4); 127 | this.tableLayoutPanel.Controls.Add(this.okButton, 1, 5); 128 | this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; 129 | this.tableLayoutPanel.Location = new System.Drawing.Point(9, 8); 130 | this.tableLayoutPanel.Name = "tableLayoutPanel"; 131 | this.tableLayoutPanel.RowCount = 6; 132 | this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); 133 | this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); 134 | this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); 135 | this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); 136 | this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); 137 | this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 10F)); 138 | this.tableLayoutPanel.Size = new System.Drawing.Size(501, 262); 139 | this.tableLayoutPanel.TabIndex = 0; 140 | // 141 | // labelCompanyName 142 | // 143 | this.labelCompanyName.Dock = System.Windows.Forms.DockStyle.Fill; 144 | this.labelCompanyName.Location = new System.Drawing.Point(146, 78); 145 | this.labelCompanyName.Margin = new System.Windows.Forms.Padding(6, 0, 3, 0); 146 | this.labelCompanyName.MaximumSize = new System.Drawing.Size(0, 16); 147 | this.labelCompanyName.Name = "labelCompanyName"; 148 | this.labelCompanyName.Size = new System.Drawing.Size(352, 16); 149 | this.labelCompanyName.TabIndex = 22; 150 | this.labelCompanyName.Text = "框 架:.NET Framework 2.0"; 151 | this.labelCompanyName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 152 | // 153 | // AboutBox 154 | // 155 | this.AcceptButton = this.okButton; 156 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 157 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 158 | this.ClientSize = new System.Drawing.Size(519, 278); 159 | this.Controls.Add(this.tableLayoutPanel); 160 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 161 | this.MaximizeBox = false; 162 | this.MinimizeBox = false; 163 | this.Name = "AboutBox"; 164 | this.Padding = new System.Windows.Forms.Padding(9, 8, 9, 8); 165 | this.ShowIcon = false; 166 | this.ShowInTaskbar = false; 167 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 168 | this.Text = "关于"; 169 | ((System.ComponentModel.ISupportInitialize)(this.logoPictureBox)).EndInit(); 170 | this.tableLayoutPanel.ResumeLayout(false); 171 | this.tableLayoutPanel.PerformLayout(); 172 | this.ResumeLayout(false); 173 | 174 | } 175 | 176 | #endregion 177 | 178 | private System.Windows.Forms.Button okButton; 179 | private System.Windows.Forms.TextBox textBoxDescription; 180 | private System.Windows.Forms.Label labelCopyright; 181 | private System.Windows.Forms.Label labelVersion; 182 | private System.Windows.Forms.Label labelProductName; 183 | private System.Windows.Forms.PictureBox logoPictureBox; 184 | private System.Windows.Forms.TableLayoutPanel tableLayoutPanel; 185 | private System.Windows.Forms.Label labelCompanyName; 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /BaiSqlFormatForm/AboutBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Drawing; 5 | using System.Reflection; 6 | using System.Windows.Forms; 7 | 8 | namespace BaiSqlFormatForm 9 | { 10 | partial class AboutBox : Form 11 | { 12 | public AboutBox() 13 | { 14 | InitializeComponent(); 15 | this.textBoxDescription.Text = AssemblyDescription; 16 | } 17 | 18 | 19 | public string AssemblyDescription 20 | { 21 | get 22 | { 23 | return "1) 本程序理论上支持所有SQL/HQL语句的格式调整,包括但不限于普通数据库DDL、DML、DCL," + 24 | "理论上也支持存储过程、视图等语句格式调整。但不能保证效果完美(由于时间原因," + 25 | "只针对部分大数据ETL涉及到的HQL语法进行了测试)" + "\r\n\r\n" + 26 | "2) 疑似格式调整错误的日志(只保留最后一个错误日期)将会记录到本地文件夹,文件位置:本程序所在位置\\logs\\formatErrLog.log" + "\r\n\r\n" + 27 | "3) 程序错误日志也会记录在本地文件夹(所有错误信息全部保留),文件位置:本程序所在位置\\logs\\appErrLog.log"; 28 | } 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /BaiSqlFormatForm/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 | 9 | 10 | 11 | 170 12 | 13 | 14 | True 15 | 16 | 17 | True 18 | 19 | 20 | True 21 | 22 | 23 | True 24 | 25 | 26 | False 27 | 28 | 29 | False 30 | 31 | 32 | True 33 | 34 | 35 | False 36 | 37 | 38 | True 39 | 40 | 41 | True 42 | 43 | 44 | True 45 | 46 | 47 | False 48 | 49 | 50 | 35 51 | 52 | 53 | True 54 | 55 | 56 | True 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /BaiSqlFormatForm/BaiSqlFormatForm.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {949039DF-CB5D-4214-B5C6-470EAC4460A9} 8 | WinExe 9 | Properties 10 | BaiSqlFormatForm 11 | BaiSqlFormatForm 12 | v2.0 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | AnyCPU 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | 34 | 35 | sql_bai_icon.ico 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | Form 48 | 49 | 50 | AboutBox.cs 51 | 52 | 53 | Form 54 | 55 | 56 | MainForm.cs 57 | 58 | 59 | Component 60 | 61 | 62 | Component 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | AboutBox.cs 71 | 72 | 73 | MainForm.cs 74 | 75 | 76 | ResXFileCodeGenerator 77 | Resources.Designer.cs 78 | Designer 79 | 80 | 81 | True 82 | Resources.resx 83 | True 84 | 85 | 86 | 87 | SettingsSingleFileGenerator 88 | Settings.Designer.cs 89 | 90 | 91 | True 92 | Settings.settings 93 | True 94 | 95 | 96 | 97 | 98 | {ADBDFDCA-CAB6-4569-9151-0BD42E65B400} 99 | BaiSqlFormatLib 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 117 | -------------------------------------------------------------------------------- /BaiSqlFormatForm/FrameworkClassReplacements/CustomContentWebBrowser.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System.Runtime.InteropServices; 22 | 23 | namespace BaiSqlFormatForm.FrameworkClassReplacements 24 | { 25 | public class CustomContentWebBrowser : System.Windows.Forms.WebBrowser 26 | { 27 | // WebBrowser control, modified to allow easy setting of HTML content, based on: 28 | //http://weblogs.asp.net/gunnarpeipman/archive/2009/08/15/displaying-custom-html-in-webbrowser-control.aspx 29 | // Also disabling navigation sound, as per: 30 | //https://connect.microsoft.com/VisualStudio/feedback/details/345528/webbrowser-control-in-wpf-disable-sound 31 | 32 | private const int DISABLE_NAVIGATION_SOUNDS = 21; 33 | private const int SET_FEATURE_ON_PROCESS = 0x00000002; 34 | 35 | [DllImport("urlmon.dll")] 36 | [PreserveSig] 37 | [return: MarshalAs(UnmanagedType.Error)] 38 | static extern int CoInternetSetFeatureEnabled(int FeatureEntry, [MarshalAs(UnmanagedType.U4)] int dwFlags, bool fEnable); 39 | 40 | public void SetHTML(string htmlContent) 41 | { 42 | bool allowedNavigation = AllowNavigation; 43 | AllowNavigation = true; 44 | CoInternetSetFeatureEnabled(DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, true); 45 | this.Navigate("about:blank"); 46 | if (this.Document != null) 47 | { 48 | this.Document.Write(string.Empty); 49 | } 50 | this.DocumentText = htmlContent; 51 | CoInternetSetFeatureEnabled(DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, false); 52 | AllowNavigation = allowedNavigation; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /BaiSqlFormatForm/FrameworkClassReplacements/SelectableTextBox.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | using System.Windows.Forms; 23 | 24 | namespace BaiSqlFormatForm.FrameworkClassReplacements 25 | { 26 | public class SelectableTextBox : TextBox 27 | { 28 | //Ctrl-A support in .Net multiline textboxes. 29 | // adapted from stackoverflow: 30 | // http://stackoverflow.com/questions/225711/stop-the-bell-on-ctrl-a-winforms/230417#230417 31 | 32 | protected override bool ProcessCmdKey(ref Message msg, Keys keyData) 33 | { 34 | if (keyData == (Keys.A | Keys.Control)) 35 | { 36 | this.SelectionStart = 0; 37 | this.SelectionLength = this.Text.Length; 38 | this.Focus(); 39 | return true; 40 | } 41 | return base.ProcessCmdKey(ref msg, keyData); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /BaiSqlFormatForm/Others/HTMLHelp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Text.RegularExpressions; 5 | 6 | namespace BaiSqlFormatForm.Others 7 | { 8 | class HTMLHelp 9 | { 10 | /// 11 | /// 提取HTML中的内容 12 | /// 13 | /// 14 | /// 15 | public static string StripHTML(string strHtml) 16 | { 17 | string[] aryReg ={ 18 | @"&(nbsp|#160);", 19 | @"]*?>.*?", 20 | @"<(\/\s*)?!?((\w+:)?\w+)(\w+(\s*=?\s*(([""'])(\\[""'tbnr]|[^\7])*?\7|\w+)|.{0})|\s)*?(\/\s*)?>", 21 | @"([\r\n])[\s]+", 22 | @"&(quot|#34);", 23 | @"&(amp|#38);", 24 | @"&(lt|#60);", 25 | @"&(gt|#62);", 26 | 27 | @"&(iexcl|#161);", 28 | @"&(cent|#162);", 29 | @"&(pound|#163);", 30 | @"&(copy|#169);", 31 | @"&#(\d+);", 32 | @"-->", 33 | @" 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 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /BaiSqlFormatForm/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace BaiSqlFormatForm.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.UserScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.DefaultSettingValueAttribute("170")] 29 | public int MaxLineWidth { 30 | get { 31 | return ((int)(this["MaxLineWidth"])); 32 | } 33 | set { 34 | this["MaxLineWidth"] = value; 35 | } 36 | } 37 | 38 | [global::System.Configuration.UserScopedSettingAttribute()] 39 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 40 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 41 | public bool ExpandCommaLists { 42 | get { 43 | return ((bool)(this["ExpandCommaLists"])); 44 | } 45 | set { 46 | this["ExpandCommaLists"] = value; 47 | } 48 | } 49 | 50 | [global::System.Configuration.UserScopedSettingAttribute()] 51 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 52 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 53 | public bool KeywordAlign { 54 | get { 55 | return ((bool)(this["KeywordAlign"])); 56 | } 57 | set { 58 | this["KeywordAlign"] = value; 59 | } 60 | } 61 | 62 | [global::System.Configuration.UserScopedSettingAttribute()] 63 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 64 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 65 | public bool ExpandBooleanExpressions { 66 | get { 67 | return ((bool)(this["ExpandBooleanExpressions"])); 68 | } 69 | set { 70 | this["ExpandBooleanExpressions"] = value; 71 | } 72 | } 73 | 74 | [global::System.Configuration.UserScopedSettingAttribute()] 75 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 76 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 77 | public bool ExpandCaseStatements { 78 | get { 79 | return ((bool)(this["ExpandCaseStatements"])); 80 | } 81 | set { 82 | this["ExpandCaseStatements"] = value; 83 | } 84 | } 85 | 86 | [global::System.Configuration.UserScopedSettingAttribute()] 87 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 88 | [global::System.Configuration.DefaultSettingValueAttribute("False")] 89 | public bool ExpandBetweenConditions { 90 | get { 91 | return ((bool)(this["ExpandBetweenConditions"])); 92 | } 93 | set { 94 | this["ExpandBetweenConditions"] = value; 95 | } 96 | } 97 | 98 | [global::System.Configuration.UserScopedSettingAttribute()] 99 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 100 | [global::System.Configuration.DefaultSettingValueAttribute("False")] 101 | public bool ExpandInLists { 102 | get { 103 | return ((bool)(this["ExpandInLists"])); 104 | } 105 | set { 106 | this["ExpandInLists"] = value; 107 | } 108 | } 109 | 110 | [global::System.Configuration.UserScopedSettingAttribute()] 111 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 112 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 113 | public bool BreakJoinOnSections { 114 | get { 115 | return ((bool)(this["BreakJoinOnSections"])); 116 | } 117 | set { 118 | this["BreakJoinOnSections"] = value; 119 | } 120 | } 121 | 122 | [global::System.Configuration.UserScopedSettingAttribute()] 123 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 124 | [global::System.Configuration.DefaultSettingValueAttribute("False")] 125 | public bool UppercaseKeywords { 126 | get { 127 | return ((bool)(this["UppercaseKeywords"])); 128 | } 129 | set { 130 | this["UppercaseKeywords"] = value; 131 | } 132 | } 133 | 134 | [global::System.Configuration.UserScopedSettingAttribute()] 135 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 136 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 137 | public bool HTMLColoring { 138 | get { 139 | return ((bool)(this["HTMLColoring"])); 140 | } 141 | set { 142 | this["HTMLColoring"] = value; 143 | } 144 | } 145 | 146 | [global::System.Configuration.UserScopedSettingAttribute()] 147 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 148 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 149 | public bool AllIndent { 150 | get { 151 | return ((bool)(this["AllIndent"])); 152 | } 153 | set { 154 | this["AllIndent"] = value; 155 | } 156 | } 157 | 158 | [global::System.Configuration.UserScopedSettingAttribute()] 159 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 160 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 161 | public bool AsAlign { 162 | get { 163 | return ((bool)(this["AsAlign"])); 164 | } 165 | set { 166 | this["AsAlign"] = value; 167 | } 168 | } 169 | 170 | [global::System.Configuration.UserScopedSettingAttribute()] 171 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 172 | [global::System.Configuration.DefaultSettingValueAttribute("False")] 173 | public bool AllUpper { 174 | get { 175 | return ((bool)(this["AllUpper"])); 176 | } 177 | set { 178 | this["AllUpper"] = value; 179 | } 180 | } 181 | 182 | [global::System.Configuration.UserScopedSettingAttribute()] 183 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 184 | [global::System.Configuration.DefaultSettingValueAttribute("35")] 185 | public int KeywordLengthOfAs { 186 | get { 187 | return ((int)(this["KeywordLengthOfAs"])); 188 | } 189 | set { 190 | this["KeywordLengthOfAs"] = value; 191 | } 192 | } 193 | 194 | [global::System.Configuration.UserScopedSettingAttribute()] 195 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 196 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 197 | public bool chkdefault { 198 | get { 199 | return ((bool)(this["chkdefault"])); 200 | } 201 | set { 202 | this["chkdefault"] = value; 203 | } 204 | } 205 | 206 | [global::System.Configuration.UserScopedSettingAttribute()] 207 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 208 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 209 | public bool addSemicolon { 210 | get { 211 | return ((bool)(this["addSemicolon"])); 212 | } 213 | set { 214 | this["addSemicolon"] = value; 215 | } 216 | } 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /BaiSqlFormatForm/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 170 7 | 8 | 9 | True 10 | 11 | 12 | True 13 | 14 | 15 | True 16 | 17 | 18 | True 19 | 20 | 21 | False 22 | 23 | 24 | False 25 | 26 | 27 | True 28 | 29 | 30 | False 31 | 32 | 33 | True 34 | 35 | 36 | True 37 | 38 | 39 | True 40 | 41 | 42 | False 43 | 44 | 45 | 35 46 | 47 | 48 | True 49 | 50 | 51 | True 52 | 53 | 54 | -------------------------------------------------------------------------------- /BaiSqlFormatForm/SingleAssemblyResourceManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | using System.Collections; 23 | using System.Globalization; 24 | using System.IO; 25 | using System.Resources; 26 | using System.Reflection; 27 | 28 | namespace BaiSqlFormatForm.FrameworkClassReplacements 29 | { 30 | public class SingleAssemblyResourceManager : System.Resources.ResourceManager 31 | { 32 | private Type _contextTypeInfo; 33 | private string _namespace; 34 | private CultureInfo _neutralResourcesCulture; 35 | 36 | public SingleAssemblyResourceManager(Type t) 37 | : base(t) 38 | { 39 | _contextTypeInfo = t; 40 | } 41 | 42 | public SingleAssemblyResourceManager(string baseName, Assembly assembly, Type sameNameSpaceType) 43 | : base(baseName, assembly) 44 | { 45 | _contextTypeInfo = null; 46 | _namespace = sameNameSpaceType.Namespace; 47 | } 48 | 49 | protected override ResourceSet InternalGetResourceSet(CultureInfo culture, bool createIfNotExists, bool tryParents) 50 | { 51 | ResourceSet rs = (ResourceSet)this.ResourceSets[culture]; 52 | if (rs == null) 53 | { 54 | Stream store = null; 55 | string resourceFileName = null; 56 | 57 | //lazy-load default language (without caring about duplicate assignment in race conditions, no harm done); 58 | if (this._neutralResourcesCulture == null) 59 | { 60 | this._neutralResourcesCulture = GetNeutralResourcesLanguage(this.MainAssembly); 61 | } 62 | 63 | //if we're asking for the default language, then ask for the invaliant (non-specific) resources. 64 | if (_neutralResourcesCulture.Equals(culture)) 65 | culture = CultureInfo.InvariantCulture; 66 | resourceFileName = GetResourceFileName(culture); 67 | 68 | if (this._contextTypeInfo != null) 69 | store = this.MainAssembly.GetManifestResourceStream(this._contextTypeInfo, resourceFileName); 70 | else 71 | store = this.MainAssembly.GetManifestResourceStream(_namespace + "." + resourceFileName); 72 | 73 | //If we found the appropriate resources in the local assembly 74 | if (store != null) 75 | { 76 | rs = new ResourceSet(store); 77 | //save for later. 78 | AddResourceSet(this.ResourceSets, culture, ref rs); 79 | } 80 | else 81 | { 82 | rs = base.InternalGetResourceSet(culture, createIfNotExists, tryParents); 83 | } 84 | } 85 | return rs; 86 | } 87 | 88 | //private method in framework, had to be re-specified 89 | private static void AddResourceSet(Hashtable localResourceSets, CultureInfo culture, ref ResourceSet rs) 90 | { 91 | lock (localResourceSets) 92 | { 93 | ResourceSet objA = (ResourceSet)localResourceSets[culture]; 94 | if (objA != null) 95 | { 96 | if (!object.Equals(objA, rs)) 97 | { 98 | rs.Dispose(); 99 | rs = objA; 100 | } 101 | } 102 | else 103 | { 104 | localResourceSets.Add(culture, rs); 105 | } 106 | } 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /BaiSqlFormatForm/sql_bai_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baihongbin/SqlFormat/2aaedc1f9ae84e67b8ef528b7041de0044dcc870/BaiSqlFormatForm/sql_bai_icon.ico -------------------------------------------------------------------------------- /BaiSqlFormatForm2/AboutBox.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace BaiSqlFormatForm2 2 | { 3 | partial class AboutBox 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | /// 30 | private void InitializeComponent() 31 | { 32 | DevExpress.XtraBars.Docking2010.WindowsUIButtonImageOptions windowsUIButtonImageOptions4 = new DevExpress.XtraBars.Docking2010.WindowsUIButtonImageOptions(); 33 | this.layoutControl = new DevExpress.XtraLayout.LayoutControl(); 34 | this.me_info = new DevExpress.XtraEditors.MemoEdit(); 35 | this.me_explain = new DevExpress.XtraEditors.MemoEdit(); 36 | this.layoutControlGroup = new DevExpress.XtraLayout.LayoutControlGroup(); 37 | this.splitterItem1 = new DevExpress.XtraLayout.SplitterItem(); 38 | this.layoutControlItem1 = new DevExpress.XtraLayout.LayoutControlItem(); 39 | this.layoutControlItem2 = new DevExpress.XtraLayout.LayoutControlItem(); 40 | this.windowsUIButtonPanel = new DevExpress.XtraBars.Docking2010.WindowsUIButtonPanel(); 41 | ((System.ComponentModel.ISupportInitialize)(this.layoutControl)).BeginInit(); 42 | this.layoutControl.SuspendLayout(); 43 | ((System.ComponentModel.ISupportInitialize)(this.me_info.Properties)).BeginInit(); 44 | ((System.ComponentModel.ISupportInitialize)(this.me_explain.Properties)).BeginInit(); 45 | ((System.ComponentModel.ISupportInitialize)(this.layoutControlGroup)).BeginInit(); 46 | ((System.ComponentModel.ISupportInitialize)(this.splitterItem1)).BeginInit(); 47 | ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).BeginInit(); 48 | ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem2)).BeginInit(); 49 | this.SuspendLayout(); 50 | // 51 | // layoutControl 52 | // 53 | this.layoutControl.AllowCustomization = false; 54 | this.layoutControl.Controls.Add(this.me_info); 55 | this.layoutControl.Controls.Add(this.me_explain); 56 | this.layoutControl.Dock = System.Windows.Forms.DockStyle.Fill; 57 | this.layoutControl.Location = new System.Drawing.Point(0, 0); 58 | this.layoutControl.Name = "layoutControl"; 59 | this.layoutControl.Root = this.layoutControlGroup; 60 | this.layoutControl.Size = new System.Drawing.Size(546, 271); 61 | this.layoutControl.TabIndex = 1; 62 | // 63 | // me_info 64 | // 65 | this.me_info.Location = new System.Drawing.Point(84, 2); 66 | this.me_info.Name = "me_info"; 67 | this.me_info.Size = new System.Drawing.Size(413, 107); 68 | this.me_info.StyleController = this.layoutControl; 69 | this.me_info.TabIndex = 5; 70 | // 71 | // me_explain 72 | // 73 | this.me_explain.Location = new System.Drawing.Point(84, 113); 74 | this.me_explain.Name = "me_explain"; 75 | this.me_explain.Size = new System.Drawing.Size(413, 146); 76 | this.me_explain.StyleController = this.layoutControl; 77 | this.me_explain.TabIndex = 6; 78 | // 79 | // layoutControlGroup 80 | // 81 | this.layoutControlGroup.EnableIndentsWithoutBorders = DevExpress.Utils.DefaultBoolean.True; 82 | this.layoutControlGroup.GroupBordersVisible = false; 83 | this.layoutControlGroup.Items.AddRange(new DevExpress.XtraLayout.BaseLayoutItem[] { 84 | this.splitterItem1, 85 | this.layoutControlItem1, 86 | this.layoutControlItem2}); 87 | this.layoutControlGroup.Name = "Root"; 88 | this.layoutControlGroup.Padding = new DevExpress.XtraLayout.Utils.Padding(47, 47, 0, 0); 89 | this.layoutControlGroup.Size = new System.Drawing.Size(546, 271); 90 | this.layoutControlGroup.TextVisible = false; 91 | // 92 | // splitterItem1 93 | // 94 | this.splitterItem1.AllowHotTrack = true; 95 | this.splitterItem1.Location = new System.Drawing.Point(0, 261); 96 | this.splitterItem1.Name = "splitterItem1"; 97 | this.splitterItem1.Size = new System.Drawing.Size(452, 10); 98 | // 99 | // layoutControlItem1 100 | // 101 | this.layoutControlItem1.Control = this.me_info; 102 | this.layoutControlItem1.Location = new System.Drawing.Point(0, 0); 103 | this.layoutControlItem1.Name = "layoutControlItem1"; 104 | this.layoutControlItem1.Size = new System.Drawing.Size(452, 111); 105 | this.layoutControlItem1.Text = " 简介 "; 106 | this.layoutControlItem1.TextSize = new System.Drawing.Size(32, 14); 107 | // 108 | // layoutControlItem2 109 | // 110 | this.layoutControlItem2.Control = this.me_explain; 111 | this.layoutControlItem2.Location = new System.Drawing.Point(0, 111); 112 | this.layoutControlItem2.Name = "layoutControlItem2"; 113 | this.layoutControlItem2.Size = new System.Drawing.Size(452, 150); 114 | this.layoutControlItem2.Text = " 说明 "; 115 | this.layoutControlItem2.TextSize = new System.Drawing.Size(32, 14); 116 | // 117 | // windowsUIButtonPanel 118 | // 119 | this.windowsUIButtonPanel.AppearanceButton.Hovered.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(130)))), ((int)(((byte)(130)))), ((int)(((byte)(130))))); 120 | this.windowsUIButtonPanel.AppearanceButton.Hovered.FontSizeDelta = -1; 121 | this.windowsUIButtonPanel.AppearanceButton.Hovered.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(130)))), ((int)(((byte)(130)))), ((int)(((byte)(130))))); 122 | this.windowsUIButtonPanel.AppearanceButton.Hovered.Options.UseBackColor = true; 123 | this.windowsUIButtonPanel.AppearanceButton.Hovered.Options.UseFont = true; 124 | this.windowsUIButtonPanel.AppearanceButton.Hovered.Options.UseForeColor = true; 125 | this.windowsUIButtonPanel.AppearanceButton.Normal.FontSizeDelta = -1; 126 | this.windowsUIButtonPanel.AppearanceButton.Normal.Options.UseFont = true; 127 | this.windowsUIButtonPanel.AppearanceButton.Pressed.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(159)))), ((int)(((byte)(159)))), ((int)(((byte)(159))))); 128 | this.windowsUIButtonPanel.AppearanceButton.Pressed.FontSizeDelta = -1; 129 | this.windowsUIButtonPanel.AppearanceButton.Pressed.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(159)))), ((int)(((byte)(159)))), ((int)(((byte)(159))))); 130 | this.windowsUIButtonPanel.AppearanceButton.Pressed.Options.UseBackColor = true; 131 | this.windowsUIButtonPanel.AppearanceButton.Pressed.Options.UseFont = true; 132 | this.windowsUIButtonPanel.AppearanceButton.Pressed.Options.UseForeColor = true; 133 | this.windowsUIButtonPanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(63)))), ((int)(((byte)(63)))), ((int)(((byte)(63))))); 134 | windowsUIButtonImageOptions4.ImageUri.Uri = "Apply;Size32x32;GrayScaled"; 135 | this.windowsUIButtonPanel.Buttons.AddRange(new DevExpress.XtraEditors.ButtonPanel.IBaseButton[] { 136 | new DevExpress.XtraBars.Docking2010.WindowsUIButton("确认", true, windowsUIButtonImageOptions4, DevExpress.XtraBars.Docking2010.ButtonStyle.PushButton, "", -1, true, null, true, false, true, null, -1, false)}); 137 | this.windowsUIButtonPanel.Dock = System.Windows.Forms.DockStyle.Bottom; 138 | this.windowsUIButtonPanel.EnableImageTransparency = true; 139 | this.windowsUIButtonPanel.ForeColor = System.Drawing.Color.White; 140 | this.windowsUIButtonPanel.Location = new System.Drawing.Point(0, 271); 141 | this.windowsUIButtonPanel.Margin = new System.Windows.Forms.Padding(5); 142 | this.windowsUIButtonPanel.MaximumSize = new System.Drawing.Size(0, 65); 143 | this.windowsUIButtonPanel.MinimumSize = new System.Drawing.Size(70, 65); 144 | this.windowsUIButtonPanel.Name = "windowsUIButtonPanel"; 145 | this.windowsUIButtonPanel.Size = new System.Drawing.Size(546, 65); 146 | this.windowsUIButtonPanel.TabIndex = 5; 147 | this.windowsUIButtonPanel.Text = "windowsUIButtonPanel"; 148 | this.windowsUIButtonPanel.UseButtonBackgroundImages = false; 149 | this.windowsUIButtonPanel.ButtonClick += new DevExpress.XtraBars.Docking2010.ButtonEventHandler(this.windowsUIButtonPanel_ButtonClick); 150 | // 151 | // AboutBox 152 | // 153 | this.Appearance.BackColor = System.Drawing.Color.White; 154 | this.Appearance.Options.UseBackColor = true; 155 | this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F); 156 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 157 | this.ClientSize = new System.Drawing.Size(546, 336); 158 | this.Controls.Add(this.layoutControl); 159 | this.Controls.Add(this.windowsUIButtonPanel); 160 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; 161 | this.Name = "AboutBox"; 162 | this.ShowIcon = false; 163 | this.ShowInTaskbar = false; 164 | this.Text = "关于"; 165 | ((System.ComponentModel.ISupportInitialize)(this.layoutControl)).EndInit(); 166 | this.layoutControl.ResumeLayout(false); 167 | ((System.ComponentModel.ISupportInitialize)(this.me_info.Properties)).EndInit(); 168 | ((System.ComponentModel.ISupportInitialize)(this.me_explain.Properties)).EndInit(); 169 | ((System.ComponentModel.ISupportInitialize)(this.layoutControlGroup)).EndInit(); 170 | ((System.ComponentModel.ISupportInitialize)(this.splitterItem1)).EndInit(); 171 | ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem1)).EndInit(); 172 | ((System.ComponentModel.ISupportInitialize)(this.layoutControlItem2)).EndInit(); 173 | this.ResumeLayout(false); 174 | 175 | } 176 | 177 | #endregion 178 | 179 | private DevExpress.XtraLayout.LayoutControl layoutControl; 180 | private DevExpress.XtraLayout.LayoutControlGroup layoutControlGroup; 181 | private DevExpress.XtraBars.Docking2010.WindowsUIButtonPanel windowsUIButtonPanel; 182 | private DevExpress.XtraLayout.SplitterItem splitterItem1; 183 | private DevExpress.XtraEditors.MemoEdit me_info; 184 | private DevExpress.XtraEditors.MemoEdit me_explain; 185 | private DevExpress.XtraLayout.LayoutControlItem layoutControlItem1; 186 | private DevExpress.XtraLayout.LayoutControlItem layoutControlItem2; 187 | } 188 | } -------------------------------------------------------------------------------- /BaiSqlFormatForm2/AboutBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Text; 7 | using System.Linq; 8 | using System.Windows.Forms; 9 | using DevExpress.XtraEditors; 10 | using System.ComponentModel.DataAnnotations; 11 | using DevExpress.XtraBars; 12 | 13 | namespace BaiSqlFormatForm2 14 | { 15 | public partial class AboutBox : XtraForm 16 | { 17 | public AboutBox() 18 | { 19 | InitializeComponent(); 20 | this.me_info.ReadOnly = true; 21 | this.me_explain.ReadOnly = true; 22 | this.me_info.Text = "产品名称:SQL代码格式调整工具\r\n\r\n"+ 23 | "版 本:v2.0\r\n\r\n" + 24 | "作 者:Bai\r\n\r\n" + 25 | "框 架:.NET Framework 4.0"; 26 | this.me_explain.Text = AssemblyDescription; 27 | } 28 | 29 | public string AssemblyDescription 30 | { 31 | get 32 | { 33 | return "1) 本程序理论上支持所有SQL/HQL语句的格式调整,包括但不限于普通数据库DDL、DML、DCL," + 34 | "理论上也支持存储过程、视图等语句格式调整。但不能保证效果完美(由于时间原因," + 35 | "只针对部分大数据ETL涉及到的HQL语法进行了测试)" + "\r\n\r\n" + 36 | "2) 疑似格式调整错误的日志(只保留最后一个错误日期)将会记录到本地文件夹,文件位置:本程序所在位置\\logs\\formatErrLog.log" + "\r\n\r\n" + 37 | "3) 程序错误日志也会记录在本地文件夹(所有错误信息全部保留),文件位置:本程序所在位置\\logs\\appErrLog.log"; 38 | } 39 | } 40 | 41 | private void windowsUIButtonPanel_ButtonClick(object sender, DevExpress.XtraBars.Docking2010.ButtonEventArgs e) 42 | { 43 | switch (e.Button.ToString()) 44 | { 45 | case "Caption = '确认'": 46 | this.Close(); 47 | break; 48 | default: 49 | break; 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/AboutBox.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/App.config: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/BaiSqlFormatForm2.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 8.0.30703 7 | 2.0 8 | {D78DC06C-52B1-4877-9A3E-12DA3C36DBC2} 9 | WinExe 10 | Properties 11 | BaiSqlFormatForm2 12 | BaiSqlFormatForm2 13 | v4.0 14 | 512 15 | publish\ 16 | true 17 | Disk 18 | false 19 | Foreground 20 | 7 21 | Days 22 | false 23 | false 24 | true 25 | 0 26 | 1.0.0.%2a 27 | false 28 | false 29 | true 30 | 31 | 32 | AnyCPU 33 | true 34 | full 35 | false 36 | bin\Debug\ 37 | DEBUG;TRACE 38 | prompt 39 | 4 40 | 41 | 42 | AnyCPU 43 | pdbonly 44 | true 45 | bin\Release\ 46 | TRACE 47 | prompt 48 | 4 49 | 50 | 51 | sql_bai_icon.ico 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 | Form 80 | 81 | 82 | AboutBox.cs 83 | 84 | 85 | Component 86 | 87 | 88 | Component 89 | 90 | 91 | Form 92 | 93 | 94 | MainForm.cs 95 | 96 | 97 | 98 | 99 | 100 | AboutBox.cs 101 | 102 | 103 | MainForm.cs 104 | 105 | 106 | 107 | ResXFileCodeGenerator 108 | Resources.Designer.cs 109 | Designer 110 | 111 | 112 | True 113 | Resources.resx 114 | 115 | 116 | 117 | SettingsSingleFileGenerator 118 | Settings.Designer.cs 119 | 120 | 121 | True 122 | Settings.settings 123 | True 124 | 125 | 126 | 127 | 128 | {adbdfdca-cab6-4569-9151-0bd42e65b400} 129 | BaiSqlFormatLib 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | False 138 | Microsoft .NET Framework 4 %28x86 和 x64%29 139 | true 140 | 141 | 142 | False 143 | .NET Framework 3.5 SP1 144 | false 145 | 146 | 147 | False 148 | Windows Installer 4.5 149 | true 150 | 151 | 152 | 153 | 160 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/FrameworkClassReplacements/CustomContentWebBrowser.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | using System.Windows.Forms; 23 | using System.Runtime.InteropServices; 24 | 25 | namespace BaiSqlFormatForm2.FrameworkClassReplacements 26 | { 27 | public class CustomContentWebBrowser : System.Windows.Forms.WebBrowser 28 | { 29 | // WebBrowser control, modified to allow easy setting of HTML content, based on: 30 | //http://weblogs.asp.net/gunnarpeipman/archive/2009/08/15/displaying-custom-html-in-webbrowser-control.aspx 31 | // Also disabling navigation sound, as per: 32 | //https://connect.microsoft.com/VisualStudio/feedback/details/345528/webbrowser-control-in-wpf-disable-sound 33 | 34 | private const int DISABLE_NAVIGATION_SOUNDS = 21; 35 | private const int SET_FEATURE_ON_PROCESS = 0x00000002; 36 | 37 | [DllImport("urlmon.dll")] 38 | [PreserveSig] 39 | [return: MarshalAs(UnmanagedType.Error)] 40 | static extern int CoInternetSetFeatureEnabled(int FeatureEntry, [MarshalAs(UnmanagedType.U4)] int dwFlags, bool fEnable); 41 | 42 | public void SetHTML(string htmlContent) 43 | { 44 | bool allowedNavigation = AllowNavigation; 45 | AllowNavigation = true; 46 | CoInternetSetFeatureEnabled(DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, true); 47 | this.Navigate("about:blank"); 48 | if (this.Document != null) 49 | { 50 | this.Document.Write(string.Empty); 51 | } 52 | this.DocumentText = htmlContent; 53 | CoInternetSetFeatureEnabled(DISABLE_NAVIGATION_SOUNDS, SET_FEATURE_ON_PROCESS, false); 54 | AllowNavigation = allowedNavigation; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/FrameworkClassReplacements/SelectableTextBox.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | using System.Windows.Forms; 23 | 24 | namespace BaiSqlFormatForm2.FrameworkClassReplacements 25 | { 26 | public class SelectableTextBox : TextBox 27 | { 28 | //Ctrl-A support in .Net multiline textboxes. 29 | // adapted from stackoverflow: 30 | // http://stackoverflow.com/questions/225711/stop-the-bell-on-ctrl-a-winforms/230417#230417 31 | 32 | protected override bool ProcessCmdKey(ref Message msg, Keys keyData) 33 | { 34 | if (keyData == (Keys.A | Keys.Control)) 35 | { 36 | this.SelectionStart = 0; 37 | this.SelectionLength = this.Text.Length; 38 | this.Focus(); 39 | return true; 40 | } 41 | return base.ProcessCmdKey(ref msg, keyData); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/Others/WriteLog.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | 3 | namespace BaiSqlFormatForm2.Others 4 | { 5 | class WriteLog 6 | { 7 | static object _formatLogLock = new object(); 8 | static object _errLogLock = new object(); 9 | 10 | /// 11 | /// 记录格式调整错误信息 12 | /// 13 | /// txt文件保存的路径,没有就创建,有内容就覆盖。例:"E:\\text.txt" 14 | /// 要写入的内容 15 | public static void WriteFormatLog(string path, string fileName, string content) 16 | { 17 | 18 | if (!Directory.Exists(path)) Directory.CreateDirectory(path); 19 | if (!File.Exists(path + "//" + fileName)) File.Create(path + "//" + fileName); 20 | 21 | lock (_formatLogLock) 22 | { 23 | using (StreamWriter file = new StreamWriter(path + "//" + fileName)) 24 | { 25 | file.Write(content); 26 | file.Close(); 27 | } 28 | } 29 | } 30 | 31 | 32 | /// 33 | /// 记录程序错误日志 34 | /// 35 | /// 36 | public static void WriteErrLog(string content) 37 | { 38 | if (!Directory.Exists("logs")) 39 | { 40 | Directory.CreateDirectory("logs"); 41 | } 42 | lock (_errLogLock) 43 | { 44 | using (var sw = new StreamWriter(@"logs\appErrLog.log", true)) 45 | { 46 | sw.WriteLine(content); 47 | sw.WriteLine("------------------------------------------------------------------------------------------------------------------------"); 48 | sw.Close(); 49 | } 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using DevExpress.UserSkins; 4 | using System.Threading; 5 | using BaiSqlFormatForm2.Others; 6 | 7 | namespace BaiSqlFormatForm2 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | try 18 | { 19 | //添加事件处理程序未捕获的异常 20 | Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); 21 | //添加事件处理UI线程异常 22 | Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); 23 | //添加事件处理非UI线程异常 24 | AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); 25 | Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("zh-Hans"); 26 | Application.EnableVisualStyles(); 27 | Application.SetCompatibleTextRenderingDefault(false); 28 | 29 | bool isAppRunning = false; 30 | Mutex mutex = new Mutex(true, System.Diagnostics.Process.GetCurrentProcess().ProcessName, out isAppRunning); 31 | if (!isAppRunning) 32 | { 33 | DevExpress.XtraEditors.XtraMessageBox.Show("程序已运行,不能再次打开!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); 34 | Environment.Exit(1); 35 | } 36 | 37 | BonusSkins.Register(); 38 | Application.Run(new MainForm()); 39 | } 40 | catch (Exception ex) 41 | { 42 | string str = ""; 43 | string strDateInfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n" + "出现应用程序未处理的异常:\r\n"; 44 | 45 | if (ex != null) 46 | { 47 | str = string.Format(strDateInfo + "异常类型:{0}\r\n异常消息:{1}\r\n异常信息:{2}\r\n", 48 | ex.GetType().Name, ex.Message, ex.StackTrace); 49 | } 50 | else 51 | { 52 | str = string.Format("应用程序线程错误:{0}", ex); 53 | } 54 | 55 | //写日志 56 | WriteLog.WriteErrLog(str); 57 | DevExpress.XtraEditors.XtraMessageBox.Show("程序发生错误,请及时联系作者!", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); 58 | } 59 | } 60 | 61 | 62 | /// 63 | /// 程序异常处理 64 | /// 65 | /// 66 | /// 67 | static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) 68 | { 69 | 70 | string str = ""; 71 | string strDateInfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n" + "出现应用程序未处理的异常:\r\n"; 72 | Exception error = e.Exception as Exception; 73 | if (error != null) 74 | { 75 | str = string.Format(strDateInfo + "异常类型:{0}\r\n异常消息:{1}\r\n异常信息:{2}\r\n", 76 | error.GetType().Name, error.Message, error.StackTrace); 77 | } 78 | else 79 | { 80 | str = string.Format("应用程序线程错误:{0}", e); 81 | } 82 | //写日志 83 | WriteLog.WriteErrLog(str); 84 | DevExpress.XtraEditors.XtraMessageBox.Show("程序发生错误,请及时联系作者!", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); 85 | } 86 | 87 | /// 88 | /// 处理UI异常 89 | /// 90 | /// 91 | /// 92 | static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) 93 | { 94 | string str = ""; 95 | Exception error = e.ExceptionObject as Exception; 96 | string strDateInfo = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\r\n" + "出现应用程序未处理的异常:\r\n"; 97 | if (error != null) 98 | { 99 | str = string.Format(strDateInfo + "Application UnhandledException:{0};\n\r堆栈信息:{1}", error.Message, error.StackTrace); 100 | } 101 | else 102 | { 103 | str = string.Format("Application UnhandledError:{0}", e); 104 | } 105 | //写日志 106 | WriteLog.WriteErrLog(str); 107 | DevExpress.XtraEditors.XtraMessageBox.Show("程序发生错误,请及时联系作者!", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error); 108 | } 109 | } 110 | } -------------------------------------------------------------------------------- /BaiSqlFormatForm2/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.InteropServices; 3 | // General Information about an assembly is controlled through the following 4 | // set of attributes. Change these attribute values to modify the information 5 | // associated with an assembly. 6 | [assembly: AssemblyTitle("BaiSqlFormatForm2")] 7 | [assembly: AssemblyDescription("")] 8 | [assembly: AssemblyConfiguration("")] 9 | [assembly: AssemblyCompany("")] 10 | [assembly: AssemblyProduct("BaiSqlFormatForm2")] 11 | [assembly: AssemblyCopyright("Copyright © 2019")] 12 | [assembly: AssemblyTrademark("")] 13 | [assembly: AssemblyCulture("")] 14 | // Setting ComVisible to false makes the types in this assembly not visible 15 | // to COM components. If you need to access a type in this assembly from 16 | // COM, set the ComVisible attribute to true on that type. 17 | [assembly: ComVisible(false)] 18 | // The following GUID is for the ID of the typelib if this project is exposed to COM 19 | [assembly: Guid("83f9d8f8-1fc1-4c57-bef0-9b0f33d4ff9e")] 20 | // Version information for an assembly consists of the following four values: 21 | // 22 | // Major Version 23 | // Minor Version 24 | // Build Number 25 | // Revision 26 | // 27 | // You can specify all the values or you can default the Build and Revision Numbers 28 | // by using the '*' as shown below: 29 | // [assembly: AssemblyVersion("1.0.*")] 30 | [assembly: AssemblyVersion("1.0.0.0")] 31 | [assembly: AssemblyFileVersion("1.0.0.0")] 32 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.42000 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace FluentDesignForm.Properties 12 | { 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources 26 | { 27 | 28 | private static global::System.Resources.ResourceManager resourceMan; 29 | 30 | private static global::System.Globalization.CultureInfo resourceCulture; 31 | 32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 33 | internal Resources() 34 | { 35 | } 36 | 37 | /// 38 | /// Returns the cached ResourceManager instance used by this class. 39 | /// 40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 41 | internal static global::System.Resources.ResourceManager ResourceManager 42 | { 43 | get 44 | { 45 | if ((resourceMan == null)) 46 | { 47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FluentDesignForm.Properties.Resources", typeof(Resources).Assembly); 48 | resourceMan = temp; 49 | } 50 | return resourceMan; 51 | } 52 | } 53 | 54 | /// 55 | /// Overrides the current thread's CurrentUICulture property for all 56 | /// resource lookups using this strongly typed resource class. 57 | /// 58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 59 | internal static global::System.Globalization.CultureInfo Culture 60 | { 61 | get 62 | { 63 | return resourceCulture; 64 | } 65 | set 66 | { 67 | resourceCulture = value; 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 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 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace BaiSqlFormatForm2.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | 26 | [global::System.Configuration.UserScopedSettingAttribute()] 27 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 28 | [global::System.Configuration.DefaultSettingValueAttribute("170")] 29 | public int MaxLineWidth { 30 | get { 31 | return ((int)(this["MaxLineWidth"])); 32 | } 33 | set { 34 | this["MaxLineWidth"] = value; 35 | } 36 | } 37 | 38 | [global::System.Configuration.UserScopedSettingAttribute()] 39 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 40 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 41 | public bool ExpandCommaLists { 42 | get { 43 | return ((bool)(this["ExpandCommaLists"])); 44 | } 45 | set { 46 | this["ExpandCommaLists"] = value; 47 | } 48 | } 49 | 50 | [global::System.Configuration.UserScopedSettingAttribute()] 51 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 52 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 53 | public bool KeywordAlign { 54 | get { 55 | return ((bool)(this["KeywordAlign"])); 56 | } 57 | set { 58 | this["KeywordAlign"] = value; 59 | } 60 | } 61 | 62 | [global::System.Configuration.UserScopedSettingAttribute()] 63 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 64 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 65 | public bool ExpandBooleanExpressions { 66 | get { 67 | return ((bool)(this["ExpandBooleanExpressions"])); 68 | } 69 | set { 70 | this["ExpandBooleanExpressions"] = value; 71 | } 72 | } 73 | 74 | [global::System.Configuration.UserScopedSettingAttribute()] 75 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 76 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 77 | public bool ExpandCaseStatements { 78 | get { 79 | return ((bool)(this["ExpandCaseStatements"])); 80 | } 81 | set { 82 | this["ExpandCaseStatements"] = value; 83 | } 84 | } 85 | 86 | [global::System.Configuration.UserScopedSettingAttribute()] 87 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 88 | [global::System.Configuration.DefaultSettingValueAttribute("False")] 89 | public bool ExpandBetweenConditions { 90 | get { 91 | return ((bool)(this["ExpandBetweenConditions"])); 92 | } 93 | set { 94 | this["ExpandBetweenConditions"] = value; 95 | } 96 | } 97 | 98 | [global::System.Configuration.UserScopedSettingAttribute()] 99 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 100 | [global::System.Configuration.DefaultSettingValueAttribute("False")] 101 | public bool ExpandInLists { 102 | get { 103 | return ((bool)(this["ExpandInLists"])); 104 | } 105 | set { 106 | this["ExpandInLists"] = value; 107 | } 108 | } 109 | 110 | [global::System.Configuration.UserScopedSettingAttribute()] 111 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 112 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 113 | public bool BreakJoinOnSections { 114 | get { 115 | return ((bool)(this["BreakJoinOnSections"])); 116 | } 117 | set { 118 | this["BreakJoinOnSections"] = value; 119 | } 120 | } 121 | 122 | [global::System.Configuration.UserScopedSettingAttribute()] 123 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 124 | [global::System.Configuration.DefaultSettingValueAttribute("False")] 125 | public bool UppercaseKeywords { 126 | get { 127 | return ((bool)(this["UppercaseKeywords"])); 128 | } 129 | set { 130 | this["UppercaseKeywords"] = value; 131 | } 132 | } 133 | 134 | [global::System.Configuration.UserScopedSettingAttribute()] 135 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 136 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 137 | public bool HTMLColoring { 138 | get { 139 | return ((bool)(this["HTMLColoring"])); 140 | } 141 | set { 142 | this["HTMLColoring"] = value; 143 | } 144 | } 145 | 146 | [global::System.Configuration.UserScopedSettingAttribute()] 147 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 148 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 149 | public bool AllIndent { 150 | get { 151 | return ((bool)(this["AllIndent"])); 152 | } 153 | set { 154 | this["AllIndent"] = value; 155 | } 156 | } 157 | 158 | [global::System.Configuration.UserScopedSettingAttribute()] 159 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 160 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 161 | public bool AsAlign { 162 | get { 163 | return ((bool)(this["AsAlign"])); 164 | } 165 | set { 166 | this["AsAlign"] = value; 167 | } 168 | } 169 | 170 | [global::System.Configuration.UserScopedSettingAttribute()] 171 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 172 | [global::System.Configuration.DefaultSettingValueAttribute("False")] 173 | public bool AllUpper { 174 | get { 175 | return ((bool)(this["AllUpper"])); 176 | } 177 | set { 178 | this["AllUpper"] = value; 179 | } 180 | } 181 | 182 | [global::System.Configuration.UserScopedSettingAttribute()] 183 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 184 | [global::System.Configuration.DefaultSettingValueAttribute("35")] 185 | public int KeywordLengthOfAs { 186 | get { 187 | return ((int)(this["KeywordLengthOfAs"])); 188 | } 189 | set { 190 | this["KeywordLengthOfAs"] = value; 191 | } 192 | } 193 | 194 | [global::System.Configuration.UserScopedSettingAttribute()] 195 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 196 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 197 | public bool chkdefault { 198 | get { 199 | return ((bool)(this["chkdefault"])); 200 | } 201 | set { 202 | this["chkdefault"] = value; 203 | } 204 | } 205 | 206 | [global::System.Configuration.UserScopedSettingAttribute()] 207 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 208 | [global::System.Configuration.DefaultSettingValueAttribute("True")] 209 | public bool addSemicolon { 210 | get { 211 | return ((bool)(this["addSemicolon"])); 212 | } 213 | set { 214 | this["addSemicolon"] = value; 215 | } 216 | } 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 170 7 | 8 | 9 | True 10 | 11 | 12 | True 13 | 14 | 15 | True 16 | 17 | 18 | True 19 | 20 | 21 | False 22 | 23 | 24 | False 25 | 26 | 27 | True 28 | 29 | 30 | False 31 | 32 | 33 | True 34 | 35 | 36 | True 37 | 38 | 39 | True 40 | 41 | 42 | False 43 | 44 | 45 | 35 46 | 47 | 48 | True 49 | 50 | 51 | True 52 | 53 | 54 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/Properties/licenses.licx: -------------------------------------------------------------------------------- 1 | DevExpress.XtraBars.Docking.DockManager, DevExpress.XtraBars.v18.1, Version=18.1.11.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a 2 | DevExpress.XtraBars.Docking2010.DocumentManager, DevExpress.XtraBars.v18.1, Version=18.1.11.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a 3 | DevExpress.XtraBars.Ribbon.RibbonControl, DevExpress.XtraBars.v18.1, Version=18.1.11.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a 4 | DevExpress.XtraEditors.CheckEdit, DevExpress.XtraEditors.v18.1, Version=18.1.11.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a 5 | -------------------------------------------------------------------------------- /BaiSqlFormatForm2/sql_bai_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baihongbin/SqlFormat/2aaedc1f9ae84e67b8ef528b7041de0044dcc870/BaiSqlFormatForm2/sql_bai_icon.ico -------------------------------------------------------------------------------- /BaiSqlFormatLib/BaiSqlFormatLib.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {ADBDFDCA-CAB6-4569-9151-0BD42E65B400} 9 | Library 10 | Properties 11 | BaiSqlFormatLib 12 | BaiSqlFormatLib 13 | v2.0 14 | 512 15 | 16 | 17 | 18 | 19 | 3.5 20 | 21 | 22 | 23 | true 24 | full 25 | false 26 | bin\Debug\ 27 | DEBUG;TRACE 28 | prompt 29 | 4 30 | false 31 | 32 | 33 | pdbonly 34 | true 35 | bin\Release\ 36 | TRACE 37 | prompt 38 | 4 39 | false 40 | 41 | 42 | 43 | False 44 | References\LinqBridge\LinqBridge.dll 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 | 94 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/BaseFormatterState.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | 20 | */ 21 | 22 | using System; 23 | using System.Text; 24 | 25 | namespace BaiSqlFormatLib 26 | { 27 | internal class BaseFormatterState 28 | { 29 | public BaseFormatterState(bool htmlOutput) 30 | { 31 | HtmlOutput = htmlOutput; 32 | } 33 | 34 | protected bool HtmlOutput { get; set; } 35 | protected StringBuilder _outBuilder = new StringBuilder(); 36 | 37 | public virtual void AddOutputContent(string content) 38 | { 39 | AddOutputContent(content, null); 40 | } 41 | 42 | public virtual void AddOutputContent(string content, string htmlClassName) 43 | { 44 | if (HtmlOutput) 45 | { 46 | if (!string.IsNullOrEmpty(htmlClassName)) 47 | _outBuilder.Append(@""); 48 | _outBuilder.Append(Utils.HtmlEncode(content)); 49 | if (!string.IsNullOrEmpty(htmlClassName)) 50 | _outBuilder.Append(""); 51 | } 52 | else 53 | _outBuilder.Append(content); 54 | } 55 | 56 | public virtual void OpenClass(string htmlClassName) 57 | { 58 | if (htmlClassName == null) 59 | throw new ArgumentNullException("htmlClassName"); 60 | 61 | if (HtmlOutput) 62 | _outBuilder.Append(@""); 63 | } 64 | 65 | public virtual void CloseClass() 66 | { 67 | if (HtmlOutput) 68 | _outBuilder.Append(@""); 69 | } 70 | 71 | public virtual void AddOutputContentRaw(string content) 72 | { 73 | _outBuilder.Append(content); 74 | } 75 | 76 | public virtual void AddOutputLineBreak() 77 | { 78 | _outBuilder.Append(Environment.NewLine); 79 | } 80 | 81 | public string DumpOutput() 82 | { 83 | return _outBuilder.ToString(); 84 | } 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Formatters/HtmlPageWrapper.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | using BaiSqlFormatLib.Interfaces; 23 | 24 | namespace BaiSqlFormatLib.Formatters 25 | { 26 | public class HtmlPageWrapper : ISqlTreeFormatter 27 | { 28 | ISqlTreeFormatter _underlyingFormatter; 29 | 30 | public HtmlPageWrapper(ISqlTreeFormatter underlyingFormatter) 31 | { 32 | if (underlyingFormatter == null) 33 | throw new ArgumentNullException("underlyingFormatter"); 34 | 35 | _underlyingFormatter = underlyingFormatter; 36 | } 37 | 38 | private const string HTML_OUTER_PAGE = @" 39 | 40 | 41 | 42 | 43 | 74 |
{0}
75 | 76 | 77 | "; 78 | 79 | public bool HTMLFormatted { get { return true; } } 80 | public string ErrorOutputPrefix { 81 | get 82 | { 83 | return _underlyingFormatter.ErrorOutputPrefix; 84 | } 85 | set 86 | { 87 | throw new NotSupportedException("Error output prefix should be set on the underlying formatter - it cannot be set on the Html Page Wrapper."); 88 | } 89 | } 90 | 91 | public string FormatSQLTree(BaiSqlFormatLib.ParseStructure.Node sqlTree) 92 | { 93 | string formattedResult = _underlyingFormatter.FormatSQLTree(sqlTree); 94 | string SqlHtml; 95 | if (_underlyingFormatter.HTMLFormatted) 96 | SqlHtml = string.Format(HTML_OUTER_PAGE, formattedResult); 97 | else 98 | SqlHtml = string.Format(HTML_OUTER_PAGE, Utils.HtmlEncode(formattedResult)); 99 | 100 | 101 | return SqlHtml; 102 | } 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Formatters/TSqlStandardFormatterOptions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2013 Tao Klerks 5 | 6 | Additional Contributors: 7 | * Timothy Klenke, 2012 8 | 9 | This program is free software: you can redistribute it and/or modify 10 | it under the terms of the GNU Affero General Public License as published by 11 | the Free Software Foundation, either version 3 of the License, or 12 | (at your option) any later version. 13 | 14 | This program is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 | GNU Affero General Public License for more details. 18 | 19 | You should have received a copy of the GNU Affero General Public License 20 | along with this program. If not, see . 21 | 22 | */ 23 | 24 | using System; 25 | using System.Collections.Generic; 26 | using System.Linq; 27 | 28 | namespace BaiSqlFormatLib.Formatters 29 | { 30 | public class TSqlStandardFormatterOptions 31 | { 32 | public TSqlStandardFormatterOptions() 33 | { 34 | IndentString = "\t"; 35 | SpacesPerTab = 4; 36 | MaxLineWidth = 999; 37 | ExpandCommaLists = true; 38 | TrailingCommas = false; 39 | SpaceAfterExpandedComma = false; 40 | ExpandBooleanExpressions = true; 41 | ExpandBetweenConditions = true; 42 | ExpandCaseStatements = true; 43 | UppercaseKeywords = true; 44 | BreakJoinOnSections = false; 45 | HTMLColoring = false; 46 | KeywordStandardization = false; 47 | ExpandInLists = true; 48 | NewClauseLineBreaks = 1; 49 | NewStatementLineBreaks = 2; 50 | } 51 | 52 | //Doesn't particularly need to be lazy-loaded, and doesn't need to be threadsafe. 53 | private static readonly TSqlStandardFormatterOptions _defaultOptions = new TSqlStandardFormatterOptions(); 54 | 55 | public TSqlStandardFormatterOptions(string serializedString) : this() { 56 | 57 | if (string.IsNullOrEmpty(serializedString)) 58 | return; 59 | 60 | //PLEASE NOTE: This is not reusable/general-purpose key-value serialization: it does not handle commas in data. 61 | // This will need to be enhanced if we ever need to store formatter options that might contain equals signs or 62 | // commas. 63 | foreach (string kvp in serializedString.Split(',')) 64 | { 65 | string[] splitPair = kvp.Split('='); 66 | string key = splitPair[0]; 67 | string value = splitPair[1]; 68 | 69 | if (key == "IndentString") IndentString = value; 70 | else if (key == "SpacesPerTab") SpacesPerTab = Convert.ToInt32(value); 71 | else if (key == "MaxLineWidth") MaxLineWidth = Convert.ToInt32(value); 72 | else if (key == "ExpandCommaLists") ExpandCommaLists = Convert.ToBoolean(value); 73 | else if (key == "TrailingCommas") TrailingCommas = Convert.ToBoolean(value); 74 | else if (key == "SpaceAfterExpandedComma") SpaceAfterExpandedComma = Convert.ToBoolean(value); 75 | else if (key == "ExpandBooleanExpressions") ExpandBooleanExpressions = Convert.ToBoolean(value); 76 | else if (key == "ExpandBetweenConditions") ExpandBetweenConditions = Convert.ToBoolean(value); 77 | else if (key == "ExpandCaseStatements") ExpandCaseStatements = Convert.ToBoolean(value); 78 | else if (key == "UppercaseKeywords") UppercaseKeywords = Convert.ToBoolean(value); 79 | else if (key == "BreakJoinOnSections") BreakJoinOnSections = Convert.ToBoolean(value); 80 | else if (key == "HTMLColoring") HTMLColoring = Convert.ToBoolean(value); 81 | else if (key == "KeywordStandardization") KeywordStandardization = Convert.ToBoolean(value); 82 | else if (key == "ExpandInLists") ExpandInLists = Convert.ToBoolean(value); 83 | else if (key == "NewClauseLineBreaks") NewClauseLineBreaks = Convert.ToInt32(value); 84 | else if (key == "NewStatementLineBreaks") NewStatementLineBreaks = Convert.ToInt32(value); 85 | else throw new ArgumentException("Unknown option: " + key); 86 | } 87 | 88 | } 89 | 90 | //PLEASE NOTE: This is not reusable/general-purpose key-value serialization: it does not handle commas in data. 91 | // This will need to be enhanced if we ever need to store formatter options that might contain equals signs or 92 | // commas. 93 | public string ToSerializedString() 94 | { 95 | var overrides = new Dictionary(); 96 | 97 | if (IndentString != _defaultOptions.IndentString) overrides.Add("IndentString", IndentString); 98 | if (SpacesPerTab != _defaultOptions.SpacesPerTab) overrides.Add("SpacesPerTab", SpacesPerTab.ToString()); 99 | if (MaxLineWidth != _defaultOptions.MaxLineWidth) overrides.Add("MaxLineWidth", MaxLineWidth.ToString()); 100 | if (ExpandCommaLists != _defaultOptions.ExpandCommaLists) overrides.Add("ExpandCommaLists", ExpandCommaLists.ToString()); 101 | if (TrailingCommas != _defaultOptions.TrailingCommas) overrides.Add("TrailingCommas", TrailingCommas.ToString()); 102 | if (SpaceAfterExpandedComma != _defaultOptions.SpaceAfterExpandedComma) overrides.Add("SpaceAfterExpandedComma", SpaceAfterExpandedComma.ToString()); 103 | if (ExpandBooleanExpressions != _defaultOptions.ExpandBooleanExpressions) overrides.Add("ExpandBooleanExpressions", ExpandBooleanExpressions.ToString()); 104 | if (ExpandBetweenConditions != _defaultOptions.ExpandBetweenConditions) overrides.Add("ExpandBetweenConditions", ExpandBetweenConditions.ToString()); 105 | if (ExpandCaseStatements != _defaultOptions.ExpandCaseStatements) overrides.Add("ExpandCaseStatements", ExpandCaseStatements.ToString()); 106 | if (UppercaseKeywords != _defaultOptions.UppercaseKeywords) overrides.Add("UppercaseKeywords", UppercaseKeywords.ToString()); 107 | if (BreakJoinOnSections != _defaultOptions.BreakJoinOnSections) overrides.Add("BreakJoinOnSections", BreakJoinOnSections.ToString()); 108 | if (HTMLColoring != _defaultOptions.HTMLColoring) overrides.Add("HTMLColoring", HTMLColoring.ToString()); 109 | if (KeywordStandardization != _defaultOptions.KeywordStandardization) overrides.Add("KeywordStandardization", KeywordStandardization.ToString()); 110 | if (ExpandInLists != _defaultOptions.ExpandInLists) overrides.Add("ExpandInLists", ExpandInLists.ToString()); 111 | if (NewClauseLineBreaks != _defaultOptions.NewClauseLineBreaks) overrides.Add("NewClauseLineBreaks", NewClauseLineBreaks.ToString()); 112 | if (NewStatementLineBreaks != _defaultOptions.NewStatementLineBreaks) overrides.Add("NewStatementLineBreaks", NewStatementLineBreaks.ToString()); 113 | NewStatementLineBreaks = 2; 114 | 115 | if (overrides.Count == 0) return string.Empty; 116 | return string.Join(",", overrides.Select((kvp) => kvp.Key + "=" + kvp.Value).ToArray()); 117 | 118 | } 119 | 120 | private string _indentString; 121 | public string IndentString 122 | { 123 | get 124 | { 125 | return _indentString; 126 | } 127 | set 128 | { 129 | _indentString = value.Replace("\\t", "\t").Replace("\\s", " "); 130 | } 131 | } 132 | 133 | public int SpacesPerTab { get; set; } 134 | public int MaxLineWidth { get; set; } 135 | public bool ExpandCommaLists { get; set; } 136 | public bool TrailingCommas { get; set; } 137 | public bool SpaceAfterExpandedComma { get; set; } 138 | public bool ExpandBooleanExpressions { get; set; } 139 | public bool ExpandCaseStatements { get; set; } 140 | public bool ExpandBetweenConditions { get; set; } 141 | public bool UppercaseKeywords { get; set; } 142 | public bool BreakJoinOnSections { get; set; } 143 | public bool HTMLColoring { get; set; } 144 | public bool KeywordStandardization { get; set; } 145 | public bool ExpandInLists { get; set; } 146 | public int NewClauseLineBreaks { get; set; } 147 | public int NewStatementLineBreaks { get; set; } 148 | public bool KeywordAlign { get; set; } 149 | public bool AsAlign { get; set; } 150 | public bool AllIndent { get; set; } 151 | public bool AllUpper { get; set; } 152 | public int KeywordLengthOfAs { get; set; } 153 | } 154 | } 155 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Interfaces/IParseTree.cs: -------------------------------------------------------------------------------- 1 | using System.Xml; 2 | 3 | namespace BaiSqlFormatLib.Interfaces 4 | { 5 | interface IParseTree 6 | { 7 | XmlDocument ToXmlDoc(); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Interfaces/ISqlTokenFormatter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | namespace BaiSqlFormatLib.Interfaces 22 | { 23 | public interface ISqlTokenFormatter 24 | { 25 | string ErrorOutputPrefix { get; set; } 26 | string FormatSQLTokens(ITokenList sqlTokenList); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Interfaces/ISqlTokenParser.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using BaiSqlFormatLib.ParseStructure; 22 | 23 | namespace BaiSqlFormatLib.Interfaces 24 | { 25 | public interface ISqlTokenParser 26 | { 27 | Node ParseSQL(ITokenList tokenList); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Interfaces/ISqlTokenizer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | namespace BaiSqlFormatLib.Interfaces 22 | { 23 | public interface ISqlTokenizer 24 | { 25 | ITokenList TokenizeSQL(string inputSQL); 26 | ITokenList TokenizeSQL(string inputSQL, long? requestedMarkerPosition); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Interfaces/ISqlTreeFormatter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using BaiSqlFormatLib.ParseStructure; 22 | 23 | namespace BaiSqlFormatLib.Interfaces 24 | { 25 | public interface ISqlTreeFormatter 26 | { 27 | bool HTMLFormatted { get; } 28 | string ErrorOutputPrefix { get; set; } 29 | string FormatSQLTree(Node sqlTree); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Interfaces/IToken.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | 23 | namespace BaiSqlFormatLib.Interfaces 24 | { 25 | public interface IToken 26 | { 27 | SqlTokenType Type { get; set; } 28 | string Value { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Interfaces/ITokenList.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | using System.Collections.Generic; 23 | 24 | namespace BaiSqlFormatLib.Interfaces 25 | { 26 | public interface ITokenList : IList 27 | { 28 | bool HasUnfinishedToken { get; set; } 29 | string PrettyPrint(); 30 | IList GetRange(int index, int count); 31 | IList GetRangeByIndex(int fromIndex, int toIndex); 32 | IToken MarkerToken { get; } 33 | long? MarkerPosition { get; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Interfaces/MessagingConstants.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | namespace BaiSqlFormatLib.Interfaces 22 | { 23 | public static class MessagingConstants 24 | { 25 | public const string FormatErrorDefaultMessage = "--注意!SQL解析过程中遇到错误!请检查输入SQL是否正确!"; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Interfaces/SqlHtmlConstants.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | 23 | namespace BaiSqlFormatLib.Interfaces 24 | { 25 | public static class SqlHtmlConstants 26 | { 27 | public const string CLASS_OPERATOR = "SQLOperator"; 28 | public const string CLASS_COMMENT = "SQLComment"; 29 | public const string CLASS_STRING = "SQLString"; 30 | public const string CLASS_FUNCTION = "SQLFunction"; 31 | public const string CLASS_KEYWORD = "SQLKeyword"; 32 | public const string CLASS_ERRORHIGHLIGHT = "SQLErrorHighlight"; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Interfaces/SqlStructureConstants.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | namespace BaiSqlFormatLib.Interfaces 22 | { 23 | public static class SqlStructureConstants 24 | { 25 | 26 | public const string ENAME_SQL_ROOT = "SqlRoot"; 27 | public const string ENAME_SQL_STATEMENT = "SqlStatement"; 28 | public const string ENAME_SQL_CLAUSE = "Clause"; 29 | public const string ENAME_SET_OPERATOR_CLAUSE = "SetOperatorClause"; 30 | public const string ENAME_INSERT_CLAUSE = "InsertClause"; 31 | public const string ENAME_BEGIN_END_BLOCK = "BeginEndBlock"; 32 | public const string ENAME_TRY_BLOCK = "TryBlock"; 33 | public const string ENAME_CATCH_BLOCK = "CatchBlock"; 34 | public const string ENAME_BATCH_SEPARATOR = "BatchSeparator"; 35 | public const string ENAME_CASE_STATEMENT = "CaseStatement"; 36 | public const string ENAME_CASE_INPUT = "Input"; 37 | public const string ENAME_CASE_WHEN = "When"; 38 | public const string ENAME_CASE_THEN = "Then"; 39 | public const string ENAME_CASE_ELSE = "CaseElse"; 40 | public const string ENAME_IF_STATEMENT = "IfStatement"; 41 | public const string ENAME_ELSE_CLAUSE = "ElseClause"; 42 | public const string ENAME_BOOLEAN_EXPRESSION = "BooleanExpression"; 43 | public const string ENAME_WHILE_LOOP = "WhileLoop"; 44 | public const string ENAME_CURSOR_DECLARATION = "CursorDeclaration"; 45 | public const string ENAME_CURSOR_FOR_BLOCK = "CursorForBlock"; 46 | public const string ENAME_CURSOR_FOR_OPTIONS = "CursorForOptions"; 47 | public const string ENAME_CTE_WITH_CLAUSE = "CTEWithClause"; 48 | public const string ENAME_CTE_ALIAS = "CTEAlias"; 49 | public const string ENAME_CTE_AS_BLOCK = "CTEAsBlock"; 50 | public const string ENAME_BEGIN_TRANSACTION = "BeginTransaction"; 51 | public const string ENAME_COMMIT_TRANSACTION = "CommitTransaction"; 52 | public const string ENAME_ROLLBACK_TRANSACTION = "RollbackTransaction"; 53 | public const string ENAME_SAVE_TRANSACTION = "SaveTransaction"; 54 | public const string ENAME_DDL_DECLARE_BLOCK = "DDLDeclareBlock"; 55 | public const string ENAME_DDL_PROCEDURAL_BLOCK = "DDLProceduralBlock"; 56 | public const string ENAME_DDL_OTHER_BLOCK = "DDLOtherBlock"; 57 | public const string ENAME_DDL_AS_BLOCK = "DDLAsBlock"; 58 | public const string ENAME_DDL_PARENS = "DDLParens"; 59 | public const string ENAME_DDL_SUBCLAUSE = "DDLSubClause"; 60 | public const string ENAME_DDL_RETURNS = "DDLReturns"; 61 | public const string ENAME_DDLDETAIL_PARENS = "DDLDetailParens"; 62 | public const string ENAME_DDL_WITH_CLAUSE = "DDLWith"; 63 | public const string ENAME_PERMISSIONS_BLOCK = "PermissionsBlock"; 64 | public const string ENAME_PERMISSIONS_DETAIL = "PermissionsDetail"; 65 | public const string ENAME_PERMISSIONS_TARGET = "PermissionsTarget"; 66 | public const string ENAME_PERMISSIONS_RECIPIENT = "PermissionsRecipient"; 67 | public const string ENAME_TRIGGER_CONDITION = "TriggerCondition"; 68 | public const string ENAME_SELECTIONTARGET_PARENS = "SelectionTargetParens"; 69 | public const string ENAME_EXPRESSION_PARENS = "ExpressionParens"; 70 | public const string ENAME_FUNCTION_PARENS = "FunctionParens"; 71 | public const string ENAME_IN_PARENS = "InParens"; 72 | public const string ENAME_FUNCTION_KEYWORD = "FunctionKeyword"; 73 | public const string ENAME_DATATYPE_KEYWORD = "DataTypeKeyword"; 74 | public const string ENAME_COMPOUNDKEYWORD = "CompoundKeyword"; 75 | public const string ENAME_OTHERKEYWORD = "OtherKeyword"; 76 | public const string ENAME_LABEL = "Label"; 77 | public const string ENAME_CONTAINER_OPEN = "ContainerOpen"; 78 | public const string ENAME_CONTAINER_MULTISTATEMENT = "ContainerMultiStatementBody"; 79 | public const string ENAME_CONTAINER_SINGLESTATEMENT = "ContainerSingleStatementBody"; 80 | public const string ENAME_CONTAINER_GENERALCONTENT = "ContainerContentBody"; 81 | public const string ENAME_CONTAINER_CLOSE = "ContainerClose"; 82 | public const string ENAME_SELECTIONTARGET = "SelectionTarget"; 83 | public const string ENAME_MERGE_CLAUSE = "MergeClause"; 84 | public const string ENAME_MERGE_TARGET = "MergeTarget"; 85 | public const string ENAME_MERGE_USING = "MergeUsing"; 86 | public const string ENAME_MERGE_CONDITION = "MergeCondition"; 87 | public const string ENAME_MERGE_WHEN = "MergeWhen"; 88 | public const string ENAME_MERGE_THEN = "MergeThen"; 89 | public const string ENAME_MERGE_ACTION = "MergeAction"; 90 | public const string ENAME_JOIN_ON_SECTION = "JoinOn"; 91 | 92 | public const string ENAME_PSEUDONAME = "PseudoName"; 93 | public const string ENAME_WHITESPACE = "WhiteSpace"; 94 | public const string ENAME_OTHERNODE = "Other"; 95 | public const string ENAME_COMMENT_SINGLELINE = "SingleLineComment"; 96 | public const string ENAME_COMMENT_SINGLELINE_CSTYLE = "SingleLineCommentCStyle"; 97 | public const string ENAME_COMMENT_MULTILINE = "MultiLineComment"; 98 | public const string ENAME_STRING = "String"; 99 | public const string ENAME_NSTRING = "NationalString"; 100 | public const string ENAME_QUOTED_STRING = "QuotedString"; 101 | public const string ENAME_BRACKET_QUOTED_NAME = "BracketQuotedName"; 102 | public const string ENAME_COMMA = "Comma"; 103 | public const string ENAME_PERIOD = "Period"; 104 | public const string ENAME_SEMICOLON = "Semicolon"; 105 | public const string ENAME_SCOPERESOLUTIONOPERATOR = "ScopeResolutionOperator"; 106 | public const string ENAME_ASTERISK = "Asterisk"; 107 | public const string ENAME_EQUALSSIGN = "EqualsSign"; 108 | public const string ENAME_ALPHAOPERATOR = "AlphaOperator"; 109 | public const string ENAME_OTHEROPERATOR = "OtherOperator"; 110 | 111 | public const string ENAME_AND_OPERATOR = "And"; 112 | public const string ENAME_OR_OPERATOR = "Or"; 113 | public const string ENAME_BETWEEN_CONDITION = "Between"; 114 | public const string ENAME_BETWEEN_LOWERBOUND = "LowerBound"; 115 | public const string ENAME_BETWEEN_UPPERBOUND = "UpperBound"; 116 | 117 | public const string ENAME_NUMBER_VALUE = "NumberValue"; 118 | public const string ENAME_MONETARY_VALUE = "MonetaryValue"; 119 | public const string ENAME_BINARY_VALUE = "BinaryValue"; 120 | 121 | //attribute names 122 | public const string ANAME_ERRORFOUND = "errorFound"; 123 | public const string ANAME_HASERROR = "hasError"; 124 | public const string ANAME_DATALOSS = "dataLossLimitation"; 125 | public const string ANAME_SIMPLETEXT = "simpleText"; 126 | 127 | public static string[] ENAMELIST_COMMENT = new string[] { 128 | ENAME_COMMENT_MULTILINE, 129 | ENAME_COMMENT_SINGLELINE, 130 | ENAME_COMMENT_SINGLELINE_CSTYLE 131 | }; 132 | 133 | public static string[] ENAMELIST_NONCONTENT = new string[] { 134 | ENAME_WHITESPACE, 135 | ENAME_COMMENT_MULTILINE, 136 | ENAME_COMMENT_SINGLELINE, 137 | ENAME_COMMENT_SINGLELINE_CSTYLE 138 | }; 139 | 140 | public static string[] ENAMELIST_NONSEMANTICCONTENT = new string[] { 141 | ENAME_SQL_CLAUSE, 142 | ENAME_DDL_PROCEDURAL_BLOCK, 143 | ENAME_DDL_OTHER_BLOCK, 144 | ENAME_DDL_DECLARE_BLOCK 145 | }; 146 | 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Interfaces/SqlTokenType.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2013 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | 23 | namespace BaiSqlFormatLib.Interfaces 24 | { 25 | public enum SqlTokenType 26 | { 27 | OpenParens, 28 | CloseParens, 29 | WhiteSpace, 30 | OtherNode, 31 | SingleLineComment, 32 | SingleLineCommentCStyle, 33 | MultiLineComment, 34 | String, 35 | NationalString, 36 | BracketQuotedName, 37 | QuotedString, 38 | Comma, 39 | Period, 40 | Semicolon, 41 | Colon, 42 | Asterisk, 43 | EqualsSign, 44 | MonetaryValue, 45 | Number, 46 | BinaryValue, 47 | OtherOperator, 48 | PseudoName 49 | } 50 | } -------------------------------------------------------------------------------- /BaiSqlFormatLib/Interfaces/SqlXmlConstants.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0, written in C#. 4 | Copyright (C) 2011-2013 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | 22 | namespace BaiSqlFormatLib.Interfaces 23 | { 24 | public static class SqlXmlConstants 25 | { 26 | 27 | public const string ENAME_SQL_ROOT = "SqlRoot"; 28 | public const string ENAME_SQL_STATEMENT = "SqlStatement"; 29 | public const string ENAME_SQL_CLAUSE = "Clause"; 30 | public const string ENAME_SET_OPERATOR_CLAUSE = "SetOperatorClause"; 31 | public const string ENAME_INSERT_CLAUSE = "InsertClause"; 32 | public const string ENAME_BEGIN_END_BLOCK = "BeginEndBlock"; 33 | public const string ENAME_TRY_BLOCK = "TryBlock"; 34 | public const string ENAME_CATCH_BLOCK = "CatchBlock"; 35 | public const string ENAME_BATCH_SEPARATOR = "BatchSeparator"; 36 | public const string ENAME_CASE_STATEMENT = "CaseStatement"; 37 | public const string ENAME_CASE_INPUT = "Input"; 38 | public const string ENAME_CASE_WHEN = "When"; 39 | public const string ENAME_CASE_THEN = "Then"; 40 | public const string ENAME_CASE_ELSE = "CaseElse"; 41 | public const string ENAME_IF_STATEMENT = "IfStatement"; 42 | public const string ENAME_ELSE_CLAUSE = "ElseClause"; 43 | public const string ENAME_BOOLEAN_EXPRESSION = "BooleanExpression"; 44 | public const string ENAME_WHILE_LOOP = "WhileLoop"; 45 | public const string ENAME_CURSOR_DECLARATION = "CursorDeclaration"; 46 | public const string ENAME_CURSOR_FOR_BLOCK = "CursorForBlock"; 47 | public const string ENAME_CURSOR_FOR_OPTIONS = "CursorForOptions"; 48 | public const string ENAME_CTE_WITH_CLAUSE = "CTEWithClause"; 49 | public const string ENAME_CTE_ALIAS = "CTEAlias"; 50 | public const string ENAME_CTE_AS_BLOCK = "CTEAsBlock"; 51 | public const string ENAME_BEGIN_TRANSACTION = "BeginTransaction"; 52 | public const string ENAME_COMMIT_TRANSACTION = "CommitTransaction"; 53 | public const string ENAME_ROLLBACK_TRANSACTION = "RollbackTransaction"; 54 | public const string ENAME_SAVE_TRANSACTION = "SaveTransaction"; 55 | public const string ENAME_DDL_DECLARE_BLOCK = "DDLDeclareBlock"; 56 | public const string ENAME_DDL_PROCEDURAL_BLOCK = "DDLProceduralBlock"; 57 | public const string ENAME_DDL_OTHER_BLOCK = "DDLOtherBlock"; 58 | public const string ENAME_DDL_AS_BLOCK = "DDLAsBlock"; 59 | public const string ENAME_DDL_PARENS = "DDLParens"; 60 | public const string ENAME_DDL_SUBCLAUSE = "DDLSubClause"; 61 | public const string ENAME_DDL_RETURNS = "DDLReturns"; 62 | public const string ENAME_DDLDETAIL_PARENS = "DDLDetailParens"; 63 | public const string ENAME_DDL_WITH_CLAUSE = "DDLWith"; 64 | public const string ENAME_PERMISSIONS_BLOCK = "PermissionsBlock"; 65 | public const string ENAME_PERMISSIONS_DETAIL = "PermissionsDetail"; 66 | public const string ENAME_PERMISSIONS_TARGET = "PermissionsTarget"; 67 | public const string ENAME_PERMISSIONS_RECIPIENT = "PermissionsRecipient"; 68 | public const string ENAME_TRIGGER_CONDITION = "TriggerCondition"; 69 | public const string ENAME_SELECTIONTARGET_PARENS = "SelectionTargetParens"; 70 | public const string ENAME_EXPRESSION_PARENS = "ExpressionParens"; 71 | public const string ENAME_FUNCTION_PARENS = "FunctionParens"; 72 | public const string ENAME_IN_PARENS = "InParens"; 73 | public const string ENAME_FUNCTION_KEYWORD = "FunctionKeyword"; 74 | public const string ENAME_DATATYPE_KEYWORD = "DataTypeKeyword"; 75 | public const string ENAME_COMPOUNDKEYWORD = "CompoundKeyword"; 76 | public const string ENAME_OTHERKEYWORD = "OtherKeyword"; 77 | public const string ENAME_LABEL = "Label"; 78 | public const string ENAME_CONTAINER_OPEN = "ContainerOpen"; 79 | public const string ENAME_CONTAINER_MULTISTATEMENT = "ContainerMultiStatementBody"; 80 | public const string ENAME_CONTAINER_SINGLESTATEMENT = "ContainerSingleStatementBody"; 81 | public const string ENAME_CONTAINER_GENERALCONTENT = "ContainerContentBody"; 82 | public const string ENAME_CONTAINER_CLOSE = "ContainerClose"; 83 | public const string ENAME_SELECTIONTARGET = "SelectionTarget"; 84 | public const string ENAME_MERGE_CLAUSE = "MergeClause"; 85 | public const string ENAME_MERGE_TARGET = "MergeTarget"; 86 | public const string ENAME_MERGE_USING = "MergeUsing"; 87 | public const string ENAME_MERGE_CONDITION = "MergeCondition"; 88 | public const string ENAME_MERGE_WHEN = "MergeWhen"; 89 | public const string ENAME_MERGE_THEN = "MergeThen"; 90 | public const string ENAME_MERGE_ACTION = "MergeAction"; 91 | public const string ENAME_JOIN_ON_SECTION = "JoinOn"; 92 | 93 | public const string ENAME_PSEUDONAME = "PseudoName"; 94 | public const string ENAME_WHITESPACE = "WhiteSpace"; 95 | public const string ENAME_OTHERNODE = "Other"; 96 | public const string ENAME_COMMENT_SINGLELINE = "SingleLineComment"; 97 | public const string ENAME_COMMENT_SINGLELINE_CSTYLE = "SingleLineCommentCStyle"; 98 | public const string ENAME_COMMENT_MULTILINE = "MultiLineComment"; 99 | public const string ENAME_STRING = "String"; 100 | public const string ENAME_NSTRING = "NationalString"; 101 | public const string ENAME_QUOTED_STRING = "QuotedString"; 102 | public const string ENAME_BRACKET_QUOTED_NAME = "BracketQuotedName"; 103 | public const string ENAME_COMMA = "Comma"; 104 | public const string ENAME_PERIOD = "Period"; 105 | public const string ENAME_SEMICOLON = "Semicolon"; 106 | public const string ENAME_SCOPERESOLUTIONOPERATOR = "ScopeResolutionOperator"; 107 | public const string ENAME_ASTERISK = "Asterisk"; 108 | public const string ENAME_EQUALSSIGN = "EqualsSign"; 109 | public const string ENAME_ALPHAOPERATOR = "AlphaOperator"; 110 | public const string ENAME_OTHEROPERATOR = "OtherOperator"; 111 | 112 | public const string ENAME_AND_OPERATOR = "And"; 113 | public const string ENAME_OR_OPERATOR = "Or"; 114 | public const string ENAME_BETWEEN_CONDITION = "Between"; 115 | public const string ENAME_BETWEEN_LOWERBOUND = "LowerBound"; 116 | public const string ENAME_BETWEEN_UPPERBOUND = "UpperBound"; 117 | 118 | public const string ENAME_NUMBER_VALUE = "NumberValue"; 119 | public const string ENAME_MONETARY_VALUE = "MonetaryValue"; 120 | public const string ENAME_BINARY_VALUE = "BinaryValue"; 121 | 122 | //attribute names 123 | public const string ANAME_ERRORFOUND = "errorFound"; 124 | public const string ANAME_HASERROR = "hasError"; 125 | public const string ANAME_DATALOSS = "dataLossLimitation"; 126 | public const string ANAME_SIMPLETEXT = "simpleText"; 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Key.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baihongbin/SqlFormat/2aaedc1f9ae84e67b8ef528b7041de0044dcc870/BaiSqlFormatLib/Key.snk -------------------------------------------------------------------------------- /BaiSqlFormatLib/NetUtils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | 20 | */ 21 | 22 | using BaiSqlFormatLib.ParseStructure; 23 | using System.Xml; 24 | 25 | namespace BaiSqlFormatLib 26 | { 27 | public static class NetUtils 28 | { 29 | public static XmlDocument ToXmlDoc(this Node value) 30 | { 31 | var outDoc = new XmlDocument(); 32 | outDoc.AppendChild(ConvertThingToXmlNode(outDoc, value)); 33 | return outDoc; 34 | } 35 | 36 | private static XmlNode ConvertThingToXmlNode(XmlDocument outDoc, Node currentNode) 37 | { 38 | XmlNode copyOfThisNode = outDoc.CreateNode(XmlNodeType.Element, currentNode.Name, null); 39 | 40 | foreach (var attribute in currentNode.Attributes) 41 | { 42 | XmlAttribute newAttribute = outDoc.CreateAttribute(null, attribute.Key, null); 43 | newAttribute.Value = attribute.Value; 44 | copyOfThisNode.Attributes.Append(newAttribute); 45 | } 46 | 47 | copyOfThisNode.InnerText = currentNode.TextValue ?? ""; 48 | 49 | foreach (Node child in currentNode.Children) 50 | copyOfThisNode.AppendChild(ConvertThingToXmlNode(outDoc, child)); 51 | 52 | return copyOfThisNode; 53 | } 54 | 55 | public static char ToLowerInvariant(this char value) => char.ToLowerInvariant(value); 56 | public static char ToUpperInvariant(this char value) => char.ToLowerInvariant(value); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/ObfuscatingKeywordMapping.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | using System.Collections.Generic; 23 | 24 | namespace BaiSqlFormatLib 25 | { 26 | static class ObfuscatingKeywordMapping 27 | { 28 | public static Dictionary Instance { get; private set; } 29 | static ObfuscatingKeywordMapping() 30 | { 31 | Instance = new Dictionary(); 32 | 33 | Instance.Add("PROCEDURE", "PROC"); 34 | Instance.Add("LEFT OUTER JOIN", "LEFT JOIN"); 35 | Instance.Add("RIGHT OUTER JOIN", "RIGHT JOIN"); 36 | Instance.Add("FULL OUTER JOIN", "FULL JOIN"); 37 | Instance.Add("INNER JOIN", "JOIN"); 38 | Instance.Add("TRANSACTION", "TRAN"); 39 | Instance.Add("BEGIN TRANSACTION", "BEGIN TRAN"); 40 | Instance.Add("COMMIT TRANSACTION", "COMMIT TRAN"); 41 | Instance.Add("ROLLBACK TRANSACTION", "ROLLBACK TRAN"); 42 | Instance.Add("VARBINARY", "BINARY VARYING"); 43 | Instance.Add("VARCHAR", "CHARACTER VARYING"); 44 | Instance.Add("CHARACTER", "CHAR"); 45 | Instance.Add("CHAR VARYING", "VARCHAR"); 46 | Instance.Add("DECIMAL", "DEC"); 47 | Instance.Add("FLOAT", "DOUBLE PRECISION"); 48 | Instance.Add("INTEGER", "INT"); 49 | Instance.Add("NCHAR", "NATIONAL CHARACTER"); 50 | Instance.Add("NATIONAL CHAR", "NCHAR"); 51 | Instance.Add("NVARCHAR", "NATIONAL CHARACTER VARYING"); 52 | Instance.Add("NATIONAL CHAR VARYING", "NVARCHAR"); 53 | Instance.Add("NTEXT", "NATIONAL TEXT"); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/ParseStructure/Node.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System.Collections.Generic; 22 | 23 | namespace BaiSqlFormatLib.ParseStructure 24 | { 25 | public interface Node 26 | { 27 | string Name { get; } 28 | string TextValue { get; } 29 | IDictionary Attributes { get; } 30 | void SetAttribute(string name, string value); 31 | string GetAttributeValue(string name); 32 | void RemoveAttribute(string name); 33 | Node Parent { get; } 34 | IEnumerable Children { get; } 35 | void AddChild(Node child); 36 | void InsertChildBefore(Node newChild, Node existingChild); 37 | void RemoveChild(Node childThing); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/ParseStructure/NodeExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | 22 | using System; 23 | using System.Collections.Generic; 24 | using System.Linq; 25 | 26 | namespace BaiSqlFormatLib.ParseStructure 27 | { 28 | public static class NodeExtensions 29 | { 30 | public static Node FollowingChild(this Node value, Node fromChild) 31 | { 32 | if (value == null) 33 | return null; 34 | 35 | if (fromChild == null) 36 | throw new ArgumentNullException("fromChild"); 37 | 38 | bool targetFound = false; 39 | Node sibling = null; 40 | 41 | foreach (var child in value.Children) 42 | { 43 | if (targetFound) 44 | { 45 | sibling = child; 46 | break; 47 | } 48 | 49 | if (child == fromChild) 50 | targetFound = true; 51 | } 52 | 53 | return sibling; 54 | } 55 | 56 | public static Node PreviousChild(this Node value, Node fromChild) 57 | { 58 | if (value == null) 59 | return null; 60 | 61 | if (fromChild == null) 62 | throw new ArgumentNullException("fromChild"); 63 | 64 | Node previousSibling = null; 65 | 66 | foreach (var child in value.Children) 67 | { 68 | if (child == fromChild) 69 | return previousSibling; 70 | 71 | previousSibling = child; 72 | } 73 | 74 | return null; 75 | } 76 | 77 | public static Node NextSibling(this Node value) 78 | { 79 | if (value == null || value.Parent == null) 80 | return null; 81 | 82 | return value.Parent.FollowingChild(value); 83 | } 84 | 85 | public static Node PreviousSibling(this Node value) 86 | { 87 | if (value == null || value.Parent == null) 88 | return null; 89 | 90 | return value.Parent.PreviousChild(value); 91 | } 92 | 93 | public static Node RootContainer(this Node value) 94 | { 95 | if (value == null) 96 | return null; 97 | 98 | Node currentParent = value; 99 | while (currentParent.Parent != null) 100 | currentParent = currentParent.Parent; 101 | return currentParent; 102 | } 103 | 104 | public static IEnumerable ChildrenByName(this Node value, string name) 105 | { 106 | if (value == null) 107 | return Enumerable.Empty(); 108 | 109 | return value.Children.Where(p => p.Name == name); 110 | } 111 | 112 | public static IEnumerable ChildrenByNames(this Node value, IEnumerable names) 113 | { 114 | if (value == null) 115 | return Enumerable.Empty(); 116 | 117 | return value.Children.Where(p => names.Contains(p.Name)); 118 | } 119 | 120 | public static IEnumerable ChildrenExcludingNames(this Node value, IEnumerable names) 121 | { 122 | if (value == null) 123 | return Enumerable.Empty(); 124 | 125 | return value.Children.Where(p => !names.Contains(p.Name)); 126 | } 127 | 128 | public static Node ChildByName(this Node value, string name) 129 | { 130 | return value.ChildrenByName(name).SingleOrDefault(); 131 | } 132 | 133 | public static Node ChildByNames(this Node value, IEnumerable names) 134 | { 135 | return value.ChildrenByNames(names).SingleOrDefault(); 136 | } 137 | 138 | public static Node ChildExcludingNames(this Node value, IEnumerable names) 139 | { 140 | return value.ChildrenExcludingNames(names).SingleOrDefault(); 141 | } 142 | 143 | public static Node ExtractStructureBetween(Node startingElement, Node endingElement) 144 | { 145 | Node currentNode = startingElement; 146 | Node previousNode = null; 147 | Node remainder = null; 148 | Node remainderPosition = null; 149 | 150 | while (currentNode != null) 151 | { 152 | if (currentNode.Equals(endingElement)) 153 | break; 154 | 155 | if (previousNode != null) 156 | { 157 | Node copyOfThisNode = NodeFactory.CreateNode(currentNode.Name, currentNode.TextValue); 158 | 159 | foreach (var attribute in currentNode.Attributes) 160 | copyOfThisNode.SetAttribute(attribute.Key, attribute.Value); 161 | 162 | if (remainderPosition == null) 163 | { 164 | remainderPosition = copyOfThisNode; 165 | remainder = copyOfThisNode; 166 | } 167 | else if (currentNode.Equals(previousNode.Parent) && remainderPosition.Parent != null) 168 | { 169 | remainderPosition = remainderPosition.Parent; 170 | } 171 | else if (currentNode.Equals(previousNode.Parent) && remainderPosition.Parent == null) 172 | { 173 | copyOfThisNode.AddChild(remainderPosition); 174 | remainderPosition = copyOfThisNode; 175 | remainder = copyOfThisNode; 176 | } 177 | else if (currentNode.Equals(previousNode.NextSibling()) && remainderPosition.Parent != null) 178 | { 179 | remainderPosition.Parent.AddChild(copyOfThisNode); 180 | remainderPosition = copyOfThisNode; 181 | } 182 | else if (currentNode.Equals(previousNode.NextSibling()) && remainderPosition.Parent == null) 183 | { 184 | Node copyOfThisNodesParent = NodeFactory.CreateNode(currentNode.Parent.Name, currentNode.Parent.TextValue); 185 | remainder = copyOfThisNodesParent; 186 | remainder.AddChild(remainderPosition); 187 | remainder.AddChild(copyOfThisNode); 188 | remainderPosition = copyOfThisNode; 189 | } 190 | else 191 | { 192 | //we must be a child 193 | remainderPosition.AddChild(copyOfThisNode); 194 | remainderPosition = copyOfThisNode; 195 | } 196 | } 197 | 198 | Node nextNode = null; 199 | if (previousNode != null 200 | && currentNode.Children.Any() 201 | && !(currentNode.Equals(previousNode.Parent))) 202 | { 203 | nextNode = currentNode.Children.FirstOrDefault(); 204 | } 205 | else if (currentNode.NextSibling() != null) 206 | { 207 | nextNode = currentNode.NextSibling(); 208 | } 209 | else 210 | { 211 | nextNode = currentNode.Parent; 212 | } 213 | 214 | previousNode = currentNode; 215 | currentNode = nextNode; 216 | } 217 | 218 | return remainder; 219 | } 220 | 221 | } 222 | } 223 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/ParseStructure/NodeFactory.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | namespace BaiSqlFormatLib.ParseStructure 22 | { 23 | public static class NodeFactory 24 | { 25 | public static Node CreateNode(string name, string textValue) 26 | { 27 | return new NodeImpl() { Name = name, TextValue = textValue }; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/ParseStructure/NodeImpl.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | using System.Collections.Generic; 23 | using System.Linq; 24 | 25 | namespace BaiSqlFormatLib.ParseStructure 26 | { 27 | internal class NodeImpl : Node 28 | { 29 | public NodeImpl() 30 | { 31 | Attributes = new Dictionary(); 32 | Children = new List(); 33 | } 34 | 35 | public string Name { get; set; } 36 | public string TextValue { get; set; } 37 | public Node Parent { get; set; } 38 | 39 | public IDictionary Attributes { get; private set; } 40 | public IEnumerable Children { get; private set; } 41 | 42 | public void AddChild(Node child) 43 | { 44 | SetParentOnChild(child); 45 | ((IList)Children).Add(child); 46 | } 47 | 48 | public void InsertChildBefore(Node newChild, Node existingChild) 49 | { 50 | SetParentOnChild(newChild); 51 | var childList = Children as IList; 52 | childList.Insert(childList.IndexOf(existingChild), newChild); 53 | } 54 | 55 | private void SetParentOnChild(Node child) 56 | { 57 | //TODO: NOT THREAD-SAFE AT ALL! 58 | if (child.Parent != null) 59 | throw new ArgumentException("Child cannot already have a parent!"); 60 | ((NodeImpl)child).Parent = this; 61 | } 62 | 63 | public void RemoveChild(Node child) 64 | { 65 | //TODO: NOT THREAD-SAFE AT ALL! 66 | ((IList)Children).Remove(child); 67 | ((NodeImpl)child).Parent = null; 68 | } 69 | 70 | 71 | public string GetAttributeValue(string aName) 72 | { 73 | string outVal = null; 74 | Attributes.TryGetValue(aName, out outVal); 75 | return outVal; 76 | } 77 | 78 | public void SetAttribute(string name, string value) 79 | { 80 | Attributes[name] = value; 81 | } 82 | 83 | public void RemoveAttribute(string name) 84 | { 85 | Attributes.Remove(name); 86 | } 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0, written in C#. 4 | Copyright (C) 2011 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | using System.Reflection; 23 | using System.Runtime.CompilerServices; 24 | using System.Runtime.InteropServices; 25 | 26 | [assembly: AssemblyTitle("PoorMansTSqlFormatterLib")] 27 | [assembly: AssemblyDescription("A simple free (AGPL) T-SQL formatting library for .Net 2.0.")] 28 | [assembly: AssemblyConfiguration("")] 29 | [assembly: AssemblyCompany("")] 30 | [assembly: AssemblyProduct("PoorMansTSqlFormatterLib")] 31 | [assembly: AssemblyCopyright("Copyright © 2011-2013 Tao Klerks")] 32 | [assembly: AssemblyTrademark("")] 33 | [assembly: AssemblyCulture("")] 34 | [assembly: CLSCompliant(true)] 35 | [assembly: ComVisible(false)] 36 | [assembly: AssemblyVersion("1.5.1.*")] 37 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/References/LinqBridge/COPYING.txt: -------------------------------------------------------------------------------- 1 | LINQBridge Copyright (c) 2007-2009, Atif Aziz, Joseph Albahari 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | - Neither the name of the original authors nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/References/LinqBridge/LinqBridge.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baihongbin/SqlFormat/2aaedc1f9ae84e67b8ef528b7041de0044dcc870/BaiSqlFormatLib/References/LinqBridge/LinqBridge.dll -------------------------------------------------------------------------------- /BaiSqlFormatLib/SimplifiedStringReader.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | namespace PoorMansTSqlFormatterLib.Tokenizers 22 | { 23 | internal class SimplifiedStringReader 24 | { 25 | private char[] inputChars; 26 | private int nextCharIndex = 0; 27 | 28 | public SimplifiedStringReader(string inputString) 29 | { 30 | this.inputChars = inputString.ToCharArray(); 31 | } 32 | 33 | internal int Read() 34 | { 35 | int nextChar = Peek(); 36 | nextCharIndex++; 37 | return nextChar; 38 | } 39 | 40 | internal int Peek() 41 | { 42 | if (nextCharIndex < inputChars.Length) 43 | return inputChars[nextCharIndex]; 44 | else 45 | return -1; 46 | } 47 | 48 | //note, intentional difference between index (zero-based) and position (1-based). Zero here means "nothing output yet". 49 | internal long LastCharacterPosition 50 | { 51 | get 52 | { 53 | if (nextCharIndex <= inputChars.Length) 54 | return nextCharIndex; 55 | else 56 | return inputChars.Length; 57 | } 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /BaiSqlFormatLib/SqlFormattingManager.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | 22 | #if !SIMPLIFIEDFW 23 | using System; 24 | using System.Runtime.InteropServices; 25 | #endif 26 | using BaiSqlFormatLib.Interfaces; 27 | using BaiSqlFormatLib.ParseStructure; 28 | 29 | namespace BaiSqlFormatLib 30 | { 31 | #if !SIMPLIFIEDFW 32 | //These COM-related attributes exist JUST so that we can use this class from VB6 - there is no need to 33 | // expose these classes to COM in order for this library to be used in a .Net project. 34 | [Guid("A7FD140A-C3C3-4233-95DB-A64B50C8DF2B")] 35 | [ClassInterface(ClassInterfaceType.None)] 36 | [ComVisible(true)] 37 | [ProgId("PoorMansTSqlFormatter.SqlFormattingManager")] 38 | #endif 39 | public class SqlFormattingManager : _SqlFormattingManager 40 | { 41 | //default to built-in 42 | public SqlFormattingManager() : this(new Tokenizers.TSqlStandardTokenizer(), new Parsers.TSqlStandardParser(), new Formatters.TSqlStandardFormatter()) { } 43 | 44 | //most common use-case, define only formatter 45 | public SqlFormattingManager(ISqlTreeFormatter formatter) : this(new Tokenizers.TSqlStandardTokenizer(), new Parsers.TSqlStandardParser(), formatter) { } 46 | 47 | public SqlFormattingManager(ISqlTokenizer tokenizer, ISqlTokenParser parser, ISqlTreeFormatter formatter) 48 | { 49 | Tokenizer = tokenizer; 50 | Parser = parser; 51 | Formatter = formatter; 52 | } 53 | 54 | public ISqlTokenizer Tokenizer { get; set; } 55 | public ISqlTokenParser Parser { get; set; } 56 | public ISqlTreeFormatter Formatter { get; set; } 57 | 58 | public string Format(string inputSQL) 59 | { 60 | bool error = false; 61 | return Format(inputSQL, ref error); 62 | } 63 | 64 | public string Format(string inputSQL, ref bool errorEncountered) 65 | { 66 | Node sqlTree = Parser.ParseSQL(Tokenizer.TokenizeSQL(inputSQL)); 67 | errorEncountered = (sqlTree.GetAttributeValue(SqlStructureConstants.ANAME_ERRORFOUND) == "1"); 68 | return Formatter.FormatSQLTree(sqlTree); 69 | } 70 | 71 | public static string DefaultFormat(string inputSQL) 72 | { 73 | return new SqlFormattingManager().Format(inputSQL); 74 | } 75 | 76 | public static string DefaultFormat(string inputSQL, ref bool errorsEncountered) 77 | { 78 | return new SqlFormattingManager().Format(inputSQL, ref errorsEncountered); 79 | } 80 | } 81 | 82 | //This COM interface exists JUST so that we can use this class from VB6 - there is no need to expose 83 | // these classes to COM in order for this library to be used in a .Net project. 84 | #if !SIMPLIFIEDFW 85 | [Guid("A7FD140A-C3C3-4233-95DB-A64B50C8DF2A")] 86 | [CLSCompliant(false), ComVisible(true)] 87 | [InterfaceType(ComInterfaceType.InterfaceIsDual)] 88 | #endif 89 | public interface _SqlFormattingManager 90 | { 91 | string Format(string inputSQL); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/StandardKeywordRemapping.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | using System.Collections.Generic; 23 | 24 | namespace BaiSqlFormatLib 25 | { 26 | static class StandardKeywordRemapping 27 | { 28 | public static Dictionary Instance { get; private set; } 29 | static StandardKeywordRemapping() 30 | { 31 | Instance = new Dictionary(); 32 | 33 | Instance.Add("PROC", "PROCEDURE"); 34 | Instance.Add("LEFT OUTER JOIN", "LEFT JOIN"); 35 | Instance.Add("RIGHT OUTER JOIN", "RIGHT JOIN"); 36 | Instance.Add("FULL OUTER JOIN", "FULL JOIN"); 37 | Instance.Add("JOIN", "INNER JOIN"); 38 | //TODO: This is now wrong in MERGE statements... we now need a scope-limitation strategy :( 39 | //Instance.Add("INSERT", "INSERT INTO"); 40 | Instance.Add("TRAN", "TRANSACTION"); 41 | Instance.Add("BEGIN TRAN", "BEGIN TRANSACTION"); 42 | Instance.Add("COMMIT TRAN", "COMMIT TRANSACTION"); 43 | Instance.Add("ROLLBACK TRAN", "ROLLBACK TRANSACTION"); 44 | Instance.Add("BINARY VARYING", "VARBINARY"); 45 | Instance.Add("CHAR VARYING", "VARCHAR"); 46 | Instance.Add("CHARACTER", "CHAR"); 47 | Instance.Add("CHARACTER VARYING", "VARCHAR"); 48 | Instance.Add("DEC", "DECIMAL"); 49 | Instance.Add("DOUBLE PRECISION", "FLOAT"); 50 | Instance.Add("INTEGER", "INT"); 51 | Instance.Add("NATIONAL CHARACTER", "NCHAR"); 52 | Instance.Add("NATIONAL CHAR", "NCHAR"); 53 | Instance.Add("NATIONAL CHARACTER VARYING", "NVARCHAR"); 54 | Instance.Add("NATIONAL CHAR VARYING", "NVARCHAR"); 55 | Instance.Add("NATIONAL TEXT", "NTEXT"); 56 | Instance.Add("OUT", "OUTPUT"); 57 | //TODO: This is wrong when a TIMESTAMP column is unnamed; ROWVERSION does not auto-name. Due to context-sensitivity, this mapping is disabled for now. 58 | // REF: http://msdn.microsoft.com/en-us/library/ms182776.aspx 59 | //Instance.Add("TIMESTAMP", "ROWVERSION"); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Token.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using BaiSqlFormatLib.Interfaces; 22 | 23 | namespace BaiSqlFormatLib 24 | { 25 | public class Token : IToken 26 | { 27 | public Token(SqlTokenType type, string value) 28 | { 29 | Type = type; 30 | Value = value; 31 | } 32 | 33 | public SqlTokenType Type { get; set; } 34 | public string Value { get; set; } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/TokenList.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System; 22 | using System.Collections.Generic; 23 | using System.Text; 24 | using BaiSqlFormatLib.Interfaces; 25 | 26 | namespace BaiSqlFormatLib 27 | { 28 | public class TokenList : List, ITokenList 29 | { 30 | public bool HasUnfinishedToken { get; set; } 31 | 32 | public string PrettyPrint() 33 | { 34 | StringBuilder outString = new StringBuilder(); 35 | foreach(IToken contentToken in this) 36 | { 37 | string tokenType = contentToken.Type.ToString(); 38 | outString.Append(tokenType.PadRight(20)); 39 | outString.Append(": "); 40 | outString.Append(contentToken.Value); 41 | if (contentToken.Equals(this.MarkerToken)) 42 | { 43 | outString.Append(" (MARKER - pos "); 44 | outString.Append(this.MarkerPosition.ToString()); 45 | outString.Append(")"); 46 | } 47 | outString.AppendLine(); 48 | } 49 | return outString.ToString(); 50 | } 51 | 52 | public new IList GetRange(int index, int count) 53 | { 54 | return base.GetRange(index, count); 55 | } 56 | 57 | public IList GetRangeByIndex(int fromIndex, int toIndex) 58 | { 59 | return this.GetRange(fromIndex, toIndex - fromIndex + 1); 60 | } 61 | 62 | public IToken MarkerToken { get; set; } 63 | 64 | public long? MarkerPosition { get; set; } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /BaiSqlFormatLib/Tokenizers/SimplifiedStringReader.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2011-2017 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | 20 | */ 21 | 22 | namespace BaiSqlFormatLib.Tokenizers 23 | { 24 | internal class SimplifiedStringReader 25 | { 26 | private char[] inputChars; 27 | private int nextCharIndex = 0; 28 | 29 | public SimplifiedStringReader(string inputString) 30 | { 31 | this.inputChars = inputString.ToCharArray(); 32 | } 33 | 34 | internal int Read() 35 | { 36 | int nextChar = Peek(); 37 | nextCharIndex++; 38 | return nextChar; 39 | } 40 | 41 | internal int Peek() 42 | { 43 | if (nextCharIndex < inputChars.Length) 44 | return inputChars[nextCharIndex]; 45 | else 46 | return -1; 47 | } 48 | 49 | //note, intentional difference between index (zero-based) and position (1-based). Zero here means "nothing output yet". 50 | internal long LastCharacterPosition 51 | { 52 | get 53 | { 54 | if (nextCharIndex <= inputChars.Length) 55 | return nextCharIndex; 56 | else 57 | return inputChars.Length; 58 | } 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /BaiSqlFormatLib/Utils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | Poor Man's T-SQL Formatter - a small free Transact-SQL formatting 3 | library for .Net 2.0 and JS, written in C#. 4 | Copyright (C) 2012 Tao Klerks 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU Affero General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU Affero General Public License for more details. 15 | 16 | You should have received a copy of the GNU Affero General Public License 17 | along with this program. If not, see . 18 | 19 | */ 20 | 21 | using System.Text; 22 | 23 | namespace BaiSqlFormatLib 24 | { 25 | public static class Utils 26 | { 27 | public static string HtmlEncode(string raw) 28 | { 29 | /* 30 | * This is a "Roll Your Own" implementation of HtmlEncode, which was necessary in the end because people want 31 | * to use the library with .Net 3.5 Client Profile and other restricted environments; the dependency on 32 | * System.Web just for HtmlEncode was always a little disturbing anyway. 33 | * I've attempted to optimize the implementation towards strings that don't actually contain any special 34 | * characters, and I've also skipped some of the more interesting stuff that I see in the MS implementation 35 | * (pointers, and some special handling in the WinAnsi special range of characters?), keeping it to the basic 36 | * 4 "known bad" characters. 37 | */ 38 | 39 | if (raw == null) 40 | return null; 41 | 42 | StringBuilder outBuilder = null; 43 | int latestCheckPos = 0; 44 | int latestReplacementPos = 0; 45 | 46 | foreach (char c in raw) 47 | { 48 | string replacementString = null; 49 | 50 | switch (c) 51 | { 52 | case '>': 53 | replacementString = ">"; 54 | break; 55 | case '<': 56 | replacementString = "<"; 57 | break; 58 | case '&': 59 | replacementString = "&"; 60 | break; 61 | case '"': 62 | replacementString = """; 63 | break; 64 | } 65 | 66 | if (replacementString != null) 67 | { 68 | if (outBuilder == null) 69 | outBuilder = new StringBuilder(raw.Length); 70 | 71 | if (latestReplacementPos < latestCheckPos) 72 | outBuilder.Append(raw.Substring(latestReplacementPos, latestCheckPos - latestReplacementPos)); 73 | 74 | outBuilder.Append(replacementString); 75 | 76 | latestReplacementPos = latestCheckPos + 1; 77 | } 78 | 79 | latestCheckPos++; 80 | } 81 | 82 | if (outBuilder != null) 83 | { 84 | if (latestReplacementPos < latestCheckPos) 85 | outBuilder.Append(raw.Substring(latestReplacementPos)); 86 | 87 | return outBuilder.ToString(); 88 | } 89 | else 90 | return raw; 91 | } 92 | 93 | #if SIMPLIFIEDFW 94 | 95 | //Invariant conversions are not implemented in Bridge.Net and .Net Standard... 96 | public static string ToLowerInvariant(this string value) => value.ToLower(); 97 | public static string ToUpperInvariant(this string value) => value.ToUpper(); 98 | public static char ToLowerInvariant(this char value) => char.ToLower(value); 99 | public static char ToUpperInvariant(this char value) => char.ToUpper(value); 100 | 101 | #endif 102 | 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SqlFormat 2 | 这是一个SQL格式化/SQL美化工具,可以将SQL格式化为自己想要的格式(**可以进行自定义配置**)。 3 | 主要功能基于**Poor Man's T-SQL Formatter**,地址:https://github.com/TaoK/PoorMansTSqlFormatter#poor-mans-t-sql-formatter 4 | 在**Poor Man's T-SQL Formatter**的基础上进行了一些改动(主要为大数据ETL所涉及到的SQL/HQL支持,字段对齐等等),以便满足我们自己的需求。 5 | 6 | *** 7 | **程序已经打包好,可以直接下载使用。地址**:https://github.com/baihongbin/SqlFormatForm 8 | *** 9 | 10 | ### 使用.NET框架 11 | - BaiSqlFormatForm(v1.0)基于.NET Framework 2.0 12 | - BaiSqlFormatForm2(v2.0)基于.NET Framework 4 13 | 14 | ### 功能截图(v2.0) 15 | ![](https://i.imgur.com/yv5UVXa.jpg) 16 | --------------------------------------------------------------------------------