Skip to content

Commit 2fa35fc

Browse files
Merge pull request #698 from fredericDelaporte/NH-1752
NH-1752 - NHibernate Date type converts to NULL
2 parents 60839bd + d533eb0 commit 2fa35fc

File tree

36 files changed

+358
-101
lines changed

36 files changed

+358
-101
lines changed

build-common/nhibernate-properties.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<project xmlns="http://nant.sf.net/release/0.85-rc3/nant.xsd">
33
<property name="nhibernate.dialect" value="NHibernate.Dialect.MsSql2008Dialect" overwrite="false"/>
44
<property name="nhibernate.command_timeout" value="444" overwrite="false"/>
5-
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" overwrite="false"/>
5+
<property name="nhibernate.connection.driver_class" value="NHibernate.Driver.Sql2008ClientDriver" overwrite="false"/>
66
<property name="nhibernate.connection.connection_string" value="Server=.\SQLExpress;initial catalog=nhibernate;Integrated Security=SSPI" overwrite="false"/>
77
</project>

build-common/teamcity-hibernate.cfg.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<property name="format_sql">true</property>
1616

1717
<!-- This is the System.Data.dll provider for MSSQL Server -->
18-
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
18+
<property name="connection.driver_class">NHibernate.Driver.Sql2008ClientDriver</property>
1919
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
2020
<property name="connection.connection_string">Server=.\SQLExpress;initial catalog=nhibernate;Integrated Security=SSPI</property>
2121
<property name="show_sql">false</property>

doc/reference/modules/configuration.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,12 +1002,6 @@ ISession session = sessions.OpenSession(conn);
10021002
<session-factory>
10031003
10041004
<!-- properties -->
1005-
<property name="connection.provider">
1006-
NHibernate.Connection.DriverConnectionProvider
1007-
</property>
1008-
<property name="connection.driver_class">
1009-
NHibernate.Driver.SqlClientDriver
1010-
</property>
10111005
<property name="connection.connection_string">
10121006
Server=localhost;initial catalog=nhibernate;User Id=;Password=
10131007
</property>

doc/reference/modules/example_weblog.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,6 @@ namespace Eg
333333
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
334334
<session-factory>
335335
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
336-
<property name="connection.provider">
337-
NHibernate.Connection.DriverConnectionProvider
338-
</property>
339336
<property name="connection.connection_string">
340337
Server=localhost\SQLEXPRESS;initial catalog=Eg;Integrated Security=True
341338
</property>

doc/reference/modules/quickstart.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
5353
<session-factory>
5454
<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>
55-
<property name="connection.provider">
56-
NHibernate.Connection.DriverConnectionProvider
57-
</property>
5855
<property name="connection.connection_string">
5956
Server=localhost\SQLEXPRESS;initial catalog=quickstart;Integrated Security=True
6057
</property>

src/NHibernate.Config.Templates/MSSQL.cfg.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ for your own use before compile tests in VisualStudio.
77
<!-- This is the System.Data.dll provider for SQL Server -->
88
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
99
<session-factory name="NHibernate.Test">
10-
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
10+
<property name="connection.driver_class">NHibernate.Driver.Sql2008ClientDriver</property>
1111
<property name="connection.connection_string">
1212
Server=(local);initial catalog=nhibernate;Integrated Security=SSPI
1313
</property>
1414
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
1515
</session-factory>
16-
</hibernate-configuration>
16+
</hibernate-configuration>

src/NHibernate.Example.Web/Infrastructure/AppSessionFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public AppSessionFactory(Microsoft.Extensions.Logging.ILoggerFactory loggerFacto
2424
{
2525
db.ConnectionString = @"Server=(local)\SQLEXPRESS;initial catalog=nhibernate;Integrated Security=true";
2626
db.Dialect<MsSql2008Dialect>();
27-
db.Driver<SqlClientDriver>();
27+
db.Driver<Sql2008ClientDriver>();
2828
})
2929
.AddMapping(domainMapping);
3030
Configuration.SessionFactory().GenerateStatistics();
@@ -37,4 +37,4 @@ public ISession OpenSession()
3737
return SessionFactory.OpenSession();
3838
}
3939
}
40-
}
40+
}

src/NHibernate.Test/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
3232

33-
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <!-- Shouldn't be necessary, but is required by some tests -->
33+
<property name="connection.driver_class">NHibernate.Driver.Sql2008ClientDriver</property> <!-- Shouldn't be necessary, but is required by some tests -->
3434
<property name="connection.connection_string_name">TestConnectionString</property>
3535
<property name="connection.provider">NHibernate.Test.DebugConnectionProvider, NHibernate.Test</property>
3636
<property name="connection.isolation">ReadCommitted</property> <!-- See System.Data.IsolationLevel for valid values -->

src/NHibernate.Test/Async/FilterTest/DynamicFilterTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,4 +773,4 @@ public void Dispose()
773773
}
774774
}
775775
}
776-
}
776+
}

