Skip to content

Commit 2d728f5

Browse files
author
DAIKOZ
committed
SQLWrapper 2.0.1
1 parent 8b5cdbe commit 2d728f5

File tree

12 files changed

+297
-94
lines changed

12 files changed

+297
-94
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changelog
2+
3+
## [2.0.1] (2024-04-12)
4+
5+
### SQLWrapper
6+
- Order caseinsentive input SQL variables.
7+
- Enhance display warning message
8+
- MariaDB/MySQL: Fix UNION column checking with BOOL, INT, INTEGER type
9+
10+
### Daikoz.SQLWrapper NuGet Package
11+
- Visual Studio can generate wrapper in background
12+
- Fix compilation error after clean the project, the generated source is now added to compile process. Don't need to build again the project.
13+
- Enhance display warning message
14+
- Update readme.md
15+
16+
### Template
17+
- **C# Helper**: Use int type for length or long instead of uint to avoid int cast with index of string function.
18+
- **C# Helper**: Rename SQLWrapper::UpdateIfModified to SQLWrapperHelper::UpdateIfModified method and move it in same namespace to avoid warning this Daikoz.SQLWrapper NuGet package.
19+
- **C# Helper**: Fix tab/space mix
20+
- **C# Helper**: Fix spaces

Daikoz.SQLWrapper/Daikoz.SQLWrapper.csproj

Lines changed: 28 additions & 7 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.0.0</Version>
15-
<AssemblyVersion>2.0.0</AssemblyVersion>
16-
<FileVersion>2.0.0</FileVersion>
14+
<Version>2.0.1</Version>
15+
<AssemblyVersion>2.0.1</AssemblyVersion>
16+
<FileVersion>2.0.1</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

@@ -28,10 +28,27 @@ Overall, DAIKOZ.SQLWrapper is a handy tool for making SQL code easier to work wi
2828
<RepositoryUrl>https://github.com/daikoz/SQLWrapper</RepositoryUrl>
2929
<RepositoryType>github</RepositoryType>
3030
<PackageTags>sql;wrapper;sqlwrapper;ORM;dapper;linq;database;mysql;mariadb;server;mssql;pgsql;sqlite;postgres;postgresql;query;builder</PackageTags>
31-
<PackageReleaseNotes>Version 2.0.0:
32-
- increase performance to generate code from sql query
33-
- Add MariaDB database
34-
- Genere code under each sql file</PackageReleaseNotes>
31+
<PackageReleaseNotes># Changelog
32+
33+
## [2.0.1] (2024-04-12)
34+
35+
### SQLWrapper
36+
- Order caseinsentive input SQL variables.
37+
- Enhance display warning message
38+
- MariaDB/MySQL: Fix UNION column checking with BOOL, INT, INTEGER type
39+
40+
### Daikoz.SQLWrapper NuGet Package
41+
- Visual Studio can generate wrapper in background
42+
- Fix compilation error after clean the project, the generated source is now added to compile process. Don't need to build again the project.
43+
- Enhance display warning message
44+
- Update readme.md
45+
46+
### Template
47+
- **C# Helper**: Use int type for length or long instead of uint to avoid int cast with index of string function.
48+
- **C# Helper**: Rename SQLWrapper::UpdateIfModified to SQLWrapperHelper::UpdateIfModified method and move it in same namespace to avoid warning this Daikoz.SQLWrapper NuGet package.
49+
- **C# Helper**: Fix tab/space mix
50+
- **C# Helper**: Fix spaces
51+
</PackageReleaseNotes>
3552
<PackageLicenseFile>license.txt</PackageLicenseFile>
3653
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
3754

@@ -75,4 +92,8 @@ Overall, DAIKOZ.SQLWrapper is a handy tool for making SQL code easier to work wi
7592
</EmbeddedResource>
7693
</ItemGroup>
7794

95+
<Target Name="CopyReadme" BeforeTargets="BeforeBuild">
96+
<Copy SourceFiles="..\..\..\SQLWrapper\README.md" DestinationFolder="$(MSBuildProjectDirectory)" />
97+
</Target>
98+
7899
</Project>

