Select to view content in your preferred language

C# QueryFilter prefixClause "DISTINCT" non-functional

1969
4
Jump to solution
07-01-2019 07:50 AM
MikeRatcliffe
Frequent Contributor

I'm finding that QueryFilter prefixClause "DISTINCT" is non-functional in the SDK and must use a workaround:

                QueryFilter filter = new QueryFilter
                {
                    //PrefixClause = "DISTINCT",              //DISTINCT does not work in this query. See workaround below.
                    SubFields = "FY",
                    WhereClause = "FY IS NOT NULL AND FY <> '-9' AND FY <> ' '",
                    PostfixClause = "ORDER BY FY"
                };

                using (RowCursor rowCursor = sso_lyr.Search(filter))
                {
                    int fldIndex = rowCursor.FindField("FY");

                    List<string> valuelist = new List<string>();

                    while (rowCursor.MoveNext())
                    {
                        string value = rowCursor.Current.GetOriginalValue(fldIndex) as string;
                        valuelist.Add(value);
                    }

                    IEnumerable<string> distinctvaluelist = valuelist.Select(x => x).Distinct(); //distinct from list b/c DISTINCT prefixclause non-functional above.

                    foreach (string item in distinctvaluelist)
                    {
                        Invoke(new MethodInvoker(delegate { Sso_combo.Items.Add(item); }));
                    }
                }

This is okay for very short lists of values, but not for 100,000 records; which is the requirement.

Has anyone else encountered this?  I'm using documentation from this source:

https://github.com/esri/arcgis-pro-sdk/wiki/ProConcepts-Geodatabase

Word find: "distinct" on the page...

0 Kudos
1 Solution

Accepted Solutions
RichRuh
Esri Regular Contributor

Shape files do not support the Distinct clause.  

To see what clauses are supported by a particular datastore, you can call Datastore.GetSQLSyntax().  This method returns a SQLSyntax object.  SQLSyntax.GetSupportedClauses() returns a list of the supported clauses.

I'll update the conceptual doc to make this more clear.

--Rich

View solution in original post

4 Replies
RichRuh
Esri Regular Contributor

Hi Mike,

What kind of database are you trying to run this against?

Thanks,

--Rich

0 Kudos
MikeRatcliffe
Frequent Contributor

Hey, Rich.

it is a FeatureLayer with the source of SSO_Events.shp > SSO_Events.lyr.

0 Kudos
RichRuh
Esri Regular Contributor

Shape files do not support the Distinct clause.  

To see what clauses are supported by a particular datastore, you can call Datastore.GetSQLSyntax().  This method returns a SQLSyntax object.  SQLSyntax.GetSupportedClauses() returns a list of the supported clauses.

I'll update the conceptual doc to make this more clear.

--Rich

MikeRatcliffe
Frequent Contributor

Thanks, Rich.

0 Kudos