|
1 | 1 | namespace Simple.Data.Ado |
2 | 2 | { |
3 | 3 | using System; |
| 4 | + using System.Collections.Generic; |
| 5 | + using System.Text; |
4 | 6 | using Schema; |
5 | 7 |
|
6 | 8 | class SimpleReferenceFormatter |
7 | 9 | { |
8 | 10 | private readonly IFunctionNameConverter _functionNameConverter = new FunctionNameConverter(); |
9 | 11 | private readonly DatabaseSchema _schema; |
| 12 | + private readonly ICommandBuilder _commandBuilder; |
10 | 13 |
|
11 | | - public SimpleReferenceFormatter(DatabaseSchema schema) |
| 14 | + public SimpleReferenceFormatter(DatabaseSchema schema, ICommandBuilder commandBuilder) |
12 | 15 | { |
13 | 16 | _schema = schema; |
| 17 | + _commandBuilder = commandBuilder; |
14 | 18 | } |
15 | 19 |
|
16 | 20 | public string FormatColumnClause(SimpleReference reference) |
@@ -65,13 +69,25 @@ private string TryFormatAsFunctionReference(FunctionReference functionReference) |
65 | 69 |
|
66 | 70 | var sqlName = _functionNameConverter.ConvertToSqlName(functionReference.Name); |
67 | 71 | return functionReference.Alias == null |
68 | | - ? string.Format("{0}({1})", sqlName, |
69 | | - FormatColumnClause(functionReference.Argument)) |
| 72 | + ? string.Format("{0}({1}{2})", sqlName, |
| 73 | + FormatColumnClause(functionReference.Argument), |
| 74 | + FormatAdditionalArguments(functionReference.AdditionalArguments)) |
70 | 75 | : string.Format("{0}({1}) AS {2}", sqlName, |
71 | 76 | FormatColumnClause(functionReference.Argument), |
72 | 77 | _schema.QuoteObjectName(functionReference.Alias)); |
73 | 78 | } |
74 | 79 |
|
| 80 | + private string FormatAdditionalArguments(IEnumerable<object> additionalArguments) |
| 81 | + { |
| 82 | + StringBuilder builder = null; |
| 83 | + foreach (var additionalArgument in additionalArguments) |
| 84 | + { |
| 85 | + if (builder == null) builder = new StringBuilder(); |
| 86 | + builder.AppendFormat(",{0}", _commandBuilder.AddParameter(additionalArgument)); |
| 87 | + } |
| 88 | + return builder != null ? builder.ToString() : string.Empty; |
| 89 | + } |
| 90 | + |
75 | 91 | private string TryFormatAsObjectReference(ObjectReference objectReference) |
76 | 92 | { |
77 | 93 | if (ReferenceEquals(objectReference, null)) return null; |
|
0 commit comments