SelectByQuery()

Summary

Selects records based on an SQL query.

Changes

Optional options array introduced in Version 5.0. Show Progress Bar option added in Version 2017.

Syntax

n_selected = SelectByQuery (string set_name, string operation, string query [, array options])

Argument Contents
set_name The name of the selection set
operation The operation to perform, as indicated below
query The SQL query string
Operation Meaning
several Replaces the contents of the selection set
less Removes features from the selection set
more Adds features to the selection set
subset Selects a subset of the selection set
Option Type Contents
Index Limit Integer The number of records above which a temporary index will not be built. The default behavior of SelectByQuery() is to build an index if it determines that the index will speed up the query. The "Index Limit" option can prevent this by using a value of 0
Inclusion String "Enclosed" or "Intersecting", overriding the current setting; for more information, see SetSelectInclusion()
Max Integer Maximum number of records to select
Display Boolean "True" or "False" overriding the current setting; for more information, see SetSelectDisplay()
Auto Redraw Boolean "True" or "False" overriding the current setting; for more information, see SetSelectAutoRedraw()
Source And String A selection set on the current layer that records must be in to be selected
Source Not String A selection set on the current layer that records must not be in to be selected
Show Progress Bar Boolean "True" to show the progress bar, otherwise "False"

Returns

An integer indicating the number of records in the selection set.

Notes

  • The options array is an optional argument.

  • All selection commands operate on the current layer or view.

  • If the set does not already exist, SelectByQuery() creates it.

  • Queries must be of the form "Select * where condition." Condition must be a valid boolean expression as described in "Formulas, Conditions, and Functions" in the Maptitude Help.

  • SelectByQuery() displays a progress bar. To add a Cancel button to the progress bar, precede the function call with an "on escape" clause. For more information, see Error Handling.

Examples

qry1 = "Select * where Income > 50000"
qry2 = 'Select * where Category = "Retail" '
n1 = SelectByQuery("High Income", "Several", qry1,)
n2 = SelectByQuery("Retail Stores", "Several", qry2, {{"Index Limit", 0}})

Error Codes

Error Type Meaning
Error The set name, operation type, or query string is invalid, or the view has not been set
NotFound The value being checked for doesn't exist

See Also

Function Summary
SelectByQueryFile() Selects records based on an SQL query that is stored in a file