| Development licensing | Deployment licensing |
|---|---|
| ArcView | ArcView |
| ArcEditor | ArcEditor |
| ArcInfo | ArcInfo |
| Engine Developer Kit | Engine Runtime |
|
Requirement
|
IQueryFilter
|
ISpatialFilter
|
IQueryDef
|
|
Apply attribute constraints
|
True
|
True
|
True
|
|
Apply spatial constraints
|
False
|
True
|
False
|
|
Query results contain fields from multiple tables
|
False
|
False
|
True
|
|
Query results returned as a cursor
|
True
|
True
|
True
|
|
RecordSet objects can be created from results
|
True
|
True
|
True
|
|
Returned records can be edited
|
True
|
True
|
False
|
static ICursor getRestaurants(ITable table)throws Exception
{
// Create the query filter.
IQueryFilter queryFilter = new QueryFilter();
// Select the fields to be returned - the name and address of the businesses.
queryFilter.setSubFields("NAME, ADDRESS");
// Set the filter to return only restaurants.
queryFilter.setWhereClause("TYPE = 'Restaurant'");
// Use the PostfixClause to alphabetically order the set by name.
IQueryFilterDefinition queryFilterDef = (IQueryFilterDefinition)queryFilter;
queryFilterDef.setPostfixClause("ORDER BY NAME");
ICursor cursor = table.ITable_search(queryFilter, true);
return cursor;
}
static IFeatureCursor getStreetsInEnvelope(IFeatureClass featureClass)throws
Exception
{
// Create the envelope and define its position.
IEnvelope envelope = new Envelope();
envelope.putCoords( - 84.4078, 33.7787, - 84.3856, 33.7997);
// Create the spatial filter and set its spatial constraints.
ISpatialFilter spatialFilter = new SpatialFilter();
spatialFilter.setGeometryByRef(envelope);
spatialFilter.setGeometryField(featureClass.getShapeFieldName());
spatialFilter.setSpatialRel(esriSpatialRelEnum.esriSpatialRelIntersects);
// Set the attribute constraints and subfields.
// We want to exclude ramps, highways and interstates.
spatialFilter.setWhereClause(
"NAME <> 'Ramp' AND PRE_TYPE NOT IN ('Hwy', 'I')");
spatialFilter.setSubFields("NAME, TYPE");
// Execute the query.
IFeatureCursor featureCursor = featureClass.search(spatialFilter, true);
return featureCursor;
}
// For example, tables = "customers"
// subFields = "NAME, ADDRESS"
// whereClause = "ADDRESS LIKE '%CENTER%'"
public ICursor useQueryDef(IFeatureWorkspace featureWorkspace, String tables,
String subFields, String whereClause)throws Exception
{
// Create the query definition.
IQueryDef queryDef = featureWorkspace.createQueryDef();
// Provide a list of table(s) to join.
queryDef.setTables(tables);
// Declare the subfields to retrieve.
queryDef.setSubFields(subFields);
// Assign a where clause to filter the results.
queryDef.setWhereClause(whereClause);
// Evaluate queryDef to execute a database query and return a cursor to the application.
ICursor cursor = queryDef.evaluate();
return cursor;
}
public ITable createQueryTable(IWorkspace workspace, IQueryDef queryDef, String
tableName)throws Exception
{
// Create a reference to a TableQueryName object.
IQueryName2 queryName2 = new TableQueryName();
queryName2.setPrimaryKey("");
// Specify the query definition.
queryName2.setQueryDef(queryDef);
// Get a name object for the workspace.
IDataset dataset = (IDataset)workspace;
IWorkspaceName workspaceName = (IWorkspaceName)dataset.getFullName();
// Cast the TableQueryName object to the IDatasetName interface and open it.
IDatasetName datasetName = (IDatasetName)queryName2;
datasetName.setWorkspaceNameByRef(workspaceName);
datasetName.setName(tableName);
IName name = (IName)datasetName;
// Open the name object and get a reference to a table object.
ITable table = (ITable)name.open();
return table;
}
|
Predicate
|
Meaning
|
Example
|
|
=
|
Equals
|
TYPE = 3
|
|
<>
|
Is not equal to
|
PROVINCE <> 'NS'
|
|
>=
|
Is greater than or equal to
|
POPULATION >= 10000
|
|
<=
|
Is less than or equal to
|
AVG_TEMP <= 25
|
|
>
|
Is greater than
|
HEIGHT > 10
|
|
<
|
Is less than
|
SPD_LIMIT < 65
|
|
[NOT] BETWEEN
|
Is between a minimum and maximum value
|
DIAMETER BETWEEN 5 AND 10
|
|
[NOT] IN
|
Is in a list or the results of a subquery
|
TYPE IN ('City', 'Town')
|
| [NOT] EXISTS |
Checks a subquery for results
|
EXISTS (SELECT * FROM PARCELS WHERE TYPE='RES')
|
|
[NOT] LIKE
|
Matches a string pattern
|
CITY_NAME LIKE 'Montr_al'
|
|
IS [NOT] NULL
|
Is value NULL
|
WEBSITE IS NULL
|
static boolean isPredicateSupported(IWorkspace workspace, int predicate)throws
Exception
{
// Cast to the ISQLSyntax interface and get the supportedPredicates value.
ISQLSyntax sqlSyntax = (ISQLSyntax)workspace;
int supportedPredicates = sqlSyntax.getSupportedPredicates();
//use bitwise arithmetic to check for support.
int predicateValue = predicate;
int supportedValue = predicateValue & supportedPredicates;
boolean isSupported = supportedValue > 0;
return isSupported;
}
|
CITY_NAME LIKE 'New%' AND POPULATION >= 100000
|
|
NOT (PROV = 'NS' AND TERM = 'City')
|
|
CITY_NAME = 'St. John''s'
|
|
NAME LIKE '%$_%' ESCAPE '$'
|
|
"DESC" LIKE '%cold%'
|
|
COUNTRY_NAME IN (SELECT COUNTRY_NAME FROM WTO_COUNTRIES)
|
|
GDP > (SELECT AVG(GDP) FROM COUNTRIES)
|
|
EXTRACT(YEAR FROM START_DATE) = 2000
|
|
SIN(Direction / 57.296) > 0.707
|
|
UPPER(COUNTRY_NAME) LIKE 'REPUBLIC OF %'
|
|
CAST(SUBSTRING(NAME, CHAR_LENGTH(NAME) - 2, 3) AS INT) BETWEEN 100 AND 199
|
static String functionNameForWorkspace(IWorkspace workspace, int
sqlFunctionName)throws Exception
{
// Cast to the ISQLSyntax interface and get the correct function name.
ISQLSyntax sqlSyntax = (ISQLSyntax)workspace;
String functionName = sqlSyntax.getFunctionName(sqlFunctionName);
// If functionName is null, the function is not supported and an exception should be thrown.
if (functionName == null)
{
throw new Exception("SQL Function Not Supported.");
}
return functionName;
}
|
FID, Shape, STATE_NAME, POPULATION
|