| 1 |
/****************************************************************************** |
| 2 |
* |
| 3 |
* Project: OpenGIS Simple Features Reference Implementation |
| 4 |
* Purpose: Implements OGRIDBDriver class. |
| 5 |
* (based on ODBC and PG drivers). |
| 6 |
* Author: Oleg Semykin, [email protected] |
| 7 |
* |
| 8 |
****************************************************************************** |
| 9 |
* Copyright (c) 2006, Oleg Semykin |
| 10 |
* |
| 11 |
* SPDX-License-Identifier: MIT |
| 12 |
****************************************************************************/ |
| 13 |
|
| 14 |
#include "ogr_idb.h" |
| 15 |
#include "cpl_conv.h" |
| 16 |
|
| 17 |
#include "ogridbdrivercore.h" |
| 18 |
|
| 19 |
/************************************************************************/ |
| 20 |
/* Open() */ |
| 21 |
/************************************************************************/ |
| 22 |
|
| 23 |
static GDALDataset *OGRIDBDriverOpen(GDALOpenInfo *poOpenInfo) |
| 24 |
|
| 25 |
{ |
| 26 |
OGRIDBDataSource *poDS; |
| 27 |
|
| 28 |
if (!STARTS_WITH_CI(poOpenInfo->pszFilename, "IDB:")) |
| 29 |
return nullptr; |
| 30 |
|
| 31 |
poDS = new OGRIDBDataSource(); |
| 32 |
|
| 33 |
if (!poDS->Open(poOpenInfo->pszFilename, |
| 34 |
(poOpenInfo->nOpenFlags & GDAL_OF_UPDATE) != 0, TRUE)) |
| 35 |
{ |
| 36 |
delete poDS; |
| 37 |
return nullptr; |
| 38 |
} |
| 39 |
else |
| 40 |
return poDS; |
| 41 |
} |
| 42 |
|
| 43 |
/************************************************************************/ |
| 44 |
/* CreateDataSource() */ |
| 45 |
/************************************************************************/ |
| 46 |
|
| 47 |
static GDALDataset *OGRIDBDriverCreate(const char *pszName, int /* nBands */, |
| 48 |
int /* nXSize */, int /* nYSize */, |
| 49 |
GDALDataType /* eDT */, |
| 50 |
char ** /*papszOptions*/) |
| 51 |
|
| 52 |
{ |
| 53 |
OGRIDBDataSource *poDS; |
| 54 |
|
| 55 |
if (!STARTS_WITH_CI(pszName, "IDB:")) |
| 56 |
return nullptr; |
| 57 |
|
| 58 |
poDS = new OGRIDBDataSource(); |
| 59 |
|
| 60 |
if (!poDS->Open(pszName, TRUE, TRUE)) |
| 61 |
{ |
| 62 |
delete poDS; |
| 63 |
CPLError(CE_Failure, CPLE_AppDefined, |
| 64 |
"IDB driver doesn't currently support database creation."); |
| 65 |
return nullptr; |
| 66 |
} |
| 67 |
|
| 68 |
return poDS; |
| 69 |
} |
| 70 |
|
| 71 |
/************************************************************************/ |
| 72 |
/* RegisterOGRIDB() */ |
| 73 |
/************************************************************************/ |
| 74 |
|
| 75 |
void RegisterOGRIDB() |
| 76 |
|
| 77 |
{ |
| 78 |
if (!GDAL_CHECK_VERSION("IDB driver")) |
| 79 |
return; |
| 80 |
if (GDALGetDriverByName(DRIVER_NAME) != nullptr) |
| 81 |
return; |
| 82 |
|
| 83 |
GDALDriver *poDriver = new GDALDriver(); |
| 84 |
OGRIDBDriverSetCommonMetadata(poDriver); |
| 85 |
|
| 86 |
poDriver->pfnOpen = OGRIDBDriverOpen; |
| 87 |
poDriver->pfnCreate = OGRIDBDriverCreate; |
| 88 |
|
| 89 |
GetGDALDriverManager()->RegisterDriver(poDriver); |
| 90 |
} |