require(["esri/core/sql/WhereClause"], (WhereClause) => { /* code goes here */ });
import WhereClause from "@arcgis/core/core/sql/WhereClause.js";
esri/core/sql/WhereClause
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
Name | Type | Summary | Object |
---|---|---|---|
String[] | An array of the field names used in the where clause. | WhereClause | |
Boolean | Returns | WhereClause | |
SQLNode | A parse tree is a data structure for representing a parsed sql statement. | WhereClause |
Property Details
-
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
isStandardized Booleanreadonly
-
Returns
true
if the parsed where clause meets the requirements of standardized sql.
-
parseTree
parseTree SQLNode
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, parseTree added at 4.24. -
A parse tree is a data structure for representing a parsed sql statement. Parsing a statement requires the grammar of the language that the statement was written.
Method Overview
Name | Return Type | Summary | Object |
---|---|---|---|
Object | Executes the where clause against a feature to generate a value. | WhereClause | |
Boolean | Tests the attributes of a feature against the | WhereClause |
Method Details
-
calculateValue
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.Parameterfeature ObjectThe feature to check against the where clause.
ReturnsType Description Object Returns 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
testFeature(feature){Boolean}
-
Tests the attributes of a feature against the
whereClause
, and returnstrue
if the test passes,false
otherwise.Parameterfeature ObjectThe feature to test against the
whereClause
.ReturnsType Description Boolean Returns true
if the test passes,false
otherwise.Examplesql.parseWhereClause("POPULATION > 100000", layer.fieldsIndex) .then(function(clause){ let testResult = clause.testFeature(new Graphic({ attributes: { POPULATION: 300000 } }); console.log(testResult); // prints true });
Type Definitions
-
BinaryNode
BinaryNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, BinaryNode added at 4.24. -
A binary expression node. It is an operator that defines the way two expressions are combined to yield a single result. It can be an arithmetic operator, the assignment operator (=), a comparison operator (>=), a logical operator (AND), or a string concatenation operator (+).
- Properties
-
type String
The value is always "binary-expression".
operator StringDefines the way two expressions are combined to yield a single result.
Possible Values:"AND"|"OR"|"IS"|"ISNOT"|"IN"|"NOT IN"|"BETWEEN"|"NOTBETWEEN"|"LIKE"|"NOT LIKE"|"<>"|"<"|">"|">="|"<="|"="|"*"|"-"|"+"|"/"
left SQLNodeSQL node to the left of the binary node.
right SQLNodeSQL node to the right of the binary node.
escape StringEscape string.
-
BoolNode
BoolNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, BoolNode added at 4.24. -
A node that contains a boolean expression. Used for expressing a condition or criterion which can be either true or false.
-
ColumnNode
ColumnNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, ColumnNode added at 4.24. -
A node that contains column name of a layer or table.
-
CurrentTimeNode
CurrentTimeNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, CurrentTimeNode added at 4.24. -
A node that contains
CURRENT_TIME
orCURRENT_DATE
functions.
-
DateNode
DateNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, DateNode added at 4.24. -
A node that contains date.
-
FunctionNode
FunctionNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, FunctionNode added at 4.24. -
A nodes that contains SQL function.
-
IntervalNode
IntervalNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, IntervalNode added at 4.24. -
Interval node indicates that the character literal is an interval. An interval is defined as the difference between two dates and times.
- Properties
-
type String
The value is always "interval".
value StringNodeInterval node value.
op StringInterval node sign.
Possible Values:"+"|"-"|""
qualifier IntervalQualifierNode|IntervalPeriodNodeThe interval qualifier can either be a single datetime field or be composed of two datetime fields, in the form:
TO .
-
IntervalPeriodNode
IntervalPeriodNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, IntervalPeriodNode added at 4.24. -
Interval period node.
-
IntervalQualifierNode
IntervalQualifierNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, IntervalQualifierNode added at 4.24. -
Node that contains interval qualifier. The interval qualifier can either be a single datetime field or be composed of two datetime fields, in the form:
<leading field> TO <trailing field>
.- Properties
-
type String
The value is always "interval-qualifier".
period StringInterval node periods.
Possible Values:"day"|"month"|"hour"|"second"|"year"|"minute"
precision NumberPrecision for an interval data type includes interval leading precision, interval precision, and seconds precision.
secondary StringSeconds precision.
The value is always "number".
-
ListNode
ListNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, ListNode added at 4.24. -
A node that contains a list.
-
NullNode
NullNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, NullNode added at 4.24. -
A node that contains
NULL
value.
-
NumberNode
NumberNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, NumberNode added at 4.24. -
A node that contains number.
-
SearchedCaseNode
SearchedCaseNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, SearchedCaseNode added at 4.24. -
Node that contains case expression.
-
SimpleCaseNode
SimpleCaseNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, SimpleCaseNode added at 4.24. -
Simple case expression node. Case expressions provide a decoding capability that allows one expression to be transformed into another. Case expressions can appear anywhere that other forms of expressions can be used.
-
SQLNode
SQLNode BinaryNode|BoolNode|ColumnNode|CurrentTimeNode|DateNode|FunctionNode|IntervalNode|IntervalPeriodNode|IntervalQualifierNode|NullNode|StringNode|ListNode|NumberNode|SimpleCaseNode|SearchedCaseNode|TimeStampNode|TimeNode|UnaryNode|WhenNode
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, SQLNode added at 4.24. -
SQL parse tree is composed of SqlNodes. It may be an operator, literal, function, list, and so forth.
-
StringNode
StringNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, StringNode added at 4.24. -
A node that contains string.
-
TimeNode
TimeNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, TimeNode added at 4.24. -
A node that contains time.
-
TimeStampNode
TimeStampNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, TimeStampNode added at 4.24. -
A node that contains date.
-
UnaryNode
UnaryNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, UnaryNode added at 4.24. -
A node that contains unary operator. Unary operators can be applied only to expressions that evaluate to any one of the data types of the numeric data type category.