Skip to content

Commit c433a43

Browse files
committed
SQLWrapper 1.1.7
1 parent 7f77a4e commit c433a43

File tree

6 files changed

+91
-38
lines changed

6 files changed

+91
-38
lines changed

Daikoz.SQLWrapper/Daikoz.SQLWrapper.csproj

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<LangVersion>latest</LangVersion>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
8-
<Version>1.0.0</Version>
8+
<Version>1.1.7</Version>
99
<Authors>DAIKOZ</Authors>
1010
<Company>DAIKOZ</Company>
1111
<Copyright>© 2019 - DAIKOZ - All rights reserved</Copyright>
@@ -24,19 +24,19 @@
2424

2525
Thus, SQL Wrapper can generate SQL call code from any language like C#, Java, Python, Javascript, VB .NET, ADO .NET ...
2626
</Description>
27-
<AssemblyVersion>0.4.3</AssemblyVersion>
28-
<FileVersion>0.4.3</FileVersion>
27+
<AssemblyVersion>1.1.7.0</AssemblyVersion>
28+
<FileVersion>1.1.7.0</FileVersion>
2929
<PackageLicenseUrl></PackageLicenseUrl>
30-
<PackageLicenseExpression></PackageLicenseExpression>
31-
<PackageIconUrl>https://www.daikoz.com/img/sqlwrapper.png</PackageIconUrl>
3230
<BuildOutputTargetFolder>dll</BuildOutputTargetFolder>
3331
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
3432
<NoWarn>NU5100</NoWarn>
33+
<PackageIcon>sqlwrapper.png</PackageIcon>
34+
<PackageIconUrl />
3535
</PropertyGroup>
3636

3737
<ItemGroup>
38-
<PackageReference Include="Microsoft.Build.Framework" Version="16.4.0" PrivateAssets="All" />
39-
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.4.0" PrivateAssets="All" />
38+
<PackageReference Include="Microsoft.Build.Framework" Version="16.5.0" PrivateAssets="All" />
39+
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.5.0" PrivateAssets="All" />
4040
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
4141
<PrivateAssets>all</PrivateAssets>
4242
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -56,6 +56,10 @@
5656
<Compile Remove="Properties\PublishProfiles\**" />
5757
<EmbeddedResource Remove="Properties\PublishProfiles\**" />
5858
<None Remove="Properties\PublishProfiles\**" />
59+
<None Include="..\..\Web\SQLWrapper.com\wwwroot\img\sqlwrapper.png">
60+
<Pack>True</Pack>
61+
<PackagePath></PackagePath>
62+
</None>
5963
</ItemGroup>
6064

6165
<ItemGroup>

Daikoz.SQLWrapper/SQLWrapperBuild.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class SQLWrapperBuild : Task
1212

