Skip to content

Commit

Permalink
v1.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemAvramenko committed Jan 3, 2025
1 parent b54be27 commit 288c637
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 77 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2024 Artem Avramenko
Copyright (c) 2025 Artem Avramenko

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Lib/Dumper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// <copyright file="Dumper.cs">
// SqlDump - Simple SQL Server database dumper
// (c) 2023 Artem Avramenko. https://github.com/ArtemAvramenko/SqlDump
// (c) 2025 Artem Avramenko. https://github.com/ArtemAvramenko/SqlDump
// License: MIT
// </copyright>

Expand Down
22 changes: 0 additions & 22 deletions Lib/DumperEventArgs.cs

This file was deleted.

53 changes: 30 additions & 23 deletions Lib/Formatters.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// <copyright file="Formatters.cs">
// SqlDump - Simple SQL Server database dumper
// (c) 2023 Artem Avramenko. https://github.com/ArtemAvramenko/SqlDump
// (c) 2025 Artem Avramenko. https://github.com/ArtemAvramenko/SqlDump
// License: MIT
// </copyright>

Expand All @@ -27,25 +27,26 @@ private static class Formatters
{
private static readonly Dictionary<string, Func<object, string>> _sqlTypeFormatters =
new Dictionary<string, Func<object, string>>()
{
{ "date", x => string.Format("'{0:yyyy-MM-dd}'", x) },
{ "datetime", x => FormatDateTime(((SqlDateTime)x).Value, precision:"fff")},
{ "decimal", x => x.ToString() },
{ "xml", x => FormatString(((SqlXml)x).Value)}
{
{ "date", x => string.Format("'{0:yyyy-MM-dd}'", x) },
{ "datetime", x => FormatDateTime(((SqlDateTime)x).Value, precision:"fff")},
{ "decimal", x => x.ToString() },
{ "xml", x => FormatString(((SqlXml)x).Value)}
};

private static readonly Dictionary<Type, Func<object, string>> _clrTypeFormatters =
new Dictionary<Type, Func<object, string>>()
{
(string x) => FormatString(x),
(DateTime x) => FormatDateTime(x),
(DateTimeOffset x) =>
$"'{FormatDateTime(x.DateTime, quote:false)}" +
$"{x.ToString("zzz", CultureInfo.InvariantCulture)}'",
(TimeSpan x) => FormatDateTime(new DateTime(x.Ticks), date: false),
(bool x) => x ? "1" : "0",
(byte[] x) => "0x" + BitConverter.ToString(x).Replace("-",""),
(Guid x) => $"'{x}'"
(string x) => FormatString(x),
(DateTime x) => FormatDateTime(x),
(DateTimeOffset x) =>
$"'{FormatDateTime(x.DateTime, quote:false)}" +
$"{x.ToString("zzz", CultureInfo.InvariantCulture)}'",
(TimeSpan x) => FormatDateTime(new DateTime(x.Ticks), date: false),
(bool x) => x ? "1" : "0",
(byte[] x) => "0x" + BitConverter.ToString(x).Replace("-",""),
(Guid x) => $"'{x}'",
(object x) => FormatVariant(x)
};

private static readonly string[] _ignoredSqlTypes = new[] { "timestamp" };
Expand Down Expand Up @@ -74,14 +75,7 @@ public static Func<string> GetFormatter(DbDataReader reader, int ordinal)
}
if (!_clrTypeFormatters.TryGetValue(reader.GetFieldType(ordinal), out var clrFormatter))
{
clrFormatter = value =>
{
if (value is IFormattable formattable)
{
return formattable.ToString(null, CultureInfo.InvariantCulture);
}
return value.ToString();
};
clrFormatter = FormatVariant;
}
return () =>
{
Expand All @@ -94,6 +88,19 @@ public static Func<string> GetFormatter(DbDataReader reader, int ordinal)
};
}

private static string FormatVariant(object value)
{
//TODO: add cast
if (_clrTypeFormatters.TryGetValue(value.GetType(), out var valueFormatter))
{
return valueFormatter(value);
}
if (value is IFormattable formattable)
{
return formattable.ToString(null, CultureInfo.InvariantCulture);
}
return FormatString(value.ToString());
}

private static string FormatDateTime(
DateTime x,
Expand Down
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# SqlDump
Simple SQL Server database dumper. Shipped as source-only [NuGet package](https://www.nuget.org/packages/SqlDump.Sources).

# Installing
## Installing
* Package Manager: `Install-Package SqlDump.Sources`
* .NET command line: `dotnet add package SqlDump.Sources`

# Example
## Example
``` csharp
private void GenerateBackupScript(string connectionString, string outputFile)
{
Expand All @@ -19,10 +19,13 @@ private void GenerateBackupScript(string connectionString, string outputFile)
```
See [result](https://raw.githubusercontent.com/ArtemAvramenko/SqlDump/master/Tests/Data.sql)

# Lecacy System.Data.SqlClient
## Support for sql_variant type
Support for the sql_variant type is still very limited and requires setting the RowsInStatement to 1.

## Lecacy System.Data.SqlClient
Add SQL_CLIENT_LEGACY to project defines.

# ProgressChanged event
## ProgressChanged Event
``` csharp
dumper.ProgressChanged += (sender, e) =>
{
Expand Down
2 changes: 1 addition & 1 deletion SqlDump.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<LangVersion>7</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.3" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.2.2" />
</ItemGroup>
</Project>
49 changes: 24 additions & 25 deletions SqlDump.nuspec
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>SqlDump.Sources</id>
<title>SqlDump (Source-Only)</title>
<version>1.4.0</version>
<authors>Artem Avramenko</authors>
<owners>ArtemA</owners>
<projectUrl>https://github.com/ArtemAvramenko/SqlDump</projectUrl>
<license type="expression">MIT</license>
<iconUrl>https://github.com/ArtemAvramenko/SqlDump/raw/master/SqlDump.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<repositoryUrl>https://github.com/ArtemAvramenko/SqlDump</repositoryUrl>
<repositoryType>git</repositoryType>
<summary>
Simple SQL Server database dumper.
</summary>
<description>
Simple SQL Server database dumper. Shipped as source-only NuGet package.
</description>
<copyright>Copyright (c) 2023 Artem Avramenko</copyright>
<tags>ms sql dump dumper backup script generator</tags>
</metadata>
<files>
<file src="Lib\*.cs" target="contentFiles/cs/any/SqlDump.Sources" />
<file src="Lib\*.cs" target="content/App_Packages/SqlDump.Sources" />
</files>
<metadata>
<id>SqlDump.Sources</id>
<title>SqlDump (Source-Only)</title>
<version>1.5.0</version>
<authors>Artem Avramenko</authors>
<owners>ArtemA</owners>
<projectUrl>https://github.com/ArtemAvramenko/SqlDump</projectUrl>
<license type="expression">MIT</license>
<iconUrl>https://github.com/ArtemAvramenko/SqlDump/raw/master/SqlDump.png</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<repository type="git" url="https://github.com/ArtemAvramenko/SqlDump"/>
<summary>
Simple SQL Server database dumper.
</summary>
<description>
Simple SQL Server database dumper. Shipped as source-only NuGet package.
</description>
<copyright>Copyright (c) 2025 Artem Avramenko</copyright>
<tags>ms sql dump dumper backup script generator</tags>
</metadata>
<files>
<file src="Lib\*.cs" target="contentFiles/cs/any/SqlDump.Sources" />
<file src="Lib\*.cs" target="content/App_Packages/SqlDump.Sources" />
</files>
</package>

0 comments on commit 288c637

Please sign in to comment.