From 7011c508e8bdbe12835e069c7e4e01b19ea632c2 Mon Sep 17 00:00:00 2001 From: Daniel Cohen Gindi Date: Wed, 3 Feb 2016 13:32:37 +0200 Subject: [PATCH] Added CountDistinct phrase --- .../Sql/Phrases/Quantitative/CountDistinct.cs | 58 +++++++++++++++++++ dg.Sql/dg.Sql.csproj | 1 + 2 files changed, 59 insertions(+) create mode 100644 dg.Sql/Sql/Phrases/Quantitative/CountDistinct.cs diff --git a/dg.Sql/Sql/Phrases/Quantitative/CountDistinct.cs b/dg.Sql/Sql/Phrases/Quantitative/CountDistinct.cs new file mode 100644 index 00000000..8a74a18e --- /dev/null +++ b/dg.Sql/Sql/Phrases/Quantitative/CountDistinct.cs @@ -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; + } + } +} diff --git a/dg.Sql/dg.Sql.csproj b/dg.Sql/dg.Sql.csproj index 70564cd1..1599c86e 100644 --- a/dg.Sql/dg.Sql.csproj +++ b/dg.Sql/dg.Sql.csproj @@ -84,6 +84,7 @@ +