Skip to content

Commit 7602f5f

Browse files
committed
Fix DateTime.Kind and update NullableExpressionDetector to support static properties
1 parent 4c3fe84 commit 7602f5f

24 files changed

+86
-39
lines changed

src/NHibernate.Test/Linq/PreEvaluationTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,21 @@ protected override void Configure(Configuration configuration)
3131
configuration.SetProperty(Environment.LinqToHqlFallbackOnPreEvaluation, FallbackOnPreEvaluation.ToString());
3232
}
3333

34+
[Test]
35+
public void CanQueryByDateTimeNowUsingNotEqual()
36+
{
37+
var isSupported = IsFunctionSupported("current_timestamp");
38+
RunTest(
39+
isSupported,
40+
spy =>
41+
{
42+
var x = db.Orders.Count(o => o.OrderDate.Value != DateTime.Now);
43+
44+
Assert.That(x, Is.GreaterThan(0));
45+
AssertFunctionInSql("current_timestamp", spy);
46+
});
47+
}
48+
3449
[Test]
3550
public void CanQueryByDateTimeNow()
3651
{
@@ -60,6 +75,7 @@ public void CanSelectDateTimeNow()
6075
.OrderBy(o => o.id).Take(1).ToList();
6176

6277
Assert.That(x, Has.Count.GreaterThan(0));
78+
Assert.That(x[0].d.Kind, Is.EqualTo(DateTimeKind.Local));
6379
AssertFunctionInSql("current_timestamp", spy);
6480
});
6581
}
@@ -93,6 +109,7 @@ public void CanSelectDateTimeUtcNow()
93109
.OrderBy(o => o.id).Take(1).ToList();
94110

95111
Assert.That(x, Has.Count.GreaterThan(0));
112+
Assert.That(x[0].d.Kind, Is.EqualTo(DateTimeKind.Utc));
96113
AssertFunctionInSql("current_utctimestamp", spy);
97114
});
98115
}
@@ -126,6 +143,7 @@ public void CanSelectDateTimeToday()
126143
.OrderBy(o => o.id).Take(1).ToList();
127144

128145
Assert.That(x, Has.Count.GreaterThan(0));
146+
Assert.That(x[0].d.Kind, Is.EqualTo(DateTimeKind.Local));
129147
AssertFunctionInSql("current_date", spy);
130148
});
131149
}
@@ -166,6 +184,7 @@ public void CanSelectDateTimeOffsetNow()
166184
.OrderBy(o => o.id).Take(1).ToList();
167185

168186
Assert.That(x, Has.Count.GreaterThan(0));
187+
Assert.That(x[0].d.Offset, Is.EqualTo(DateTimeOffset.Now.Offset));
169188
AssertFunctionInSql("current_timestamp_offset", spy);
170189
});
171190
}
@@ -206,6 +225,7 @@ public void CanSelectDateTimeOffsetUtcNow()
206225
.OrderBy(o => o.id).Take(1).ToList();
207226

208227
Assert.That(x, Has.Count.GreaterThan(0));
228+
Assert.That(x[0].d.Offset, Is.EqualTo(TimeSpan.Zero));
209229
AssertFunctionInSql("current_utctimestamp_offset", spy);
210230
});
211231
}

src/NHibernate/Dialect/DB2Dialect.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ public DB2Dialect()
8888
RegisterFunction("tan", new StandardSQLFunction("tan", NHibernateUtil.Double));
8989
RegisterFunction("variance", new StandardSQLFunction("variance", NHibernateUtil.Double));
9090

