1
1
using System ;
2
2
using System . Collections ;
3
+ using System . Collections . Generic ;
3
4
using System . Data ;
4
5
using System . Data . Common ;
5
6
using NHibernate . Dialect . Function ;
@@ -147,7 +148,7 @@ public CastedFunction(string name, IType returnType) : base(name, returnType, fa
147
148
148
149
public override SqlString Render ( IList args , ISessionFactoryImplementor factory )
149
150
{
150
- return new SqlString ( "cast('" , Name , "' as " , FunctionReturnType . SqlTypes ( factory ) [ 0 ] . ToString ( ) , ")" ) ;
151
+ return new SqlString ( "cast('" , FunctionName , "' as " , FunctionReturnType . SqlTypes ( factory ) [ 0 ] . ToString ( ) , ")" ) ;
151
152
}
152
153
}
153
154
@@ -160,7 +161,7 @@ public CurrentTimeStamp() : base("current_timestamp", NHibernateUtil.DateTime, t
160
161
161
162
public override SqlString Render ( IList args , ISessionFactoryImplementor factory )
162
163
{
163
- return new SqlString ( Name ) ;
164
+ return new SqlString ( FunctionName ) ;
164
165
}
165
166
}
166
167
@@ -205,7 +206,7 @@ public override string SelectGUIDString
205
206
}
206
207
207
208
[ Serializable ]
208
- private class PositionFunction : ISQLFunction
209
+ private class PositionFunction : ISQLFunction , ISQLFunctionExtended
209
210
{
210
211
// The cast is needed, at least in the case that ?3 is a named integer parameter, otherwise firebird will generate an error.
211
212
// We have a unit test to cover this potential firebird bug.
@@ -214,11 +215,28 @@ private class PositionFunction : ISQLFunction
214
215
private static readonly ISQLFunction LocateWith3Params = new SQLFunctionTemplate ( NHibernateUtil . Int32 ,
215
216
"position(?1, ?2, cast(?3 as int))" ) ;
216
217
218
+ // Since v5.3
219
+ [ Obsolete ( "Use GetReturnType method instead." ) ]
217
220
public IType ReturnType ( IType columnType , IMapping mapping )
218
221
{
219
222
return NHibernateUtil . Int32 ;
220
223
}
221
224
225
+ /// <inheritdoc />
226
+ public IType GetReturnType ( IEnumerable < IType > argumentTypes , IMapping mapping , bool throwOnError )
227
+ {
228
+ return NHibernateUtil . Int32 ;
229
+ }
230
+
231
+ /// <inheritdoc />
232
+ public IType GetEffectiveReturnType ( IEnumerable < IType > argumentTypes , IMapping mapping , bool throwOnError )
233
+ {
234
+ return GetReturnType ( argumentTypes , mapping , throwOnError ) ;
235
+ }
236
+
237
+ /// <inheritdoc />
238
+ public string FunctionName => "position" ;
239
+
222
240
public bool HasArguments
223
241
{
224
242
get { return true ; }
@@ -417,7 +435,8 @@ private void OverrideStandardHQLFunctions()
417
435
RegisterFunction ( "nullif" , new StandardSafeSQLFunction ( "nullif" , 2 ) ) ;
418
436
RegisterFunction ( "lower" , new StandardSafeSQLFunction ( "lower" , NHibernateUtil . String , 1 ) ) ;
419
437
RegisterFunction ( "upper" , new StandardSafeSQLFunction ( "upper" , NHibernateUtil . String , 1 ) ) ;
420
- RegisterFunction ( "mod" , new StandardSafeSQLFunction ( "mod" , NHibernateUtil . Double , 2 ) ) ;
438
+ // Modulo does not throw for decimal parameters but they are casted to int by Firebird, which produces unexpected results
439
+ RegisterFunction ( "mod" , new ModulusFunction ( false , false ) ) ;
421
440
RegisterFunction ( "str" , new SQLFunctionTemplate ( NHibernateUtil . String , "cast(?1 as VARCHAR(255))" ) ) ;
422
441
RegisterFunction ( "strguid" , new StandardSQLFunction ( "uuid_to_char" , NHibernateUtil . String ) ) ;
423
442
RegisterFunction ( "sysdate" , new CastedFunction ( "today" , NHibernateUtil . Date ) ) ;
@@ -435,7 +454,7 @@ private void RegisterFirebirdServerEmbeddedFunctions()
435
454
RegisterFunction ( "yesterday" , new CastedFunction ( "yesterday" , NHibernateUtil . Date ) ) ;
436
455
RegisterFunction ( "tomorrow" , new CastedFunction ( "tomorrow" , NHibernateUtil . Date ) ) ;
437
456
RegisterFunction ( "now" , new CastedFunction ( "now" , NHibernateUtil . DateTime ) ) ;
438
- RegisterFunction ( "iif" , new StandardSafeSQLFunction ( "iif" , 3 ) ) ;
457
+ RegisterFunction ( "iif" , new IifSafeSQLFunction ( ) ) ;
439
458
// New embedded functions in FB 2.0 (http://www.firebirdsql.org/rlsnotes20/rnfbtwo-str.html#str-string-func)
440
459
RegisterFunction ( "char_length" , new StandardSafeSQLFunction ( "char_length" , NHibernateUtil . Int64 , 1 ) ) ;
441
460
RegisterFunction ( "bit_length" , new StandardSafeSQLFunction ( "bit_length" , NHibernateUtil . Int64 , 1 ) ) ;
0 commit comments