Last active
May 5, 2016 08:41
-
-
Save smarenich/e735cbf44edbbaa3fd1c49b40ab2aa51 to your computer and use it in GitHub Desktop.
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using PX.SM; | |
using PX.TM; | |
using PX.Data; | |
namespace PX.Objects.CR | |
{ | |
public sealed class ScalarCount<Field> : IBqlFunction | |
where Field : IBqlField | |
{ | |
public void GetAggregates(List<IBqlFunction> fields) | |
{ | |
//Return this as count is aggregate function | |
fields.Add(this); | |
} | |
public void Parse(PXGraph graph, List<IBqlParameter> pars, List<Type> tables, List<Type> fields, List<IBqlSortColumn> sortColumns, StringBuilder text, BqlCommand.Selection selection) | |
{ | |
if (tables != null) | |
{ | |
tables.Add(typeof(int)); | |
} | |
if (graph != null && text != null) | |
{ | |
//adding count function to the field | |
StringBuilder bld = new StringBuilder("COUNT(DISTINCT "); | |
bld.Append(BqlCommand.GetSingleField(typeof(Field), graph, tables, selection, BqlCommand.FieldPlace.Condition)); | |
bld.Append(')'); | |
} | |
} | |
public void Verify(PXCache cache, object item, List<object> pars, ref bool? result, ref object value) { } | |
//Return name of function | |
public string GetFunction() { return "COUNT"; } | |
//return name of field what we need to count | |
public Type GetField() { return typeof(Field); ; } | |
//it is not group by | |
public bool IsGroupBy() { return false; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment