WhereClause

require(["esri/core/sql/WhereClause"], function(WhereClause) { /* code goes here */ });
Object: esri/core/sql/WhereClause
Since: ArcGIS API for JavaScript 4.14

The WhereClause is used to extract the features that meet a specified condition by parsing the provided results in to a value. The sql.parseWhereClause() method returns a Promise that resolves to an instance of this module.

Property Overview

Any properties can be set, retrieved or listened to. See the Working with Properties topic.
NameTypeSummaryObject
String[]

An array of the field names used in the where clause.

more details
more detailsWhereClause
Boolean

Returns true if the parsed where clause meets the requirements of standardized sql.

more details
more detailsWhereClause

Property Details

fieldNames String[]

An array of the field names used in the where clause. It can be used to get the appropriate fields when querying layers.

Example:
// parse layer's definition expression into where clause object
sql.parseWhereClause(layer.definitionExpression, layer.fieldsIndex)
.then(function(clause){
  layer.queryFeatures({
    where: "1=1",
    // where clause object returns layer fields
    // use these fields to query features from the layer
    outFields: clause.fieldsNames
  }).then(function(results) {
   // process query results
  });
});
isStandardized Booleanreadonly

Returns true if the parsed where clause meets the requirements of standardized sql.

Method Overview

NameReturn TypeSummaryObject
Object

Executes the where clause against a feature to generate a value.

more details
more detailsWhereClause
Boolean

Tests the attributes of a feature against the whereClause, and returns true if the test passes, false otherwise.

more details
more detailsWhereClause

Method Details

calculateValue(feature){Object}

Executes the where clause against a feature to generate a value. It is used when the WhereClause is being used as a simple expression. For example, you can use the expression to gather values for statistics.

Parameter:
feature Object

The feature to check against the where clause.

Returns:
TypeDescription
ObjectReturns a value after check feature against the provided where clause. Returns null if the provided value is unknown.
Example:
// calculate the grand total sales price of all features
featureLayer.queryFeatures().then(function(results){
  let total;
  const expression = "totalSales * totalPrice";
  sql.parseWhereClause(expression, layer.fieldsIndex)
  .then(function(whereClause){
    // check if the where clause meets requirements of standardized sql
    if (whereClause.isStandardized){
      features.forEach(function(feature){
        total += whereClause.calculateValue(feature)
      });
      console.log(total); // prints the total sales price of all features
    }
  });
});
testFeature(feature){Boolean}

Tests the attributes of a feature against the whereClause, and returns true if the test passes, false otherwise.

Parameter:
feature Object

The feature to test against the whereClause.

Returns:
TypeDescription
BooleanReturns true if the test passes, false otherwise.
Example:
sql.parseWhereClause("POPULATION > 100000", layer.fieldsIndex)
.then(function(clause){
  var testResult = clause.testFeature(new Graphic({
    attributes: {
      POPULATION: 300000
   }
 });
 console.log(testResult); // prints true
});

API Reference search results

NameTypeModule
Loading...