Line data Source code
1 : /****************************************************************************** 2 : * 3 : * Project: OpenGIS Simple Features Reference Implementation 4 : * Purpose: Implements OGRMySQLDriver class. 5 : * Author: Frank Warmerdam, warmerdam@pobox.com 6 : * 7 : ****************************************************************************** 8 : * Copyright (c) 2004, 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 "ogrsf_frmts.h" 30 : 31 : #include "ogrmysqldrivercore.h" 32 : 33 : /************************************************************************/ 34 : /* OGRMySQLDriverIdentify() */ 35 : /************************************************************************/ 36 : 37 42886 : int OGRMySQLDriverIdentify(GDALOpenInfo *poOpenInfo) 38 : 39 : { 40 42886 : return STARTS_WITH_CI(poOpenInfo->pszFilename, "MYSQL:"); 41 : } 42 : 43 : /************************************************************************/ 44 : /* OGRMySQLDriverSetCommonMetadata() */ 45 : /************************************************************************/ 46 : 47 1227 : void OGRMySQLDriverSetCommonMetadata(GDALDriver *poDriver) 48 : { 49 1227 : poDriver->SetDescription(DRIVER_NAME); 50 1227 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 51 1227 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); 52 1227 : poDriver->SetMetadataItem(GDAL_DCAP_DELETE_LAYER, "YES"); 53 1227 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES"); 54 1227 : poDriver->SetMetadataItem(GDAL_DCAP_MEASURED_GEOMETRIES, "YES"); 55 1227 : poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); 56 1227 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "MySQL"); 57 1227 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/mysql.html"); 58 : 59 1227 : poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, "MYSQL:"); 60 : 61 1227 : poDriver->SetMetadataItem( 62 : GDAL_DMD_OPENOPTIONLIST, 63 : "<OpenOptionList>" 64 : " <Option name='DBNAME' type='string' description='Database name' " 65 : "required='true'/>" 66 : " <Option name='PORT' type='int' description='Port'/>" 67 : " <Option name='USER' type='string' description='User name'/>" 68 : " <Option name='PASSWORD' type='string' description='Password'/>" 69 : " <Option name='HOST' type='string' description='Server hostname'/>" 70 : " <Option name='TABLES' type='string' description='Restricted set of " 71 : "tables to list (comma separated)'/>" 72 1227 : "</OpenOptionList>"); 73 : 74 1227 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONOPTIONLIST, 75 1227 : "<CreationOptionList/>"); 76 : 77 1227 : poDriver->SetMetadataItem( 78 : GDAL_DS_LAYER_CREATIONOPTIONLIST, 79 : "<LayerCreationOptionList>" 80 : " <Option name='OVERWRITE' type='boolean' description='Whether to " 81 : "overwrite an existing table with the layer name to be created' " 82 : "default='NO'/>" 83 : " <Option name='LAUNDER' type='boolean' description='Whether layer " 84 : "and field names will be laundered' default='YES'/>" 85 : " <Option name='PRECISION' type='boolean' description='Whether fields " 86 : "created should keep the width and precision' default='YES'/>" 87 : " <Option name='GEOMETRY_NAME' type='string' description='Name of " 88 : "geometry column.' default='SHAPE'/>" 89 : " <Option name='SPATIAL_INDEX' type='boolean' description='Whether to " 90 : "create a spatial index' default='YES'/>" 91 : " <Option name='FID' type='string' description='Name of the FID " 92 : "column to create' default='OGR_FID' deprecated_alias='MYSQL_FID'/>" 93 : " <Option name='FID64' type='boolean' description='Whether to create " 94 : "the FID column with BIGINT type to handle 64bit wide ids' " 95 : "default='NO'/>" 96 : " <Option name='ENGINE' type='string' description='Database engine to " 97 : "use.'/>" 98 1227 : "</LayerCreationOptionList>"); 99 : 100 1227 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATATYPES, 101 : "Integer Integer64 Real String Date DateTime " 102 1227 : "Time Binary"); 103 1227 : poDriver->SetMetadataItem(GDAL_DCAP_NOTNULL_FIELDS, "YES"); 104 1227 : poDriver->SetMetadataItem(GDAL_DCAP_DEFAULT_FIELDS, "YES"); 105 1227 : poDriver->SetMetadataItem(GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, "YES"); 106 1227 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, 107 1227 : "NATIVE OGRSQL SQLITE"); 108 : 109 1227 : poDriver->pfnIdentify = OGRMySQLDriverIdentify; 110 1227 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 111 1227 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE, "YES"); 112 1227 : } 113 : 114 : /************************************************************************/ 115 : /* DeclareDeferredOGRMySQLPlugin() */ 116 : /************************************************************************/ 117 : 118 : #ifdef PLUGIN_FILENAME 119 1511 : void DeclareDeferredOGRMySQLPlugin() 120 : { 121 1511 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 122 : { 123 295 : return; 124 : } 125 1216 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 126 : #ifdef PLUGIN_INSTALLATION_MESSAGE 127 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 128 : PLUGIN_INSTALLATION_MESSAGE); 129 : #endif 130 1216 : OGRMySQLDriverSetCommonMetadata(poDriver); 131 1216 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 132 : } 133 : #endif