GetQueryDescription(String,String) Method
Gets the
QueryDescription object associated with the
query layer that is created from one or more database table(s) as specified by . This method must be called on the MCT. Use QueuedTask.Run.
Parameters
- queryStatement
- A valid SQL SELECT statement that describes how the query layer should be created.
- queryLayerName
-
A given name.
Return Value
The
QueryDescription object that fully describes how the underlying database table(s) that make up the query layer should be represented as a
Table or
FeatureClass if the query layer is spatially enabled.
Create QueryDescription from a custom query for a Database table
public async Task CustomQueryDescription()
{
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
DatabaseConnectionProperties databaseConnectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)
{
AuthenticationMode = AuthenticationMode.DBMS,
Instance = "instance",
Database = "database",
User = "user",
Password = "password"
};
using (Database database = new Database(databaseConnectionProperties))
{
QueryDescription queryDescription = database.GetQueryDescription("SELECT OBJECTID, Shape, FACILITYID FROM EmergencyFacility WHERE JURISDICT = 'Municipal'", "MunicipalEmergencyFacilities");
using (Table table = database.OpenTable(queryDescription))
{
// Use the table.
}
}
});
}
Create QueryDescription from a join query where there is no non-nullable unique id column
public async Task JoinQueryDescription()
{
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
DatabaseConnectionProperties databaseConnectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)
{
AuthenticationMode = AuthenticationMode.DBMS,
Instance = "instance",
Database = "database",
User = "user",
Password = "password"
};
using (Database database = new Database(databaseConnectionProperties))
{
QueryDescription queryDescription = database.GetQueryDescription("SELECT BUSLINES.ID as BUSLINESID, BUSSTOPS.ID as BUSSTOPSID, BUSLINES.RTE_DESC, BUSLINES.DIR, BUSSTOPS.JURISDIC, BUSSTOPS.LOCATION, BUSSTOPS.ROUTE,BUSSTOPS.SHAPE from demosql.dbo.BUSSTOPS JOIN demosql.dbo.BUSLINES ON BUSSTOPS.ROUTE = BUSLINES.ROUTE", "BusInfo");
queryDescription.SetObjectIDFields("BUSLINESID,BUSSTOPSID");
using (Table table = database.OpenTable(queryDescription))
{
// Use the table.
}
}
});
}
Create QueryDescription from a query for a Database table which has more than one shape type
public async Task MultiGeometryQueryDescription()
{
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
DatabaseConnectionProperties databaseConnectionProperties = new DatabaseConnectionProperties(EnterpriseDatabaseType.SQLServer)
{
AuthenticationMode = AuthenticationMode.DBMS,
Instance = "instance",
Database = "database",
User = "user",
Password = "password"
};
using (Database database = new Database(databaseConnectionProperties))
{
QueryDescription pointQueryDescription = database.GetQueryDescription("select Description, SHAPE, UniqueID from MULTIGEOMETRYTEST", "MultiGeometryPoint");
pointQueryDescription.SetShapeType(GeometryType.Point);
using (Table pointTable = database.OpenTable(pointQueryDescription))
{
//use pointTable
}
QueryDescription polygonQueryDescription = database.GetQueryDescription("select Description, SHAPE, UniqueID from MULTIGEOMETRYTEST", "MultiGeometryPolygon");
polygonQueryDescription.SetShapeType(GeometryType.Polygon);
using (Table polygonTable = database.OpenTable(polygonQueryDescription))
{
//use polygonTable
}
}
});
}
Create QueryDescription from a query for an SQLite Database table
public async Task SqliteQueryDescription()
{
await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
using (Database database = new Database(new SQLiteConnectionPath(new Uri("Path\\To\\Sqlite\\Database\\USA.sqlite"))))
{
QueryDescription washingtonCitiesQueryDescription = database.GetQueryDescription("select OBJECTID, Shape, CITY_FIPS, CITY_NAME, STATE_FIPS, STATE_CITY, TYPE, CAPITAL from main.cities where STATE_NAME='Washington'", "WashingtonCities");
using (Table washingtonTable = database.OpenTable(washingtonCitiesQueryDescription))
{
// Use washingtonTable.
}
}
});
}
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3 or higher.