Daikoz.SQLWrapper/SQLWrapperLauncher.cs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Microsoft.Build.Framework;
22
using Microsoft.Build.Utilities;
33
using System;
4+
using System.Collections.Generic;
45
using System.Diagnostics;
56
using System.Globalization;
67
using System.IO;
@@ -13,6 +14,8 @@ namespace Daikoz.SQLWrapper
1314
{
1415
public class SQLWrapperLauncher
1516
{
17+
public List<string> GeneratedSources { get; set; } = [];
18+
1619
private readonly string _ConfigurationFilePath;
1720
private readonly string _RootNamespace;
1821
private readonly DateTime _ConfigurationModifiedDate;
@@ -155,7 +158,36 @@ private void StartProcess(string arguments, string logCategory, string logFile)
155158
if (!string.IsNullOrWhiteSpace(standartOutput))
156159
{
157160
LogMessage("Output [" + Environment.NewLine + standartOutput + ']');
158-
_Log.LogWarning(logCategory, "", "", logFile, 0, 0, 0, 0, standartOutput, null);
161+
int lineNumber = 0;
162+
int columnNumber = 0;
163+
string code = string.Empty;
164+
string error = string.Empty;
165+
string errorLogFile = logFile;
166+
167+
Match match = _RegexSQLWrapperErrorSQL.Match(standartOutput);
168+
if (match.Success)
169+
{
170+
errorLogFile = match.Groups["filepath"].Value;
171+
lineNumber = int.Parse(match.Groups["line"].Value, CultureInfo.InvariantCulture);
172+
columnNumber = int.Parse(match.Groups["position"].Value, CultureInfo.InvariantCulture);
173+
code = match.Groups["code"].Value.TrimStart();
174+
error = match.Groups["message"].Value.TrimStart();
175+
176+
_Log.LogWarning(logCategory, code, "", errorLogFile, lineNumber, columnNumber, 0, 0, error.Trim(), null);
177+
}
178+
else
179+
{
180+
match = _RegexSQLWrapperErrorLog.Match(standartOutput);
181+
if (match.Success)
182+
{
183+
code = match.Groups["code"].Value.TrimStart();
184+
error = match.Groups["message"].Value.TrimStart();
185+
186+
_Log.LogWarning(logCategory, code, "", logFile, 0, 0, 0, 0, error.Trim(), null);
187+
}
188+
else
189+
_Log.LogWarning(logCategory, "", "", logFile, 0, 0, 0, 0, standartOutput, null);
190+
}
159191
}
160192

161193
// Read error
@@ -321,6 +353,8 @@ private void GenerateHelper(Helper helper)
321353
return;
322354
}
323355
}
356+
else
357+
GeneratedSources.Add(outputFilePath);
324358

325359
// Generate
326360
LogMessage(string.Format("Generate Helper for database {0} ('{1}') with XSLT '{2}': '{3}'", helper.Database, databaseFilePath, xlstFilePath, outputFilePath));
@@ -420,6 +454,8 @@ private void GenerateWrapper(Wrapper wrapper)
420454
continue;
421455
}
422456
}
457+
else
458+
GeneratedSources.Add(outputFilePath);
423459

424460
// Generate
425461
LogMessage(string.Format("Generate wrapper: '{0}'", sqlFilePath));

Daikoz.SQLWrapper/SQLWrapperTask.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55

