|
GDAL
|
00001 /****************************************************************************** 00002 * $Id: ogr_gensql.h 37576 2017-03-03 14:29:55Z rouault $ 00003 * 00004 * Project: OpenGIS Simple Features Reference Implementation 00005 * Purpose: Classes related to generic implementation of ExecuteSQL(). 00006 * Author: Frank Warmerdam, warmerdam@pobox.com 00007 * 00008 ****************************************************************************** 00009 * Copyright (c) 2002, Frank Warmerdam 00010 * Copyright (c) 2010-2013, Even Rouault <even dot rouault at mines-paris dot org> 00011 * 00012 * Permission is hereby granted, free of charge, to any person obtaining a 00013 * copy of this software and associated documentation files (the "Software"), 00014 * to deal in the Software without restriction, including without limitation 00015 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00016 * and/or sell copies of the Software, and to permit persons to whom the 00017 * Software is furnished to do so, subject to the following conditions: 00018 * 00019 * The above copyright notice and this permission notice shall be included 00020 * in all copies or substantial portions of the Software. 00021 * 00022 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00023 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00024 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00025 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 00026 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 00027 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 00028 * DEALINGS IN THE SOFTWARE. 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 #include "cpl_string.h" 00038 00039 #include <vector> 00040 00043 #define GEOM_FIELD_INDEX_TO_ALL_FIELD_INDEX(poFDefn, iGeom) \ 00044 ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + (iGeom)) 00045 00046 #define IS_GEOM_FIELD_INDEX(poFDefn, idx) \ 00047 (((idx) >= (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT) && \ 00048 ((idx) < (poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT + (poFDefn)->GetGeomFieldCount())) 00049 00050 #define ALL_FIELD_INDEX_TO_GEOM_FIELD_INDEX(poFDefn, idx) \ 00051 ((idx) - ((poFDefn)->GetFieldCount() + SPECIAL_FIELD_COUNT)) 00052 00053 /************************************************************************/ 00054 /* OGRGenSQLResultsLayer */ 00055 /************************************************************************/ 00056 00057 class CPL_DLL OGRGenSQLResultsLayer : public OGRLayer 00058 { 00059 private: 00060 GDALDataset *poSrcDS; 00061 OGRLayer *poSrcLayer; 00062 void *pSelectInfo; 00063 00064 char *pszWHERE; 00065 00066 OGRLayer **papoTableLayers; 00067 00068 OGRFeatureDefn *poDefn; 00069 00070 int *panGeomFieldToSrcGeomField; 00071 00072 size_t nIndexSize; 00073 GIntBig *panFIDIndex; 00074 int bOrderByValid; 00075 00076 GIntBig nNextIndexFID; 00077 OGRFeature *poSummaryFeature; 00078 00079 int iFIDFieldIndex; 00080 00081 int nExtraDSCount; 00082 GDALDataset **papoExtraDS; 00083 00084 GIntBig nIteratedFeatures; 00085 std::vector<CPLString> m_oDistinctList; 00086 00087 int PrepareSummary(); 00088 00089 OGRFeature *TranslateFeature( OGRFeature * ); 00090 void CreateOrderByIndex(); 00091 void ReadIndexFields( OGRFeature* poSrcFeat, 00092 int nOrderItems, 00093 OGRField *pasIndexFields ); 00094 void SortIndexSection( const OGRField *pasIndexFields, 00095 GIntBig *panMerged, 00096 size_t nStart, size_t nEntries ); 00097 void FreeIndexFields(OGRField *pasIndexFields, 00098 size_t l_nIndexSize, 00099 bool bFreeArray = true); 00100 int Compare( const OGRField *pasFirst, const OGRField *pasSecond ); 00101 00102 void ClearFilters(); 00103 void ApplyFiltersToSource(); 00104 00105 void FindAndSetIgnoredFields(); 00106 void ExploreExprForIgnoredFields(swq_expr_node* expr, CPLHashSet* hSet); 00107 void AddFieldDefnToSet(int iTable, int iColumn, CPLHashSet* hSet); 00108 00109 int ContainGeomSpecialField(swq_expr_node* expr); 00110 00111 void InvalidateOrderByIndex(); 00112 00113 int MustEvaluateSpatialFilterOnGenSQL(); 00114 00115 public: 00116 OGRGenSQLResultsLayer( GDALDataset *poSrcDS, 00117 void *pSelectInfo, 00118 OGRGeometry *poSpatFilter, 00119 const char *pszWHERE, 00120 const char *pszDialect ); 00121 virtual ~OGRGenSQLResultsLayer(); 00122 00123 virtual OGRGeometry *GetSpatialFilter() override; 00124 00125 virtual void ResetReading() override; 00126 virtual OGRFeature *GetNextFeature() override; 00127 virtual OGRErr SetNextByIndex( GIntBig nIndex ) override; 00128 virtual OGRFeature *GetFeature( GIntBig nFID ) override; 00129 00130 virtual OGRFeatureDefn *GetLayerDefn() override; 00131 00132 virtual GIntBig GetFeatureCount( int bForce = TRUE ) override; 00133 virtual OGRErr GetExtent(OGREnvelope *psExtent, int bForce = TRUE) override { return GetExtent(0, psExtent, bForce); } 00134 virtual OGRErr GetExtent(int iGeomField, OGREnvelope *psExtent, int bForce = TRUE) override; 00135 00136 virtual int TestCapability( const char * ) override; 00137 00138 virtual void SetSpatialFilter( OGRGeometry * poGeom ) override { SetSpatialFilter(0, poGeom); } 00139 virtual void SetSpatialFilter( int iGeomField, OGRGeometry * ) override; 00140 virtual OGRErr SetAttributeFilter( const char * ) override; 00141 }; 00142 00145 #endif /* ndef OGR_GENSQL_H_INCLUDED */
1.7.6.1.