1 /******************************************************************************
2 *
3 * Project: OpenGIS Simple Features Reference Implementation
4 * Purpose: Implements OGRIngresDriver class.
5 * Author: Frank Warmerdam, warmerdam@pobox.com
6 *
7 ******************************************************************************
8 * Copyright (c) 2008, Frank Warmerdam <warmerdam@pobox.com>
9 *
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
16 *
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 ****************************************************************************/
28
29 #include "ogr_ingres.h"
30 #include "cpl_conv.h"
31
32 CPL_CVSID("$Id: ogringresdriver.cpp 2dc350b1c738a002da1ec5c4cbe3e42fec4069dc 2021-03-04 16:15:13 +0100 Even Rouault $")
33
34 /************************************************************************/
35 /* ~OGRIngresDriver() */
36 /************************************************************************/
37
~OGRIngresDriver()38 OGRIngresDriver::~OGRIngresDriver()
39
40 {
41 }
42
43 /************************************************************************/
44 /* GetName() */
45 /************************************************************************/
46
GetName()47 const char *OGRIngresDriver::GetName()
48
49 {
50 return "Ingres";
51 }
52
53 /************************************************************************/
54 /* ParseWrappedName() */
55 /************************************************************************/
56
ParseWrappedName(const char * pszEncodedName)57 char **OGRIngresDriver::ParseWrappedName( const char *pszEncodedName )
58
59 {
60 if( pszEncodedName[0] != '@' )
61 return NULL;
62
63 return CSLTokenizeStringComplex( pszEncodedName+1, ",", TRUE, FALSE );
64 }
65
66 /************************************************************************/
67 /* Open() */
68 /************************************************************************/
69
Open(const char * pszFilename,int bUpdate)70 OGRDataSource *OGRIngresDriver::Open( const char * pszFilename,
71 int bUpdate )
72
73 {
74 OGRIngresDataSource *poDS = NULL;
75 char **papszOptions = ParseWrappedName( pszFilename );
76 const char *pszDriver = CSLFetchNameValue( papszOptions, "driver" );
77 if( pszDriver != NULL && EQUAL(pszDriver,"ingres") )
78 {
79 poDS = new OGRIngresDataSource();
80
81 if( !poDS->Open( pszFilename, papszOptions, TRUE ) )
82 {
83 delete poDS;
84 poDS = NULL;
85 }
86 }
87
88 CSLDestroy( papszOptions );
89
90 if( !GDALIsDriverDeprecatedForGDAL35StillEnabled("INGRES") )
91 {
92 delete poDS;
93 return nullptr;
94 }
95
96 return poDS;
97 }
98
99 /************************************************************************/
100 /* CreateDataSource() */
101 /************************************************************************/
102
CreateDataSource(const char * pszName,char **)103 OGRDataSource *OGRIngresDriver::CreateDataSource( const char * pszName,
104 char ** /* papszOptions */ )
105
106 {
107 if( !GDALIsDriverDeprecatedForGDAL35StillEnabled("INGRES") )
108 {
109 return nullptr;
110 }
111
112 OGRIngresDataSource *poDS = NULL;
113
114 char **papszOpenOptions = ParseWrappedName( pszName );
115
116 const char *pszDriver = CSLFetchNameValue( papszOpenOptions, "driver" );
117
118 if( pszDriver != NULL && EQUAL(pszDriver,"ingres") )
119 {
120 poDS = new OGRIngresDataSource();
121 if( !poDS->Open( pszName, papszOpenOptions, TRUE ) )
122 {
123 delete poDS;
124 poDS = NULL;
125 CPLError( CE_Failure, CPLE_AppDefined,
126 "Ingres driver doesn't currently support database creation.\n"
127 "Please create database before using." );
128 }
129 }
130
131 CSLDestroy( papszOpenOptions );
132
133 return poDS;
134 }
135
136 /************************************************************************/
137 /* TestCapability() */
138 /************************************************************************/
139
TestCapability(const char * pszCap)140 int OGRIngresDriver::TestCapability( const char * pszCap )
141
142 {
143 if( EQUAL(pszCap,ODsCCreateLayer) )
144 return TRUE;
145 if( EQUAL(pszCap,ODsCDeleteLayer) )
146 return TRUE;
147 if( EQUAL(pszCap,ODrCCreateDataSource) )
148 return TRUE;
149
150 return FALSE;
151 }
152
153 /************************************************************************/
154 /* RegisterOGRIngres() */
155 /************************************************************************/
156
RegisterOGRIngres()157 void RegisterOGRIngres()
158
159 {
160 if( !GDAL_CHECK_VERSION("Ingres") )
161 return;
162 OGRSFDriverRegistrar::GetRegistrar()->RegisterDriver(new OGRIngresDriver);
163 }
164