1313
public override bool Execute()
1414
{
15-
// Debugger.Launch();
15+
//System.Diagnostics.Debugger.Launch();
1616

1717
try
1818
{

Daikoz.SQLWrapper/SQLWrapperExecute.cs

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Diagnostics;
6+
using System.Globalization;
67
using System.IO;
78
using System.Runtime.Serialization.Json;
89
using System.Text;
10+
using System.Text.RegularExpressions;
911

1012
namespace Daikoz.SQLWrapper
1113
{
@@ -83,7 +85,7 @@ public bool Execute()
8385
argument.Append(" -p namespace=" + config.Namespace);
8486
argument.Append(" -x " + helperPath);
8587

86-
StartProcess(config.SQLWrapperPath, argument.ToString(), "SQLWrapper Helper", helperPath, "SW000004");
88+
StartProcess(config.SQLWrapperPath, argument.ToString(), "SQLWrapper Helper", helperPath);
8789
}
8890

8991
++configIdx;
@@ -93,7 +95,7 @@ public bool Execute()
9395
return true;
9496
}
9597

96-
private void StartProcess(string sqlWrapperPath, string arguments, string logCategory, string logFile, string logCode)
98+
private void StartProcess(string sqlWrapperPath, string arguments, string logCategory, string logFile)
9799
{
98100
using Process sqlwrapperProcess = new Process();
99101

@@ -120,12 +122,27 @@ private void StartProcess(string sqlWrapperPath, string arguments, string logCat
120122
StreamReader readerOutput = sqlwrapperProcess.StandardOutput;
121123
string error = readerOutput.ReadToEnd();
122124
if (!string.IsNullOrWhiteSpace(error))
123-
_log.LogWarning(logCategory, logCode, "", logFile, 0, 0, 0, 0, error, null);
125+
_log.LogWarning(logCategory, "", "", logFile, 0, 0, 0, 0, error, null);
124126

125127
StreamReader readerError = sqlwrapperProcess.StandardError;
126128
error = readerError.ReadToEnd();
127129
if (!string.IsNullOrWhiteSpace(error))
128-
_log.LogError(logCategory, logCode, "", logFile, 0, 0, 0, 0, error, null);
130+
{
131+
int lineNumber = 0;
132+
int columnNumber = 0;
133+
string code = "";
134+
Match match = Regex.Match(error, @"(?<filepath>.*):\((?<line>.*),(?<position>\d+)\):(?<code>[^:]*):(?<message>.*)");
135+
if (match.Success)
136+
{
137+
logFile = match.Groups["filepath"].Value;
138+
lineNumber = int.Parse(match.Groups["line"].Value, CultureInfo.InvariantCulture);
139+
columnNumber = int.Parse(match.Groups["position"].Value, CultureInfo.InvariantCulture);
140+
code = match.Groups["code"].Value.TrimStart();
141+
error = match.Groups["message"].Value.TrimStart();
142+
}
143+
144+
_log.LogError(logCategory, code, "", logFile, lineNumber, columnNumber, 0, 0, error, null);
145+
}
129146

130147
sqlwrapperProcess.WaitForExit();
131148
}
@@ -146,7 +163,7 @@ private void CacheDatabase(string cacheDBPath, string[] connectionStrings, strin
146163
argument.Append(" \"" + connectionString.Replace("\"", "\"\"") + "\" ");
147164
argument.Append(" -o " + cacheDBPath);
148165

149-
StartProcess(sqlWrapperPath, argument.ToString(), "SQLWrapper Database", cacheDBPath, "SW000006");
166+
StartProcess(sqlWrapperPath, argument.ToString(), "SQLWrapper Database", cacheDBPath);
150167

151168
_cacheDBModifiedDate = DateTime.UtcNow;
152169
}
@@ -206,7 +223,7 @@ private void Execute(string relativePath, string filePattern, string namespaceNa
206223
}
207224
argument.Append(" -x " + Path.Combine("tools", "Template", "CSharp", "ADO.xslt"));
208225

209-
StartProcess(sqlWrapperPath, argument.ToString(), "SQLWrapper Wrapper", subdirectory, "SW000009");
226+
StartProcess(sqlWrapperPath, argument.ToString(), "SQLWrapper Wrapper", subdirectory);
210227
}
211228
}
212229
}
93 KB
Binary file not shown.

Daikoz.SQLWrapper/tools/Template/CSharp/ADO.xslt

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
<xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
77
<xsl:preserve-space elements="*" />
88

9-
<xsl:template match="type">
9+
<xsl:template match="type" mode="typeonly">
1010
<xsl:choose>
1111
<xsl:when test="@custom">
12-
<xsl:value-of select="@custom"/>
12+
<xsl:value-of select="@custom"/><xsl:if test="@isnull = 1">?</xsl:if>
1313
</xsl:when>
1414
<xsl:otherwise>
1515
<xsl:if test="not(@unsigned = 1)">
1616
<xsl:choose>
1717
<xsl:when test=". = 'bigint'">long<xsl:if test="@isnull = 1">?</xsl:if></xsl:when>
1818
<xsl:when test=". = 'binary'">byte[]</xsl:when>
1919
<xsl:when test=". = 'bit'">ulong<xsl:if test="@isnull = 1">?</xsl:if></xsl:when>
20-
<xsl:when test=". = 'blob'">byte[]</xsl:when>
20+
<xsl:when test=". = 'blob'">byte[]</xsl:when>
21+
<xsl:when test=". = 'bool'">bool<xsl:if test="@isnull = 1">?</xsl:if></xsl:when>
2122
<xsl:when test=". = 'char'">string</xsl:when>
2223
<xsl:when test=". = 'date'">DateTime<xsl:if test="@isnull = 1">?</xsl:if></xsl:when>
2324
<xsl:when test=". = 'datetime'">DateTime<xsl:if test="@isnull = 1">?</xsl:if></xsl:when>
@@ -37,7 +38,7 @@
3738
<xsl:when test=". = 'time'">TimeSpan<xsl:if test="@isnull = 1">?</xsl:if></xsl:when>
3839
<xsl:when test=". = 'timestamp'">DateTime<xsl:if test="@isnull = 1">?</xsl:if></xsl:when>
3940
<xsl:when test=". = 'tinyblob'">byte[]</xsl:when>
40-
<xsl:when test=". = 'tinyint'">bool<xsl:if test="@isnull = 1">?</xsl:if></xsl:when>
41+
<xsl:when test=". = 'tinyint'">sbyte<xsl:if test="@isnull = 1">?</xsl:if></xsl:when>
4142
<xsl:when test=". = 'tinytext'">string</xsl:when>
4243
<xsl:when test=". = 'varbinary'">byte[]</xsl:when>
4344
<xsl:when test=". = 'varchar'">string</xsl:when>
@@ -58,6 +59,17 @@
5859
</xsl:if>
5960
</xsl:otherwise>
6061
</xsl:choose>
62+
</xsl:template>
63+
64+
<xsl:template match="type" mode="input">
65+
<xsl:if test="@array = 1">IEnumerable&lt;</xsl:if>
66+
<xsl:apply-templates select="." mode="typeonly"/>
67+
<xsl:if test="@array = 1">&gt;</xsl:if>
68+
<xsl:if test="@array = 1 and . = 'char'">ERROR_SQL_INJECTION</xsl:if>
69+
</xsl:template>
70+
71+
<xsl:template match="type">
72+
<xsl:apply-templates select="." mode="typeonly"/>
6173
<xsl:if test="@array = 1">[]</xsl:if>
6274
<xsl:if test="@array = 1 and . = 'char'">ERROR_SQL_INJECTION</xsl:if>
6375
</xsl:template>
@@ -92,7 +104,7 @@
92104

