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 |
---|---|---|---|
An array of the field names used in the where clause. | WhereClause | ||
Returns | WhereClause | ||
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 |
---|---|---|---|
Executes the where clause against a feature to generate a value. | WhereClause | ||
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".
location SQLSourceLocationoperator String|"||"Defines 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.
- Properties
-
type String
The value is always "boolean".
location SQLSourceLocationvalue BooleanValues are
true
orfalse
.
-
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.
- Properties
-
type String
The value is always "column-reference".
location SQLSourceLocationcolumn StringColumn or field name.
-
CurrentTimeNode
CurrentTimeNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, CurrentTimeNode added at 4.24. -
A node that contains
CURRENT_TIMESTAMP
,CURRENT_TIME
, orCURRENT_DATE
functions.- Properties
-
type String
The value is always "current-time".
location SQLSourceLocationmode StringThe current time node mode.
Possible Values:"timestamp"|"date"|"time"
-
CurrentUserNode
CurrentUserNode Object
Since: ArcGIS Maps SDK for JavaScript 4.31WhereClause since 4.14, CurrentUserNode added at 4.31. -
A node that contains
CURRENT_USER
function.- Properties
-
type String
The value is always "current-user".
location SQLSourceLocation
-
DataTypeNode
DataTypeNode Object
Since: ArcGIS Maps SDK for JavaScript 4.26WhereClause since 4.14, DataTypeNode added at 4.26. -
- Properties
-
type String
The value is always "data-type".
location SQLSourceLocationvalue Object
-
DateNode
DateNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, DateNode added at 4.24. -
A node that contains date.
- Properties
-
type String
The value is always "date".
location SQLSourceLocationvalue StringThe date value.
-
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.
- Properties
-
type String
The value is always "function".
location SQLSourceLocationname StringName of the SQL function.
args ListNodeFunction arguments.
-
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".
location SQLSourceLocationvalue StringNode|ParamNodeInterval 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.
- Properties
-
type String
The value is always "interval-period".
location SQLSourceLocationperiod StringInterval node periods.
Possible Values:"day"|"month"|"hour"|"second"|"year"|"minute"
Precision for an interval data type includes interval leading precision, interval precision, and seconds precision.
Seconds precision.
-
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".
location SQLSourceLocationstart IntervalPeriodNode
-
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.
- Properties
-
type String
The value is always "expression-list".
location SQLSourceLocationSQL expressions for the 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.- Properties
-
type String
The value is always "null".
location SQLSourceLocationvalue nullNull 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.
- Properties
-
type String
The value is always "number".
location SQLSourceLocationvalue NumberNumeric value.
-
ParamNode
ParamNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, ParamNode added at 4.24. -
ParamNode.
- Properties
-
type String
The value is always "parameter".
location SQLSourceLocationvalue String
-
SQLNode
SQLNode BinaryNode |BoolNode |ColumnNode |CurrentTimeNode |CurrentUserNode |DataTypeNode |DateNode |FunctionNode |IntervalNode |IntervalPeriodNode |IntervalQualifierNode |ListNode |NullNode |NumberNode |ParamNode |SearchedCaseNode |SimpleCaseNode |StringNode |TimeNode |TimeStampNode |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.
-
SQLSourceLocation
SQLSourceLocation Object
-
- Properties
-
start SQLSourcePosition
-
SQLSourcePosition
SQLSourcePosition Object
-
SQLSyntaxError
SQLSyntaxError Object
-
- Properties
-
name String
The value is always "SyntaxError".
location SQLSourceLocationmessage String
-
SearchedCaseNode
SearchedCaseNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, SearchedCaseNode added at 4.24. -
Node that contains case expression.
- Properties
-
type String
The value is always "case-expression".
location SQLSourceLocationformat StringCase expression format. Value for this property is always
searched
.The value is always "searched".
When clauses.
Else SQL node.
elseLocation SQLSourceLocation|null
-
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.
- Properties
-
type String
The value is always "case-expression".
location SQLSourceLocationformat StringThe value is always "simple".
When nodes.
operand SQLNodeSQL node.
else sql node.
elseLocation SQLSourceLocation|null
-
StringNode
StringNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, StringNode added at 4.24. -
A node that contains string.
- Properties
-
type String
The value is always "string".
location SQLSourceLocationvalue StringThe string value.
-
TimeNode
TimeNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, TimeNode added at 4.24. -
A node that contains time.
- Properties
-
type String
The value is always "time".
location SQLSourceLocationvalue StringThe time value.
-
TimeStampNode
TimeStampNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, TimeStampNode added at 4.24. -
A node that contains date.
- Properties
-
type String
The value is always "timestamp".
location SQLSourceLocationvalue StringString date value.
-
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.
- Properties
-
type String
The value is always "unary-expression".
location SQLSourceLocationoperator StringThe value is always "NOT".
expr SQLNodeThe sql node.
-
WhenNode
WhenNode Object
Since: ArcGIS Maps SDK for JavaScript 4.24WhereClause since 4.14, WhenNode added at 4.24. -
Node that contains when clause.
- Properties
-
type String
The value is always "when-clause".
location SQLSourceLocationoperand SQLNodeoperand.
value SQLNodevalue.