Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OpenGIS Simple Features Reference Implementation 4 : * Purpose: Implements OGRODBCDriver class. 5 : * Author: Frank Warmerdam, warmerdam@pobox.com 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2003, Frank Warmerdam <warmerdam@pobox.com> 9 : * 10 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "gdal_frmts.h" 14 : #include "gdalplugindriverproxy.h" 15 : 16 : #include "ogrsf_frmts.h" 17 : 18 : #include "ogrodbcdrivercore.h" 19 : 20 : /************************************************************************/ 21 : /* OGRODBCDriverIsSupportedMsAccessFileExtension() */ 22 : /************************************************************************/ 23 : 24 54287 : bool OGRODBCDriverIsSupportedMsAccessFileExtension(const char *pszExtension) 25 : { 26 : // these are all possible extensions for MS Access databases 27 108572 : return EQUAL(pszExtension, "MDB") || EQUAL(pszExtension, "ACCDB") || 28 108572 : EQUAL(pszExtension, "STYLE"); 29 : } 30 : 31 : /************************************************************************/ 32 : /* OGRODBCDriverIdentify() */ 33 : /************************************************************************/ 34 : 35 54289 : int OGRODBCDriverIdentify(GDALOpenInfo *poOpenInfo) 36 : 37 : { 38 54289 : if (STARTS_WITH_CI(poOpenInfo->pszFilename, "PGEO:")) 39 : { 40 0 : return FALSE; 41 : } 42 : 43 54289 : if (STARTS_WITH_CI(poOpenInfo->pszFilename, "ODBC:")) 44 0 : return TRUE; 45 : 46 54289 : const char *psExtension = poOpenInfo->osExtension.c_str(); 47 54289 : if (EQUAL(psExtension, "mdb")) 48 4 : return -1; // Could potentially be a PGeo MDB database 49 : 50 54285 : if (OGRODBCDriverIsSupportedMsAccessFileExtension(psExtension)) 51 0 : return TRUE; // An Access database which isn't a .MDB file (we checked 52 : // that above), so this is the only candidate driver 53 : 54 : // doesn't start with "ODBC:", and isn't an access database => not supported 55 54285 : return FALSE; 56 : } 57 : 58 : /************************************************************************/ 59 : /* OGRODBCDriverSetCommonMetadata() */ 60 : /************************************************************************/ 61 : 62 2109 : void OGRODBCDriverSetCommonMetadata(GDALDriver *poDriver) 63 : { 64 2109 : poDriver->SetDescription(DRIVER_NAME); 65 2109 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 66 2109 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, 67 2109 : "Open Database Connectivity (ODBC)"); 68 2109 : poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, "ODBC:"); 69 2109 : poDriver->SetMetadataItem(GDAL_DMD_EXTENSIONS, "mdb accdb"); 70 2109 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/odbc.html"); 71 2109 : poDriver->SetMetadataItem(GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, "YES"); 72 2109 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, 73 2109 : "NATIVE OGRSQL SQLITE"); 74 : 75 2109 : poDriver->SetMetadataItem( 76 : GDAL_DMD_OPENOPTIONLIST, 77 : "<OpenOptionList>" 78 : " <Option name='LIST_ALL_TABLES' type='string-select' scope='vector' " 79 : "description='Whether all tables, including system and internal tables " 80 : "(such as MSys* tables) should be listed' default='NO'>" 81 : " <Value>YES</Value>" 82 : " <Value>NO</Value>" 83 : " </Option>" 84 2109 : "</OpenOptionList>"); 85 : 86 2109 : poDriver->pfnIdentify = OGRODBCDriverIdentify; 87 2109 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 88 2109 : } 89 : 90 : /************************************************************************/ 91 : /* DeclareDeferredOGRODBCPlugin() */ 92 : /************************************************************************/ 93 : 94 : #ifdef PLUGIN_FILENAME 95 2038 : void DeclareDeferredOGRODBCPlugin() 96 : { 97 2038 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 98 : { 99 283 : return; 100 : } 101 1755 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 102 : #ifdef PLUGIN_INSTALLATION_MESSAGE 103 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 104 : PLUGIN_INSTALLATION_MESSAGE); 105 : #endif 106 1755 : OGRODBCDriverSetCommonMetadata(poDriver); 107 1755 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 108 : } 109 : #endif