src/NHibernate.Test/Async/Hql/Ast/LimitClauseFixture.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
using System.Linq;
1212
using NHibernate.Cfg;
13+
using NHibernate.Driver;
1314
using NHibernate.Hql.Ast.ANTLR;
15+
using NHibernate.Util;
1416
using NUnit.Framework;
1517

1618
namespace NHibernate.Test.Hql.Ast
@@ -22,7 +24,8 @@ public class LimitClauseFixtureAsync : BaseFixture
2224
protected override bool AppliesTo(Dialect.Dialect dialect)
2325
{
2426
return dialect.SupportsVariableLimit
25-
&& !(Dialect is Dialect.MsSql2000Dialect && cfg.Properties[Environment.ConnectionDriver] == typeof(Driver.OdbcDriver).FullName); // don't know why, but these tests don't work on SQL Server using ODBC
27+
&& !(Dialect is Dialect.MsSql2000Dialect && // don't know why, but these tests don't work on SQL Server using ODBC
28+
typeof(OdbcDriver).IsAssignableFrom(ReflectHelper.ClassForName(cfg.GetProperty(Environment.ConnectionDriver))));
2629
}
2730

2831
protected override void OnSetUp()
@@ -186,4 +189,4 @@ public async Task TakeWithParameterAsync()
186189
s.Close();
187190
}
188191
}
189-
}
192+
}

src/NHibernate.Test/Async/NHSpecificTest/NH1144/Fixture.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using NHibernate.AdoNet;
1313
using NHibernate.Cfg;
1414
using NHibernate.Driver;
15+
using NHibernate.Util;
1516
using NUnit.Framework;
1617

1718
namespace NHibernate.Test.NHSpecificTest.NH1144
@@ -36,7 +37,7 @@ protected override void Configure(Configuration configuration)
3637
[Test]
3738
public async Task CanSaveInSingleBatchAsync()
3839
{
39-
if (configuration.Properties[Environment.ConnectionDriver].Contains(typeof (OracleDataClientDriver).Name) == false)
40+
if (!typeof(OracleDataClientDriver).IsAssignableFrom(ReflectHelper.ClassForName(cfg.GetProperty(Environment.ConnectionDriver))))
4041
{
4142
Assert.Ignore("Only applicable for Oracle Data Client driver");
4243
}
@@ -85,4 +86,4 @@ public async Task CanSaveInSingleBatchAsync()
8586
Assert.IsTrue(executedBatch);
8687
}
8788
}
88-
}
89+
}
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System;
12+
using System.Data;
13+
using NHibernate.Dialect;
14+
using NHibernate.Driver;
15+
using NHibernate.Engine;
16+
using NUnit.Framework;
17+
18+
namespace NHibernate.Test.NHSpecificTest.NH2207
19+
{
20+
using System.Threading.Tasks;
21+
using System.Threading;
22+
[TestFixture]
23+
public class SampleTestAsync : BugTestCase
24+
{
25+
protected override bool AppliesTo(Dialect.Dialect dialect)
26+
{
27+
return dialect is MsSql2008Dialect;
28+
}
29+
30+
protected override bool AppliesTo(ISessionFactoryImplementor factory)
31+
{
32+
return factory.ConnectionProvider.Driver is Sql2008ClientDriver;
33+
}
34+
35+
[Test]
36+
public async Task WithoutUseNHSqlDataProviderWorkProperlyAsync()
37+
{
38+
var createTable = "CREATE TABLE TryDate([Id] [int] IDENTITY(1,1) NOT NULL,[MyDate] [date] NOT NULL)";
39+
var dropTable = "DROP TABLE TryDate";
40+
var insertTable = "INSERT INTO TryDate([MyDate]) VALUES(@p0)";
41+
using(var sqlConnection = new System.Data.SqlClient.SqlConnection(cfg.Properties[Cfg.Environment.ConnectionString]))
42+
{
43+
await (sqlConnection.OpenAsync(CancellationToken.None));
44+
using (var tx = sqlConnection.BeginTransaction())
45+
{
46+
var command = sqlConnection.CreateCommand();
47+
command.Transaction = tx;
48+
command.CommandText = createTable;
49+
await (command.ExecuteNonQueryAsync(CancellationToken.None));
50+
tx.Commit();
51+
}
52+
53+
try
54+
{
55+
using (var tx = sqlConnection.BeginTransaction())
56+
{
57+
var command = sqlConnection.CreateCommand();
58+
command.Transaction = tx;
59+
command.CommandText = insertTable;
60+
var dateParam = command.CreateParameter();
61+
dateParam.ParameterName = "@p0";
62+
dateParam.DbType = DbType.Date;
63+
dateParam.SqlDbType = SqlDbType.Date;
64+
dateParam.Value = DateTime.MinValue.Date;
65+
command.Parameters.Add(dateParam);
66+
await (command.ExecuteNonQueryAsync(CancellationToken.None));
67+
tx.Commit();
68+
}
69+
}
70+
finally
71+
{
72+
using (var tx = sqlConnection.BeginTransaction())
73+
{
74+
var command = sqlConnection.CreateCommand();
75+
command.Transaction = tx;
76+
command.CommandText = dropTable;
77+
await (command.ExecuteNonQueryAsync(CancellationToken.None));
78+
tx.Commit();
79+
}
80+
}
81+
}
82+
}
83+
84+
[Test]
85+
public async Task Dates_Before_1753_Should_Not_Insert_NullAsync()
86+
{
87+
object savedId;
88+
var expectedStoredValue = DateTime.MinValue.Date.AddDays(1).Date;
89+
using (ISession session = OpenSession())
90+
using (var tx = session.BeginTransaction())
91+
{
92+
var concrete = new DomainClass{Date = expectedStoredValue.AddMinutes(90)};
93+
savedId = await (session.SaveAsync(concrete));
94+
await (tx.CommitAsync());
95+
}
96+
97+
using (ISession session = OpenSession())
98+
using (var tx = session.BeginTransaction())
99+
{
100+
var savedObj = await (session.GetAsync<DomainClass>(savedId));
101+
Assert.That(savedObj.Date, Is.EqualTo(expectedStoredValue));
102+
await (session.DeleteAsync(savedObj));
103+
await (tx.CommitAsync());
104+
}
105+
}
106+
}
107+
}

