-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f436600
commit 7011c50
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters