Skip to content

Commit

Permalink
Added CountDistinct phrase
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgindi committed Feb 3, 2016
1 parent f436600 commit 7011c50
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
58 changes: 58 additions & 0 deletions dg.Sql/Sql/Phrases/Quantitative/CountDistinct.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System;
using System.Collections.Generic;
using System.Text;
using dg.Sql.Connector;

namespace dg.Sql.Phrases
{
public class CountDistinct : IPhrase
{
string TableName;
object Object;
ValueObjectType ObjectType;

public CountDistinct(string tableName, string columnName)
{
this.TableName = tableName;
this.Object = columnName;
this.ObjectType = ValueObjectType.ColumnName;
}

public CountDistinct(string columnName)
: this(null, columnName)
{
}

public CountDistinct(object theObject, ValueObjectType objectType)
{
this.Object = theObject;
this.ObjectType = objectType;
}

public string BuildPhrase(ConnectorBase conn)
{
string ret;

ret = @"COUNT(DISTINCT ";

if (ObjectType == ValueObjectType.ColumnName)
{
if (TableName != null && TableName.Length > 0)
{
ret += conn.EncloseFieldName(TableName);
ret += ".";
}
ret += conn.EncloseFieldName(Object.ToString());
}
else if (ObjectType == ValueObjectType.Value)
{
ret += conn.PrepareValue(Object);
}
else ret += Object;

ret += ")";

return ret;
}
}
}
1 change: 1 addition & 0 deletions dg.Sql/dg.Sql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<Compile Include="Sql\Phrases\Math\Round.cs" />
<Compile Include="Sql\Phrases\Quantitative\Avg.cs" />
<Compile Include="Sql\Phrases\Quantitative\Aggregate.cs" />
<Compile Include="Sql\Phrases\Quantitative\CountDistinct.cs" />
<Compile Include="Sql\Phrases\Quantitative\StandardDeviationOfPopulation.cs" />
<Compile Include="Sql\Phrases\Quantitative\StandardDeviationOfSample.cs" />
<Compile Include="Sql\Phrases\Quantitative\StandardVarianceOfSample.cs" />
Expand Down

0 comments on commit 7011c50

Please sign in to comment.