Skip to content

Commit 84f6ed3

Browse files
committed
SQLWrapper 1.1.19
1 parent f050dd7 commit 84f6ed3

File tree

7 files changed

+597
-37
lines changed

7 files changed

+597
-37
lines changed

Daikoz.SQLWrapper/Daikoz.SQLWrapper.csproj

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
<LangVersion>latest</LangVersion>
66
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
77
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
8-
<Version>1.1.8</Version>
8+
<Version>1.1.19</Version>
99
<Authors>DAIKOZ</Authors>
1010
<Company>DAIKOZ</Company>
11-
<Copyright2019 - DAIKOZ - All rights reserved</Copyright>
11+
<Copyright2020 - DAIKOZ - All rights reserved</Copyright>
1212
<PackageLicense>https://www.sqlwrapper.com</PackageLicense>
1313
<PackageProjectUrl>https://www.sqlwrapper.com</PackageProjectUrl>
1414
<RepositoryUrl>https://github.com/daikoz/SQLWrapper</RepositoryUrl>
15-
<PackageTags>sql;wrapper;sqlwrapper;ado;dapper;mysql;mariadb;</PackageTags>
15+
<PackageTags>sql;wrapper;sqlwrapper;ado;dapper;mysql;mariadb;sql wrapper</PackageTags>
1616
<PackageReleaseNotes></PackageReleaseNotes>
1717
<Title>SQLWrapper</Title>
1818
<Description>
@@ -24,23 +24,25 @@
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>1.1.8.0</AssemblyVersion>
28-
<FileVersion>1.1.8.0</FileVersion>
27+
<AssemblyVersion>1.1.19.0</AssemblyVersion>
28+
<FileVersion>1.1.19.0</FileVersion>
2929
<PackageLicenseUrl></PackageLicenseUrl>
3030
<BuildOutputTargetFolder>dll</BuildOutputTargetFolder>
3131
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
3232
<NoWarn>NU5100</NoWarn>
3333
<PackageIcon>sqlwrapper.png</PackageIcon>
3434
<PackageIconUrl />
35+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
36+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
37+
</PropertyGroup>
38+
39+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
40+
<PlatformTarget>AnyCPU</PlatformTarget>
3541
</PropertyGroup>
3642

3743
<ItemGroup>
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" />
40-
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8">
41-
<PrivateAssets>all</PrivateAssets>
42-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
43-
</PackageReference>
44+
<PackageReference Include="Microsoft.Build.Framework" Version="16.8.0" PrivateAssets="All" />
45+
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="16.8.0" PrivateAssets="All" />
4446
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" PrivateAssets="All" />
4547
</ItemGroup>
4648

Daikoz.SQLWrapper/SQLWrapperExecute.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,12 @@ public bool Execute()
8383
argument.Append(" -d " + cacheDBPath);
8484
argument.Append(" -o " + Path.Combine(System.Environment.CurrentDirectory, config.HelperRelativePath));
8585
argument.Append(" -p namespace=" + config.Namespace);
86+
if (config.CustomTypes != null && config.CustomTypes.Length > 0)
87+
{
88+
argument.Append(" -t");
89+
foreach (string type in config.CustomTypes)
90+
argument.Append(" \"" + type.Replace("\"", "\"\"") + "\" ");
91+
}
8692
argument.Append(" -x " + helperPath);
8793

8894
StartProcess(config.SQLWrapperPath, argument.ToString(), "SQLWrapper Helper", helperPath);
3.09 MB
Binary file not shown.

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

