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: 2012-12-26 Functions: 27 23 85.2 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogr_sqlite.h 25129 2012-10-14 22:05:58Z 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                 :   public:
     224                 :                         OGRSQLiteLayer();
     225                 :     virtual             ~OGRSQLiteLayer();
     226                 : 
     227                 :     virtual void        Finalize();
     228                 : 
     229                 :     virtual void        ResetReading();
     230                 :     virtual OGRFeature *GetNextRawFeature();
     231                 :     virtual OGRFeature *GetNextFeature();
     232                 : 
     233                 :     virtual OGRFeature *GetFeature( long nFeatureId );
     234                 :     
     235              87 :     virtual OGRFeatureDefn *GetLayerDefn() { return poFeatureDefn; }
     236                 : 
     237                 :     virtual OGRSpatialReference *GetSpatialRef();
     238                 : 
     239                 :     virtual const char *GetFIDColumn();
     240                 :     virtual const char *GetGeometryColumn();
     241                 : 
     242                 :     virtual int         TestCapability( const char * );
     243                 : 
     244                 :     virtual OGRErr       StartTransaction();
     245                 :     virtual OGRErr       CommitTransaction();
     246                 :     virtual OGRErr       RollbackTransaction();
     247                 : 
     248               1 :     virtual void        InvalidateCachedFeatureCountAndExtent() { }
     249                 : 
     250              10 :     virtual int          IsTableLayer() { return FALSE; }
     251                 : 
     252               0 :     virtual int          HasSpatialIndex() { return bHasSpatialIndex; }
     253                 : 
     254               0 :     virtual CPLString     GetSpatialWhere(OGRGeometry* poFilterGeom) { return ""; }
     255                 : 
     256                 :     static OGRErr       ImportSpatiaLiteGeometry( const GByte *, int,
     257                 :                                                   OGRGeometry ** );
     258                 :     static OGRErr       ExportSpatiaLiteGeometry( const OGRGeometry *,
     259                 :                                                   GInt32, OGRwkbByteOrder,
     260                 :                                                   int, int, int bUseComprGeom, GByte **, int * );
     261                 : 
     262                 : };
     263                 : 
     264                 : /************************************************************************/
     265                 : /*                         OGRSQLiteTableLayer                          */
     266                 : /************************************************************************/
     267                 : 
     268                 : class OGRSQLiteTableLayer : public OGRSQLiteLayer
     269                 : {
     270                 :     int                 bLaunderColumnNames;
     271                 :     int                 bSpatialite2D;
     272                 : 
     273                 :     CPLString           osWHERE;
     274                 :     CPLString           osQuery;
     275                 :     int                 bHasCheckedSpatialIndexTable;
     276                 :     int                 bDeferedSpatialIndexCreation;
     277                 : 
     278                 :     OGRwkbGeometryType  eGeomType;
     279                 : 
     280                 :     char               *pszTableName;
     281                 :     char               *pszEscapedTableName;
     282                 :     CPLString           osLayerName;
     283                 : 
     284                 :     int                 bLayerDefnError;
     285                 : 
     286                 :     sqlite3_stmt       *hInsertStmt;
     287                 :     CPLString           osLastInsertStmt;
     288                 :     void                ClearInsertStmt();
     289                 : 
     290                 :     void                BuildWhere(void);
     291                 : 
     292                 :     virtual OGRErr      ResetStatement();
     293                 : 
     294                 :     OGRErr              AddColumnAncientMethod( OGRFieldDefn& oField);
     295                 : 
     296                 :     void                InitFieldListForRecrerate(char* & pszNewFieldList,
     297                 :                                                   char* & pszFieldListForSelect,
     298                 :                                                   int nExtraSpace = 0);
     299                 :     OGRErr              RecreateTable(const char* pszFieldListForSelect,
     300                 :                                       const char* pszNewFieldList,
     301                 :                                       const char* pszGenericErrorMessage);
     302                 :     OGRErr              BindValues( OGRFeature *poFeature,
     303                 :                                         sqlite3_stmt* hStmt,
     304                 :                                         int bBindNullValues );
     305                 : 
     306                 :     int                 CheckSpatialIndexTable();
     307                 : 
     308                 :     CPLErr              EstablishFeatureDefn();
     309                 : 
     310                 :     int                 bStatisticsNeedsToBeFlushed;
     311                 :     OGREnvelope         oCachedExtent;
     312                 :     int                 bCachedExtentIsValid;
     313                 :     GIntBig             nFeatureCount; /* if -1, means not up-to-date */
     314                 : 
     315                 :     void                LoadStatistics();
     316                 :     void                LoadStatisticsSpatialite4DB();
     317                 : 
     318                 :   public:
     319                 :                         OGRSQLiteTableLayer( OGRSQLiteDataSource * );
     320                 :                         ~OGRSQLiteTableLayer();
     321                 : 
     322                 :     CPLErr              Initialize( const char *pszTableName, 
     323                 :                                     const char *pszGeomCol,
     324                 :                                     int bMustIncludeGeomColName,
     325                 :                                     OGRwkbGeometryType eGeomType,
     326                 :                                     const char *pszGeomFormat,
     327                 :                                     OGRSpatialReference *poSRS,
     328                 :                                     int nSRSId = UNINITIALIZED_SRID,
     329                 :                                     int bHasSpatialIndex = FALSE,
     330                 :                                     int bHasM = FALSE,
     331                 :                                     int bIsVirtualShapeIn = FALSE);
     332                 : 
     333                 :     virtual const char* GetName();
     334              56 :     virtual OGRwkbGeometryType GetGeomType() { return (eGeomType != wkbUnknown) ? eGeomType : OGRLayer::GetGeomType(); }
     335                 : 
     336                 :     virtual int         GetFeatureCount( int );
     337                 :     virtual OGRErr      GetExtent(OGREnvelope *psExtent, int bForce);
     338                 : 
     339                 :     virtual OGRFeatureDefn *GetLayerDefn();
     340            1854 :     int                 HasLayerDefnError() { GetLayerDefn(); return bLayerDefnError; }
     341                 : 
     342                 :     virtual void        SetSpatialFilter( OGRGeometry * );
     343                 :     virtual OGRErr      SetAttributeFilter( const char * );
     344                 :     virtual OGRErr      SetFeature( OGRFeature *poFeature );
     345                 :     virtual OGRErr      DeleteFeature( long nFID );
     346                 :     virtual OGRErr      CreateFeature( OGRFeature *poFeature );
     347                 : 
     348                 :     virtual OGRErr      CreateField( OGRFieldDefn *poField,
     349                 :                                      int bApproxOK = TRUE );
     350                 :     virtual OGRErr      DeleteField( int iField );
     351                 :     virtual OGRErr      ReorderFields( int* panMap );
     352                 :     virtual OGRErr      AlterFieldDefn( int iField, OGRFieldDefn* poNewFieldDefn, int nFlags );
     353                 : 
     354                 :     virtual OGRFeature *GetNextFeature();
     355                 :     virtual OGRFeature *GetFeature( long nFeatureId );
     356                 : 
     357                 :     virtual int         TestCapability( const char * );
     358                 : 
     359                 :     // follow methods are not base class overrides
     360             112 :     void                SetLaunderFlag( int bFlag ) 
     361             112 :                                 { bLaunderColumnNames = bFlag; }
     362              32 :     void                SetUseCompressGeom( int bFlag )
     363              32 :                                 { bUseComprGeom = bFlag; }
     364              70 :     void                SetDeferedSpatialIndexCreation( int bFlag )
     365              70 :                                 { bDeferedSpatialIndexCreation = bFlag; }
     366                 :     int                 CreateSpatialIndex();
     367                 : 
     368                 :     void                CreateSpatialIndexIfNecessary();
     369                 : 
     370                 :     void                InitFeatureCount();
     371                 :     int                 DoStatisticsNeedToBeFlushed();
     372                 :     void                ForceStatisticsToBeFlushed();
     373                 :     int                 AreStatisticsValid();
     374                 :     int                 SaveStatistics();
     375                 : 
     376                 :     virtual void        InvalidateCachedFeatureCountAndExtent();
     377                 : 
     378            2378 :     virtual int          IsTableLayer() { return TRUE; }
     379                 : 
     380                 :     virtual int          HasSpatialIndex();
     381                 : 
     382                 :     virtual CPLString    GetSpatialWhere(OGRGeometry* poFilterGeom);
     383                 : };
     384                 : 
     385                 : /************************************************************************/
     386                 : /*                         OGRSQLiteViewLayer                           */
     387                 : /************************************************************************/
     388                 : 
     389                 : class OGRSQLiteViewLayer : public OGRSQLiteLayer
     390                 : {
     391                 :     CPLString           osWHERE;
     392                 :     CPLString           osQuery;
     393                 :     int                 bHasCheckedSpatialIndexTable;
     394                 : 
     395                 :     char               *pszViewName;
     396                 :     char               *pszEscapedTableName;
     397                 :     char               *pszEscapedUnderlyingTableName;
     398                 : 
     399                 :     int                 bLayerDefnError;
     400                 : 
     401                 :     CPLString           osUnderlyingTableName;
     402                 :     CPLString           osUnderlyingGeometryColumn;
     403                 : 
     404                 :     OGRSQLiteLayer     *poUnderlyingLayer;
     405                 :     OGRSQLiteLayer     *GetUnderlyingLayer();
     406                 : 
     407                 :     void                BuildWhere(void);
     408                 : 
     409                 :     virtual OGRErr      ResetStatement();
     410                 : 
     411                 :     CPLErr              EstablishFeatureDefn();
     412                 : 
     413                 :   public:
     414                 :                         OGRSQLiteViewLayer( OGRSQLiteDataSource * );
     415                 :                         ~OGRSQLiteViewLayer();
     416                 : 
     417              17 :     virtual const char* GetName() { return pszViewName; }
     418                 :     virtual OGRwkbGeometryType GetGeomType();
     419                 : 
     420                 :     CPLErr              Initialize( const char *pszViewName,
     421                 :                                     const char *pszViewGeometry,
     422                 :                                     const char *pszViewRowid,
     423                 :                                     const char *pszTableName,
     424                 :                                     const char *pszGeometryColumn);
     425                 : 
     426                 :     virtual OGRFeatureDefn *GetLayerDefn();
     427              20 :     int                 HasLayerDefnError() { GetLayerDefn(); return bLayerDefnError; }
     428                 : 
     429                 :     virtual OGRFeature *GetNextFeature();
     430                 :     virtual int         GetFeatureCount( int );
     431                 : 
     432                 :     virtual void        SetSpatialFilter( OGRGeometry * );
     433                 :     virtual OGRErr      SetAttributeFilter( const char * );
     434                 : 
     435                 :     virtual OGRFeature *GetFeature( long nFeatureId );
     436                 : 
     437                 :     virtual int         TestCapability( const char * );
     438                 : 
     439                 :     virtual OGRSpatialReference *GetSpatialRef();
     440                 : 
     441                 :     virtual CPLString    GetSpatialWhere(OGRGeometry* poFilterGeom);
     442                 : };
     443                 : 
     444                 : /************************************************************************/
     445                 : /*                         OGRSQLiteSelectLayer                         */
     446                 : /************************************************************************/
     447                 : 
     448                 : class OGRSQLiteSelectLayer : public OGRSQLiteLayer
     449             542 : {
     450                 :     CPLString           osSQLBase;
     451                 :     CPLString           osSQLCurrent;
     452                 : 
     453                 :     int                 bEmptyLayer;
     454                 :     int                 bSpatialFilterInSQL;
     455                 : 
     456                 :     virtual OGRErr      ResetStatement();
     457                 : 
     458                 :     OGRSQLiteLayer     *GetBaseLayer(size_t& i);
     459                 :     int                 RebuildSQLWithSpatialClause();
     460                 : 
     461                 :   public:
     462                 :                         OGRSQLiteSelectLayer( OGRSQLiteDataSource *, 
     463                 :                                               CPLString osSQL,
     464                 :                                               sqlite3_stmt *,
     465                 :                                               int bUseStatementForGetNextFeature,
     466                 :                                               int bEmptyLayer );
     467                 : 
     468                 :     virtual OGRFeature *GetNextFeature();
     469                 :     virtual int         GetFeatureCount( int );
     470                 : 
     471                 :     virtual void        SetSpatialFilter( OGRGeometry * );
     472                 : 
     473                 :     virtual int         TestCapability( const char * );
     474                 : 
     475                 :     virtual OGRErr      GetExtent(OGREnvelope *psExtent, int bForce);
     476                 : };
     477                 : 
     478                 : /************************************************************************/
     479                 : /*                   OGRSQLiteSingleFeatureLayer                        */
     480                 : /************************************************************************/
     481                 : 
     482                 : class OGRSQLiteSingleFeatureLayer : public OGRLayer
     483                 : {
     484                 :   private:
     485                 :     int                 nVal;
     486                 :     char               *pszVal;
     487                 :     OGRFeatureDefn     *poFeatureDefn;
     488                 :     int                 iNextShapeId;
     489                 : 
     490                 :   public:
     491                 :                         OGRSQLiteSingleFeatureLayer( const char* pszLayerName,
     492                 :                                                      int nVal );
     493                 :                         OGRSQLiteSingleFeatureLayer( const char* pszLayerName,
     494                 :                                                      const char *pszVal );
     495                 :                         ~OGRSQLiteSingleFeatureLayer();
     496                 : 
     497                 :     virtual void        ResetReading();
     498                 :     virtual OGRFeature *GetNextFeature();
     499                 :     virtual OGRFeatureDefn *GetLayerDefn();
     500                 :     virtual int         TestCapability( const char * );
     501                 : };
     502                 : 
     503                 : /************************************************************************/
     504                 : /*                         OGRSQLiteDataSource                          */
     505                 : /************************************************************************/
     506                 : 
     507                 : class OGRSQLiteDataSource : public OGRDataSource
     508                 : {
     509                 :     OGRSQLiteLayer    **papoLayers;
     510                 :     int                 nLayers;
     511                 :     
     512                 :     char               *pszName;
     513                 : 
     514                 :     sqlite3             *hDB;
     515                 :     int                 bUpdate;
     516                 : 
     517                 :     int                 nSoftTransactionLevel;
     518                 : 
     519                 :     // We maintain a list of known SRID to reduce the number of trips to
     520                 :     // the database to get SRSes. 
     521                 :     int                 nKnownSRID;
     522                 :     int                *panSRID;
     523                 :     OGRSpatialReference **papoSRS;
     524                 :     void                AddSRIDToCache(int nId, OGRSpatialReference * poSRS );
     525                 : 
     526                 :     int                 bHaveGeometryColumns;
     527                 :     int                 bIsSpatiaLiteDB;
     528                 :     int                 bSpatialite4Layout;
     529                 : 
     530                 :     int                 nUndefinedSRID;
     531                 : 
     532                 :     void               *hRegExpCache;
     533                 : 
     534                 :     virtual void        DeleteLayer( const char *pszLayer );
     535                 : 
     536                 :     const char*         GetSRTEXTColName();
     537                 : 
     538                 :     int                 OpenOrCreateDB(int flags);
     539                 :     int                 InitWithEPSG();
     540                 :     int                 SetSynchronous();
     541                 :     int                 SetCacheSize();
     542                 : 
     543                 :     int                 OpenVirtualTable(const char* pszName, const char* pszSQL);
     544                 : 
     545                 : #ifdef HAVE_SQLITE_VFS
     546                 :     sqlite3_vfs*        pMyVFS;
     547                 : #endif
     548                 : 
     549                 :     VSILFILE*           fpMainFile; /* Set by the VFS layer when it opens the DB */
     550                 :                                     /* Must *NOT* be closed by the datasource explicitely. */
     551                 :     GIntBig             nFileTimestamp;
     552                 :     int                 bLastSQLCommandIsUpdateLayerStatistics;
     553                 : 
     554                 :     std::map<CPLString, OGREnvelope> oMapSQLEnvelope;
     555                 : 
     556                 :     std::map< CPLString, std::set<CPLString> > aoMapTableToSetOfGeomCols;
     557                 : 
     558                 :     void                SaveStatistics();
     559                 : 
     560                 :   public:
     561                 :                         OGRSQLiteDataSource();
     562                 :                         ~OGRSQLiteDataSource();
     563                 : 
     564                 :     int                 Open( const char *, int bUpdateIn );
     565                 :     int                 Create( const char *, char **papszOptions );
     566                 : 
     567                 :     int                 OpenTable( const char *pszTableName, 
     568                 :                                    const char *pszGeomCol = NULL,
     569                 :                                    int bMustIncludeGeomColName = FALSE,
     570                 :                                    OGRwkbGeometryType eGeomType = wkbUnknown,
     571                 :                                    const char *pszGeomFormat = NULL,
     572                 :                                    OGRSpatialReference *poSRS = NULL,
     573                 :                                    int nSRID = UNINITIALIZED_SRID,
     574                 :                                    int bHasSpatialIndex = FALSE,
     575                 :                                    int bHasM = FALSE,
     576                 :                                    int bIsVirtualShapeIn = FALSE );
     577                 :     int                  OpenView( const char *pszViewName,
     578                 :                                    const char *pszViewGeometry,
     579                 :                                    const char *pszViewRowid,
     580                 :                                    const char *pszTableName,
     581                 :                                    const char *pszGeometryColumn);
     582                 : 
     583             191 :     const char          *GetName() { return pszName; }
     584            2008 :     int                 GetLayerCount() { return nLayers; }
     585                 :     OGRLayer            *GetLayer( int );
     586                 :     
     587                 :     virtual OGRLayer    *CreateLayer( const char *pszLayerName, 
     588                 :                                       OGRSpatialReference *poSRS, 
     589                 :                                       OGRwkbGeometryType eType, 
     590                 :                                       char **papszOptions );
     591                 :     virtual OGRErr      DeleteLayer(int);
     592                 : 
     593                 :     int                 TestCapability( const char * );
     594                 : 
     595                 :     virtual OGRLayer *  ExecuteSQL( const char *pszSQLCommand,
     596                 :                                     OGRGeometry *poSpatialFilter,
     597                 :                                     const char *pszDialect );
     598                 :     virtual void        ReleaseResultSet( OGRLayer * poLayer );
     599                 : 
     600                 :     OGRErr              SoftStartTransaction();
     601                 :     OGRErr              SoftCommit();
     602                 :     OGRErr              SoftRollback();
     603                 :     
     604                 :     OGRErr              FlushSoftTransaction();
     605                 : 
     606            6538 :     sqlite3            *GetDB() { return hDB; }
     607                 : 
     608                 :     char               *LaunderName( const char * );
     609                 :     int                 FetchSRSId( OGRSpatialReference * poSRS );
     610                 :     OGRSpatialReference*FetchSRS( int nSRID );
     611                 : 
     612             592 :     int                 GetUpdate() const { return bUpdate; }
     613               0 :     void                SetUpdate(int bUpdateIn) { bUpdate = bUpdateIn; }
     614                 : 
     615                 :     void                SetName(const char* pszNameIn);
     616                 : 
     617                 :     void                NotifyFileOpened (const char* pszFilename,
     618                 :                                           VSILFILE* fp);
     619                 : 
     620                 :     const OGREnvelope*  GetEnvelopeFromSQL(const CPLString& osSQL);
     621                 :     void                SetEnvelopeForSQL(const CPLString& osSQL, const OGREnvelope& oEnvelope);
     622                 : 
     623             733 :     const std::set<CPLString>& GetGeomColsForTable(const char* pszTableName)
     624             733 :             { return aoMapTableToSetOfGeomCols[pszTableName]; }
     625                 : 
     626            1154 :     GIntBig             GetFileTimestamp() const { return nFileTimestamp; }
     627                 :     
     628            1675 :     int                 IsSpatialiteDB() const { return bIsSpatiaLiteDB; }
     629            1225 :     int                 HasSpatialite4Layout() const { return bSpatialite4Layout; }
     630                 : 
     631            1252 :     int                 GetUndefinedSRID() const { return nUndefinedSRID; }
     632                 : };
     633                 : 
     634                 : /************************************************************************/
     635                 : /*                           OGRSQLiteDriver                            */
     636                 : /************************************************************************/
     637                 : 
     638                 : class OGRSQLiteDriver : public OGRSFDriver
     639             226 : {
     640                 :   public:
     641                 :                 ~OGRSQLiteDriver();
     642                 :                 
     643                 :     const char *GetName();
     644                 :     OGRDataSource *Open( const char *, int );
     645                 : 
     646                 :     virtual OGRDataSource *CreateDataSource( const char *pszName,
     647                 :                                              char ** = NULL );
     648                 :     virtual OGRErr      DeleteDataSource( const char *pszName );
     649                 :     
     650                 :     int                 TestCapability( const char * );
     651                 : };
     652                 : 
     653                 : /* To escape literals. The returned string doesn't contain the surrounding single quotes */
     654                 : CPLString OGRSQLiteEscape( const char *pszLiteral );
     655                 : 
     656                 : /* To escape table or field names. The returned string doesn't contain the surrounding double quotes */
     657                 : CPLString OGRSQLiteEscapeName( const char* pszName );
     658                 : 
     659                 : CPLString OGRSQLiteParamsUnquote(const char* pszVal);
     660                 : 
     661                 : CPLString OGRSQLiteFieldDefnToSQliteFieldDefn( OGRFieldDefn* poFieldDefn );
     662                 : 
     663                 : int OGRSQLITEStringToDateTimeField( OGRFeature* poFeature, int iField,
     664                 :                                     const char* pszValue );
     665                 : 
     666                 : #ifdef HAVE_SQLITE_VFS
     667                 : typedef void (*pfnNotifyFileOpenedType)(void* pfnUserData, const char* pszFilename, VSILFILE* fp);
     668                 : sqlite3_vfs* OGRSQLiteCreateVFS(pfnNotifyFileOpenedType pfn, void* pfnUserData);
     669                 : #endif
     670                 : 
     671                 : #endif /* ndef _OGR_SQLITE_H_INCLUDED */
     672                 : 
     673                 : 

Generated by: LCOV version 1.7