forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStandardSQLFunction.cs
110 lines (97 loc) · 2.61 KB
/
StandardSQLFunction.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System.Collections;
using System.Text;
using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.Type;
using System;
using System.Collections.Generic;
using System.Linq;
namespace NHibernate.Dialect.Function
{
/// <summary>
/// Provides a standard implementation that supports the majority of the HQL
/// functions that are translated to SQL.
/// </summary>
/// <remarks>
/// The Dialect and its sub-classes use this class to provide details required
/// for processing of the associated function.
/// </remarks>
[Serializable]
public class StandardSQLFunction : ISQLFunction, ISQLFunctionExtended
{
private IType returnType = null;
protected readonly string name;
/// <summary>
/// Initializes a new instance of the StandardSQLFunction class.
/// </summary>
/// <param name="name">SQL function name.</param>
public StandardSQLFunction(string name)
{
this.name = name;
}
/// <summary>
/// Initializes a new instance of the StandardSQLFunction class.
/// </summary>
/// <param name="name">SQL function name.</param>
/// <param name="typeValue">Return type for the function.</param>
public StandardSQLFunction(string name, IType typeValue)
: this(name)
{
returnType = typeValue;
}
#region ISQLFunction Members
// Since v5.3
[Obsolete("Use GetReturnType method instead.")]
public virtual IType ReturnType(IType columnType, IMapping mapping)
{
return returnType ?? columnType;
}
/// <inheritdoc />
public virtual IType GetReturnType(IEnumerable<IType> argumentTypes, IMapping mapping, bool throwOnError)
{
#pragma warning disable 618
return ReturnType(argumentTypes.FirstOrDefault(), mapping);
#pragma warning restore 618
}
/// <inheritdoc />
public virtual IType GetEffectiveReturnType(IEnumerable<IType> argumentTypes, IMapping mapping, bool throwOnError)
{
return GetReturnType(argumentTypes, mapping, throwOnError);
}
/// <inheritdoc />
public string Name => name;
public bool HasArguments
{
get { return true; }
}
public bool HasParenthesesIfNoArguments
{
get { return true; }
}
public virtual SqlString Render(IList args, ISessionFactoryImplementor factory)
{
SqlStringBuilder buf = new SqlStringBuilder();
buf.Add(name)
.Add("(");
for (int i = 0; i < args.Count; i++)
{
object arg = args[i];
if (arg is Parameter || arg is SqlString)
{
buf.AddObject(arg);
}
else
{
buf.Add(arg.ToString());
}
if (i < (args.Count - 1)) buf.Add(", ");
}
return buf.Add(")").ToSqlString();
}
#endregion
public override string ToString()
{
return name;
}
}
}