00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _OGR_GENSQL_H_INCLUDED
00032 #define _OGR_GENSQL_H_INCLUDED
00033
00034 #include "ogrsf_frmts.h"
00035 #include "swq.h"
00036 #include "cpl_hash_set.h"
00037
00038 #define GEOM_FIELD_INDEX_TO_ALL_FIELD_INDEX(poFDefn, iGeom) \
00039 ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + (iGeom))
00040
00041 #define IS_GEOM_FIELD_INDEX(poFDefn, idx) \
00042 (((idx) >= (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT) && \
00043 ((idx) < (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + (poFDefn)->GetGeomFieldCount()))
00044
00045 #define ALL_FIELD_INDEX_TO_GEOM_FIELD_INDEX(poFDefn, idx) \
00046 ((idx) - ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT))
00047
00048
00049
00050
00051
00052 class CPL_DLL OGRGenSQLResultsLayer : public OGRLayer
00053 {
00054 private:
00055 OGRDataSource *poSrcDS;
00056 OGRLayer *poSrcLayer;
00057 void *pSelectInfo;
00058
00059 char *pszWHERE;
00060
00061 OGRLayer **papoTableLayers;
00062
00063 OGRFeatureDefn *poDefn;
00064
00065 int PrepareSummary();
00066
00067 int *panGeomFieldToSrcGeomField;
00068
00069 int nIndexSize;
00070 long *panFIDIndex;
00071 int bOrderByValid;
00072
00073 int nNextIndexFID;
00074 OGRFeature *poSummaryFeature;
00075
00076 int iFIDFieldIndex;
00077
00078 int nExtraDSCount;
00079 OGRDataSource **papoExtraDS;
00080
00081 OGRFeature *TranslateFeature( OGRFeature * );
00082 void CreateOrderByIndex();
00083 void SortIndexSection( OGRField *pasIndexFields,
00084 int nStart, int nEntries );
00085 int Compare( OGRField *pasFirst, OGRField *pasSecond );
00086
00087 void ClearFilters();
00088 void ApplyFiltersToSource();
00089
00090 void FindAndSetIgnoredFields();
00091 void ExploreExprForIgnoredFields(swq_expr_node* expr, CPLHashSet* hSet);
00092 void AddFieldDefnToSet(int iTable, int iColumn, CPLHashSet* hSet);
00093
00094 int ContainGeomSpecialField(swq_expr_node* expr);
00095
00096 void InvalidateOrderByIndex();
00097
00098 int MustEvaluateSpatialFilterOnGenSQL();
00099
00100 public:
00101 OGRGenSQLResultsLayer( OGRDataSource *poSrcDS,
00102 void *pSelectInfo,
00103 OGRGeometry *poSpatFilter,
00104 const char *pszWHERE,
00105 const char *pszDialect );
00106 virtual ~OGRGenSQLResultsLayer();
00107
00108 virtual OGRGeometry *GetSpatialFilter();
00109
00110 virtual void ResetReading();
00111 virtual OGRFeature *GetNextFeature();
00112 virtual OGRErr SetNextByIndex( long nIndex );
00113 virtual OGRFeature *GetFeature( long nFID );
00114
00115 virtual OGRFeatureDefn *GetLayerDefn();
00116
00117 virtual int GetFeatureCount( int bForce = TRUE );
00118 virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) { return GetExtent(0, psExtent, bForce); }
00119 virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce = TRUE);
00120
00121 virtual int TestCapability( const char * );
00122
00123 virtual void SetSpatialFilter( OGRGeometry * poGeom ) { SetSpatialFilter(0, poGeom); }
00124 virtual void SetSpatialFilter( int iGeomField, OGRGeometry * );
00125 virtual OGRErr SetAttributeFilter( const char * );
00126 };
00127
00128 #endif
00129