LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/sqlite - ogr_sqlite.h (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 29 26 89.7 %
Date: 2013-03-30 Functions: 27 23 85.2 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogr_sqlite.h 25694 2013-03-01 17:26:40Z rouault $
       3                 :  *
       4                 :  * Project:  OpenGIS Simple Features Reference Implementation
       5                 :  * Purpose:  Private definitions for OGR/SQLite driver.
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2004, Frank Warmerdam <warmerdam@pobox.com>
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : 
      30                 : #ifndef _OGR_SQLITE_H_INCLUDED
      31                 : #define _OGR_SQLITE_H_INCLUDED
      32                 : 
      33                 : #include "ogrsf_frmts.h"
      34                 : #include "cpl_error.h"
      35                 : #include <map>
      36                 : #include <set>
      37                 : 
      38                 : #ifdef HAVE_SPATIALITE
      39                 :   #ifdef SPATIALITE_AMALGAMATION
      40                 :     /*
      41                 :     / using an AMALGAMATED version of SpatiaLite
      42                 :     / a private internal copy of SQLite is included:
      43                 :     / so we are required including the SpatiaLite's 
      44                 :     / own header 
      45                 :     /
      46                 :     / IMPORTANT NOTICE: using AMALAGATION is only
      47                 :     / useful on Windows (to skip DLL hell related oddities)
      48                 :     */
      49                 :     #include <spatialite/sqlite3.h>
      50                 :   #else
      51                 :     /*
      52                 :     / You MUST NOT use AMALGAMATION on Linux or any
      53                 :     / other "sane" operating system !!!!
      54                 :     */
      55                 :     #include "sqlite3.h"
      56                 :   #endif
      57                 : #else
      58                 : #include "sqlite3.h"
      59                 : #endif
      60                 : 
      61                 : #if SQLITE_VERSION_NUMBER >= 3006000
      62                 : #define HAVE_SQLITE_VFS
      63                 : #define HAVE_SQLITE3_PREPARE_V2
      64                 : #endif
      65                 : 
      66                 : #define UNINITIALIZED_SRID  -2
      67                 : 
      68                 : int OGRSQLiteIsSpatialiteLoaded();
      69                 : int OGRSQLiteGetSpatialiteVersionNumber();
      70                 : 
      71                 : /************************************************************************/
      72                 : /*      Format used to store geometry data in the database.             */
      73                 : /************************************************************************/
      74                 : 
      75                 : enum OGRSQLiteGeomFormat
      76                 : {
      77                 :     OSGF_None = 0,
      78                 :     OSGF_WKT = 1,
      79                 :     OSGF_WKB = 2,
      80                 :     OSGF_FGF = 3,
      81                 :     OSGF_SpatiaLite = 4
      82                 : };
      83                 : 
      84                 : /************************************************************************/
      85                 : /*      SpatiaLite's own Geometry type IDs.                             */
      86                 : /************************************************************************/
      87                 : 
      88                 : enum OGRSpatialiteGeomType
      89                 : {
      90                 : // 2D [XY]
      91                 :     OGRSplitePointXY                     = 1,
      92                 :     OGRSpliteLineStringXY                = 2,
      93                 :     OGRSplitePolygonXY                   = 3,
      94                 :     OGRSpliteMultiPointXY                = 4,
      95                 :     OGRSpliteMultiLineStringXY           = 5,
      96                 :     OGRSpliteMultiPolygonXY              = 6,
      97                 :     OGRSpliteGeometryCollectionXY        = 7,
      98                 : // 3D [XYZ]
      99                 :     OGRSplitePointXYZ                    = 1001,
     100                 :     OGRSpliteLineStringXYZ               = 1002,
     101                 :     OGRSplitePolygonXYZ                  = 1003,
     102                 :     OGRSpliteMultiPointXYZ               = 1004,
     103                 :     OGRSpliteMultiLineStringXYZ          = 1005,
     104                 :     OGRSpliteMultiPolygonXYZ             = 1006,
     105                 :     OGRSpliteGeometryCollectionXYZ       = 1007,
     106                 : // 2D with Measure [XYM] 
     107                 :     OGRSplitePointXYM                    = 2001,
     108                 :     OGRSpliteLineStringXYM               = 2002,
     109                 :     OGRSplitePolygonXYM                  = 2003,
     110                 :     OGRSpliteMultiPointXYM               = 2004,
     111                 :     OGRSpliteMultiLineStringXYM          = 2005,
     112                 :     OGRSpliteMultiPolygonXYM             = 2006,
     113                 :     OGRSpliteGeometryCollectionXYM       = 2007,
     114                 : // 3D with Measure [XYZM]
     115                 :     OGRSplitePointXYZM                   = 3001,
     116                 :     OGRSpliteLineStringXYZM              = 3002,
     117                 :     OGRSplitePolygonXYZM                 = 3003,
     118                 :     OGRSpliteMultiPointXYZM              = 3004,
     119                 :     OGRSpliteMultiLineStringXYZM         = 3005,
     120                 :     OGRSpliteMultiPolygonXYZM            = 3006,
     121                 :     OGRSpliteGeometryCollectionXYZM      = 3007,
     122                 : // COMPRESSED: 2D [XY]
     123                 :     OGRSpliteComprLineStringXY           = 1000002,
     124                 :     OGRSpliteComprPolygonXY              = 1000003,
     125                 :     OGRSpliteComprMultiPointXY           = 1000004,
     126                 :     OGRSpliteComprMultiLineStringXY      = 1000005,
     127                 :     OGRSpliteComprMultiPolygonXY         = 1000006,
     128                 :     OGRSpliteComprGeometryCollectionXY   = 1000007,
     129                 : // COMPRESSED: 3D [XYZ]
     130                 :     OGRSpliteComprLineStringXYZ          = 1001002,
     131                 :     OGRSpliteComprPolygonXYZ             = 1001003,
     132                 :     OGRSpliteComprMultiPointXYZ          = 1001004,
     133                 :     OGRSpliteComprMultiLineStringXYZ     = 1001005,
     134                 :     OGRSpliteComprMultiPolygonXYZ        = 1001006,
     135                 :     OGRSpliteComprGeometryCollectionXYZ  = 1001007,
     136                 : // COMPRESSED: 2D with Measure [XYM]
     137                 :     OGRSpliteComprLineStringXYM          = 1002002,
     138                 :     OGRSpliteComprPolygonXYM             = 1002003,
     139                 :     OGRSpliteComprMultiPointXYM          = 1002004,
     140                 :     OGRSpliteComprMultiLineStringXYM     = 1002005,
     141                 :     OGRSpliteComprMultiPolygonXYM        = 1002006,
     142                 :     OGRSpliteComprGeometryCollectionXYM  = 1002007,
     143                 : // COMPRESSED: 3D with Measure [XYZM]
     144                 :     OGRSpliteComprLineStringXYZM         = 1003002,
     145                 :     OGRSpliteComprPolygonXYZM            = 1003003,
     146                 :     OGRSpliteComprMultiPointXYZM         = 1003004,
     147                 :     OGRSpliteComprMultiLineStringXYZM    = 1003005,
     148                 :     OGRSpliteComprMultiPolygonXYZM       = 1003006,
     149                 :     OGRSpliteComprGeometryCollectionXYZM = 1003007
     150                 : };
     151                 : 
     152                 : /************************************************************************/
     153                 : /*                            OGRSQLiteLayer                            */
     154                 : /************************************************************************/
     155                 : 
     156                 : class OGRSQLiteDataSource;
     157                 :     
     158                 : class OGRSQLiteLayer : public OGRLayer
     159                 : {
     160                 :   private:
     161                 :     static OGRErr       createFromSpatialiteInternal(const GByte *pabyData,
     162                 :                                                      OGRGeometry **ppoReturn,
     163                 :                                                      int nBytes,
     164                 :                                                      OGRwkbByteOrder eByteOrder,
     165                 :                                                      int* pnBytesConsumed,
     166                 :                                                      int nRecLevel);
     167                 : 
     168                 :     static int          CanBeCompressedSpatialiteGeometry(const OGRGeometry *poGeometry);
     169                 : 
     170                 :     static int          ComputeSpatiaLiteGeometrySize(const OGRGeometry *poGeometry,
     171                 :                                                       int bHasM, int bSpatialite2D,
     172                 :                                                       int bUseComprGeom );
     173                 : 
     174                 :     static int          GetSpatialiteGeometryCode(const OGRGeometry *poGeometry,
     175                 :                                                   int bHasM, int bSpatialite2D,
     176                 :                                                   int bUseComprGeom,
     177                 :                                                   int bAcceptMultiGeom);
     178                 : 
     179                 :     static int          ExportSpatiaLiteGeometryInternal(const OGRGeometry *poGeometry,
     180                 :                                                         OGRwkbByteOrder eByteOrder,
     181                 :                                                         int bHasM, int bSpatialite2D,
     182                 :                                                         int bUseComprGeom,
     183                 :                                                         GByte* pabyData );
     184                 : 
     185                 :   protected:
     186                 :     OGRFeatureDefn     *poFeatureDefn;
     187                 : 
     188                 :     // Layer spatial reference system, and srid.
     189                 :     OGRSpatialReference *poSRS;
     190                 :     int                 nSRSId;
     191                 : 
     192                 :     int                 iNextShapeId;
     193                 : 
     194                 :     sqlite3_stmt        *hStmt;
     195                 :     int                  bDoStep;
     196                 : 
     197                 :     OGRSQLiteDataSource *poDS;
     198                 : 
     199                 :     int                 bTriedAsSpatiaLite;
     200                 :     CPLString           osGeomColumn;
     201                 :     OGRSQLiteGeomFormat eGeomFormat;
     202                 : 
     203                 :     char                *pszFIDColumn;
     204                 : 
     205                 :     int                *panFieldOrdinals;
     206                 :     int                 iFIDCol;
     207                 :     int                 iGeomCol;
     208                 : 
     209                 :     int                 bHasSpatialIndex;
     210                 :     int                 bHasM;
     211                 : 
     212                 :     int                 bIsVirtualShape;
     213                 : 
     214                 :     void                BuildFeatureDefn( const char *pszLayerName,
     215                 :                                           sqlite3_stmt *hStmt,
     216                 :                                           const std::set<CPLString>& aosGeomCols);
     217                 : 
     218                 :     void                ClearStatement();
     219                 :     virtual OGRErr      ResetStatement() = 0;
     220                 : 
     221                 :     int                 bUseComprGeom;
     222                 : 
     223                 :     char              **papszCompressedColumns;
     224                 : 
     225                 :   public:
     226                 :                         OGRSQLiteLayer();
     227                 :     virtual             ~OGRSQLiteLayer();
     228                 : 
     229                 :     virtual void        Finalize();
     230                 : 
     231                 :     virtual void        ResetReading();
     232                 :     virtual OGRFeature *GetNextRawFeature();
     233                 :     virtual OGRFeature *GetNextFeature();
     234                 : 
     235                 :     virtual OGRFeature *GetFeature( long nFeatureId );
     236                 :     
     237              87 :     virtual OGRFeatureDefn *GetLayerDefn() { return poFeatureDefn; }
     238                 : 
     239                 :     virtual OGRSpatialReference *GetSpatialRef();
     240                 : 
     241                 :     virtual const char *GetFIDColumn();
     242                 :     virtual const char *GetGeometryColumn();
     243                 : 
     244                 :     virtual int         TestCapability( const char * );
     245                 : 
     246                 :     virtual OGRErr       StartTransaction();
     247                 :     virtual OGRErr       CommitTransaction();
     248                 :     virtual OGRErr       RollbackTransaction();
     249                 : 
     250               1 :     virtual void        InvalidateCachedFeatureCountAndExtent() { }
     251                 : 
     252              10 :     virtual int          IsTableLayer() { return FALSE; }
     253                 : 
     254               0 :     virtual int          HasSpatialIndex() { return bHasSpatialIndex; }
     255                 : 
     256               0 :     virtual CPLString     GetSpatialWhere(OGRGeometry* poFilterGeom) { return ""; }
     257                 : 
     258                 :     static OGRErr       ImportSpatiaLiteGeometry( const GByte *, int,
     259                 :                                                   OGRGeometry ** );
     260                 :     static OGRErr       ImportSpatiaLiteGeometry( const GByte *, int,
     261                 :                                                   OGRGeometry **, int *pnSRID );
     262                 :     static OGRErr       ExportSpatiaLiteGeometry( const OGRGeometry *,
     263                 :                                                   GInt32, OGRwkbByteOrder,
     264                 :                                                   int, int, int bUseComprGeom, GByte **, int * );
     265                 : 
     266                 : };
     267                 : 
     268                 : /************************************************************************/
     269                 : /*                         OGRSQLiteTableLayer                          */
     270                 : /************************************************************************/
     271                 : 
     272                 : class OGRSQLiteTableLayer : public OGRSQLiteLayer
     273                 : {
     274                 :     int                 bLaunderColumnNames;
     275                 :     int                 bSpatialite2D;
     276                 : 
     277                 :     CPLString           osWHERE;
     278                 :     CPLString           osQuery;
     279                 :     int                 bHasCheckedSpatialIndexTable;
     280                 :     int                 bDeferedSpatialIndexCreation;
     281                 : 
     282                 :     OGRwkbGeometryType  eGeomType;
     283                 : 
     284                 :     char               *pszTableName;
     285                 :     char               *pszEscapedTableName;
     286                 :     CPLString           osLayerName;
     287                 : 
     288                 :     int                 bLayerDefnError;
     289                 : 
     290                 :     sqlite3_stmt       *hInsertStmt;
     291                 :     CPLString           osLastInsertStmt;
     292                 : 
     293                 :     void                ClearInsertStmt();
     294                 : 
     295                 :     void                BuildWhere(void);
     296                 : 
     297                 :     virtual OGRErr      ResetStatement();
     298                 : 
     299                 :     OGRErr              AddColumnAncientMethod( OGRFieldDefn& oField);
     300                 : 
     301                 :     void                InitFieldListForRecrerate(char* & pszNewFieldList,
     302                 :                                                   char* & pszFieldListForSelect,
     303                 :                                                   int nExtraSpace = 0);
     304                 :     OGRErr              RecreateTable(const char* pszFieldListForSelect,
     305                 :                                       const char* pszNewFieldList,
     306                 :                                       const char* pszGenericErrorMessage);
     307                 :     OGRErr              BindValues( OGRFeature *poFeature,
     308                 :                                         sqlite3_stmt* hStmt,
     309                 :                                         int bBindNullValues );
     310                 : 
     311                 :     int                 CheckSpatialIndexTable();
     312                 : 
     313                 :     CPLErr              EstablishFeatureDefn();
     314                 : 
     315                 :     int                 bStatisticsNeedsToBeFlushed;
     316                 :     OGREnvelope         oCachedExtent;
     317                 :     int                 bCachedExtentIsValid;
     318                 :     GIntBig             nFeatureCount; /* if -1, means not up-to-date */
     319                 : 
     320                 :     void                LoadStatistics();
     321                 :     void                LoadStatisticsSpatialite4DB();
     322                 : 
     323                 :     CPLString           FieldDefnToSQliteFieldDefn( OGRFieldDefn* poFieldDefn );
     324                 : 
     325                 :   public:
     326                 :                         OGRSQLiteTableLayer( OGRSQLiteDataSource * );
     327                 :                         ~OGRSQLiteTableLayer();
     328                 : 
     329                 :     CPLErr              Initialize( const char *pszTableName, 
     330                 :                                     const char *pszGeomCol,
     331                 :                                     int bMustIncludeGeomColName,
     332                 :                                     OGRwkbGeometryType eGeomType,
     333                 :                                     const char *pszGeomFormat,
     334                 :                                     OGRSpatialReference *poSRS,
     335                 :                                     int nSRSId = UNINITIALIZED_SRID,
     336                 :                                     int bHasSpatialIndex = FALSE,
     337                 :                                     int bHasM = FALSE,
     338                 :                                     int bIsVirtualShapeIn = FALSE);
     339                 : 
     340                 :     virtual const char* GetName();
     341              56 :     virtual OGRwkbGeometryType GetGeomType() { return (eGeomType != wkbUnknown) ? eGeomType : OGRLayer::GetGeomType(); }
     342                 : 
     343                 :     virtual int         GetFeatureCount( int );
     344                 :     virtual OGRErr      GetExtent(OGREnvelope *psExtent, int bForce);
     345                 : 
     346                 :     virtual OGRFeatureDefn *GetLayerDefn();
     347            1943 :     int                 HasLayerDefnError() { GetLayerDefn(); return bLayerDefnError; }
     348                 : 
     349                 :     virtual void        SetSpatialFilter( OGRGeometry * );
     350                 :     virtual OGRErr      SetAttributeFilter( const char * );
     351                 :     virtual OGRErr      SetFeature( OGRFeature *poFeature );
     352                 :     virtual OGRErr      DeleteFeature( long nFID );
     353                 :     virtual OGRErr      CreateFeature( OGRFeature *poFeature );
     354                 : 
     355                 :     virtual OGRErr      CreateField( OGRFieldDefn *poField,
     356                 :                                      int bApproxOK = TRUE );
     357                 :     virtual OGRErr      DeleteField( int iField );
     358                 :     virtual OGRErr      ReorderFields( int* panMap );
     359                 :     virtual OGRErr      AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags );
     360                 : 
     361                 :     virtual OGRFeature *GetNextFeature();
     362                 :     virtual OGRFeature *GetFeature( long nFeatureId );
     363                 : 
     364                 :     virtual int         TestCapability( const char * );
     365                 : 
     366                 :     // follow methods are not base class overrides
     367             120 :     void                SetLaunderFlag( int bFlag ) 
     368             120 :                                 { bLaunderColumnNames = bFlag; }
     369              32 :     void                SetUseCompressGeom( int bFlag )
     370              32 :                                 { bUseComprGeom = bFlag; }
     371              70 :     void                SetDeferedSpatialIndexCreation( int bFlag )
     372              70 :                                 { bDeferedSpatialIndexCreation = bFlag; }
     373                 :     void                SetCompressedColumns( const char* pszCompressedColumns );
     374                 : 
     375                 :     int                 CreateSpatialIndex();
     376                 : 
     377                 :     void                CreateSpatialIndexIfNecessary();
     378                 : 
     379                 :     void                InitFeatureCount();
     380                 :     int                 DoStatisticsNeedToBeFlushed();
     381                 :     void                ForceStatisticsToBeFlushed();
     382                 :     int                 AreStatisticsValid();
     383                 :     int                 SaveStatistics();
     384                 : 
     385                 :     virtual void        InvalidateCachedFeatureCountAndExtent();
     386                 : 
     387             988 :     virtual int          IsTableLayer() { return TRUE; }
     388                 : 
     389                 :     virtual int          HasSpatialIndex();
     390                 : 
     391                 :     virtual CPLString    GetSpatialWhere(OGRGeometry* poFilterGeom);
     392                 : };
     393                 : 
     394                 : /************************************************************************/
     395                 : /*                         OGRSQLiteViewLayer                           */
     396                 : /************************************************************************/
     397                 : 
     398                 : class OGRSQLiteViewLayer : public OGRSQLiteLayer
     399                 : {
     400                 :     CPLString           osWHERE;
     401                 :     CPLString           osQuery;
     402                 :     int                 bHasCheckedSpatialIndexTable;
     403                 : 
     404                 :     char               *pszViewName;
     405                 :     char               *pszEscapedTableName;
     406                 :     char               *pszEscapedUnderlyingTableName;
     407                 : 
     408                 :     int                 bLayerDefnError;
     409                 : 
     410                 :     CPLString           osUnderlyingTableName;
     411                 :     CPLString           osUnderlyingGeometryColumn;
     412                 : 
     413                 :     OGRSQLiteLayer     *poUnderlyingLayer;
     414                 :     OGRSQLiteLayer     *GetUnderlyingLayer();
     415                 : 
     416                 :     void                BuildWhere(void);
     417                 : 
     418                 :     virtual OGRErr      ResetStatement();
     419                 : 
     420                 :     CPLErr              EstablishFeatureDefn();
     421                 : 
     422                 :   public:
     423                 :                         OGRSQLiteViewLayer( OGRSQLiteDataSource * );
     424                 :                         ~OGRSQLiteViewLayer();
     425                 : 
     426               9 :     virtual const char* GetName() { return pszViewName; }
     427                 :     virtual OGRwkbGeometryType GetGeomType();
     428                 : 
     429                 :     CPLErr              Initialize( const char *pszViewName,
     430                 :                                     const char *pszViewGeometry,
     431                 :                                     const char *pszViewRowid,
     432                 :                                     const char *pszTableName,
     433                 :                                     const char *pszGeometryColumn);
     434                 : 
     435                 :     virtual OGRFeatureDefn *GetLayerDefn();
     436              20 :     int                 HasLayerDefnError() { GetLayerDefn(); return bLayerDefnError; }
     437                 : 
     438                 :     virtual OGRFeature *GetNextFeature();
     439                 :     virtual int         GetFeatureCount( int );
     440                 : 
     441                 :     virtual void        SetSpatialFilter( OGRGeometry * );
     442                 :     virtual OGRErr      SetAttributeFilter( const char * );
     443                 : 
     444                 :     virtual OGRFeature *GetFeature( long nFeatureId );
     445                 : 
     446                 :     virtual int         TestCapability( const char * );
     447                 : 
     448                 :     virtual OGRSpatialReference *GetSpatialRef();
     449                 : 
     450                 :     virtual CPLString    GetSpatialWhere(OGRGeometry* poFilterGeom);
     451                 : };
     452                 : 
     453                 : /************************************************************************/
     454                 : /*                         OGRSQLiteSelectLayer                         */
     455                 : /************************************************************************/
     456                 : 
     457                 : class OGRSQLiteSelectLayer : public OGRSQLiteLayer
     458             807 : {
     459                 :     CPLString           osSQLBase;
     460                 :     CPLString           osSQLCurrent;
     461                 : 
     462                 :     int                 bEmptyLayer;
     463                 :     int                 bSpatialFilterInSQL;
     464                 : 
     465                 :     virtual OGRErr      ResetStatement();
     466                 : 
     467                 :     OGRSQLiteLayer     *GetBaseLayer(size_t& i);
     468                 :     int                 RebuildSQLWithSpatialClause();
     469                 : 
     470                 :     int                 bAllowResetReadingEvenIfIndexAtZero;
     471                 :  
     472                 :   public:
     473                 :                         OGRSQLiteSelectLayer( OGRSQLiteDataSource *, 
     474                 :                                               CPLString osSQL,
     475                 :                                               sqlite3_stmt *,
     476                 :                                               int bUseStatementForGetNextFeature,
     477                 :                                               int bEmptyLayer );
     478                 : 
     479                 :     virtual void        ResetReading();
     480                 : 
     481                 :     virtual OGRFeature *GetNextFeature();
     482                 :     virtual int         GetFeatureCount( int );
     483                 : 
     484                 :     virtual void        SetSpatialFilter( OGRGeometry * );
     485                 : 
     486                 :     virtual int         TestCapability( const char * );
     487                 : 
     488                 :     virtual OGRErr      GetExtent(OGREnvelope *psExtent, int bForce);
     489                 : };
     490                 : 
     491                 : /************************************************************************/
     492                 : /*                   OGRSQLiteSingleFeatureLayer                        */
     493                 : /************************************************************************/
     494                 : 
     495                 : class OGRSQLiteSingleFeatureLayer : public OGRLayer
     496                 : {
     497                 :   private:
     498                 :     int                 nVal;
     499                 :     char               *pszVal;
     500                 :     OGRFeatureDefn     *poFeatureDefn;
     501                 :     int                 iNextShapeId;
     502                 : 
     503                 :   public:
     504                 :                         OGRSQLiteSingleFeatureLayer( const char* pszLayerName,
     505                 :                                                      int nVal );
     506                 :                         OGRSQLiteSingleFeatureLayer( const char* pszLayerName,
     507                 :                                                      const char *pszVal );
     508                 :                         ~OGRSQLiteSingleFeatureLayer();
     509                 : 
     510                 :     virtual void        ResetReading();
     511                 :     virtual OGRFeature *GetNextFeature();
     512                 :     virtual OGRFeatureDefn *GetLayerDefn();
     513                 :     virtual int         TestCapability( const char * );
     514                 : };
     515                 : 
     516                 : /************************************************************************/
     517                 : /*                         OGRSQLiteDataSource                          */
     518                 : /************************************************************************/
     519                 : 
     520                 : class OGRSQLiteDataSource : public OGRDataSource
     521                 : {
     522                 :     OGRSQLiteLayer    **papoLayers;
     523                 :     int                 nLayers;
     524                 :     
     525                 :     char               *pszName;
     526                 : 
     527                 :     sqlite3             *hDB;
     528                 :     int                 bUpdate;
     529                 : 
     530                 :     int                 nSoftTransactionLevel;
     531                 : 
     532                 :     // We maintain a list of known SRID to reduce the number of trips to
     533                 :     // the database to get SRSes. 
     534                 :     int                 nKnownSRID;
     535                 :     int                *panSRID;
     536                 :     OGRSpatialReference **papoSRS;
     537                 :     void                AddSRIDToCache(int nId, OGRSpatialReference * poSRS );
     538                 : 
     539                 :     int                 bHaveGeometryColumns;
     540                 :     int                 bIsSpatiaLiteDB;
     541                 :     int                 bSpatialite4Layout;
     542                 : 
     543                 :     int                 nUndefinedSRID;
     544                 : 
     545                 :     virtual void        DeleteLayer( const char *pszLayer );
     546                 : 
     547                 :     const char*         GetSRTEXTColName();
     548                 : 
     549                 :     int                 OpenOrCreateDB(int flags);
     550                 :     int                 InitWithEPSG();
     551                 :     int                 SetSynchronous();
     552                 :     int                 SetCacheSize();
     553                 : 
     554                 :     int                 OpenVirtualTable(const char* pszName, const char* pszSQL);
     555                 : 
     556                 : #ifdef HAVE_SQLITE_VFS
     557                 :     sqlite3_vfs*        pMyVFS;
     558                 : #endif
     559                 : 
     560                 :     VSILFILE*           fpMainFile; /* Set by the VFS layer when it opens the DB */
     561                 :                                     /* Must *NOT* be closed by the datasource explicitely. */
     562                 :     GIntBig             nFileTimestamp;
     563                 :     int                 bLastSQLCommandIsUpdateLayerStatistics;
     564                 : 
     565                 :     std::map<CPLString, OGREnvelope> oMapSQLEnvelope;
     566                 : 
     567                 :     std::map< CPLString, std::set<CPLString> > aoMapTableToSetOfGeomCols;
     568                 : 
     569                 :     void                SaveStatistics();
     570                 : 
     571                 :   public:
     572                 :                         OGRSQLiteDataSource();
     573                 :                         ~OGRSQLiteDataSource();
     574                 : 
     575                 :     int                 Open( const char *, int bUpdateIn );
     576                 :     int                 Create( const char *, char **papszOptions );
     577                 : 
     578                 :     int                 OpenTable( const char *pszTableName, 
     579                 :                                    const char *pszGeomCol = NULL,
     580                 :                                    int bMustIncludeGeomColName = FALSE,
     581                 :                                    OGRwkbGeometryType eGeomType = wkbUnknown,
     582                 :                                    const char *pszGeomFormat = NULL,
     583                 :                                    OGRSpatialReference *poSRS = NULL,
     584                 :                                    int nSRID = UNINITIALIZED_SRID,
     585                 :                                    int bHasSpatialIndex = FALSE,
     586                 :                                    int bHasM = FALSE,
     587                 :                                    int bIsVirtualShapeIn = FALSE );
     588                 :     int                  OpenView( const char *pszViewName,
     589                 :                                    const char *pszViewGeometry,
     590                 :                                    const char *pszViewRowid,
     591                 :                                    const char *pszTableName,
     592                 :                                    const char *pszGeometryColumn);
     593                 : 
     594             263 :     virtual const char *GetName() { return pszName; }
     595            1087 :     virtual int         GetLayerCount() { return nLayers; }
     596                 :     virtual OGRLayer   *GetLayer( int );
     597                 :     virtual OGRLayer   *GetLayerByName( const char* );
     598                 : 
     599                 :     virtual OGRLayer    *CreateLayer( const char *pszLayerName, 
     600                 :                                       OGRSpatialReference *poSRS, 
     601                 :                                       OGRwkbGeometryType eType, 
     602                 :                                       char **papszOptions );
     603                 :     virtual OGRErr      DeleteLayer(int);
     604                 : 
     605                 :     virtual int         TestCapability( const char * );
     606                 : 
     607                 :     virtual OGRLayer *  ExecuteSQL( const char *pszSQLCommand,
     608                 :                                     OGRGeometry *poSpatialFilter,
     609                 :                                     const char *pszDialect );
     610                 :     virtual void        ReleaseResultSet( OGRLayer * poLayer );
     611                 : 
     612                 :     OGRErr              SoftStartTransaction();
     613                 :     OGRErr              SoftCommit();
     614                 :     OGRErr              SoftRollback();
     615                 :     
     616                 :     OGRErr              FlushSoftTransaction();
     617                 : 
     618            5100 :     sqlite3            *GetDB() { return hDB; }
     619                 : 
     620                 :     char               *LaunderName( const char * );
     621                 :     int                 FetchSRSId( OGRSpatialReference * poSRS );
     622                 :     OGRSpatialReference*FetchSRS( int nSRID );
     623                 : 
     624             625 :     int                 GetUpdate() const { return bUpdate; }
     625               0 :     void                SetUpdate(int bUpdateIn) { bUpdate = bUpdateIn; }
     626                 : 
     627                 :     void                SetName(const char* pszNameIn);
     628                 : 
     629                 :     void                NotifyFileOpened (const char* pszFilename,
     630                 :                                           VSILFILE* fp);
     631                 : 
     632                 :     const OGREnvelope*  GetEnvelopeFromSQL(const CPLString& osSQL);
     633                 :     void                SetEnvelopeForSQL(const CPLString& osSQL, const OGREnvelope& oEnvelope);
     634                 : 
     635             431 :     const std::set<CPLString>& GetGeomColsForTable(const char* pszTableName)
     636             431 :             { return aoMapTableToSetOfGeomCols[pszTableName]; }
     637                 : 
     638             406 :     GIntBig             GetFileTimestamp() const { return nFileTimestamp; }
     639                 :     
     640            1036 :     int                 IsSpatialiteDB() const { return bIsSpatiaLiteDB; }
     641             480 :     int                 HasSpatialite4Layout() const { return bSpatialite4Layout; }
     642                 : 
     643             573 :     int                 GetUndefinedSRID() const { return nUndefinedSRID; }
     644                 : 
     645                 :     void                ReloadLayers();
     646                 : };
     647                 : 
     648                 : /************************************************************************/
     649                 : /*                           OGRSQLiteDriver                            */
     650                 : /************************************************************************/
     651                 : 
     652                 : class OGRSQLiteDriver : public OGRSFDriver
     653             244 : {
     654                 :   public:
     655                 :                 ~OGRSQLiteDriver();
     656                 :                 
     657                 :     const char *GetName();
     658                 :     OGRDataSource *Open( const char *, int );
     659                 : 
     660                 :     virtual OGRDataSource *CreateDataSource( const char *pszName,
     661                 :                                              char ** = NULL );
     662                 :     virtual OGRErr      DeleteDataSource( const char *pszName );
     663                 :     
     664                 :     int                 TestCapability( const char * );
     665                 : };
     666                 : 
     667                 : /* To escape literals. The returned string doesn't contain the surrounding single quotes */
     668                 : CPLString OGRSQLiteEscape( const char *pszLiteral );
     669                 : 
     670                 : /* To escape table or field names. The returned string doesn't contain the surrounding double quotes */
     671                 : CPLString OGRSQLiteEscapeName( const char* pszName );
     672                 : 
     673                 : CPLString OGRSQLiteParamsUnquote(const char* pszVal);
     674                 : 
     675                 : CPLString OGRSQLiteFieldDefnToSQliteFieldDefn( OGRFieldDefn* poFieldDefn );
     676                 : 
     677                 : int OGRSQLITEStringToDateTimeField( OGRFeature* poFeature, int iField,
     678                 :                                     const char* pszValue );
     679                 : 
     680                 : #ifdef HAVE_SQLITE_VFS
     681                 : typedef void (*pfnNotifyFileOpenedType)(void* pfnUserData, const char* pszFilename, VSILFILE* fp);
     682                 : sqlite3_vfs* OGRSQLiteCreateVFS(pfnNotifyFileOpenedType pfn, void* pfnUserData);
     683                 : #endif
     684                 : 
     685                 : void OGRSQLiteRegisterInflateDeflate(sqlite3* hDB);
     686                 : 
     687                 : #endif /* ndef _OGR_SQLITE_H_INCLUDED */
     688                 : 
     689                 : 

Generated by: LCOV version 1.7