31 #ifndef OGR_GENSQL_H_INCLUDED
32 #define OGR_GENSQL_H_INCLUDED
43 #define GEOM_FIELD_INDEX_TO_ALL_FIELD_INDEX(poFDefn, iGeom) \
44 ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + (iGeom))
46 #define IS_GEOM_FIELD_INDEX(poFDefn, idx) \
47 (((idx) >= (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT) && \
48 ((idx) < (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + \
49 (poFDefn)->GetGeomFieldCount()))
51 #define ALL_FIELD_INDEX_TO_GEOM_FIELD_INDEX(poFDefn, idx) \
52 ((idx) - ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT))
60 class OGRGenSQLResultsLayer final :
public OGRLayer
65 std::unique_ptr<swq_select> m_pSelectInfo{};
67 std::string m_osInitialWHERE{};
68 bool m_bForwardWhereToSourceLayer =
true;
72 std::vector<OGRLayer *> m_apoTableLayers{};
75 std::vector<std::unique_ptr<GDALDataset, GDALDatasetUniquePtrReleaser>>
80 std::vector<int> m_anGeomFieldToSrcGeomField{};
82 std::vector<GIntBig> m_anFIDIndex{};
83 bool m_bOrderByValid =
false;
86 std::unique_ptr<OGRFeature> m_poSummaryFeature{};
88 int m_iFIDFieldIndex = 0;
90 GIntBig m_nIteratedFeatures = -1;
91 std::vector<std::string> m_aosDistinctList{};
93 bool PrepareSummary();
95 std::unique_ptr<OGRFeature> TranslateFeature(std::unique_ptr<OGRFeature>);
96 void CreateOrderByIndex();
97 void ReadIndexFields(
OGRFeature *poSrcFeat,
int nOrderItems,
99 void SortIndexSection(
const OGRField *pasIndexFields,
GIntBig *panMerged,
100 size_t nStart,
size_t nEntries);
101 void FreeIndexFields(
OGRField *pasIndexFields,
size_t l_nIndexSize);
105 void ApplyFiltersToSource();
107 void FindAndSetIgnoredFields();
108 void ExploreExprForIgnoredFields(swq_expr_node *expr,
CPLHashSet *hSet);
109 void AddFieldDefnToSet(
int iTable,
int iColumn,
CPLHashSet *hSet);
111 int ContainGeomSpecialField(swq_expr_node *expr);
113 void InvalidateOrderByIndex();
115 int MustEvaluateSpatialFilterOnGenSQL();
121 std::unique_ptr<swq_select> &&pSelectInfo,
122 const OGRGeometry *poSpatFilter,
const char *pszWHERE,
123 const char *pszDialect);
124 virtual ~OGRGenSQLResultsLayer();
143 int bForce = TRUE)
override;
A set of associated raster bands, usually from one file.
Definition: gdal_priv.h:503
Simple container for a bounding region (rectangle)
Definition: ogr_core.h:61
Definition of a feature class or feature layer.
Definition: ogr_feature.h:517
A simple feature, including geometry and attributes.
Definition: ogr_feature.h:893
Abstract base class for all geometry classes.
Definition: ogr_geometry.h:377
This class represents a layer of simple features, with access methods.
Definition: ogrsf_frmts.h:74
virtual void SetSpatialFilter(OGRGeometry *)
Set a new spatial filter.
Definition: ogrlayer.cpp:1487
virtual GIntBig GetFeatureCount(int bForce=TRUE)
Fetch the feature count in this layer.
Definition: ogrlayer.cpp:173
virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce=TRUE)
Fetch the extent of this layer.
Definition: ogrlayer.cpp:211
virtual OGRFeature * GetNextFeature()=0
Fetch the next available feature from this layer.
virtual OGRFeatureDefn * GetLayerDefn()=0
Fetch the schema information for this layer.
virtual void ResetReading()=0
Reset feature reading to start on the first feature.
virtual OGRErr SetNextByIndex(GIntBig nIndex)
Move read cursor to the nIndex'th feature in the current resultset.
Definition: ogrlayer.cpp:598
virtual OGRErr SetAttributeFilter(const char *)
Set a new attribute query.
Definition: ogrlayer.cpp:436
virtual OGRFeature * GetFeature(GIntBig nFID)
Fetch a feature by its identifier.
Definition: ogrlayer.cpp:544
virtual OGRGeometry * GetSpatialFilter()
This method returns the current spatial filter for this layer.
Definition: ogrlayer.cpp:1418
virtual int TestCapability(const char *)=0
Test if this layer supported the named capability.
struct _CPLHashSet CPLHashSet
Opaque type for a hash set.
Definition: cpl_hash_set.h:52
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition: cpl_port.h:1042
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition: cpl_port.h:215
Various convenience functions for working with strings and string lists.
int OGRErr
Type for a OGR error.
Definition: ogr_core.h:387
Classes related to registration of format support, and opening datasets.
OGRFeature field attribute value union.
Definition: ogr_core.h:910