91-
RegisterFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", NHibernateUtil.DateTime, false));
92-
RegisterFunction("current_date", new NoArgSQLFunction("current_date", NHibernateUtil.Date, false));
91+
RegisterFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", NHibernateUtil.LocalDateTime, false));
92+
RegisterFunction("current_date", new NoArgSQLFunction("current_date", NHibernateUtil.LocalDate, false));
9393
RegisterFunction("julian_day", new StandardSQLFunction("julian_day", NHibernateUtil.Int32));
9494
RegisterFunction("microsecond", new StandardSQLFunction("microsecond", NHibernateUtil.Int32));
9595
RegisterFunction("midnight_seconds", new StandardSQLFunction("midnight_seconds", NHibernateUtil.Int32));
@@ -141,8 +141,6 @@ public DB2Dialect()
141141
RegisterFunction("bxor", new Function.BitwiseFunctionOperation("bitxor"));
142142
RegisterFunction("bnot", new Function.BitwiseFunctionOperation("bitnot"));
143143

144-
RegisterFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", NHibernateUtil.DateTime, false));
145-
146144
DefaultProperties[Environment.ConnectionDriver] = "NHibernate.Driver.DB2Driver";
147145
}
148146

src/NHibernate/Dialect/Dialect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected Dialect()
105105
// the syntax of current_timestamp is extracted from H3.2 tests
106106
// - test\hql\ASTParserLoadingTest.java
107107
// - test\org\hibernate\test\hql\HQLTest.java
108-
RegisterFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", NHibernateUtil.DateTime, true));
108+
RegisterFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", NHibernateUtil.LocalDateTime, true));
109109
RegisterFunction("sysdate", new NoArgSQLFunction("sysdate", NHibernateUtil.DateTime, false));
110110

111111
//map second/minute/hour/day/month/year to ANSI extract(), override on subclasses

