Updates referencesource to .NET 4.7
[mono-project.git] / mcs / class / referencesource / System.Data.Entity / System / Data / SqlClient / SqlGen / TopClause.cs
blobe09e2252f9cf33e58b26b55e752d3f440a56c637
1 //---------------------------------------------------------------------
2 // <copyright file="TopClause.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 // </copyright>
5 //
6 // @owner Microsoft
7 // @backupOwner Microsoft
8 //---------------------------------------------------------------------
10 using System;
11 using System.Collections.Generic;
12 using System.Diagnostics;
13 using System.Globalization;
14 using System.IO;
15 using System.Text;
16 using System.Data.SqlClient;
17 using System.Data.Metadata.Edm;
18 using System.Data.Common.CommandTrees;
20 namespace System.Data.SqlClient.SqlGen
22 /// <summary>
23 /// TopClause represents the a TOP expression in a SqlSelectStatement.
24 /// It has a count property, which indicates how many TOP rows should be selected and a
25 /// boolen WithTies property.
26 /// </summary>
27 class TopClause : ISqlFragment
29 ISqlFragment topCount;
30 bool withTies;
32 /// <summary>
33 /// Do we need to add a WITH_TIES to the top statement
34 /// </summary>
35 internal bool WithTies
37 get { return withTies; }
40 /// <summary>
41 /// How many top rows should be selected.
42 /// </summary>
43 internal ISqlFragment TopCount
45 get { return topCount; }
48 /// <summary>
49 /// Creates a TopClause with the given topCount and withTies.
50 /// </summary>
51 /// <param name="topCount"></param>
52 /// <param name="withTies"></param>
53 internal TopClause(ISqlFragment topCount, bool withTies)
55 this.topCount = topCount;
56 this.withTies = withTies;
59 /// <summary>
60 /// Creates a TopClause with the given topCount and withTies.
61 /// </summary>
62 /// <param name="topCount"></param>
63 /// <param name="withTies"></param>
64 internal TopClause(int topCount, bool withTies)
66 SqlBuilder sqlBuilder = new SqlBuilder();
67 sqlBuilder.Append(topCount.ToString(CultureInfo.InvariantCulture));
68 this.topCount = sqlBuilder;
69 this.withTies = withTies;
72 #region ISqlFragment Members
74 /// <summary>
75 /// Write out the TOP part of sql select statement
76 /// It basically writes TOP (X) [WITH TIES].
77 /// The brackets around X are ommited for Sql8.
78 /// </summary>
79 /// <param name="writer"></param>
80 /// <param name="sqlGenerator"></param>
81 public void WriteSql(SqlWriter writer, SqlGenerator sqlGenerator)
83 writer.Write("TOP ");
85 if (sqlGenerator.SqlVersion != SqlVersion.Sql8)
87 writer.Write("(");
90 this.TopCount.WriteSql(writer, sqlGenerator);
92 if (sqlGenerator.SqlVersion != SqlVersion.Sql8)
94 writer.Write(")");
97 writer.Write(" ");
99 if (this.WithTies)
101 writer.Write("WITH TIES ");
105 #endregion