Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/NHibernate/Dialect/Firebird4Dialect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@ protected override void RegisterFunctions()
{
base.RegisterFunctions();
RegisterFunction("current_timestamp", new NoArgSQLFunction("localtimestamp", NHibernateUtil.LocalDateTime, false));
RegisterUdfReplacementFunctions();
}

/// <summary>
/// Maps the <c>ib_udf</c> and <c>fbudf</c> names to built-in functions, because Firebird 4 disables UDFs.
/// </summary>
/// <remarks>
/// <c>div</c>, <c>dow</c>, <c>sdow</c> and <c>getexacttimestamp</c> have no built-in equivalent. Use the <c>udf_compat</c> UDR.
/// </remarks>
private void RegisterUdfReplacementFunctions()
{
RegisterFunction("dpower", new StandardSQLFunction("power", NHibernateUtil.Double));
RegisterFunction("sright", new StandardSQLFunction("right"));
RegisterFunction("strlen", new StandardSQLFunction("char_length", NHibernateUtil.Int16));
// ib_udf substr takes the first and the last position.
RegisterFunction("substr", new SQLFunctionTemplate(null, "substring(?1 from ?2 for ?3 - ?2 + 1)"));
RegisterFunction("substrlen", new SQLFunctionTemplate(NHibernateUtil.Int16, "substring(?1 from ?2 for ?3)"));
RegisterFunction("string2blob", new SQLFunctionTemplate(null, "cast(?1 as blob sub_type text)"));
RegisterFunction("addday", new SQLFunctionTemplate(NHibernateUtil.DateTime, "dateadd(day, ?2, ?1)"));
RegisterFunction("addhour", new SQLFunctionTemplate(NHibernateUtil.DateTime, "dateadd(hour, ?2, ?1)"));
RegisterFunction("addmillisecond", new SQLFunctionTemplate(NHibernateUtil.DateTime, "dateadd(millisecond, ?2, ?1)"));
RegisterFunction("addminute", new SQLFunctionTemplate(NHibernateUtil.DateTime, "dateadd(minute, ?2, ?1)"));
RegisterFunction("addmonth", new SQLFunctionTemplate(NHibernateUtil.DateTime, "dateadd(month, ?2, ?1)"));
RegisterFunction("addsecond", new SQLFunctionTemplate(NHibernateUtil.DateTime, "dateadd(second, ?2, ?1)"));
RegisterFunction("addweek", new SQLFunctionTemplate(NHibernateUtil.DateTime, "dateadd(week, ?2, ?1)"));
RegisterFunction("addyear", new SQLFunctionTemplate(NHibernateUtil.DateTime, "dateadd(year, ?2, ?1)"));
// Native names used above.
RegisterFunction("power", new StandardSQLFunction("power", NHibernateUtil.Double));
RegisterFunction("dateadd", new StandardSQLFunction("dateadd", NHibernateUtil.DateTime));
}
}
}
2 changes: 1 addition & 1 deletion src/NHibernate/Dialect/FirebirdDialect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ private void RegisterMathematicalFunctions()
RegisterFunction("rand", new NoArgSQLFunction("rand", NHibernateUtil.Double));
RegisterFunction("random", new NoArgSQLFunction("rand", NHibernateUtil.Double));
RegisterFunction("sign", new StandardSQLFunction("sign", NHibernateUtil.Int32));
RegisterFunction("sqtr", new StandardSQLFunction("sqtr", NHibernateUtil.Double));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't this not working at all, since the spelling error was in the native name, too?

In such case, why keep the spelling error in HQL, if it was not functional? I mean, register sqrt in HQL if it is not already in the base dialect, and remove sqtr if it was not working at all.

RegisterFunction("sqtr", new StandardSQLFunction("sqrt", NHibernateUtil.Double));
RegisterFunction("trunc", new StandardSQLFunction("trunc"));
RegisterFunction("truncate", new StandardSQLFunction("trunc"));
RegisterFunction("floor", new StandardSQLFunction("floor"));
Expand Down