GDAL
|
00001 /****************************************************************************** 00002 * $Id: ogr_gensql.h 28375 2015-01-30 12:06:11Z 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 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 /* OGRGenSQLResultsLayer */ 00050 /************************************************************************/ 00051 00052 class CPL_DLL OGRGenSQLResultsLayer : public OGRLayer 00053 { 00054 private: 00055 GDALDataset *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 GIntBig nIndexSize; 00070 GIntBig *panFIDIndex; 00071 int bOrderByValid; 00072 00073 GIntBig nNextIndexFID; 00074 OGRFeature *poSummaryFeature; 00075 00076 int iFIDFieldIndex; 00077 00078 int nExtraDSCount; 00079 GDALDataset **papoExtraDS; 00080 00081 OGRFeature *TranslateFeature( OGRFeature * ); 00082 void CreateOrderByIndex(); 00083 int SortIndexSection( OGRField *pasIndexFields, 00084 GIntBig nStart, GIntBig 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( GDALDataset *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( GIntBig nIndex ); 00113 virtual OGRFeature *GetFeature( GIntBig nFID ); 00114 00115 virtual OGRFeatureDefn *GetLayerDefn(); 00116 00117 virtual GIntBig 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 /* ndef _OGR_GENSQL_H_INCLUDED */ 00129