Skip to content

Commit

Permalink
Merge pull request #28 from JordiCorbilla/feature-1
Browse files Browse the repository at this point in the history
#27 fix null issue
  • Loading branch information
JordiCorbilla authored Oct 18, 2022
2 parents 788d11f + d669f12 commit a4c36ae
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
11 changes: 11 additions & 0 deletions table.lib.tests/SqlInsertTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,16 @@ public void TestGeneration()
Assert.That(lines[3], Is.EqualTo("INSERT INTO TestClass (Field1,Field2,Field3,Field4,Field5,Field6) VALUES (13,'Hi very long text',21111121.32,1,'1970-01-01',34.43);"));
});
}

[Test]
public void TestNullGeneration()
{
var s = Table<TestClass>.Add(Samples.GetNullOutput()).ToSqlInsertString();
var lines = s.Split(Environment.NewLine);
Assert.Multiple(() =>
{
Assert.That(lines[0], Is.EqualTo("INSERT INTO TestClass (Field1,Field2,Field3,Field4,Field5,Field6) VALUES (321121,NULL,2121.32,1,'1970-01-01',34.43);"));
});
}
}
}
2 changes: 1 addition & 1 deletion table.lib/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ public string ToSqlInsertString()
DateTime time => "'" + time.ToString("yyyy-MM-dd") + "'",
decimal value1 => value1.ToString("#0.0###"),
double value1 => value1.ToString("#0.0###"),
_ => (obj != null ? obj.ToString().ToSql() : "")
_ => (obj != null ? obj.ToString().ToSql() : "NULL")
};
s += $"{p},";
}
Expand Down
8 changes: 4 additions & 4 deletions table.lib/table.lib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>table.lib</RootNamespace>
<Version>1.11.0</Version>
<Version>1.12.0</Version>
<Copyright>Jordi Corbilla</Copyright>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryUrl>https://github.com/JordiCorbilla/table.lib</RepositoryUrl>
<PackageReleaseNotes>v1.10
<PackageReleaseNotes>v1.12
- Upgrade to .net 6</PackageReleaseNotes>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Description>Simple c# (.NET 6) table library that renders any List&lt;T&gt; or Dictionary&lt;TV, T&gt; into a nicely formatted markdown, csv, html, specflow or console table, allowing for extra formats. It also supports dynamic returns from Dapper as IEnumerable&lt;IDictionary&lt;string, object&gt;&gt; via DBTable object.</Description>
<AssemblyVersion>1.11.0.0</AssemblyVersion>
<FileVersion>1.11.0.0</FileVersion>
<AssemblyVersion>1.12.0.0</AssemblyVersion>
<FileVersion>1.12.0.0</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
18 changes: 18 additions & 0 deletions table.runner/Samples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ public static List<TestClass> GetSampleOutput()
{
Field1 = 13, Field2 = "Hi \"very\" long\n text", Field3 = 21111121.32m, Field4 = true,
Field5 = new DateTime(1970, 1, 1), Field6 = 34.4300001
},
new TestClass
{
Field1 = 13, Field2 = null, Field3 = 21111121.32m, Field4 = true,
Field5 = new DateTime(1970, 1, 1), Field6 = 34.4300001
}
};
return list;
}

public static List<TestClass> GetNullOutput()
{
var list = new List<TestClass>
{
new TestClass
{
Field1 = 321121, Field2 = null, Field3 = 2121.32m, Field4 = true,
Field5 = new DateTime(1970, 1, 1), Field6 = 34.43
}
};
return list;
Expand Down

0 comments on commit a4c36ae

Please sign in to comment.