LCOV - code coverage report
Current view: directory - ogr/ogrsf_frmts/mysql - ogr_mysql.h (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 9 9 100.0 %
Date: 2010-01-09 Functions: 7 7 100.0 %

       1                 : /******************************************************************************
       2                 :  * $Id: ogr_mysql.h 16921 2009-05-03 11:41:56Z rouault $
       3                 :  *
       4                 :  * Project:  OpenGIS Simple Features Reference Implementation
       5                 :  * Purpose:  Declarations for MySQL OGR Driver Classes.
       6                 :  * Author:   Frank Warmerdam, warmerdam@pobox.com
       7                 :  * Author:   Howard Butler, hobu@hobu.net
       8                 :  *
       9                 :  ******************************************************************************
      10                 :  * Copyright (c) 2004, Frank Warmerdam <warmerdam@pobox.com>
      11                 :  *
      12                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      13                 :  * copy of this software and associated documentation files (the "Software"),
      14                 :  * to deal in the Software without restriction, including without limitation
      15                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      16                 :  * and/or sell copies of the Software, and to permit persons to whom the
      17                 :  * Software is furnished to do so, subject to the following conditions:
      18                 :  *
      19                 :  * The above copyright notice and this permission notice shall be included
      20                 :  * in all copies or substantial portions of the Software.
      21                 :  *
      22                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      23                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      24                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      25                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      26                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      27                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      28                 :  * DEALINGS IN THE SOFTWARE.
      29                 :  ****************************************************************************/
      30                 : 
      31                 : #ifndef _OGR_MYSQL_H_INCLUDED
      32                 : #define _OGR_MYSQL_H_INCLUDED
      33                 : 
      34                 : #include <my_global.h>
      35                 : #include <mysql.h>
      36                 : 
      37                 : /* my_global.h from mysql 5.1 declares the min and max macros. */
      38                 : /* This conflicts with templates in g++-4.3.2 header files. Grrr */
      39                 : #ifdef min
      40                 : #undef min
      41                 : #endif
      42                 : 
      43                 : #ifdef max
      44                 : #undef max
      45                 : #endif
      46                 : 
      47                 : #ifdef bool
      48                 : #undef bool
      49                 : #endif
      50                 : 
      51                 : #include "ogrsf_frmts.h"
      52                 : 
      53                 : /************************************************************************/
      54                 : /*                            OGRMySQLLayer                             */
      55                 : /************************************************************************/
      56                 : 
      57                 : class OGRMySQLDataSource;
      58                 :     
      59                 : class OGRMySQLLayer : public OGRLayer
      60                 : {
      61                 :   protected:
      62                 :     OGRFeatureDefn     *poFeatureDefn;
      63                 : 
      64                 :     // Layer spatial reference system, and srid.
      65                 :     OGRSpatialReference *poSRS;
      66                 :     int                 nSRSId;
      67                 : 
      68                 :     int                 iNextShapeId;
      69                 : 
      70                 :     OGRMySQLDataSource    *poDS;
      71                 :  
      72                 :     char               *pszQueryStatement;
      73                 : 
      74                 :     int                 nResultOffset;
      75                 : 
      76                 :     char                *pszGeomColumn;
      77                 :     char                *pszGeomColumnTable;
      78                 :     int                 nGeomType;
      79                 : 
      80                 :     int                 bHasFid;
      81                 :     char                *pszFIDColumn;
      82                 : 
      83                 :     MYSQL_RES           *hResultSet;
      84                 : 
      85                 :   int                 FetchSRSId();
      86                 : 
      87                 :   public:
      88                 :                         OGRMySQLLayer();
      89                 :     virtual             ~OGRMySQLLayer();
      90                 : 
      91                 :     virtual void        ResetReading();
      92                 : 
      93                 :     virtual OGRFeature *GetNextFeature();
      94                 : 
      95                 :     virtual OGRFeature *GetFeature( long nFeatureId );
      96                 :     
      97              24 :     OGRFeatureDefn *    GetLayerDefn() { return poFeatureDefn; }
      98                 : 
      99                 :     virtual OGRSpatialReference *GetSpatialRef();
     100                 : 
     101                 :     virtual const char *GetFIDColumn();
     102                 :     virtual const char *GetGeometryColumn();
     103                 : 
     104                 :     /* custom methods */
     105                 :     virtual OGRFeature *RecordToFeature( char **papszRow, unsigned long * );
     106                 :     virtual OGRFeature *GetNextRawFeature();
     107                 : };
     108                 : 
     109                 : /************************************************************************/
     110                 : /*                          OGRMySQLTableLayer                          */
     111                 : /************************************************************************/
     112                 : 
     113                 : class OGRMySQLTableLayer : public OGRMySQLLayer
     114                 : {
     115                 :     int                 bUpdateAccess;
     116                 : 
     117                 :     OGRFeatureDefn     *ReadTableDefinition(const char *);
     118                 : 
     119                 :     void                BuildWhere(void);
     120                 :     char               *BuildFields(void);
     121                 :     void                BuildFullQueryStatement(void);
     122                 : 
     123                 :     char                *pszQuery;
     124                 :     char                *pszWHERE;
     125                 : 
     126                 :     int                 bLaunderColumnNames;
     127                 :     int                 bPreservePrecision;
     128                 :     
     129                 :   public:
     130                 :                         OGRMySQLTableLayer( OGRMySQLDataSource *,
     131                 :                                          const char * pszName,
     132                 :                                          int bUpdate, int nSRSId = -2 );
     133                 :                         ~OGRMySQLTableLayer();
     134                 : 
     135                 :     OGRErr              Initialize(const char* pszTableName);
     136                 :     
     137                 :     virtual OGRFeature *GetFeature( long nFeatureId );
     138                 :     virtual void        ResetReading();
     139                 :     virtual int         GetFeatureCount( int );
     140                 : 
     141                 :     void                SetSpatialFilter( OGRGeometry * );
     142                 : 
     143                 :     virtual OGRErr      SetAttributeFilter( const char * );
     144                 :     virtual OGRErr      CreateFeature( OGRFeature *poFeature );
     145                 :     virtual OGRErr      DeleteFeature( long nFID );
     146                 :     virtual OGRErr      SetFeature( OGRFeature *poFeature );
     147                 :     
     148                 :     virtual OGRErr      CreateField( OGRFieldDefn *poField,
     149                 :                                      int bApproxOK = TRUE );
     150                 : 
     151               4 :     void                SetLaunderFlag( int bFlag )
     152               4 :                                 { bLaunderColumnNames = bFlag; }
     153               4 :     void                SetPrecisionFlag( int bFlag )
     154               4 :                                 { bPreservePrecision = bFlag; }    
     155                 : 
     156                 :     virtual int         TestCapability( const char * );
     157                 :   virtual OGRErr      GetExtent(OGREnvelope *psExtent, int bForce = TRUE);
     158                 : };
     159                 : 
     160                 : /************************************************************************/
     161                 : /*                         OGRMySQLResultLayer                          */
     162                 : /************************************************************************/
     163                 : 
     164                 : class OGRMySQLResultLayer : public OGRMySQLLayer
     165                 : {
     166                 :     void                BuildFullQueryStatement(void);
     167                 : 
     168                 :     char                *pszRawStatement;
     169                 :     
     170                 :     // Layer srid.
     171                 :     int                 nSRSId;
     172                 :     
     173                 :     int                 nFeatureCount;
     174                 : 
     175                 :   public:
     176                 :                         OGRMySQLResultLayer( OGRMySQLDataSource *,
     177                 :                                              const char * pszRawStatement,
     178                 :                                              MYSQL_RES *hResultSetIn );
     179                 :     virtual             ~OGRMySQLResultLayer();
     180                 : 
     181                 :     OGRFeatureDefn     *ReadResultDefinition();
     182                 : 
     183                 : 
     184                 :     virtual void        ResetReading();
     185                 :     virtual int         GetFeatureCount( int );
     186                 : 
     187                 :     virtual int         TestCapability( const char * );
     188                 : };
     189                 : 
     190                 : /************************************************************************/
     191                 : /*                          OGRMySQLDataSource                          */
     192                 : /************************************************************************/
     193                 : 
     194                 : class OGRMySQLDataSource : public OGRDataSource
     195                 : {
     196                 :     OGRMySQLLayer       **papoLayers;
     197                 :     int                 nLayers;
     198                 :     
     199                 :     char               *pszName;
     200                 : 
     201                 :     int                 bDSUpdate;
     202                 :     int                 bHavePostGIS;
     203                 :     int                 nSoftTransactionLevel;
     204                 : 
     205                 :     MYSQL              *hConn;
     206                 : 
     207                 :     int                DeleteLayer( int iLayer );
     208                 : 
     209                 :     // We maintain a list of known SRID to reduce the number of trips to
     210                 :     // the database to get SRSes. 
     211                 :     int                 nKnownSRID;
     212                 :     int                *panSRID;
     213                 :     OGRSpatialReference **papoSRS;
     214                 : 
     215                 :     OGRMySQLLayer      *poLongResultLayer;
     216                 :     
     217                 :   public:
     218                 :                         OGRMySQLDataSource();
     219                 :                         ~OGRMySQLDataSource();
     220                 : 
     221             235 :     MYSQL              *GetConn() { return hConn; }
     222                 : 
     223                 : 
     224                 :     int                 FetchSRSId( OGRSpatialReference * poSRS );
     225                 : 
     226                 :     OGRSpatialReference *FetchSRS( int nSRSId );
     227                 : 
     228                 :     OGRErr              InitializeMetadataTables();
     229                 : 
     230                 :     int                 Open( const char *, int bUpdate, int bTestOpen );
     231                 :     int                 OpenTable( const char *, int bUpdate, int bTestOpen );
     232                 : 
     233               1 :     const char          *GetName() { return pszName; }
     234               9 :     int                 GetLayerCount() { return nLayers; }
     235                 :     OGRLayer            *GetLayer( int );
     236                 : 
     237                 :     virtual OGRLayer    *CreateLayer( const char *, 
     238                 :                                       OGRSpatialReference * = NULL,
     239                 :                                       OGRwkbGeometryType = wkbUnknown,
     240                 :                                       char ** = NULL );
     241                 : 
     242                 : 
     243                 :     int                 TestCapability( const char * );
     244                 : 
     245                 :     virtual OGRLayer *  ExecuteSQL( const char *pszSQLCommand,
     246                 :                                     OGRGeometry *poSpatialFilter,
     247                 :                                     const char *pszDialect );
     248                 :     virtual void        ReleaseResultSet( OGRLayer * poLayer );
     249                 : 
     250                 :     // nonstandard
     251                 : 
     252                 :     void                ReportError( const char * = NULL );
     253                 :     
     254                 :     char               *LaunderName( const char * );
     255                 : 
     256                 :     void                RequestLongResult( OGRMySQLLayer * );
     257                 :     void                InterruptLongResult();
     258                 : };
     259                 : 
     260                 : /************************************************************************/
     261                 : /*                            OGRMySQLDriver                            */
     262                 : /************************************************************************/
     263                 : 
     264                 : class OGRMySQLDriver : public OGRSFDriver
     265              64 : {
     266                 :   public:
     267                 :                 ~OGRMySQLDriver();
     268                 :                 
     269                 :     const char *GetName();
     270                 :     OGRDataSource *Open( const char *, int );
     271                 :     virtual OGRDataSource *CreateDataSource( const char *pszName,
     272                 :                                              char ** = NULL );
     273                 :     int                 TestCapability( const char * );
     274                 : };
     275                 : 
     276                 : 
     277                 : #endif /* ndef _OGR_MYSQL_H_INCLUDED */
     278                 : 
     279                 : 

Generated by: LCOV version 1.7