93105
<xsl:template match="output"> public <xsl:apply-templates select="./type"/><xsl:text> </xsl:text><xsl:value-of select="name"/> { get; set; }
94106
</xsl:template>
95-
<xsl:template match="input">, <xsl:apply-templates select="./type"/><xsl:text> </xsl:text><xsl:value-of select="name"/></xsl:template>
107+
<xsl:template match="input">, <xsl:apply-templates select="./type" mode="input"/><xsl:text> </xsl:text><xsl:value-of select="name"/></xsl:template>
96108

97109
<xsl:template match="sql">
98110
<xsl:variable name="nboutput" select="count(query[@ignore = 0]/output)"/>
@@ -106,7 +118,7 @@
106118
{
107119
Connection = conn,
108120
Transaction = transaction,
109-
CommandText = @"<xsl:value-of select="text"/>"<xsl:for-each select="query/input/type[@array = 1]">.Replace("@<xsl:value-of select="../name"/>", string.Join(",", <xsl:value-of select="../name"/>), StringComparison.Ordinal)</xsl:for-each>
121+
CommandText = @"<xsl:value-of select="text"/>"<xsl:for-each select="query/input/type[@array = 1]">.Replace("@<xsl:value-of select="../name"/>", (<xsl:value-of select="../name"/> != null &amp;&amp; <xsl:value-of select="../name"/>.Any()) ? string.Join(",", <xsl:value-of select="../name"/>) : "NULL", StringComparison.Ordinal)</xsl:for-each>
110122
};
111123
<xsl:for-each select="query/input"><xsl:if test="type[@array != 1]">sqlCmd.Parameters.AddWithValue("@<xsl:value-of select="name"/>", <xsl:value-of select="name"/>);
112124
</xsl:if></xsl:for-each>
@@ -119,19 +131,22 @@
119131
<xsl:variable name="returntype">
120132
<xsl:apply-templates select="query[@ignore = 0]/output/type"/>
121133
</xsl:variable>
122-
public static async Task&lt;<xsl:value-of select="$returntype"/>&gt; <xsl:value-of select="name"/>(MySqlConnection conn, MySqlTransaction transaction<xsl:apply-templates select="query/input"/>)
134+
public static async Task&lt;<xsl:value-of select="$returntype"/>&gt; <xsl:value-of select="name"/>(MySqlConnection conn, MySqlTransaction transaction<xsl:apply-templates select="query/input"/>, bool returnDefault = false)
123135
{
124136
using MySqlCommand sqlCmd = new MySqlCommand
125137
{
126138
Connection = conn,
127139
Transaction = transaction,
128-
CommandText = @"<xsl:value-of select="text"/>"<xsl:for-each select="query/input/type[@array = 1]">.Replace("@<xsl:value-of select="../name"/>", string.Join(",", <xsl:value-of select="../name"/>), StringComparison.Ordinal)</xsl:for-each>
140+
CommandText = @"<xsl:value-of select="text"/>"<xsl:for-each select="query/input/type[@array = 1]">.Replace("@<xsl:value-of select="../name"/>", (<xsl:value-of select="../name"/> != null &amp;&amp; <xsl:value-of select="../name"/>.Any()) ? string.Join(",", <xsl:value-of select="../name"/>) : "NULL", StringComparison.Ordinal)</xsl:for-each>
129141
};
130142
<xsl:for-each select="query/input"><xsl:if test="type[@array != 1]">sqlCmd.Parameters.AddWithValue("@<xsl:value-of select="name"/>", <xsl:value-of select="name"/>);
131143
</xsl:if></xsl:for-each>
132144
Object result = await sqlCmd.ExecuteScalarAsync();
133145
if (result != null)
134-
return (<xsl:value-of select="$returntype"/>)result;
146+
<xsl:if test="not(query[@ignore = 0]/output/type[@custom])">return (<xsl:value-of select="$returntype"/>)result;</xsl:if>
147+
<xsl:if test="query[@ignore = 0]/output/type[@custom]">return (<xsl:value-of select="$returntype"/>)Convert.ChangeType(result, typeof(<xsl:value-of select="$returntype"/>), System.Globalization.CultureInfo.InvariantCulture);</xsl:if>
148+
if (!returnDefault)
149+
throw new InvalidOperationException("<xsl:value-of select="name"/> return no row");
135150
return default;
136151
}
137152
</xsl:if>
@@ -148,7 +163,7 @@
148163
{
149164
Connection = conn,
150165
Transaction = transaction,
151-
CommandText = @"<xsl:value-of select="text"/>"<xsl:for-each select="query/input/type[@array = 1]">.Replace("@<xsl:value-of select="../name"/>", String.Join(",", <xsl:value-of select="../name"/>), StringComparison.Ordinal)</xsl:for-each>
166+
CommandText = @"<xsl:value-of select="text"/>"<xsl:for-each select="query/input/type[@array = 1]">.Replace("@<xsl:value-of select="../name"/>", (<xsl:value-of select="../name"/> != null &amp;&amp; <xsl:value-of select="../name"/>.Any()) ? string.Join(",", <xsl:value-of select="../name"/>) : "NULL", StringComparison.Ordinal)</xsl:for-each>
152167
};
153168
<xsl:for-each select="query/input"><xsl:if test="type[@array != 1]">sqlCmd.Parameters.AddWithValue("@<xsl:value-of select="name"/>", <xsl:value-of select="name"/>);
154169
</xsl:if></xsl:for-each>
@@ -175,7 +190,7 @@
175190
{
176191
Connection = conn,
177192
Transaction = transaction,
178-
CommandText = @"<xsl:value-of select="text"/>"<xsl:for-each select="query/input/type[@array = 1]">.Replace("@<xsl:value-of select="../name"/>", string.Join(",", <xsl:value-of select="../name"/>), StringComparison.Ordinal)</xsl:for-each>
193+
CommandText = @"<xsl:value-of select="text"/>"<xsl:for-each select="query/input/type[@array = 1]">.Replace("@<xsl:value-of select="../name"/>", (<xsl:value-of select="../name"/> != null &amp;&amp; <xsl:value-of select="../name"/>.Any()) ? string.Join(",", <xsl:value-of select="../name"/>) : "NULL", StringComparison.Ordinal)</xsl:for-each>
179194
};
180195
<xsl:for-each select="query/input"><xsl:if test="type[@array != 1]">sqlCmd.Parameters.AddWithValue("@<xsl:value-of select="name"/>", <xsl:value-of select="name"/>);
181196
</xsl:if></xsl:for-each>
@@ -201,7 +216,7 @@
201216
{
202217
Connection = conn,
203218
Transaction = transaction,
204-
CommandText = @"<xsl:value-of select="text"/>"<xsl:for-each select="query/input/type[@array = 1]">.Replace("@<xsl:value-of select="../name"/>", string.Join(",", <xsl:value-of select="../name"/>), StringComparison.Ordinal)</xsl:for-each>
219+
CommandText = @"<xsl:value-of select="text"/>"<xsl:for-each select="query/input/type[@array = 1]">.Replace("@<xsl:value-of select="../name"/>", (<xsl:value-of select="../name"/> != null &amp;&amp; <xsl:value-of select="../name"/>.Any()) ? string.Join(",", <xsl:value-of select="../name"/>) : "NULL", StringComparison.Ordinal)</xsl:for-each>
205220
};
206221
<xsl:for-each select="query/input"><xsl:if test="type[@array != 1]">sqlCmd.Parameters.AddWithValue("@<xsl:value-of select="name"/>", <xsl:value-of select="name"/>);
207222
</xsl:if></xsl:for-each>
@@ -225,6 +240,7 @@
225240
using System;
226241
using System.Collections.Generic;
227242
using System.Data.Common;
243+
using System.Linq;
228244
using System.Threading.Tasks;
229245

230246
namespace <xsl:value-of select="$namespace"/>

0 commit comments

Comments
 (0)