diff --git a/LICENSE b/LICENSE
index 4fbb3ce..211f558 100644
--- a/LICENSE
+++ b/LICENSE
@@ -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
diff --git a/Lib/Dumper.cs b/Lib/Dumper.cs
index 26c7377..9c29064 100644
--- a/Lib/Dumper.cs
+++ b/Lib/Dumper.cs
@@ -1,6 +1,6 @@
//
// 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
//
diff --git a/Lib/DumperEventArgs.cs b/Lib/DumperEventArgs.cs
deleted file mode 100644
index e3c3cb7..0000000
--- a/Lib/DumperEventArgs.cs
+++ /dev/null
@@ -1,22 +0,0 @@
-//
-// SqlDump - Simple SQL Server database dumper
-// (c) 2023 Artem Avramenko. https://github.com/ArtemAvramenko/SqlDump
-// License: MIT
-//
-
-using System;
-
-namespace SqlDumper
-{
- public sealed class DumperEventArgs : EventArgs
- {
- private readonly string _text;
-
- public DumperEventArgs(string text)
- {
- _text = text;
- }
-
- public string Text => _text;
- }
-}
diff --git a/Lib/Formatters.cs b/Lib/Formatters.cs
index 900f882..fb00d40 100644
--- a/Lib/Formatters.cs
+++ b/Lib/Formatters.cs
@@ -1,6 +1,6 @@
//
// 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
//
@@ -27,25 +27,26 @@ private static class Formatters
{
private static readonly Dictionary> _sqlTypeFormatters =
new Dictionary>()
- {
- { "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> _clrTypeFormatters =
new Dictionary>()
{
- (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" };
@@ -74,14 +75,7 @@ public static Func 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 () =>
{
@@ -94,6 +88,19 @@ public static Func 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,
diff --git a/README.md b/README.md
index 61c2d52..6693e68 100644
--- a/README.md
+++ b/README.md
@@ -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)
{
@@ -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) =>
{
diff --git a/SqlDump.csproj b/SqlDump.csproj
index 714251a..149b430 100644
--- a/SqlDump.csproj
+++ b/SqlDump.csproj
@@ -8,6 +8,6 @@
7
-
+
\ No newline at end of file
diff --git a/SqlDump.nuspec b/SqlDump.nuspec
index dd51fca..5d423b2 100644
--- a/SqlDump.nuspec
+++ b/SqlDump.nuspec
@@ -1,28 +1,27 @@
-
- SqlDump.Sources
- SqlDump (Source-Only)
- 1.4.0
- Artem Avramenko
- ArtemA
- https://github.com/ArtemAvramenko/SqlDump
- MIT
- https://github.com/ArtemAvramenko/SqlDump/raw/master/SqlDump.png
- false
- https://github.com/ArtemAvramenko/SqlDump
- git
-
- Simple SQL Server database dumper.
-
-
- Simple SQL Server database dumper. Shipped as source-only NuGet package.
-
- Copyright (c) 2023 Artem Avramenko
- ms sql dump dumper backup script generator
-
-
-
-
-
+
+ SqlDump.Sources
+ SqlDump (Source-Only)
+ 1.5.0
+ Artem Avramenko
+ ArtemA
+ https://github.com/ArtemAvramenko/SqlDump
+ MIT
+ https://github.com/ArtemAvramenko/SqlDump/raw/master/SqlDump.png
+ false
+
+
+ Simple SQL Server database dumper.
+
+
+ Simple SQL Server database dumper. Shipped as source-only NuGet package.
+
+ Copyright (c) 2025 Artem Avramenko
+ ms sql dump dumper backup script generator
+
+
+
+
+