Skip to content

Commit dcb7bc4

Browse files
author
DAIKOZ
committed
SQLWrapper 2.2
1 parent 9f63431 commit dcb7bc4

18 files changed

+1899
-58
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
11
# Changelog
22

3+
## [2.2] (2024-08-02)
4+
5+
### SQLWrapper
6+
- Replace isnull by nullable attribute for database type
7+
8+
### Template
9+
- **Database VB**: add new template database-vb-ado.xslt and sql-vb-ado.xslt to generate Visual Basic .Net wrapper
10+
- Unify isnull and nullable for database type
11+
- **sql-csharp-ado.xslt**: Read data asyn (await reader.ReadAsync())
12+
- **Rename template** to use this rules:
13+
- database or sql: use database for template to apply to all database and use sql for template to apply on SQL queries
14+
- language: charp, vb, ...
15+
- type: ado
16+
- **Template available**:
17+
- **database-csharp-ado.xslt**: generate a database helper from schema xml in C# ADO
18+
- **database-vb-ado.xslt**: generate a database helper from schema xml in Visual Basic ADO
19+
- **sql-cshapr-ado.xslt**: generate a SQL query wrapper from schema xml and SQL query in C# ADO
20+
- **sql-vb-ado.xslt**: generate a SQL query wrapper from schema xml and SQL query in Visual Basic ADO
21+
22+
323
## [2.1.1] (2024-07-17)
424

525
### Daikoz.SQLWrapper NuGet Package

Daikoz.SQLWrapper/Daikoz.SQLWrapper.csproj

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
1212
<PackageIcon>sqlwrapper.png</PackageIcon>
1313
<Title>SQL Wrapper Generator</Title>
14-
<Version>2.1.1</Version>
15-
<AssemblyVersion>2.1.1</AssemblyVersion>
16-
<FileVersion>2.1.1</FileVersion>
14+
<Version>2.2</Version>
15+
<AssemblyVersion>2.2</AssemblyVersion>
16+
<FileVersion>2.2</FileVersion>
1717
<Authors>DAIKOZ</Authors>
1818
<Description>SQLWrapper makes it easier to create code wrappers for SQL queries. It's a powerful tool that helps speed up development by reducing the need for manual coding. It works with databases various SQL database (MySQL, MariaDB, ...), checking the syntax and performance of SQL queries before you execute them.
1919

@@ -31,16 +31,24 @@ Overall, DAIKOZ.SQLWrapper is a handy tool for making SQL code easier to work wi
3131
<PackageReleaseNotes>
3232
# Changelog
3333

34-
## [2.1.1] (2024-07-17)
34+
## [2.2] (2024-08-02)
3535

36-
### Daikoz.SQLWrapper NuGet Package
37-
- Fix issue: database name is not provided to XSLT.
36+
### SQLWrapper
37+
- Replace isnull by nullable attribute for database type
3838

3939
### Template
40-
- **Database C#**: Fix return value for function
41-
- **Database C#**: Fix column, table and method name to follow microft recommendation to avoid message IDEXXXX
42-
- **Database C#**: Move UpdateIfModified method in database class to avoid compilation error with several database helper
43-
- **SQL C# ADO**: Fix spaces
40+
- **Database VB**: add new template database-vb-ado.xslt and sql-vb-ado.xslt to generate Visual Basic .Net wrapper
41+
- Unify isnull and nullable for database type
42+
- **sql-csharp-ado.xslt**: Read data asyn (await reader.ReadAsync())
43+
- **Rename template** to use this rules:
44+
* database or sql: use database for template to apply to all database and use sql for template to apply on SQL queries
45+
* language: charp, vb, ...
46+
* type: ado
47+
- **Template available**:
48+
* **database-csharp-ado.xslt**: generate a database helper from schema xml in C# ADO
49+
* **database-vb-ado.xslt**: generate a database helper from schema xml in Visual Basic ADO
50+
* **sql-cshapr-ado.xslt**: generate a SQL query wrapper from schema xml and SQL query in C# ADO
51+
* **sql-vb-ado.xslt**: generate a SQL query wrapper from schema xml and SQL query in Visual Basic ADO
4452
</PackageReleaseNotes>
4553
<PackageLicenseFile>license.txt</PackageLicenseFile>
4654
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>

Daikoz.SQLWrapper/ErrorMessage.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@ internal class ErrorMessage
2121
public static readonly (string ErrorCode, string Message) MsgConfigurationWrapperXSLTNotFound = ("SW00514", "XSLT wrapper file not found: {0}");
2222
}
2323

24-
2524
}