Lines changed: 137 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,19 @@
8181
</xsl:variable>
8282
<xsl:choose>
8383
<xsl:when test="type[@isnull = 1]">
84-
<xsl:text> </xsl:text><xsl:value-of select="name"/> = reader[<xsl:value-of select="position()-1" />] == DBNull.Value ? null : (<xsl:apply-templates select="type"/>)reader[<xsl:value-of select="position()-1" />],
84+
<xsl:if test="not(type[@custom])">
85+
<xsl:text> </xsl:text><xsl:value-of select="name"/> = reader[<xsl:value-of select="position()-1" />] == DBNull.Value ? null : (<xsl:apply-templates select="type"/>)reader[<xsl:value-of select="position()-1" />],
86+
</xsl:if>
87+
<xsl:if test="type[@custom]">
88+
<xsl:text> </xsl:text><xsl:value-of select="name"/> = reader[<xsl:value-of select="position()-1" />] == DBNull.Value ? null : (<xsl:apply-templates select="type"/>)(typeof(<xsl:value-of select="type/@custom"/>).IsEnum ? Enum.ToObject(typeof(<xsl:value-of select="type/@custom"/>), reader[<xsl:value-of select="position()-1" />]) : Convert.ChangeType(reader[<xsl:value-of select="position()-1" />], typeof(<xsl:value-of select="type/@custom"/>), System.Globalization.CultureInfo.InvariantCulture)),
89+
</xsl:if>
8590
</xsl:when>
8691
<xsl:otherwise>
8792
<xsl:if test="not(type[@custom])">
8893
<xsl:text> </xsl:text><xsl:value-of select="name"/> = (<xsl:apply-templates select="type"/>)reader[<xsl:value-of select="position()-1" />],
8994
</xsl:if>
9095
<xsl:if test="type[@custom]">
91-
<xsl:text> </xsl:text><xsl:value-of select="name"/> = (<xsl:apply-templates select="type"/>)(typeof(<xsl:apply-templates select="type"/>).IsEnum ? Enum.ToObject(typeof(<xsl:apply-templates select="type"/>), reader[<xsl:value-of select="position()-1" />]) : Convert.ChangeType(reader[<xsl:value-of select="position()-1" />], typeof(<xsl:apply-templates select="type"/>), System.Globalization.CultureInfo.InvariantCulture)),
96+
<xsl:text> </xsl:text><xsl:value-of select="name"/> = (<xsl:apply-templates select="type"/>)(typeof(<xsl:value-of select="type/@custom"/>).IsEnum ? Enum.ToObject(typeof(<xsl:value-of select="type/@custom"/>), reader[<xsl:value-of select="position()-1" />]) : Convert.ChangeType(reader[<xsl:value-of select="position()-1" />], typeof(<xsl:value-of select="type/@custom"/>), System.Globalization.CultureInfo.InvariantCulture)),
9297
</xsl:if>
9398
</xsl:otherwise>
9499
</xsl:choose>
@@ -111,10 +116,93 @@
111116
</xsl:template>
112117
<xsl:template match="input">, <xsl:apply-templates select="./type" mode="input"/><xsl:text> </xsl:text><xsl:value-of select="name"/></xsl:template>
113118