src/NHibernate.Test/Async/NHSpecificTest/NH3202/Fixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using NHibernate.Cfg;
1414
using NHibernate.Dialect;
1515
using NHibernate.Driver;
16+
using NHibernate.Util;
1617
using NUnit.Framework;
1718

1819
namespace NHibernate.Test.NHSpecificTest.NH3202
@@ -26,7 +27,7 @@ protected override void Configure(Configuration configuration)
2627
if (!(Dialect is MsSql2008Dialect))
2728
Assert.Ignore("Test is for MS SQL Server dialect only (custom dialect).");
2829

29-
if (!Environment.ConnectionDriver.Contains("SqlClientDriver"))
30+
if (!typeof(SqlClientDriver).IsAssignableFrom(ReflectHelper.ClassForName(cfg.GetProperty(Environment.ConnectionDriver))))
3031
Assert.Ignore("Test is for MS SQL Server driver only (custom driver is used).");
3132

3233
cfg.SetProperty(Environment.Dialect, typeof(OffsetStartsAtOneTestDialect).AssemblyQualifiedName);
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by AsyncGenerator.
4+
//
5+
// Changes to this file may cause incorrect behavior and will be lost if
6+
// the code is regenerated.
7+
// </auto-generated>
8+
//------------------------------------------------------------------------------
9+
10+
11+
using System.Collections.Generic;
12+
using NHibernate.Dialect;
13+
using NHibernate.Type;
14+
using NUnit.Framework;
15+
using System;
16+
17+
namespace NHibernate.Test.TypesTest
18+
{
19+
using System.Threading.Tasks;
20+
using System.Threading;
21+
22+
[TestFixture]
23+
public class DateTypeFixtureAsync : TypeFixtureBase
24+
{
25+
protected override string TypeName
26+
{
27+
get { return "Date"; }
28+
}
29+
30+
[Test]
31+
public Task ReadWriteNormalAsync()
32+
{
33+
try
34+
{
35+
var expected = DateTime.Today;
36+
37+
return ReadWriteAsync(expected);
38+
}
39+
catch (Exception ex)
40+
{
41+
return Task.FromException<object>(ex);
42+
}
43+
}
44+
45+
[Test]
46+
public Task ReadWriteMinAsync()
47+
{
48+
try
49+
{
50+
var expected = Sfi.ConnectionProvider.Driver.MinDate;
51+
52+
return ReadWriteAsync(expected);
53+
}
54+
catch (Exception ex)
55+
{
56+
return Task.FromException<object>(ex);
57+
}
58+
}
59+
60+
[Test]
61+
public Task ReadWriteYear750Async()
62+
{
63+
try
64+
{
65+
var expected = new DateTime(750, 5, 13);
66+
if (Sfi.ConnectionProvider.Driver.MinDate > expected)
67+
{
68+
Assert.Ignore($"The driver does not support dates below {Sfi.ConnectionProvider.Driver.MinDate:O}");
69+
}
70+
return ReadWriteAsync(expected);
71+
}
72+
catch (Exception ex)
73+
{
74+
return Task.FromException<object>(ex);
75+
}
76+
}
77+
78+
private async Task ReadWriteAsync(DateTime expected, CancellationToken cancellationToken = default(CancellationToken))
79+
{
80+
// Add an hour to check it is correctly ignored once read back from db.
81+
var basic = new DateClass { DateValue = expected.AddHours(1) };
82+
object savedId;
83+
using (var s = OpenSession())
84+
{
85+
savedId = await (s.SaveAsync(basic, cancellationToken));
86+
await (s.FlushAsync(cancellationToken));
87+
}
88+
using (var s = OpenSession())
89+
{
90+
basic = await (s.GetAsync<DateClass>(savedId, cancellationToken));
91+
Assert.That(basic.DateValue, Is.EqualTo(expected));
92+
await (s.DeleteAsync(basic, cancellationToken));
93+
await (s.FlushAsync(cancellationToken));
94+
}
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)