Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OpenGIS Simple Features Reference Implementation 4 : * Purpose: Implements OGRPGDriver class. 5 : * Author: Frank Warmerdam, warmerdam@pobox.com 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2000, Frank Warmerdam 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_pg.h" 30 : #include "cpl_conv.h" 31 : 32 : #include "ogrpgdrivercore.h" 33 : 34 : /************************************************************************/ 35 : /* Open() */ 36 : /************************************************************************/ 37 : 38 383 : static GDALDataset *OGRPGDriverOpen(GDALOpenInfo *poOpenInfo) 39 : 40 : { 41 383 : if (!OGRPGDriverIdentify(poOpenInfo)) 42 0 : return nullptr; 43 : 44 383 : OGRPGDataSource *poDS = new OGRPGDataSource(); 45 : 46 383 : if (!poDS->Open(poOpenInfo->pszFilename, poOpenInfo->eAccess == GA_Update, 47 : TRUE, poOpenInfo->papszOpenOptions)) 48 : { 49 5 : delete poDS; 50 5 : return nullptr; 51 : } 52 : else 53 378 : return poDS; 54 : } 55 : 56 : /************************************************************************/ 57 : /* CreateDataSource() */ 58 : /************************************************************************/ 59 : 60 : static GDALDataset * 61 2 : OGRPGDriverCreate(const char *pszName, CPL_UNUSED int nBands, 62 : CPL_UNUSED int nXSize, CPL_UNUSED int nYSize, 63 : CPL_UNUSED GDALDataType eDT, char **papszOptions) 64 : 65 : { 66 2 : OGRPGDataSource *poDS = new OGRPGDataSource(); 67 : 68 2 : if (!poDS->Open(pszName, TRUE, TRUE, papszOptions)) 69 : { 70 0 : delete poDS; 71 0 : CPLError( 72 : CE_Failure, CPLE_AppDefined, 73 : "PostgreSQL driver doesn't currently support database creation.\n" 74 : "Please create database with the `createdb' command."); 75 0 : return nullptr; 76 : } 77 : 78 2 : return poDS; 79 : } 80 : 81 : /************************************************************************/ 82 : /* RegisterOGRPG() */ 83 : /************************************************************************/ 84 : 85 25 : void RegisterOGRPG() 86 : 87 : { 88 25 : if (!GDAL_CHECK_VERSION("PG driver")) 89 0 : return; 90 : 91 25 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 92 0 : return; 93 : 94 25 : GDALDriver *poDriver = new GDALDriver(); 95 25 : OGRPGDriverSetCommonMetadata(poDriver); 96 25 : poDriver->pfnOpen = OGRPGDriverOpen; 97 25 : poDriver->pfnCreate = OGRPGDriverCreate; 98 : 99 25 : GetGDALDriverManager()->RegisterDriver(poDriver); 100 : }