src/NHibernate/Dialect/FirebirdDialect.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public override SqlString Render(IList args, ISessionFactoryImplementor factory)
154154
[Serializable]
155155
private class CurrentTimeStamp : NoArgSQLFunction
156156
{
157-
public CurrentTimeStamp() : base("current_timestamp", NHibernateUtil.DateTime, true)
157+
public CurrentTimeStamp() : base("current_timestamp", NHibernateUtil.LocalDateTime, true)
158158
{
159159
}
160160

@@ -413,7 +413,7 @@ protected virtual void RegisterFunctions()
413413
private void OverrideStandardHQLFunctions()
414414
{
415415
RegisterFunction("current_timestamp", new CurrentTimeStamp());
416-
RegisterFunction("current_date", new NoArgSQLFunction("current_date", NHibernateUtil.Date, false));
416+
RegisterFunction("current_date", new NoArgSQLFunction("current_date", NHibernateUtil.LocalDate, false));
417417
RegisterFunction("length", new StandardSafeSQLFunction("char_length", NHibernateUtil.Int64, 1));
418418
RegisterFunction("nullif", new StandardSafeSQLFunction("nullif", 2));
419419
RegisterFunction("lower", new StandardSafeSQLFunction("lower", NHibernateUtil.String, 1));

src/NHibernate/Dialect/HanaDialectBase.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,20 +441,20 @@ protected virtual void RegisterHANAFunctions()
441441
RegisterFunction("cosh", new StandardSQLFunction("cosh", NHibernateUtil.Double));
442442
RegisterFunction("cot", new StandardSQLFunction("cot", NHibernateUtil.Double));
443443
RegisterFunction("current_connection", new NoArgSQLFunction("current_connection", NHibernateUtil.Int32));
444-
RegisterFunction("current_date", new NoArgSQLFunction("current_date", NHibernateUtil.DateTime, false));
444+
RegisterFunction("current_date", new NoArgSQLFunction("current_date", NHibernateUtil.LocalDate, false));
445445
RegisterFunction("current_identity_value", new NoArgSQLFunction("current_identity_value", NHibernateUtil.Int64));
446446
RegisterFunction("current_mvcc_snapshot_timestamp", new NoArgSQLFunction("current_mvcc_snapshot_timestamp", NHibernateUtil.Int32));
447447
RegisterFunction("current_object_schema", new NoArgSQLFunction("current_object_schema", NHibernateUtil.String));
448448
RegisterFunction("current_schema", new NoArgSQLFunction("current_schema", NHibernateUtil.String, false));
449449
RegisterFunction("current_time", new NoArgSQLFunction("current_time", NHibernateUtil.DateTime, false));
450-
RegisterFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", NHibernateUtil.DateTime, false));
450+
RegisterFunction("current_timestamp", new NoArgSQLFunction("current_timestamp", NHibernateUtil.LocalDateTime, false));
451451
RegisterFunction("current_transaction_isolation_level", new NoArgSQLFunction("current_transaction_isolation_level", NHibernateUtil.String, false));
452452
RegisterFunction("current_update_statement_sequence", new NoArgSQLFunction("current_update_statement_sequence", NHibernateUtil.Int64));
453453
RegisterFunction("current_update_transaction", new NoArgSQLFunction("current_update_transaction", NHibernateUtil.Int64));
454454
RegisterFunction("current_user", new NoArgSQLFunction("current_user", NHibernateUtil.String, false));
455455
RegisterFunction("current_utcdate", new NoArgSQLFunction("current_utcdate", NHibernateUtil.DateTime, false));
456456
RegisterFunction("current_utctime", new NoArgSQLFunction("current_utctime", NHibernateUtil.DateTime, false));
457-
RegisterFunction("current_utctimestamp", new NoArgSQLFunction("current_utctimestamp", NHibernateUtil.DateTime, false));
457+
RegisterFunction("current_utctimestamp", new NoArgSQLFunction("current_utctimestamp", NHibernateUtil.UtcDateTime, false));
458458
RegisterFunction("dayname", new StandardSQLFunction("dayname", NHibernateUtil.String));
459459
RegisterFunction("dayofmonth", new StandardSQLFunction("dayofmonth", NHibernateUtil.Int32));
460460
RegisterFunction("dayofyear", new StandardSQLFunction("dayofyear", NHibernateUtil.Int32));

src/NHibernate/Dialect/InformixDialect.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ public InformixDialect()
7878
// RegisterFunction("cast", new CastFunction());
7979
// RegisterFunction("concat", new VarArgsSQLFunction(NHibernateUtil.String, "(", "||", ")"));
8080

81-
RegisterFunction("current_timestamp", new NoArgSQLFunction("current", NHibernateUtil.DateTime, false));
82-
RegisterFunction("current_date", new NoArgSQLFunction("today", NHibernateUtil.DateTime, false));
81+
RegisterFunction("current_timestamp", new NoArgSQLFunction("current", NHibernateUtil.LocalDateTime, false));
82+
RegisterFunction("current_date", new NoArgSQLFunction("today", NHibernateUtil.LocalDate, false));
8383
RegisterFunction("sysdate", new NoArgSQLFunction("today", NHibernateUtil.DateTime, false));
8484
RegisterFunction("current", new NoArgSQLFunction("current", NHibernateUtil.DateTime, false));
8585
RegisterFunction("today", new NoArgSQLFunction("today", NHibernateUtil.DateTime, false));

src/NHibernate/Dialect/MsSql2000Dialect.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,9 +328,9 @@ protected virtual void RegisterFunctions()
328328
RegisterFunction("right", new SQLFunctionTemplate(NHibernateUtil.String, "right(?1, ?2)"));
329329
RegisterFunction("locate", new StandardSQLFunction("charindex", NHibernateUtil.Int32));
330330

331-
RegisterFunction("current_timestamp", new NoArgSQLFunction("getdate", NHibernateUtil.DateTime, true));
332-
RegisterFunction("current_date", new SQLFunctionTemplate(NHibernateUtil.Date, "dateadd(dd, 0, datediff(dd, 0, getdate()))"));
333-
RegisterFunction("current_utctimestamp", new NoArgSQLFunction("getutcdate", NHibernateUtil.DateTime, true));
331+
RegisterFunction("current_timestamp", new NoArgSQLFunction("getdate", NHibernateUtil.LocalDateTime, true));
332+
RegisterFunction("current_date", new SQLFunctionTemplate(NHibernateUtil.LocalDate, "dateadd(dd, 0, datediff(dd, 0, getdate()))"));
333+
RegisterFunction("current_utctimestamp", new NoArgSQLFunction("getutcdate", NHibernateUtil.UtcDateTime, true));
334334
RegisterFunction("second", new SQLFunctionTemplate(NHibernateUtil.Int32, "datepart(second, ?1)"));
335335
RegisterFunction("minute", new SQLFunctionTemplate(NHibernateUtil.Int32, "datepart(minute, ?1)"));
336336
RegisterFunction("hour", new SQLFunctionTemplate(NHibernateUtil.Int32, "datepart(hour, ?1)"));

src/NHibernate/Dialect/MsSql2008Dialect.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ protected override void RegisterFunctions()
5151
{
5252
RegisterFunction(
5353
"current_timestamp",
54-
new NoArgSQLFunction("sysdatetime", NHibernateUtil.DateTime, true));
54+
new NoArgSQLFunction("sysdatetime", NHibernateUtil.LocalDateTime, true));
5555
RegisterFunction(
5656
"current_utctimestamp",
57-
new NoArgSQLFunction("sysutcdatetime", NHibernateUtil.DateTime, true));
57+
new NoArgSQLFunction("sysutcdatetime", NHibernateUtil.UtcDateTime, true));
5858
}
5959

