Skip to content

Instantly share code, notes, and snippets.

@smarenich
Last active May 5, 2016 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smarenich/e735cbf44edbbaa3fd1c49b40ab2aa51 to your computer and use it in GitHub Desktop.
Save smarenich/e735cbf44edbbaa3fd1c49b40ab2aa51 to your computer and use it in GitHub Desktop.
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