Skip to content

Commit 10e4a7f

Browse files
author
gcontreras
committed
Changes to remove password from ogr database uris in legend and setting port 5151 as default for sde connections.
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10457 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent c00eaa8 commit 10e4a7f

10 files changed

+1224
-1150
lines changed

python/core/qgsdatasourceuri.sip

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,58 @@
1-
/**
2-
\struct QgsDataSourceURI
3-
\brief Structure for storing the component parts of a PostgreSQL/RDBMS datasource URI.
4-
5-
This structure stores the database connection information, including host, database,
6-
user name, password, schema, password, and sql where clause
7-
*/
8-
class QgsDataSourceURI
9-
{
10-
%TypeHeaderCode
11-
#include <qgsdatasourceuri.h>
12-
%End
13-
14-
public:
15-
enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };
16-
17-
//! default constructor
18-
QgsDataSourceURI();
19-
20-
//! constructor which parses input URI
21-
QgsDataSourceURI(QString uri);
22-
23-
//! connection info
24-
QString connectionInfo() const;
25-
26-
//! complete uri
27-
QString uri() const;
28-
29-
//! quoted table name
30-
QString quotedTablename() const;
31-
32-
//! Set all connection related members at once
33-
void setConnection(const QString& aHost,
34-
const QString& aPort,
35-
const QString& aDatabase,
36-
const QString& aUsername,
37-
const QString& aPassword,
38-
SSLmode sslmode );
39-
40-
//! Set all data source related members at once
41-
void setDataSource(const QString& aSchema,
42-
const QString& aTable,
43-
const QString& aGeometryColumn,
44-
const QString& aSql = QString());
45-
46-
QString username() const;
47-
QString schema() const;
48-
QString table() const;
49-
QString sql() const;
50-
QString geometryColumn() const;
51-
52-
void setSql(QString sql);
53-
};
1+
/**
2+
\struct QgsDataSourceURI
3+
\brief Structure for storing the component parts of a PostgreSQL/RDBMS datasource URI.
4+
5+
This structure stores the database connection information, including host, database,
6+
user name, password, schema, password, and sql where clause
7+
*/
8+
class QgsDataSourceURI
9+
{
10+
%TypeHeaderCode
11+
#include <qgsdatasourceuri.h>
12+
%End
13+
14+
public:
15+
enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };
16+
17+
//! default constructor
18+
QgsDataSourceURI();
19+
20+
//! constructor which parses input URI
21+
QgsDataSourceURI(QString uri);
22+
23+
//! connection info
24+
QString connectionInfo() const;
25+
26+
//! complete uri
27+
QString uri() const;
28+
29+
//! quoted table name
30+
QString quotedTablename() const;
31+
32+
//! Set all connection related members at once
33+
void setConnection(const QString& aHost,
34+
const QString& aPort,
35+
const QString& aDatabase,
36+
const QString& aUsername,
37+
const QString& aPassword,
38+
SSLmode sslmode );
39+
40+
//! Set all data source related members at once
41+
void setDataSource(const QString& aSchema,
42+
const QString& aTable,
43+
const QString& aGeometryColumn,
44+
const QString& aSql = QString());
45+
46+
/** Removes password from uris
47+
* @note this method was added in QGIS 1.1
48+
*/
49+
static QString removePassword( const QString& aUri);
50+
51+
QString username() const;
52+
QString schema() const;
53+
QString table() const;
54+
QString sql() const;
55+
QString geometryColumn() const;
56+
57+
void setSql(QString sql);
58+
};

src/app/ogr/qgsogrhelperfunctions.cpp

Lines changed: 105 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,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-
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+
}

src/app/ogr/qgsogrhelperfunctions.h

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
/***************************************************************************
2-
qgsogrhelperfunctions.h
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 <QString>
21-
22-
QString createDatabaseURI( QString connectionType, QString host, QString database, QString port, QString user, QString password );
23-
QString createProtocolURI( QString type, QString url );
1+
/***************************************************************************
2+
qgsogrhelperfunctions.h
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 <QString>
21+
22+
/* Create database uri from connection parameters */
23+
QString createDatabaseURI(QString connectionType, QString host, QString database, QString port, QString user, QString password);
24+
25+
/* Create protocol uri from connection parameters */
26+
QString createProtocolURI(QString type, QString url);

0 commit comments

Comments
 (0)