66
namespace Daikoz.SQLWrapper
77
{
8-
public class SQLWrapperTask : Task, ITask
8+
public class SQLWrapperTask : Task
99
{
1010
public string? ConfigurationFilePath { get; set; }
1111
public string RootNamespace { get; set; } = "Daikoz.SQLWrapper";
1212
public bool IsCleanning { get; set; }
1313

14+
[Output]
15+
public string[] GeneratedSources { get; set; } = [];
16+
17+
1418
public override bool Execute()
1519
{
1620
// System.Diagnostics.Debugger.Launch();
@@ -29,7 +33,9 @@ public override bool Execute()
2933
}
3034

3135
Daikoz.SQLWrapper.SQLWrapperLauncher sqlWrapper = new(ConfigurationFilePath, RootNamespace, Log, IsCleanning);
32-
return sqlWrapper.Execute();
36+
bool result = sqlWrapper.Execute();
37+
GeneratedSources = [.. sqlWrapper.GeneratedSources];
38+
return result;
3339
}
3440
catch (Daikoz.SQLWrapper.SQLWrapperException ex)
3541
{

Daikoz.SQLWrapper/build/Daikoz.SQLWrapper.targets

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,13 @@
3434
-->
3535
<UsingTask TaskName="Daikoz.SQLWrapper.SQLWrapperTask" AssemblyFile="..\lib\netstandard2.0\Daikoz.SQLWrapper.dll" />
3636

37-
<Target Name="SQLWrapperBuild" BeforeTargets="BeforeBuild" >
38-
<Daikoz.SQLWrapper.SQLWrapperTask ConfigurationFilePath="$(MSBuildProjectDirectory)\sqlwrapper.json" IsCleanning="false" RootNamespace="$(RootNamespace)" />
37+
<Target Name="SQLWrapperBuild" BeforeTargets="CoreCompile">
38+
<Daikoz.SQLWrapper.SQLWrapperTask ConfigurationFilePath="$(MSBuildProjectDirectory)\sqlwrapper.json" IsCleanning="false" RootNamespace="$(RootNamespace)">
39+
<Output TaskParameter="GeneratedSources" ItemName="GeneratedSources" />
40+
</Daikoz.SQLWrapper.SQLWrapperTask>
41+
<ItemGroup>
42+
<Compile Include="@(GeneratedSources)" />
43+
</ItemGroup>
3944
</Target>
4045

4146
<Target Name="SQLWrapperClean" AfterTargets="BeforeClean">

Daikoz.SQLWrapper/readme.md

Lines changed: 131 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
1-
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.
1+
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.
22

33
It's important to note that SQLWrapper isn't like other tools that map objects to database tables (ORMs). Instead, it directly generates code from your SQL queries and database structure, which performs better than tools like LINQ, EntityFramework, dapper, ... and doesn't have the same limitations.
44

55
One feature is that it can look at your database's structure to check if your SQL queries are correct, and it can create an XML file listing all the data your queries need and return. Then, you can use XSLT templates to turn that XML into code in languages like C#, and more.
66

77
Overall, SQLWrapper is a handy tool for making SQL code easier to work with, saving time, and helping you write better code.
88

9+
## Links
10+
* [Change log](https://github.com/daikoz/SQLWrapper/blob/master/CHANGELOG.md)
11+
* [Official website](https://www.sqlwrapper.com)
12+
* [Package .NET](https://www.nuget.org/packages/Daikoz.SQLWrapper/)
13+
* [Documentation](https://github.com/daikoz/SQLWrapper/wiki)
14+
* [Issues/Bugs](https://github.com/daikoz/SQLWrapper/issues)
15+
* [Videos](https://www.youtube.com/@SQLWrapper)
16+
* [Facebook](https://www.facebook.com/sqlwrapper/)
17+
* [Twitter](https://twitter.com/sqlwrapper)
18+
919
## Getting started with package NuGet Daikoz.SQLWrapper
1020

1121
**Video of demonstration:**
1222

13-
[![Watch the video](https://img.youtube.com/vi/xEeWnESZki0/hqdefault.jpg)](https://www.youtube.com/watch?v=xEeWnESZki0)
23+
[![Watch the video](https://raw.githubusercontent.com/daikoz/SQLWrapper/master/img/video.jpg)](https://www.youtube.com/watch?v=xEeWnESZki0)
1424

1525
The .NET package NuGet [Daikoz.SQLWrapper](https://www.nuget.org/packages/Daikoz.SQLWrapper) integrate SQLWrapper in build process of our .NET project.
1626

@@ -85,14 +95,124 @@ To start, follow a minimal configuration file. Modify HOSTNAME, USERID, PASSWORD
8595
* A database helper if generate in file MyDataseHelper.cs
8696
* For each *.sql, a wrapper is generated
8797

98+
8899
## Getting started with command line SQLWrapper
89100

90-
## Links
91-
* [Official web](https://www.sqlwrapper.com)
92-
* [Package .NET](https://www.nuget.org/packages/Daikoz.SQLWrapper/)
93-
* [Documentation](https://github.com/daikoz/SQLWrapper/wiki)
94-
* [Issues/Bugs](https://github.com/daikoz/SQLWrapper/issues)
95-
* [Videos](https://www.youtube.com/@SQLWrapper)
96-
* [Reddit](https://www.reddit.com/r/sqlwrapper/)
97-
* [Facebook](https://www.facebook.com/sqlwrapper/)
98-
* [Twitter](https://twitter.com/sqlwrapper)
101+
SQLWrapper can be use in console.
102+
103+
### Database
104+
105+
First, extract and cache database structure in XML File:
106+
107+
``` dos
108+
>SQLWrapper help database
109+
SQL Wrapper Generator
110+
Copyright (C) DAIKOZ. All rights reserved.
111+
USAGE:
112+
Extract and cache database structure in XML file:
113+
SQLWrapper database --connectionstring "server=servernamedb;user id=userid;password='password';database=db1" --outputfile sqlwrapper-cachedb.xml --type mariadb --verbose
114+
115+
-t, --type Required. Type of database: mysql, mariadb.
116+
117+
-c, --connectionstring Required. List of .net database connection string (https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/connection-string-syntax).
118+
119+
-o, --outputfile Output XML file (default: stdout).
120+
121+
-v, --verbose Set output to verbose messages.
122+
123+
--help Display this help screen.
124+
125+
--version Display version information.
126+
```
127+
128+
**Example:**
129+
130+
``` dos
131+
SQLWrapper database --connectionstring "server=servernamedb;user id=userid;password='password';database=db1" --outputfile sqlwrapper-cachedb.xml --type mariadb --verbose
132+
```
133+
134+
This command connect to **database** of **type** with connection information **connectionstring**. The output is written in **outputfile**.
135+
136+
### Wrapper
137+
138+
Generate the wrapper source code from SQL queries:
139+
140+
``` dos
141+
>SQLWrapper help wrapper
142+
SQL Wrapper Generator
143+
Copyright (C) DAIKOZ. All rights reserved.
144+
USAGE:
145+
Generate code from sql request:
146+
SQLWrapper wrapper --database sqlwrapper-cachedb.xml --inputfiles request1.mysql request2.mysql --outputfile mysqlrequest.cs --params namespace=DAIKOZ classname=SQLWrapper --xslt Template\CSharp\charpADO.xslt
147+
148+
-d, --database Required. XML file of cache database structure to load. Generate it before with database command
149+
150+
-i, --inputfiles Required. SQL files. Relative or full path. wildcard * is supported for filename.
151+
152+
-o, --outputfile Output file
153+
154+
-p, --params XLST Parameters
155+
156+
-t, --customtypes Force custom type for database field (table.col=MyEmu
157+
158+
-x, --xslt XSLT file path to transform XML output.
159+
160+
-v, --verbose Set output to verbose messages.
161+
162+
--help Display this help screen.
163+
164+
--version Display version information.
165+
```
166+
167+
**Example:**
168+
169+
``` dos
170+
SQLWrapper wrapper --database sqlwrapper-cachedb.xml --inputfiles request1.mysql request2.mysql --outputfile mysqlrequest.cs --params namespace=DAIKOZ classname=SQLWrapper --xslt Template\CSharp\charpADO.xslt
171+
```
172+
173+
This command create a **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).
174+
175+
### Helper
176+
177+
Generate a source code helper to help the access to database. For example: the length of all text columns.
178+
179+
``` dos
180+
>SQLWrapper help helper
181+
SQL Wrapper Generator
182+
Copyright (C) DAIKOZ. All rights reserved.
183+
USAGE:
184+
Generate code helper to access database:
185+
SQLWrapper helper --database sqlwrapper-cachedb.xml --outputfile helper.cs --xslt Template\CSharp\helper.xslt
186+
187+
-d, --database Required. XML file of cache database structure to load. Generate it before with database command
188+
189+
-o, --outputfile Output file
190+
191+
-p, --params XLST Parameters
192+
193+
-t, --customtypes Force custom type for database field (table.col=MyEmu
194+
195+
-x, --xslt XSLT file path to transform XML output.
196+
197+
-v, --verbose Set output to verbose messages.
198+
199+
--help Display this help screen.
200+
201+
--version Display version information.
202+
```
203+
204+
**Example:**
205+
206+
``` dos
207+
SQLWrapper helper --database sqlwrapper-cachedb.xml --outputfile helper.cs --xslt Template\CSharp\helper.xslt
208+
```
209+
210+
This command create a **helper** for **database**. It use **XLST** file to generate the **outputfile**.
211+
212+
213+
## Template XLST
214+
215+
In template section, you can found several XLST files to generate wrappers and helpers in several programming language.
216+
You can create or modify your own and use it with **--xslt** parameter.
217+
218+
512 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)