Skip to content

添加批量提取SQL的支持 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ConvertExecuteSQL/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
</configuration>
4 changes: 3 additions & 1 deletion ConvertExecuteSQL/ConvertExecuteSQL.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ConvertExecuteSQL</RootNamespace>
<AssemblyName>ConvertExecuteSQL</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<PublishUrl>發行\</PublishUrl>
Expand All @@ -27,6 +27,7 @@
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -80,6 +81,7 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand Down
38 changes: 36 additions & 2 deletions ConvertExecuteSQL/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

Expand Down Expand Up @@ -76,6 +77,9 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}


Regex regex = new Regex("exec (sp_executesql|sys.sp_executesql)", RegexOptions.IgnoreCase);

void DisplayClipboardData()
{
try
Expand All @@ -86,8 +90,36 @@ void DisplayClipboardData()
if (iData.GetDataPresent(DataFormats.Text))
{
var strSQL = (string)iData.GetData(DataFormats.Text);
if (!strSQL.Contains("exec sp_executesql") || strSQL.Trim() == "exec sp_executesql") return;
var newSql = ConvertSql(strSQL);

if (!regex.IsMatch(strSQL))
{
return;
}

//if (!strSQL.Contains("exec sp_executesql") || strSQL.Trim() == "exec sp_executesql") return;

string newSql = string.Empty;

//string[] batch = strSQL.Split(new[] { "Go", "go", "GO" }, StringSplitOptions.None);

//使用 正则表达式 拆分 批量操作
//Regex regexs = new Regex(@"Go$");

var options = System.Text.RegularExpressions.RegexOptions.IgnoreCase | System.Text.RegularExpressions.RegexOptions.Multiline | System.Text.RegularExpressions.RegexOptions.Singleline | System.Text.RegularExpressions.RegexOptions.CultureInvariant;



Regex regexs = new Regex(@"\bgo\b", options);

string[] batch = regexs.Split(strSQL);


foreach (var item in batch)
{
newSql += ConvertSql(item) + "\n GO \n";
}


Clipboard.SetText(newSql);
}
}
Expand All @@ -98,6 +130,8 @@ void DisplayClipboardData()

private static string ConvertSql(string origSql)
{
if (origSql.Trim() == string.Empty) { return string.Empty; }

var tableParameterSql = string.Empty;
var indexOf = origSql.IndexOf("exec sp_executesql"); // origSql.Substring(0, origSql.IndexOf("exec sp_executesql") - 1);
if (indexOf > 0)
Expand Down
66 changes: 29 additions & 37 deletions ConvertExecuteSQL/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 13 additions & 17 deletions ConvertExecuteSQL/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
6 changes: 6 additions & 0 deletions ConvertExecuteSQL/bin/Debug/ConvertExecuteSQL.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
Binary file added ConvertExecuteSQL/bin/Debug/ConvertExecuteSQL.pdb
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
</startup>
</configuration>
11 changes: 11 additions & 0 deletions ConvertExecuteSQL/bin/Debug/ConvertExecuteSQL.vshost.exe.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="asInvoker" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
D:\360极速浏览器下载\参数化提取SQL\分析\ConvertExecuteSQL\ConvertExecuteSQL\bin\Debug\ConvertExecuteSQL.exe.config
D:\360极速浏览器下载\参数化提取SQL\分析\ConvertExecuteSQL\ConvertExecuteSQL\bin\Debug\ConvertExecuteSQL.exe
D:\360极速浏览器下载\参数化提取SQL\分析\ConvertExecuteSQL\ConvertExecuteSQL\bin\Debug\ConvertExecuteSQL.pdb
D:\360极速浏览器下载\参数化提取SQL\分析\ConvertExecuteSQL\ConvertExecuteSQL\obj\Debug\ConvertExecuteSQL.csprojResolveAssemblyReference.cache
D:\360极速浏览器下载\参数化提取SQL\分析\ConvertExecuteSQL\ConvertExecuteSQL\obj\Debug\ConvertExecuteSQL.Form1.resources
D:\360极速浏览器下载\参数化提取SQL\分析\ConvertExecuteSQL\ConvertExecuteSQL\obj\Debug\ConvertExecuteSQL.Properties.Resources.resources
D:\360极速浏览器下载\参数化提取SQL\分析\ConvertExecuteSQL\ConvertExecuteSQL\obj\Debug\ConvertExecuteSQL.csproj.GenerateResource.Cache
D:\360极速浏览器下载\参数化提取SQL\分析\ConvertExecuteSQL\ConvertExecuteSQL\obj\Debug\ConvertExecuteSQL.exe
D:\360极速浏览器下载\参数化提取SQL\分析\ConvertExecuteSQL\ConvertExecuteSQL\obj\Debug\ConvertExecuteSQL.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added ConvertExecuteSQL/obj/Debug/ConvertExecuteSQL.pdb
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.