|
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 |
| -} |
| 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