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 : * SPDX-License-Identifier: MIT 11 : ****************************************************************************/ 12 : 13 : #include "ogrsf_frmts.h" 14 : 15 : #include "ogrmysqldrivercore.h" 16 : 17 : /************************************************************************/ 18 : /* OGRMySQLDriverIdentify() */ 19 : /************************************************************************/ 20 : 21 45932 : int OGRMySQLDriverIdentify(GDALOpenInfo *poOpenInfo) 22 : 23 : { 24 45932 : return STARTS_WITH_CI(poOpenInfo->pszFilename, "MYSQL:"); 25 : } 26 : 27 : /************************************************************************/ 28 : /* OGRMySQLDriverSetCommonMetadata() */ 29 : /************************************************************************/ 30 : 31 1306 : void OGRMySQLDriverSetCommonMetadata(GDALDriver *poDriver) 32 : { 33 1306 : poDriver->SetDescription(DRIVER_NAME); 34 1306 : poDriver->SetMetadataItem(GDAL_DCAP_VECTOR, "YES"); 35 1306 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_LAYER, "YES"); 36 1306 : poDriver->SetMetadataItem(GDAL_DCAP_DELETE_LAYER, "YES"); 37 1306 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE_FIELD, "YES"); 38 1306 : poDriver->SetMetadataItem(GDAL_DCAP_MEASURED_GEOMETRIES, "YES"); 39 1306 : poDriver->SetMetadataItem(GDAL_DCAP_Z_GEOMETRIES, "YES"); 40 1306 : poDriver->SetMetadataItem(GDAL_DMD_LONGNAME, "MySQL"); 41 1306 : poDriver->SetMetadataItem(GDAL_DMD_HELPTOPIC, "drivers/vector/mysql.html"); 42 : 43 1306 : poDriver->SetMetadataItem(GDAL_DMD_CONNECTION_PREFIX, "MYSQL:"); 44 : 45 1306 : poDriver->SetMetadataItem( 46 : GDAL_DMD_OPENOPTIONLIST, 47 : "<OpenOptionList>" 48 : " <Option name='DBNAME' type='string' description='Database name' " 49 : "required='true'/>" 50 : " <Option name='PORT' type='int' description='Port'/>" 51 : " <Option name='USER' type='string' description='User name'/>" 52 : " <Option name='PASSWORD' type='string' description='Password'/>" 53 : " <Option name='HOST' type='string' description='Server hostname'/>" 54 : " <Option name='TABLES' type='string' description='Restricted set of " 55 : "tables to list (comma separated)'/>" 56 1306 : "</OpenOptionList>"); 57 : 58 1306 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONOPTIONLIST, 59 1306 : "<CreationOptionList/>"); 60 : 61 1306 : poDriver->SetMetadataItem( 62 : GDAL_DS_LAYER_CREATIONOPTIONLIST, 63 : "<LayerCreationOptionList>" 64 : " <Option name='OVERWRITE' type='boolean' description='Whether to " 65 : "overwrite an existing table with the layer name to be created' " 66 : "default='NO'/>" 67 : " <Option name='LAUNDER' type='boolean' description='Whether layer " 68 : "and field names will be laundered' default='YES'/>" 69 : " <Option name='PRECISION' type='boolean' description='Whether fields " 70 : "created should keep the width and precision' default='YES'/>" 71 : " <Option name='GEOMETRY_NAME' type='string' description='Name of " 72 : "geometry column.' default='SHAPE'/>" 73 : " <Option name='SPATIAL_INDEX' type='boolean' description='Whether to " 74 : "create a spatial index' default='YES'/>" 75 : " <Option name='FID' type='string' description='Name of the FID " 76 : "column to create' default='OGR_FID' deprecated_alias='MYSQL_FID'/>" 77 : " <Option name='FID64' type='boolean' description='Whether to create " 78 : "the FID column with BIGINT type to handle 64bit wide ids' " 79 : "default='NO'/>" 80 : " <Option name='ENGINE' type='string' description='Database engine to " 81 : "use.'/>" 82 1306 : "</LayerCreationOptionList>"); 83 : 84 1306 : poDriver->SetMetadataItem(GDAL_DMD_CREATIONFIELDDATATYPES, 85 : "Integer Integer64 Real String Date DateTime " 86 1306 : "Time Binary"); 87 1306 : poDriver->SetMetadataItem(GDAL_DCAP_NOTNULL_FIELDS, "YES"); 88 1306 : poDriver->SetMetadataItem(GDAL_DCAP_DEFAULT_FIELDS, "YES"); 89 1306 : poDriver->SetMetadataItem(GDAL_DCAP_MULTIPLE_VECTOR_LAYERS, "YES"); 90 1306 : poDriver->SetMetadataItem(GDAL_DMD_SUPPORTED_SQL_DIALECTS, 91 1306 : "NATIVE OGRSQL SQLITE"); 92 : 93 1306 : poDriver->pfnIdentify = OGRMySQLDriverIdentify; 94 1306 : poDriver->SetMetadataItem(GDAL_DCAP_OPEN, "YES"); 95 1306 : poDriver->SetMetadataItem(GDAL_DCAP_CREATE, "YES"); 96 1306 : } 97 : 98 : /************************************************************************/ 99 : /* DeclareDeferredOGRMySQLPlugin() */ 100 : /************************************************************************/ 101 : 102 : #ifdef PLUGIN_FILENAME 103 1595 : void DeclareDeferredOGRMySQLPlugin() 104 : { 105 1595 : if (GDALGetDriverByName(DRIVER_NAME) != nullptr) 106 : { 107 302 : return; 108 : } 109 1293 : auto poDriver = new GDALPluginDriverProxy(PLUGIN_FILENAME); 110 : #ifdef PLUGIN_INSTALLATION_MESSAGE 111 : poDriver->SetMetadataItem(GDAL_DMD_PLUGIN_INSTALLATION_MESSAGE, 112 : PLUGIN_INSTALLATION_MESSAGE); 113 : #endif 114 1293 : OGRMySQLDriverSetCommonMetadata(poDriver); 115 1293 : GetGDALDriverManager()->DeclareDeferredPluginDriver(poDriver); 116 : } 117 : #endif