|
1 |
| -/*************************************************************************** |
2 |
| - qgsogrhelperfunctions.cpp |
3 |
| - helper functions to create ogr uris for database and protocol drivers |
4 |
| - ------------------- |
5 |
| - begin : Mon Jan 2 2009 |
6 |
| - copyright : (C) 2009 by Godofredo Contreras Nava |
7 |
| - email : frdcn at hotmail.com |
8 |
| - ***************************************************************************/ |
9 |
| - |
10 |
| -/*************************************************************************** |
11 |
| - * * |
12 |
| - * This program is free software; you can redistribute it and/or modify * |
13 |
| - * it under the terms of the GNU General Public License as published by * |
14 |
| - * the Free Software Foundation; either version 2 of the License, or * |
15 |
| - * (at your option) any later version. * |
16 |
| - * * |
17 |
| - ***************************************************************************/ |
18 |
| -/* $Id:$ */ |
19 |
| - |
20 |
| -#include "qgsogrhelperfunctions.h" |
21 |
| -#include "qgslogger.h" |
22 |
| - |
23 |
| -QString createDatabaseURI( QString connectionType, QString host, QString database, QString port, QString user, QString password ) |
24 |
| -{ |
25 |
| - QString uri = ""; |
26 |
| - |
27 |
| - if ( connectionType == "ESRI Personal GeoDatabase" ) |
28 |
| - { |
29 |
| - uri = "PGeo:" + database; |
30 |
| - } |
31 |
| - else if ( connectionType == "ESRI ArcSDE" ) |
32 |
| - { |
33 |
| - //not tested |
34 |
| - uri = "SDE:" + host + "," + database + "," + user + "," + password; |
35 |
| - } |
36 |
| - else if ( connectionType == "Informix DataBlade" ) |
37 |
| - { |
38 |
| - //not tested |
39 |
| - uri = "IDB:dbname=" + database + " server=" + host |
40 |
| - + " user=" + user |
41 |
| - + " pass=" + password; |
42 |
| - |
43 |
| - } |
44 |
| - else if ( connectionType == "INGRES" ) |
45 |
| - { |
46 |
| - //not tested |
47 |
| - uri = "@driver=ingres,dbname=" + database + ",userid=" + user + ",password=" + password; |
48 |
| - } |
49 |
| - else if ( connectionType == "MySQL" ) |
50 |
| - { |
51 |
| - uri = "MySQL:" + database + ",host=" + host |
52 |
| - + ",port=" + port + ",user=" + user |
53 |
| - + ",password=" + password + ""; |
54 |
| - } |
55 |
| - else if ( connectionType == "Oracle Spatial" ) |
56 |
| - { |
57 |
| - uri = "OCI:" + user + "/" + password |
58 |
| - + "@" + host + "/" + database; |
59 |
| - } |
60 |
| - else if ( connectionType == "ODBC" ) |
61 |
| - { |
62 |
| - if ( !user.isEmpty() ) |
63 |
| - { |
64 |
| - if ( password.isEmpty() ) |
65 |
| - { |
66 |
| - uri = "ODBC:" + user + "@" + database; |
67 |
| - } |
68 |
| - else |
69 |
| - { |
70 |
| - uri = "ODBC:" + user + "/" + password + "@" + database; |
71 |
| - } |
72 |
| - |
73 |
| - } |
74 |
| - else |
75 |
| - { |
76 |
| - uri = "ODBC:" + database; |
77 |
| - } |
78 |
| - } |
79 |
| - else if ( connectionType == "OGDI Vectors" ) |
80 |
| - { |
81 |
| - } |
82 |
| - else if ( connectionType == "PostgreSQL" ) |
83 |
| - { |
84 |
| - uri = "PG:dbname='" + database + "' host='" + host |
85 |
| - + "' port='" + port + "' user='" + user |
86 |
| - + "' password='" + password + "'"; |
87 |
| - |
88 |
| - } |
89 |
| - QgsDebugMsg( "Connection type is=" + connectionType + " and uri=" + uri ); |
90 |
| - return uri; |
91 |
| -} |
92 |
| - |
93 |
| - |
94 |
| -QString createProtocolURI( QString type, QString url ) |
95 |
| -{ |
96 |
| - QString uri = ""; |
97 |
| - if ( type == "GeoJSON" ) |
98 |
| - { |
99 |
| - uri = url; |
100 |
| - } |
101 |
| - QgsDebugMsg( "Connection type is=" + type + " and uri=" + uri ); |
102 |
| - return uri; |
103 |
| -} |
| 1 | +/*************************************************************************** |
| 2 | + qgsogrhelperfunctions.cpp |
| 3 | + helper functions to create ogr uris for database and protocol drivers |
| 4 | + ------------------- |
| 5 | + begin : Mon Jan 2 2009 |
| 6 | + copyright : (C) 2009 by Godofredo Contreras Nava |
| 7 | + email : frdcn at hotmail.com |
| 8 | + ***************************************************************************/ |
| 9 | + |
| 10 | +/*************************************************************************** |
| 11 | + * * |
| 12 | + * This program is free software; you can redistribute it and/or modify * |
| 13 | + * it under the terms of the GNU General Public License as published by * |
| 14 | + * the Free Software Foundation; either version 2 of the License, or * |
| 15 | + * (at your option) any later version. * |
| 16 | + * * |
| 17 | + ***************************************************************************/ |
| 18 | +/* $Id:$ */ |
| 19 | + |
| 20 | +#include "qgsogrhelperfunctions.h" |
| 21 | +#include "qgslogger.h" |
| 22 | +#include <QRegExp> |
| 23 | + |
| 24 | +QString createDatabaseURI( QString connectionType, QString host, QString database, QString port, QString user, QString password ) |
| 25 | +{ |
| 26 | + QString uri = ""; |
| 27 | + //todo:add default ports for all kind of databases |
| 28 | + if (connectionType=="ESRI Personal GeoDatabase") |
| 29 | + { |
| 30 | + uri="PGeo:"+database; |
| 31 | + } |
| 32 | + else if (connectionType=="ESRI ArcSDE") |
| 33 | + { |
| 34 | + if (port.isNull()||port.isEmpty()) |
| 35 | + port="5151"; |
| 36 | + uri="SDE:"+host+",PORT:"+port+","+database+","+user+","+password; |
| 37 | + } |
| 38 | + else if (connectionType=="Informix DataBlade") |
| 39 | + { |
| 40 | + //not tested |
| 41 | + uri="IDB:dbname="+database+" server="+host |
| 42 | + +" user="+user |
| 43 | + +" pass="+password+" "; |
| 44 | + |
| 45 | + } |
| 46 | + else if (connectionType=="INGRES") |
| 47 | + { |
| 48 | + //not tested |
| 49 | + uri="@driver=ingres,dbname="+database+",userid="+user+", password="+password+" "; |
| 50 | + } |
| 51 | + else if (connectionType=="MySQL") |
| 52 | + { |
| 53 | + uri="MySQL:"+database+",host="+host |
| 54 | + +",port="+port+",user="+user |
| 55 | + +", password="+password+" "; |
| 56 | + } |
| 57 | + else if (connectionType=="Oracle Spatial") |
| 58 | + { |
| 59 | + uri="OCI:"+user+"/"+password |
| 60 | + +"@"+host+"/"+database; |
| 61 | + } |
| 62 | + else if (connectionType=="ODBC") |
| 63 | + { |
| 64 | + if(!user.isEmpty()) |
| 65 | + { |
| 66 | + if(password.isEmpty()) |
| 67 | + { |
| 68 | + uri="ODBC:"+user+"@"+database; |
| 69 | + } |
| 70 | + else |
| 71 | + { |
| 72 | + uri="ODBC:"+user+"/"+password+"@"+database; |
| 73 | + } |
| 74 | + |
| 75 | + } |
| 76 | + else |
| 77 | + { |
| 78 | + uri="ODBC:"+database; |
| 79 | + } |
| 80 | + } |
| 81 | + else if (connectionType=="OGDI Vectors") |
| 82 | + { |
| 83 | + } |
| 84 | + else if (connectionType=="PostgreSQL") |
| 85 | + { |
| 86 | + uri="PG:dbname='"+database+"' host='"+host |
| 87 | + +"' port='"+port+"' user='"+user |
| 88 | + +"' password='"+password+"' "; |
| 89 | + |
| 90 | + } |
| 91 | + QgsDebugMsg("Connection type is="+connectionType+" and uri="+uri); |
| 92 | + return uri; |
| 93 | +} |
| 94 | + |
| 95 | + |
| 96 | +QString createProtocolURI( QString type, QString url ) |
| 97 | +{ |
| 98 | + QString uri = ""; |
| 99 | + if ( type == "GeoJSON" ) |
| 100 | + { |
| 101 | + uri = url; |
| 102 | + } |
| 103 | + QgsDebugMsg( "Connection type is=" + type + " and uri=" + uri ); |
| 104 | + return uri; |
| 105 | +} |
0 commit comments