Daikoz.SQLWrapper/SQLWrapperLauncher.cs

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ namespace Daikoz.SQLWrapper
1515
{
1616
public class SQLWrapperLauncher
1717
{
18+
public enum LanguageTarget
19+
{
20+
csharp,
21+
visualbasic,
22+
fsharp
23+
}
24+
1825
public List<string> GeneratedSources { get; set; } = [];
1926

2027
private readonly string _ConfigurationFilePath;
@@ -23,17 +30,19 @@ public class SQLWrapperLauncher
2330
private readonly SQLWrapperConfig _Config;
2431
private readonly TaskLoggingHelper _Log;
2532
private readonly bool _IsCleanning;
33+
private readonly LanguageTarget _LanguageTarget;
2634

2735
private readonly Regex _RegexDatabaseName = new("^[a-zA-Z0-9-_]+$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
2836
private readonly Regex _RegexSQLWrapperErrorLog = new(@"(?<code>SW[0-9]{5}):(?<message>.*)", RegexOptions.Compiled);
2937
private readonly Regex _RegexSQLWrapperErrorSQL = new(@"(?<filepath>.*):\((?<line>.*),(?<position>\d+)\):(?<code>[^:]*):(?<message>.*)", RegexOptions.Compiled);
3038

31-
public SQLWrapperLauncher(string configurationFilePath, string rootNamespace, TaskLoggingHelper log, bool isCleanning)
39+
public SQLWrapperLauncher(string configurationFilePath, string rootNamespace, TaskLoggingHelper log, bool isCleanning, LanguageTarget languageTarget)
3240
{
3341
_ConfigurationFilePath = configurationFilePath;
3442
_RootNamespace = rootNamespace;
3543
_Log = log ?? throw new ArgumentNullException(nameof(log));
3644
_IsCleanning = isCleanning;
45+
_LanguageTarget = languageTarget;
3746

3847
try
3948
{
@@ -135,8 +144,11 @@ private void StartProcess(string arguments, string logCategory, string logFile)
135144
{
136145
// Find sqlwrapper executable path
137146
string assemblyDirectory = GetAssemblyDirectory();
138-
string sqlWrapperPath = Path.Combine(assemblyDirectory, "tools", "SQLWrapper");
139-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) sqlWrapperPath += ".exe";
147+
string sqlWrapperPath = Path.Combine(assemblyDirectory, "tools", "bin");
148+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
149+
sqlWrapperPath = Path.Combine(sqlWrapperPath, "win-x64", "SQLWrapper.exe");
150+
else
151+
sqlWrapperPath = Path.Combine(sqlWrapperPath, "linux-x64", "SQLWrapper");
140152
if (!File.Exists(sqlWrapperPath))
141153
throw new SQLWrapperException(ErrorMessage.MsgConfigurationSQLWrapperToolNotFound.ErrorCode, logFile, String.Format(ErrorMessage.MsgConfigurationSQLWrapperToolNotFound.Message, sqlWrapperPath));
142154

@@ -326,7 +338,12 @@ private void GenerateHelper(Database wrapperdb)
326338

327339
// XSLT
328340
string assemblyDirectory = GetAssemblyDirectory();
329-
string xlstFilePath = Path.Combine(assemblyDirectory, "tools", "template", "csharp", "helper.xslt");
341+
string xlstFilePath = _LanguageTarget switch
342+
{
343+
LanguageTarget.visualbasic => Path.Combine(assemblyDirectory, "tools", "template", "database-vb-ado.xslt"),
344+
_ => Path.Combine(assemblyDirectory, "tools", "template", "database-csharp-ado.xslt")
345+
};
346+
330347
if (wrapperdb.XLST != null && !string.IsNullOrWhiteSpace(wrapperdb.XLST))
331348
xlstFilePath = wrapperdb.XLST;
332349
if (!Path.IsPathRooted(xlstFilePath))
@@ -404,7 +421,13 @@ private void GenerateWrapper(SQL wrappersql)
404421
{
405422
foreach (string sqlFilePath in listSQLFiles)
406423
{
407-
string codeFilePath = sqlFilePath + ".cs";
424+
string codeFilePath = sqlFilePath + (
425+
_LanguageTarget switch
426+
{
427+
LanguageTarget.visualbasic => ".vb",
428+
LanguageTarget.fsharp => ".f",
429+
_ => ".cs"
430+
});
408431
LogMessage("Remove wrapper: " + codeFilePath);
409432
File.Delete(codeFilePath);
410433
}
@@ -424,7 +447,11 @@ private void GenerateWrapper(SQL wrappersql)
424447

425448
// XSLT
426449
string assemblyDirectory = GetAssemblyDirectory();
427-
string xlstFilePath = Path.Combine(assemblyDirectory, "tools", "template", "csharp", "ADO.xslt");
450+
string xlstFilePath = _LanguageTarget switch
451+
{
452+
LanguageTarget.visualbasic => Path.Combine(assemblyDirectory, "tools", "template", "sql-vb-ado.xslt"),
453+
_ => Path.Combine(assemblyDirectory, "tools", "template", "sql-csharp-ado.xslt")
454+
};
428455
if (wrappersql.XLST != null && !string.IsNullOrWhiteSpace(wrappersql.XLST))
429456
xlstFilePath = wrappersql.XLST;
430457
if (!Path.IsPathRooted(xlstFilePath))
@@ -443,7 +470,13 @@ private void GenerateWrapper(SQL wrappersql)
443470

444471
foreach (string sqlFilePath in listSQLFiles)
445472
{
446-
string outputFilePath = sqlFilePath + ".cs";
473+
string outputFilePath = sqlFilePath + (
474+
_LanguageTarget switch
475+
{
476+
LanguageTarget.visualbasic => ".vb",
477+
LanguageTarget.fsharp => ".f",
478+
_ => ".cs"
479+
});
447480

448481
// Check uptodate
449482
if (File.Exists(outputFilePath))

Daikoz.SQLWrapper/SQLWrapperTask.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Microsoft.Build.Utilities;
33
using System;
44
using System.IO;
5+
using static Daikoz.SQLWrapper.SQLWrapperLauncher;
56

67
namespace Daikoz.SQLWrapper
78
{
@@ -10,6 +11,7 @@ public class SQLWrapperTask : Task
1011
public string? ConfigurationFilePath { get; set; }
1112
public string RootNamespace { get; set; } = "Daikoz.SQLWrapper";
1213
public bool IsCleanning { get; set; }
14+
public string LanguageTarget { get; set; } = ".csproj";
1315

1416
[Output]
1517
public string[] GeneratedSources { get; set; } = [];
@@ -32,7 +34,14 @@ public override bool Execute()
3234
return false;
3335
}
3436

35-
Daikoz.SQLWrapper.SQLWrapperLauncher sqlWrapper = new(ConfigurationFilePath, RootNamespace, Log, IsCleanning);
37+
SQLWrapperLauncher.LanguageTarget languageTarget = SQLWrapperLauncher.LanguageTarget.csharp;
38+
languageTarget = LanguageTarget switch
39+
{
40+
".vbproj" => SQLWrapperLauncher.LanguageTarget.visualbasic,
41+
".fsharp" => SQLWrapperLauncher.LanguageTarget.fsharp,
42+
_ => SQLWrapperLauncher.LanguageTarget.csharp,
43+
};
44+
Daikoz.SQLWrapper.SQLWrapperLauncher sqlWrapper = new(ConfigurationFilePath, RootNamespace, Log, IsCleanning, languageTarget);
3645
bool result = sqlWrapper.Execute();
3746
GeneratedSources = [.. sqlWrapper.GeneratedSources];
3847
return result;

Daikoz.SQLWrapper/build/Daikoz.SQLWrapper.targets

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</PropertyGroup>
1919

2020
<!--
21-
Add cs file under .sql or mysql file
21+
Add cs/vb file under .sql or mysql file
2222
-->
2323
<ItemGroup>
2424
<Compile Update="**\*.mysql.cs">
@@ -27,6 +27,12 @@
2727
<Compile Update="**\*.sql.cs">
2828
<DependentUpon>$([System.String]::Copy('%(Filename)'))</DependentUpon>
2929
</Compile>
30+
<Compile Update="**\*.mysql.vb">
31+
<DependentUpon>$([System.String]::Copy('%(Filename)'))</DependentUpon>
32+
</Compile>
33+
<Compile Update="**\*.sql.vb">
34+
<DependentUpon>$([System.String]::Copy('%(Filename)'))</DependentUpon>
35+
</Compile>
3036
</ItemGroup>
3137

3238
<!--
@@ -35,7 +41,7 @@
3541
<UsingTask TaskName="Daikoz.SQLWrapper.SQLWrapperTask" AssemblyFile="..\lib\netstandard2.0\Daikoz.SQLWrapper.dll" />
3642

3743
<Target Name="SQLWrapperBuild" BeforeTargets="CoreCompile">
38-
<Daikoz.SQLWrapper.SQLWrapperTask ConfigurationFilePath="$(MSBuildProjectDirectory)\sqlwrapper.json" IsCleanning="false" RootNamespace="$(RootNamespace)">
44+
<Daikoz.SQLWrapper.SQLWrapperTask ConfigurationFilePath="$(MSBuildProjectDirectory)\sqlwrapper.json" IsCleanning="false" RootNamespace="$(RootNamespace)" LanguageTarget="$(MSBuildProjectExtension)">
3945
<Output TaskParameter="GeneratedSources" ItemName="GeneratedSources" />
4046
</Daikoz.SQLWrapper.SQLWrapperTask>
4147
<ItemGroup>
@@ -44,7 +50,7 @@
4450
</Target>
4551

4652
<Target Name="SQLWrapperClean" AfterTargets="BeforeClean">
47-
<Daikoz.SQLWrapper.SQLWrapperTask ConfigurationFilePath="$(MSBuildProjectDirectory)\sqlwrapper.json" IsCleanning="true" RootNamespace="$(RootNamespace)" />
53+
<Daikoz.SQLWrapper.SQLWrapperTask ConfigurationFilePath="$(MSBuildProjectDirectory)\sqlwrapper.json" IsCleanning="true" RootNamespace="$(RootNamespace)" LanguageTarget="$(MSBuildProjectExtension)" />
4854
</Target>
4955

5056
</Project>

Daikoz.SQLWrapper/readme.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Overall, SQLWrapper is a handy tool for making SQL code easier to work with, sav
2020

2121
| Database | language | function wrapper | stored procedure wrapper | SQL query wrapper | check SQL query syntax |
2222
| --- | :---: | :---: | :---: | :---: | :---: |
23-
| **mysql** | C# .Net |||||
24-
| **mariadb** | C# .Net |||||
23+
| **mysql** | C# .Net<br/>Visual Basic .Net |||||
24+
| **mariadb** | C# .Net<br/>Visual Basic .Net |||||
2525

2626
## Getting started with package NuGet Daikoz.SQLWrapper
2727

@@ -162,7 +162,7 @@ Copyright (C) DAIKOZ. All rights reserved.
162162
USAGE:
163163
Generate code from sql request:
164164
SQLWrapper wrapper-sql --inputfiles request1.mysql request2.mysql --outputfile mysqlrequest.cs --params
165-
namespace=DAIKOZ classname=SQLWrapper --schema sqlwrapper-cachedb.xml --xslt Template\CSharp\charpADO.xslt
165+
namespace=DAIKOZ classname=SQLWrapper --schema sqlwrapper-cachedb.xml --xslt Template\sql-cshapr-ado.xslt
166166
167167
-s, --schema Required. XML file of cache database schema to load. Generate it before with database command
168168
@@ -186,7 +186,7 @@ Generate code from sql request:
186186
**Example:**
187187

188188
``` dos
189-
SQLWrapper wrapper-sql --schema sqlwrapper-cachedb.xml --inputfiles request1.mysql request2.mysql --outputfile mysqlrequest.cs --params namespace=DAIKOZ classname=SQLWrapper --xslt template\csharp\ADO.xslt
189+
SQLWrapper wrapper-sql --schema sqlwrapper-cachedb.xml --inputfiles request1.mysql request2.mysql --outputfile mysqlrequest.cs --params namespace=DAIKOZ classname=SQLWrapper --xslt template\sql-cshapr-ado.xslt
190190
```
191191

192192
This command create a **SQL wrapper** from **database** for 2 queries defined in **inputfiles**. It use the **XSLT** file to generate the **outputfile**. **params** give parameters defined in **XLST** file (here the namespace).
@@ -201,7 +201,7 @@ SQL Wrapper Generator 2.0.1.1+fe5be6893053615a1ac4a351bb4da3c110a6355d
201201
Copyright (C) DAIKOZ. All rights reserved.
202202
USAGE:
203203
Generate code helper to access database:
204-
SQLWrapper wrapper-database --outputfile helper.cs --schema sqlwrapper-cachedb.xml --xslt Template\CSharp\helper.xslt
204+
SQLWrapper wrapper-database --outputfile helper.cs --schema sqlwrapper-cachedb.xml --xslt Template\database-csharp-ado.xslt
205205
206206
-s, --schema Required. XML file of cache database schema to load. Generate it before with database command
207207
@@ -223,7 +223,7 @@ Generate code helper to access database:
223223
**Example:**
224224

225225
``` dos
226-
SQLWrapper wrapper-database --schema sqlwrapper-cachedb.xml --outputfile MyDatabaseHelper.cs --xslt template\csharp\helper.xslt
226+
SQLWrapper wrapper-database --schema sqlwrapper-cachedb.xml --outputfile MyDatabaseHelper.cs --xslt template\database-csharp-ado.xslt
227227
```
228228

229229
This command create a **helper** for **database**. It use **XLST** file to generate the **outputfile**.
@@ -235,4 +235,12 @@ In template section, you can found several XLST files to generate SQL and databa
235235
You can create or modify your own and use it with **--xslt** parameter.
236236
DAIKOZ can help you to create your own XLST. Contact us.
237237

238+
### Template available
238239

240+
Generate a **database helper** from XML Schema in:
241+
- C# .Net: **database-csharp-ado.xslt**
242+
- Visual Basic .Net: **database-vb-ado.xslt**
243+
244+
Generate a **SQL query wrapper** from XML schema and SQL query in:
245+
- C# .Net: **sql-cshapr-ado.xslt**
246+
- Visual Basic: **sql-vb-ado.xslt**

0 commit comments

Comments
 (0)