1 /******************************************************************************
2 * $Id: ogrocidriver.cpp 29019 2015-04-25 20:34:19Z rouault $
3 *
4 * Project: Oracle Spatial Driver
5 * Purpose: Implementation of the OGROCIDriver class.
6 * Author: Frank Warmerdam, warmerdam@pobox.com
7 *
8 ******************************************************************************
9 * Copyright (c) 2002, 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 #include "ogr_oci.h"
31
32 CPL_CVSID("$Id: ogrocidriver.cpp 29019 2015-04-25 20:34:19Z rouault $");
33
34
35 /************************************************************************/
36 /* OGROCIDriverIdentify() */
37 /************************************************************************/
38
OGROCIDriverIdentify(GDALOpenInfo * poOpenInfo)39 static int OGROCIDriverIdentify( GDALOpenInfo* poOpenInfo )
40 {
41 return EQUALN(poOpenInfo->pszFilename,"OCI:",4);
42 }
43
44 /************************************************************************/
45 /* OGROCIDriverOpen() */
46 /************************************************************************/
47
OGROCIDriverOpen(GDALOpenInfo * poOpenInfo)48 static GDALDataset *OGROCIDriverOpen( GDALOpenInfo* poOpenInfo )
49
50 {
51 if( !OGROCIDriverIdentify(poOpenInfo) )
52 return NULL;
53
54 OGROCIDataSource *poDS;
55
56 poDS = new OGROCIDataSource();
57
58 if( !poDS->Open( poOpenInfo->pszFilename, poOpenInfo->papszOpenOptions,
59 poOpenInfo->eAccess == GA_Update, TRUE ) )
60 {
61 delete poDS;
62 return NULL;
63 }
64 else
65 return poDS;
66 }
67
68 /************************************************************************/
69 /* OGROCIDriverCreate() */
70 /************************************************************************/
71
OGROCIDriverCreate(const char * pszName,CPL_UNUSED int nBands,CPL_UNUSED int nXSize,CPL_UNUSED int nYSize,CPL_UNUSED GDALDataType eDT,CPL_UNUSED char ** papszOptions)72 static GDALDataset *OGROCIDriverCreate( const char * pszName,
73 CPL_UNUSED int nBands,
74 CPL_UNUSED int nXSize,
75 CPL_UNUSED int nYSize,
76 CPL_UNUSED GDALDataType eDT,
77 CPL_UNUSED char **papszOptions )
78
79 {
80 OGROCIDataSource *poDS;
81
82 poDS = new OGROCIDataSource();
83
84
85 if( !poDS->Open( pszName, NULL, TRUE, TRUE ) )
86 {
87 delete poDS;
88 CPLError( CE_Failure, CPLE_AppDefined,
89 "Oracle driver doesn't currently support database creation.\n"
90 "Please create database with Oracle tools before loading tables." );
91 return NULL;
92 }
93
94 return poDS;
95 }
96
97 /************************************************************************/
98 /* RegisterOGROCI() */
99 /************************************************************************/
100
RegisterOGROCI()101 void RegisterOGROCI()
102
103 {
104 if (! GDAL_CHECK_VERSION("OCI driver"))
105 return;
106
107 if( GDALGetDriverByName( "OCI" ) == NULL )
108 {
109 GDALDriver* poDriver = new GDALDriver();
110
111 poDriver->SetDescription( "OCI" );
112 poDriver->SetMetadataItem( GDAL_DMD_LONGNAME,
113 "Oracle Spatial" );
114 poDriver->SetMetadataItem( GDAL_DMD_HELPTOPIC,
115 "drv_oci.html" );
116 poDriver->SetMetadataItem( GDAL_DCAP_VECTOR, "YES" );
117
118 poDriver->SetMetadataItem( GDAL_DMD_CONNECTION_PREFIX, "OCI:" );
119
120 poDriver->SetMetadataItem( GDAL_DMD_OPENOPTIONLIST,
121 "<OpenOptionList>"
122 " <Option name='DBNAME' type='string' description='Database name'/>"
123 " <Option name='USER' type='string' description='User name'/>"
124 " <Option name='PASSWORD' type='string' description='Password'/>"
125 " <Option name='TABLES' type='string' description='Restricted set of tables to list (comma separated)'/>"
126 "</OpenOptionList>");
127
128 poDriver->SetMetadataItem( GDAL_DS_LAYER_CREATIONOPTIONLIST,
129 "<LayerCreationOptionList>"
130 " <Option name='LAUNDER' type='boolean' description='Whether layer and field names will be laundered' default='NO'/>"
131 " <Option name='PRECISION' type='boolean' description='Whether fields created should keep the width and precision' default='YES'/>"
132 " <Option name='OVERWRITE' type='boolean' description='Whether to overwrite an existing table with the layer name to be created' default='NO'/>"
133 " <Option name='TRUNCATE' type='boolean' description='Whether to truncate an existing table' default='NO'/>"
134 " <Option name='SPATIAL_INDEX' type='boolean' description='Whether to create a spatial index' default='YES' deprecated_alias='INDEX'/>"
135 " <Option name='INDEX_PARAMETERS' type='string' description='Creation parameters when the spatial index is created'/>"
136 " <Option name='ADD_LAYER_GTYPE' type='boolean' description='May be set to NO to disable the constraints on the geometry type in the spatial index' default='YES'/>"
137 " <Option name='MULTI_LOAD' type='boolean' description='If enabled new features will be created in groups of 100 per SQL INSERT command' default='YES'/>"
138 " <Option name='LOADER_FILE' type='string' description='If this option is set, all feature information will be written to a file suitable for use with SQL*Loader'/>"
139 " <Option name='DIM' type='integer' description='Set to 2 to force the geometries to be 2D, or 3 to be 2.5D' default='3'/>"
140 " <Option name='GEOMETRY_NAME' type='string' description='Name of geometry column.' default='ORA_GEOMETRY'/>"
141 " <Option name='GEOMETRY_NULLABLE' type='boolean' description='Whether the values of the geometry column can be NULL' default='YES'/>"
142 " <Option name='DIMINFO_X' type='string' description='xmin,xmax,xres values to control the X dimension info written into the USER_SDO_GEOM_METADATA table'/>"
143 " <Option name='DIMINFO_Y' type='string' description='ymin,ymax,yres values to control the Y dimension info written into the USER_SDO_GEOM_METADATA table'/>"
144 " <Option name='DIMINFO_Z' type='string' description='zmin,zmax,zres values to control the Z dimension info written into the USER_SDO_GEOM_METADATA table'/>"
145 " <Option name='SRID' type='int' description='Forced SRID of the layer'/>"
146 "</LayerCreationOptionList>");
147
148 poDriver->SetMetadataItem( GDAL_DMD_CREATIONFIELDDATATYPES, "Integer Integer64 Real String Date DateTime" );
149 poDriver->SetMetadataItem( GDAL_DCAP_NOTNULL_FIELDS, "YES" );
150 poDriver->SetMetadataItem( GDAL_DCAP_DEFAULT_FIELDS, "YES" );
151 poDriver->SetMetadataItem( GDAL_DCAP_NOTNULL_GEOMFIELDS, "YES" );
152
153 poDriver->pfnOpen = OGROCIDriverOpen;
154 poDriver->pfnIdentify = OGROCIDriverIdentify;
155 poDriver->pfnCreate = OGROCIDriverCreate;
156
157 GetGDALDriverManager()->RegisterDriver( poDriver );
158 }
159 }
160
161