119+
<xsl:template match="query" mode="returntype">
120+
<xsl:variable name="name" select="../name"/>
121+
<xsl:variable name="nboutput" select="count(output)"/>
122+
<xsl:variable name="nboutputmultiple" select="@multiplerows = 1"/>
123+
<xsl:if test="position() != 1">, </xsl:if>
124+
<xsl:if test="$nboutput = 1 and $nboutputmultiple = 0"><xsl:apply-templates select="output/type"/></xsl:if>
125+
<xsl:if test="$nboutput > 1 and $nboutputmultiple = 0"><xsl:value-of select="../name"/>ResultQuery<xsl:value-of select="position()" /></xsl:if>
126+
<xsl:if test="$nboutputmultiple = 1">List&lt;<xsl:value-of select="../name"/>ResultQuery<xsl:value-of select="position()" />&gt;</xsl:if>
127+
</xsl:template>
128+
129+
<xsl:template match="query" mode="initresult">
130+
<xsl:variable name="name" select="../name"/>
131+
<xsl:variable name="nboutput" select="count(output)"/>
132+
<xsl:variable name="nboutputmultiple" select="@multiplerows = 1"/>
133+
<xsl:if test="$nboutput = 1 and $nboutputmultiple = 0"><xsl:apply-templates select="output/type"/> result<xsl:value-of select="position()" /> = default;
134+
</xsl:if>
135+
<xsl:if test="$nboutput > 1 and $nboutputmultiple = 0"><xsl:value-of select="../name"/>ResultQuery<xsl:value-of select="position()" /> result<xsl:value-of select="position()" /> = new <xsl:value-of select="../name"/>ResultQuery<xsl:value-of select="position()" />();
136+
</xsl:if>
137+
<xsl:if test="$nboutputmultiple = 1">List&lt;<xsl:value-of select="../name"/>ResultQuery<xsl:value-of select="position()" />&gt; result<xsl:value-of select="position()" /> = new List&lt;<xsl:value-of select="../name"/>ResultQuery<xsl:value-of select="position()" />&gt;();
138+
</xsl:if>
139+
</xsl:template>
140+
141+
<xsl:template match="query" mode="getresult">
142+
<xsl:variable name="nboutput" select="count(output)"/>
143+
<xsl:variable name="returntype">
144+
<xsl:apply-templates select="output/type"/>
145+
</xsl:variable>
146+
// <xsl:value-of select="../name"/>ResultQuery<xsl:value-of select="position()" />
147+
<xsl:if test="position() != 1">
148+
if(!await reader.NextResultAsync())
149+
throw new InvalidOperationException("<xsl:value-of select="../name"/>Result query <xsl:value-of select="position()" /> invalid number of result");
150+
</xsl:if>
151+
<!-- Return only one value -->
152+
<xsl:if test="$nboutput = 1 and @multiplerows = 0">
153+
if(!await reader.ReadAsync())
154+
throw new InvalidOperationException("<xsl:value-of select="../name"/>Result query <xsl:value-of select="position()" /> return no row");
155+
<xsl:if test="output/type[@isnull = 0]">
156+
<xsl:if test="not(output/type[@custom])">
157+
result<xsl:value-of select="position()" /> = (<xsl:value-of select="$returntype"/>)reader[0];
158+
</xsl:if>
159+
<xsl:if test="output/type[@custom]">
160+
result<xsl:value-of select="position()" /> = (<xsl:value-of select="$returntype"/>)Convert.ChangeType(reader[0], typeof(<xsl:value-of select="$returntype"/>), System.Globalization.CultureInfo.InvariantCulture);
161+
</xsl:if>
162+
</xsl:if>
163+
<xsl:if test="output/type[@isnull = 1]">
164+
<xsl:if test="not(output/type[@custom])">
165+
result<xsl:value-of select="position()" /> = reader[0] == DBNull.Value ? null : (<xsl:value-of select="$returntype"/>)reader[0];
166+
</xsl:if>
167+
<xsl:if test="output/type[@custom]">
168+
result<xsl:value-of select="position()" /> = reader[0] == DBNull.Value ? null : (<xsl:value-of select="$returntype"/>)Convert.ChangeType(reader[0], typeof(<xsl:value-of select="$returntype"/>), System.Globalization.CultureInfo.InvariantCulture);
169+
</xsl:if>
170+
</xsl:if>
171+
</xsl:if>
172+
173+
<!-- Return one multiple columns -->
174+
<xsl:if test="$nboutput > 1 and @multiplerows = 0">
175+
if(!await reader.ReadAsync())
176+
throw new InvalidOperationException("<xsl:value-of select="../name"/>Result query <xsl:value-of select="position()" /> return no row");
177+
178+
result<xsl:value-of select="position()" /> = new <xsl:value-of select="../name"/>ResultQuery<xsl:value-of select="position()" />
179+
{
180+
<xsl:apply-templates select="." mode="outputassign"/>
181+
};
182+
</xsl:if>
183+
184+
<!-- Return several row of one column -->
185+
<xsl:if test="$nboutput = 1 and @multiplerows = 1">
186+
while (reader.Read())
187+
result<xsl:value-of select="position()" />.Add(<xsl:apply-templates select="." mode="outputconvert"/>);
188+
</xsl:if>
189+
190+
<!-- Return several row multiple columns -->
191+
<xsl:if test="$nboutput > 1 and @multiplerows = 1">
192+
while (reader.Read())
193+
result<xsl:value-of select="position()" />.Add(new <xsl:value-of select="../name"/>ResultQuery<xsl:value-of select="position()" />
194+
{
195+
<xsl:apply-templates select="." mode="outputassign"/>
196+
});
197+
</xsl:if>
198+
199+
</xsl:template>
200+
114201
<xsl:template match="sql">
115202
<xsl:variable name="nboutput" select="count(query[@ignore = 0]/output)"/>
116203
<xsl:variable name="nboutputmultiple" select="count(query[@ignore = 0 and @multiplerows = 1])"/>
117-
204+
<xsl:variable name="nbquery" select="count(query[@ignore = 0])"/>
205+
118206
<!-- Non Query Insert Delete Update -->
119207
<xsl:if test="$nboutput = 0">
120208
public static async Task&lt;int&gt; <xsl:value-of select="name"/>(MySqlConnection conn, MySqlTransaction transaction<xsl:apply-templates select="query/input"/>)
@@ -146,18 +234,24 @@
146234
};
147235
<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"/>);
148236
</xsl:if></xsl:for-each>
149-
Object result = await sqlCmd.ExecuteScalarAsync();
237+
object result = await sqlCmd.ExecuteScalarAsync();
150238
if (result != null)
151-
<xsl:if test="not(query[@ignore = 0]/output/type[@custom])">return (<xsl:value-of select="$returntype"/>)result;</xsl:if>
152-
<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>
239+
<xsl:if test="query[@ignore = 0]/output/type[@isnull = 0]">
240+
<xsl:if test="not(query[@ignore = 0]/output/type[@custom]) and not(query[@ignore = 0]/output/type[@lastinsertid = 1])">return (<xsl:value-of select="$returntype"/>)result;</xsl:if>
241+
<xsl:if test="query[@ignore = 0]/output/type[@custom] or query[@ignore = 0]/output/type[@lastinsertid = 1]">return (<xsl:value-of select="$returntype"/>)Convert.ChangeType(result, typeof(<xsl:value-of select="$returntype"/>), System.Globalization.CultureInfo.InvariantCulture);</xsl:if>
242+
</xsl:if>
243+
<xsl:if test="query[@ignore = 0]/output/type[@isnull = 1]">
244+
<xsl:if test="not(query[@ignore = 0]/output/type[@custom])">return result == DBNull.Value ? null : (<xsl:value-of select="$returntype"/>)result;</xsl:if>
245+
<xsl:if test="query[@ignore = 0]/output/type[@custom]">return result == DBNull.Value ? null : (<xsl:value-of select="$returntype"/>)Convert.ChangeType(result, typeof(<xsl:value-of select="$returntype"/>), System.Globalization.CultureInfo.InvariantCulture);</xsl:if>
246+
</xsl:if>
153247
if (!returnDefault)
154248
throw new InvalidOperationException("<xsl:value-of select="name"/> return no row");
155249
return default;
156250
}
157251
</xsl:if>
158252

