-
Notifications
You must be signed in to change notification settings - Fork 935
NH-1752 - NHibernate Date type converts to NULL #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fredericDelaporte
merged 4 commits into
nhibernate:master
from
fredericDelaporte:NH-1752
Sep 26, 2017
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
09f8724
Purging examples configuration.
fredericDelaporte 6166cb5
Switch from old SqlClientDriver to Sql2008ClientDriver
fredericDelaporte c16868d
NH-1752 - Cease silently nullifying dates before 1753
fredericDelaporte d533eb0
NH-2207 - Enable tests for Sql2008ClientDriver
hazzik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -773,4 +773,4 @@ public void Dispose() | |
} | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/NHibernate.Test/Async/NHSpecificTest/NH2207/SampleTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System; | ||
using System.Data; | ||
using NHibernate.Dialect; | ||
using NHibernate.Driver; | ||
using NHibernate.Engine; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.NHSpecificTest.NH2207 | ||
{ | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
[TestFixture] | ||
public class SampleTestAsync : BugTestCase | ||
{ | ||
protected override bool AppliesTo(Dialect.Dialect dialect) | ||
{ | ||
return dialect is MsSql2008Dialect; | ||
} | ||
|
||
protected override bool AppliesTo(ISessionFactoryImplementor factory) | ||
{ | ||
return factory.ConnectionProvider.Driver is Sql2008ClientDriver; | ||
} | ||
|
||
[Test] | ||
public async Task WithoutUseNHSqlDataProviderWorkProperlyAsync() | ||
{ | ||
var createTable = "CREATE TABLE TryDate([Id] [int] IDENTITY(1,1) NOT NULL,[MyDate] [date] NOT NULL)"; | ||
var dropTable = "DROP TABLE TryDate"; | ||
var insertTable = "INSERT INTO TryDate([MyDate]) VALUES(@p0)"; | ||
using(var sqlConnection = new System.Data.SqlClient.SqlConnection(cfg.Properties[Cfg.Environment.ConnectionString])) | ||
{ | ||
await (sqlConnection.OpenAsync(CancellationToken.None)); | ||
using (var tx = sqlConnection.BeginTransaction()) | ||
{ | ||
var command = sqlConnection.CreateCommand(); | ||
command.Transaction = tx; | ||
command.CommandText = createTable; | ||
await (command.ExecuteNonQueryAsync(CancellationToken.None)); | ||
tx.Commit(); | ||
} | ||
|
||
try | ||
{ | ||
using (var tx = sqlConnection.BeginTransaction()) | ||
{ | ||
var command = sqlConnection.CreateCommand(); | ||
command.Transaction = tx; | ||
command.CommandText = insertTable; | ||
var dateParam = command.CreateParameter(); | ||
dateParam.ParameterName = "@p0"; | ||
dateParam.DbType = DbType.Date; | ||
dateParam.SqlDbType = SqlDbType.Date; | ||
dateParam.Value = DateTime.MinValue.Date; | ||
command.Parameters.Add(dateParam); | ||
await (command.ExecuteNonQueryAsync(CancellationToken.None)); | ||
tx.Commit(); | ||
} | ||
} | ||
finally | ||
{ | ||
using (var tx = sqlConnection.BeginTransaction()) | ||
{ | ||
var command = sqlConnection.CreateCommand(); | ||
command.Transaction = tx; | ||
command.CommandText = dropTable; | ||
await (command.ExecuteNonQueryAsync(CancellationToken.None)); | ||
tx.Commit(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
[Test] | ||
public async Task Dates_Before_1753_Should_Not_Insert_NullAsync() | ||
{ | ||
object savedId; | ||
var expectedStoredValue = DateTime.MinValue.Date.AddDays(1).Date; | ||
using (ISession session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
var concrete = new DomainClass{Date = expectedStoredValue.AddMinutes(90)}; | ||
savedId = await (session.SaveAsync(concrete)); | ||
await (tx.CommitAsync()); | ||
} | ||
|
||
using (ISession session = OpenSession()) | ||
using (var tx = session.BeginTransaction()) | ||
{ | ||
var savedObj = await (session.GetAsync<DomainClass>(savedId)); | ||
Assert.That(savedObj.Date, Is.EqualTo(expectedStoredValue)); | ||
await (session.DeleteAsync(savedObj)); | ||
await (tx.CommitAsync()); | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
//------------------------------------------------------------------------------ | ||
// <auto-generated> | ||
// This code was generated by AsyncGenerator. | ||
// | ||
// Changes to this file may cause incorrect behavior and will be lost if | ||
// the code is regenerated. | ||
// </auto-generated> | ||
//------------------------------------------------------------------------------ | ||
|
||
|
||
using System.Collections.Generic; | ||
using NHibernate.Dialect; | ||
using NHibernate.Type; | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace NHibernate.Test.TypesTest | ||
{ | ||
using System.Threading.Tasks; | ||
using System.Threading; | ||
|
||
[TestFixture] | ||
public class DateTypeFixtureAsync : TypeFixtureBase | ||
{ | ||
protected override string TypeName | ||
{ | ||
get { return "Date"; } | ||
} | ||
|
||
[Test] | ||
public Task ReadWriteNormalAsync() | ||
{ | ||
try | ||
{ | ||
var expected = DateTime.Today; | ||
|
||
return ReadWriteAsync(expected); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Task.FromException<object>(ex); | ||
} | ||
} | ||
|
||
[Test] | ||
public Task ReadWriteMinAsync() | ||
{ | ||
try | ||
{ | ||
var expected = Sfi.ConnectionProvider.Driver.MinDate; | ||
|
||
return ReadWriteAsync(expected); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Task.FromException<object>(ex); | ||
} | ||
} | ||
|
||
[Test] | ||
public Task ReadWriteYear750Async() | ||
{ | ||
try | ||
{ | ||
var expected = new DateTime(750, 5, 13); | ||
if (Sfi.ConnectionProvider.Driver.MinDate > expected) | ||
{ | ||
Assert.Ignore($"The driver does not support dates below {Sfi.ConnectionProvider.Driver.MinDate:O}"); | ||
} | ||
return ReadWriteAsync(expected); | ||
} | ||
catch (Exception ex) | ||
{ | ||
return Task.FromException<object>(ex); | ||
} | ||
} | ||
|
||
private async Task ReadWriteAsync(DateTime expected, CancellationToken cancellationToken = default(CancellationToken)) | ||
{ | ||
// Add an hour to check it is correctly ignored once read back from db. | ||
var basic = new DateClass { DateValue = expected.AddHours(1) }; | ||
object savedId; | ||
using (var s = OpenSession()) | ||
{ | ||
savedId = await (s.SaveAsync(basic, cancellationToken)); | ||
await (s.FlushAsync(cancellationToken)); | ||
} | ||
using (var s = OpenSession()) | ||
{ | ||
basic = await (s.GetAsync<DateClass>(savedId, cancellationToken)); | ||
Assert.That(basic.DateValue, Is.EqualTo(expected)); | ||
await (s.DeleteAsync(basic, cancellationToken)); | ||
await (s.FlushAsync(cancellationToken)); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our doc examples incite users to use an obsolete driver for SqlServer: I have purged unneeded parameters.