60-
RegisterFunction("current_date", new SQLFunctionTemplate(NHibernateUtil.Date, "cast(getdate() as date)"));
60+
RegisterFunction("current_date", new SQLFunctionTemplate(NHibernateUtil.LocalDate, "cast(getdate() as date)"));
6161
RegisterFunction(
6262
"current_timestamp_offset",
6363
new NoArgSQLFunction("sysdatetimeoffset", NHibernateUtil.DateTimeOffset, true));

src/NHibernate/Dialect/MsSqlCeDialect.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ protected virtual void RegisterFunctions()
172172
RegisterFunction("str", new SQLFunctionTemplate(NHibernateUtil.String, "cast(?1 as nvarchar)"));
173173
RegisterFunction("strguid", new SQLFunctionTemplate(NHibernateUtil.String, "cast(?1 as nvarchar)"));
174174

175-
RegisterFunction("current_timestamp", new NoArgSQLFunction("getdate", NHibernateUtil.DateTime, true));
176-
RegisterFunction("current_date", new SQLFunctionTemplate(NHibernateUtil.Date, "dateadd(dd, 0, datediff(dd, 0, getdate()))"));
175+
RegisterFunction("current_timestamp", new NoArgSQLFunction("getdate", NHibernateUtil.LocalDateTime, true));
176+
RegisterFunction("current_date", new SQLFunctionTemplate(NHibernateUtil.LocalDate, "dateadd(dd, 0, datediff(dd, 0, getdate()))"));
177177
RegisterFunction("date", new SQLFunctionTemplate(NHibernateUtil.DateTime, "dateadd(dd, 0, datediff(dd, 0, ?1))"));
178178
RegisterFunction("second", new SQLFunctionTemplate(NHibernateUtil.Int32, "datepart(second, ?1)"));
179179
RegisterFunction("minute", new SQLFunctionTemplate(NHibernateUtil.Int32, "datepart(minute, ?1)"));

src/NHibernate/Dialect/MySQL55Dialect.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ protected override void RegisterFunctions()
1515
{
1616
base.RegisterFunctions();
1717

18-
RegisterFunction("current_utctimestamp", new NoArgSQLFunction("UTC_TIMESTAMP", NHibernateUtil.DateTime, true));
18+
RegisterFunction("current_utctimestamp", new NoArgSQLFunction("UTC_TIMESTAMP", NHibernateUtil.UtcDateTime, true));
1919
}
2020
}
2121
}

0 commit comments

Comments
 (0)