|
1 | 1 | using System.Collections;
|
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
2 | 4 | using NHibernate.Engine;
|
3 | 5 | using NHibernate.SqlCommand;
|
4 | 6 | using NHibernate.Type;
|
@@ -41,4 +43,47 @@ public interface ISQLFunction
|
41 | 43 | /// <returns>SQL fragment for the function.</returns>
|
42 | 44 | SqlString Render(IList args, ISessionFactoryImplementor factory);
|
43 | 45 | }
|
| 46 | + |
| 47 | + // 6.0 TODO: Remove |
| 48 | + internal static class SQLFunctionExtensions |
| 49 | + { |
| 50 | + /// <summary> |
| 51 | + /// Get the type that will be effectively returned by the underlying database. |
| 52 | + /// </summary> |
| 53 | + /// <param name="sqlFunction">The sql function.</param> |
| 54 | + /// <param name="argumentTypes">The types of arguments.</param> |
| 55 | + /// <param name="mapping">The mapping for retrieving the argument sql types.</param> |
| 56 | + /// <param name="throwOnError">Whether to throw when the number of arguments is invalid or they are not supported.</param> |
| 57 | + /// <returns>The type returned by the underlying database or <see langword="null"/> when the number of arguments |
| 58 | + /// is invalid or they are not supported.</returns> |
| 59 | + /// <exception cref="QueryException">When <paramref name="throwOnError"/> is set to <see langword="true"/> and the |
| 60 | + /// number of arguments is invalid or they are not supported.</exception> |
| 61 | + public static IType GetEffectiveReturnType( |
| 62 | + this ISQLFunction sqlFunction, |
| 63 | + IEnumerable<IType> argumentTypes, |
| 64 | + IMapping mapping, |
| 65 | + bool throwOnError) |
| 66 | + { |
| 67 | + if (!(sqlFunction is ISQLFunctionExtended extendedSqlFunction)) |
| 68 | + { |
| 69 | + try |
| 70 | + { |
| 71 | +#pragma warning disable 618 |
| 72 | + return sqlFunction.ReturnType(argumentTypes.FirstOrDefault(), mapping); |
| 73 | +#pragma warning restore 618 |
| 74 | + } |
| 75 | + catch (QueryException) |
| 76 | + { |
| 77 | + if (throwOnError) |
| 78 | + { |
| 79 | + throw; |
| 80 | + } |
| 81 | + |
| 82 | + return null; |
| 83 | + } |
| 84 | + } |
| 85 | + |
| 86 | + return extendedSqlFunction.GetEffectiveReturnType(argumentTypes, mapping, throwOnError); |
| 87 | + } |
| 88 | + } |
44 | 89 | }
|
0 commit comments