1 : /******************************************************************************
2 : * $Id: ogr_pgdump.h 19705 2010-05-14 19:42:02Z rouault $
3 : *
4 : * Project: OpenGIS Simple Features Reference Implementation
5 : * Purpose: Private definitions for OGR/PostgreSQL dump driver.
6 : * Author: Even Rouault, <even dot rouault at mines dash paris dot org>
7 : *
8 : ******************************************************************************
9 : * Copyright (c) 2010, Even Rouault
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_PGDUMP_H_INCLUDED
31 : #define _OGR_PGDUMP_H_INCLUDED
32 :
33 : #include "ogrsf_frmts.h"
34 : #include "cpl_string.h"
35 :
36 : /************************************************************************/
37 : /* OGRPGDumpLayer */
38 : /************************************************************************/
39 :
40 :
41 : class OGRPGDumpDataSource;
42 :
43 : class OGRPGDumpLayer : public OGRLayer
44 : {
45 : char *pszSqlTableName;
46 : char *pszGeomColumn;
47 : char *pszFIDColumn;
48 : int nCoordDimension;
49 : int nSRSId;
50 : OGRFeatureDefn *poFeatureDefn;
51 : OGRPGDumpDataSource *poDS;
52 : int nFeatures;
53 : int bLaunderColumnNames;
54 : int bPreservePrecision;
55 : int bUseCopy;
56 : int bWriteAsHex;
57 : int bCopyActive;
58 : int bCreateTable;
59 :
60 : void AppendFieldValue(CPLString& osCommand,
61 : OGRFeature* poFeature, int i);
62 : char* GByteArrayToBYTEA( const GByte* pabyData, int nLen);
63 : char* GeometryToHex( OGRGeometry * poGeometry, int nSRSId );
64 :
65 : OGRErr StartCopy();
66 : CPLString BuildCopyFields();
67 :
68 : public:
69 : OGRPGDumpLayer(OGRPGDumpDataSource* poDS,
70 : const char* pszSchemaName,
71 : const char* pszLayerName,
72 : const char* pszGeomColumn,
73 : const char *pszFIDColumn,
74 : int nCoordDimension,
75 : int nSRSId,
76 : int bWriteAsHexIn,
77 : int bCreateTable);
78 : virtual ~OGRPGDumpLayer();
79 :
80 3 : virtual OGRFeatureDefn *GetLayerDefn() {return poFeatureDefn;}
81 :
82 0 : virtual void ResetReading() { }
83 : virtual int TestCapability( const char * );
84 :
85 : virtual OGRErr CreateFeature( OGRFeature *poFeature );
86 : virtual OGRErr CreateFeatureViaInsert( OGRFeature *poFeature );
87 : virtual OGRErr CreateFeatureViaCopy( OGRFeature *poFeature );
88 :
89 : virtual OGRErr CreateField( OGRFieldDefn *poField,
90 : int bApproxOK = TRUE );
91 :
92 : virtual OGRFeature *GetNextFeature();
93 :
94 : // follow methods are not base class overrides
95 3 : void SetLaunderFlag( int bFlag )
96 3 : { bLaunderColumnNames = bFlag; }
97 3 : void SetPrecisionFlag( int bFlag )
98 3 : { bPreservePrecision = bFlag; }
99 :
100 : OGRErr EndCopy();
101 : };
102 :
103 : /************************************************************************/
104 : /* OGRPGDumpDataSource */
105 : /************************************************************************/
106 : class OGRPGDumpDataSource : public OGRDataSource
107 : {
108 : int nLayers;
109 : OGRPGDumpLayer** papoLayers;
110 : char* pszName;
111 : int bTriedOpen;
112 : FILE* fp;
113 : int bInTransaction;
114 : OGRPGDumpLayer* poLayerInCopyMode;
115 : const char* pszEOL;
116 :
117 : public:
118 : OGRPGDumpDataSource(const char* pszName,
119 : char** papszOptions);
120 : ~OGRPGDumpDataSource();
121 :
122 : char *LaunderName( const char *pszSrcName );
123 : void Log(const char* pszStr, int bAddSemiColumn = TRUE);
124 :
125 3 : virtual const char *GetName() { return pszName; }
126 0 : virtual int GetLayerCount() { return nLayers; }
127 : virtual OGRLayer *GetLayer( int );
128 :
129 : virtual OGRLayer *CreateLayer( const char *,
130 : OGRSpatialReference * = NULL,
131 : OGRwkbGeometryType = wkbUnknown,
132 : char ** = NULL );
133 :
134 : virtual int TestCapability( const char * );
135 :
136 : void StartTransaction();
137 : void Commit();
138 :
139 : void StartCopy( OGRPGDumpLayer *poPGLayer );
140 : OGRErr EndCopy( );
141 : };
142 :
143 : /************************************************************************/
144 : /* OGRPGDriver */
145 : /************************************************************************/
146 :
147 : class OGRPGDumpDriver : public OGRSFDriver
148 80 : {
149 : public:
150 : ~OGRPGDumpDriver();
151 :
152 : virtual const char *GetName();
153 : virtual OGRDataSource *Open( const char *, int );
154 :
155 : virtual OGRDataSource *CreateDataSource( const char *pszName,
156 : char ** = NULL );
157 :
158 : virtual int TestCapability( const char * );
159 : };
160 :
161 : #endif /* ndef _OGR_PGDUMP_H_INCLUDED */
162 :
|