1 : /******************************************************************************
2 : * $Id: ogr_pgdump.h 25366 2012-12-27 18:38:53Z 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 : CPLString OGRPGDumpEscapeColumnName(const char* pszColumnName);
37 : CPLString OGRPGDumpEscapeString( const char* pszStrValue, int nMaxLength,
38 : const char* pszFieldName);
39 :
40 : /************************************************************************/
41 : /* OGRPGDumpLayer */
42 : /************************************************************************/
43 :
44 :
45 : class OGRPGDumpDataSource;
46 :
47 : class OGRPGDumpLayer : public OGRLayer
48 : {
49 : char *pszSqlTableName;
50 : char *pszGeomColumn;
51 : char *pszFIDColumn;
52 : int nCoordDimension;
53 : int nSRSId;
54 : OGRFeatureDefn *poFeatureDefn;
55 : OGRPGDumpDataSource *poDS;
56 : int nFeatures;
57 : int bLaunderColumnNames;
58 : int bPreservePrecision;
59 : int bUseCopy;
60 : int bWriteAsHex;
61 : int bCopyActive;
62 : int bFIDColumnInCopyFields;
63 : int bCreateTable;
64 :
65 : char **papszOverrideColumnTypes;
66 :
67 : void AppendFieldValue(CPLString& osCommand,
68 : OGRFeature* poFeature, int i);
69 : char* GByteArrayToBYTEA( const GByte* pabyData, int nLen);
70 : char* GeometryToHex( OGRGeometry * poGeometry, int nSRSId );
71 :
72 : OGRErr StartCopy(int bSetFID);
73 : CPLString BuildCopyFields(int bSetFID);
74 :
75 : public:
76 : OGRPGDumpLayer(OGRPGDumpDataSource* poDS,
77 : const char* pszSchemaName,
78 : const char* pszLayerName,
79 : const char* pszGeomColumn,
80 : const char *pszFIDColumn,
81 : int nCoordDimension,
82 : int nSRSId,
83 : int bWriteAsHexIn,
84 : int bCreateTable);
85 : virtual ~OGRPGDumpLayer();
86 :
87 3 : virtual OGRFeatureDefn *GetLayerDefn() {return poFeatureDefn;}
88 :
89 0 : virtual void ResetReading() { }
90 : virtual int TestCapability( const char * );
91 :
92 : virtual OGRErr CreateFeature( OGRFeature *poFeature );
93 : virtual OGRErr CreateFeatureViaInsert( OGRFeature *poFeature );
94 : virtual OGRErr CreateFeatureViaCopy( OGRFeature *poFeature );
95 :
96 : virtual OGRErr CreateField( OGRFieldDefn *poField,
97 : int bApproxOK = TRUE );
98 :
99 : virtual OGRFeature *GetNextFeature();
100 :
101 : // follow methods are not base class overrides
102 3 : void SetLaunderFlag( int bFlag )
103 3 : { bLaunderColumnNames = bFlag; }
104 3 : void SetPrecisionFlag( int bFlag )
105 3 : { bPreservePrecision = bFlag; }
106 :
107 : void SetOverrideColumnTypes( const char* pszOverrideColumnTypes );
108 :
109 : OGRErr EndCopy();
110 : };
111 :
112 : /************************************************************************/
113 : /* OGRPGDumpDataSource */
114 : /************************************************************************/
115 : class OGRPGDumpDataSource : public OGRDataSource
116 : {
117 : int nLayers;
118 : OGRPGDumpLayer** papoLayers;
119 : char* pszName;
120 : int bTriedOpen;
121 : VSILFILE* fp;
122 : int bInTransaction;
123 : OGRPGDumpLayer* poLayerInCopyMode;
124 : const char* pszEOL;
125 :
126 : public:
127 : OGRPGDumpDataSource(const char* pszName,
128 : char** papszOptions);
129 : ~OGRPGDumpDataSource();
130 :
131 : char *LaunderName( const char *pszSrcName );
132 : void Log(const char* pszStr, int bAddSemiColumn = TRUE);
133 :
134 3 : virtual const char *GetName() { return pszName; }
135 0 : virtual int GetLayerCount() { return nLayers; }
136 : virtual OGRLayer *GetLayer( int );
137 :
138 : virtual OGRLayer *CreateLayer( const char *,
139 : OGRSpatialReference * = NULL,
140 : OGRwkbGeometryType = wkbUnknown,
141 : char ** = NULL );
142 :
143 : virtual int TestCapability( const char * );
144 :
145 : void StartTransaction();
146 : void Commit();
147 :
148 : void StartCopy( OGRPGDumpLayer *poPGLayer );
149 : OGRErr EndCopy( );
150 : };
151 :
152 : /************************************************************************/
153 : /* OGRPGDriver */
154 : /************************************************************************/
155 :
156 : class OGRPGDumpDriver : public OGRSFDriver
157 244 : {
158 : public:
159 : ~OGRPGDumpDriver();
160 :
161 : virtual const char *GetName();
162 : virtual OGRDataSource *Open( const char *, int );
163 :
164 : virtual OGRDataSource *CreateDataSource( const char *pszName,
165 : char ** = NULL );
166 :
167 : virtual int TestCapability( const char * );
168 : };
169 :
170 : #endif /* ndef _OGR_PGDUMP_H_INCLUDED */
171 :
|