159253
<!-- Return one multiple columns -->
160-
<xsl:if test="$nboutput > 1 and $nboutputmultiple = 0">
254+
<xsl:if test="$nboutput > 1 and $nboutputmultiple = 0 and $nbquery = 1">
161255
public class <xsl:value-of select="name"/>Result
162256
{
163257
<xsl:apply-templates select="query/output"/> }
@@ -210,7 +304,7 @@
210304
</xsl:if>
211305

212306
<!-- Return several row multiple columns -->
213-
<xsl:if test="$nboutput > 1 and $nboutputmultiple = 1">
307+
<xsl:if test="$nboutput > 1 and $nboutputmultiple = 1 and $nbquery = 1">
214308
public class <xsl:value-of select="name"/>Result
215309
{
216310
<xsl:apply-templates select="query/output"/> }
@@ -238,10 +332,44 @@
238332
return listResult;
239333
}
240334
</xsl:if>
335+
336+
<!-- Return several queries -->
337+
<xsl:if test="$nboutput > 1 and $nbquery > 1">
338+
<xsl:variable name="name" select="name"/>
339+
<xsl:for-each select="query[@ignore = 0]">
340+
<xsl:if test="count(output) > 1">
341+
public class <xsl:value-of select="$name"/>ResultQuery<xsl:value-of select="position()" />
342+
{
343+
<xsl:apply-templates select="output"/> }
344+
</xsl:if>
345+
</xsl:for-each>
346+
public static async Task&lt;(<xsl:apply-templates select="query[@ignore = 0]" mode="returntype"/>)&gt; <xsl:value-of select="name"/>(MySqlConnection conn, MySqlTransaction transaction<xsl:apply-templates select="query/input"/>)
347+
{
348+
using MySqlCommand sqlCmd = new MySqlCommand
349+
{
350+
Connection = conn,
351+
Transaction = transaction,
352+
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>
353+
};
354+
<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"/>);
355+
</xsl:if></xsl:for-each>
356+
<xsl:text>
357+
</xsl:text>
358+
<xsl:apply-templates select="query[@ignore = 0]" mode="initresult"/>
359+
using (DbDataReader reader = await sqlCmd.ExecuteReaderAsync())
360+
if (reader != null)
361+
{
362+
<xsl:apply-templates select="query[@ignore = 0]" mode="getresult"/>
363+
}
364+
365+
return (<xsl:for-each select="query[@ignore = 0]"><xsl:if test="position() != 1">, </xsl:if>result<xsl:value-of select="position()" /></xsl:for-each>);
366+
}
367+
368+
</xsl:if>
241369

242370
</xsl:template>
243371

244-
<xsl:template match="/">using MySql.Data.MySqlClient;
372+
<xsl:template match="/">using MySqlConnector;
245373
using System;
246374
using System.Collections.Generic;
247375
using System.Data.Common;

0 commit comments

Comments
 (0)