-
Notifications
You must be signed in to change notification settings - Fork 933
/
Copy pathConditionalFragment.cs
62 lines (53 loc) · 1.19 KB
/
ConditionalFragment.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
using System;
using System.Text;
using NHibernate.Util;
namespace NHibernate.SqlCommand
{
public class ConditionalFragment
{
private string tableAlias;
private string[] lhs;
private string[] rhs;
private string op = "=";
/// <summary>
/// Sets the op
/// </summary>
/// <param name="op">The op to set</param>
public ConditionalFragment SetOp(string op)
{
this.op = op;
return this;
}
public ConditionalFragment SetTableAlias(string tableAlias)
{
this.tableAlias = tableAlias;
return this;
}
public ConditionalFragment SetCondition(string[] lhs, string[] rhs)
{
this.lhs = lhs;
this.rhs = rhs;
return this;
}
public ConditionalFragment SetCondition(string[] lhs, string rhs)
{
this.lhs = lhs;
this.rhs = ArrayHelper.FillArray(rhs, lhs.Length);
return this;
}
public SqlString ToSqlStringFragment()
{
StringBuilder buf = new StringBuilder( lhs.Length * 10 );
for ( int i=0; i<lhs.Length; i++ )
{
buf.Append(tableAlias)
.Append(StringHelper.Dot)
.Append( lhs[i] )
.Append(op)
.Append( rhs[i] );
if (i<lhs.Length-1) buf.Append(" and ");
}
return new SqlString(buf.ToString());
}
}
}