Skip to content

Commit

Permalink
Changes to remove password from ogr database uris in legend and setti…
Browse files Browse the repository at this point in the history
…ng port 5151 as default for sde connections.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10457 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
gcontreras committed Apr 3, 2009
1 parent c00eaa8 commit 10e4a7f
Show file tree
Hide file tree
Showing 10 changed files with 1,224 additions and 1,150 deletions.
111 changes: 58 additions & 53 deletions python/core/qgsdatasourceuri.sip
Original file line number Diff line number Diff line change
@@ -1,53 +1,58 @@
/**
\struct QgsDataSourceURI
\brief Structure for storing the component parts of a PostgreSQL/RDBMS datasource URI.

This structure stores the database connection information, including host, database,
user name, password, schema, password, and sql where clause
*/
class QgsDataSourceURI
{
%TypeHeaderCode
#include <qgsdatasourceuri.h>
%End

public:
enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };

//! default constructor
QgsDataSourceURI();

//! constructor which parses input URI
QgsDataSourceURI(QString uri);

//! connection info
QString connectionInfo() const;

//! complete uri
QString uri() const;

//! quoted table name
QString quotedTablename() const;

//! Set all connection related members at once
void setConnection(const QString& aHost,
const QString& aPort,
const QString& aDatabase,
const QString& aUsername,
const QString& aPassword,
SSLmode sslmode );

//! Set all data source related members at once
void setDataSource(const QString& aSchema,
const QString& aTable,
const QString& aGeometryColumn,
const QString& aSql = QString());

QString username() const;
QString schema() const;
QString table() const;
QString sql() const;
QString geometryColumn() const;

void setSql(QString sql);
};
/**
\struct QgsDataSourceURI
\brief Structure for storing the component parts of a PostgreSQL/RDBMS datasource URI.

This structure stores the database connection information, including host, database,
user name, password, schema, password, and sql where clause
*/
class QgsDataSourceURI
{
%TypeHeaderCode
#include <qgsdatasourceuri.h>
%End

public:
enum SSLmode { SSLprefer, SSLdisable, SSLallow, SSLrequire };

//! default constructor
QgsDataSourceURI();

//! constructor which parses input URI
QgsDataSourceURI(QString uri);

//! connection info
QString connectionInfo() const;

//! complete uri
QString uri() const;

//! quoted table name
QString quotedTablename() const;

//! Set all connection related members at once
void setConnection(const QString& aHost,
const QString& aPort,
const QString& aDatabase,
const QString& aUsername,
const QString& aPassword,
SSLmode sslmode );

//! Set all data source related members at once
void setDataSource(const QString& aSchema,
const QString& aTable,
const QString& aGeometryColumn,
const QString& aSql = QString());

/** Removes password from uris
* @note this method was added in QGIS 1.1
*/
static QString removePassword( const QString& aUri);

QString username() const;
QString schema() const;
QString table() const;
QString sql() const;
QString geometryColumn() const;

void setSql(QString sql);
};
208 changes: 105 additions & 103 deletions src/app/ogr/qgsogrhelperfunctions.cpp
Original file line number Diff line number Diff line change
@@ -1,103 +1,105 @@
/***************************************************************************
qgsogrhelperfunctions.cpp
helper functions to create ogr uris for database and protocol drivers
-------------------
begin : Mon Jan 2 2009
copyright : (C) 2009 by Godofredo Contreras Nava
email : frdcn at hotmail.com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id:$ */

#include "qgsogrhelperfunctions.h"
#include "qgslogger.h"

QString createDatabaseURI( QString connectionType, QString host, QString database, QString port, QString user, QString password )
{
QString uri = "";

if ( connectionType == "ESRI Personal GeoDatabase" )
{
uri = "PGeo:" + database;
}
else if ( connectionType == "ESRI ArcSDE" )
{
//not tested
uri = "SDE:" + host + "," + database + "," + user + "," + password;
}
else if ( connectionType == "Informix DataBlade" )
{
//not tested
uri = "IDB:dbname=" + database + " server=" + host
+ " user=" + user
+ " pass=" + password;

}
else if ( connectionType == "INGRES" )
{
//not tested
uri = "@driver=ingres,dbname=" + database + ",userid=" + user + ",password=" + password;
}
else if ( connectionType == "MySQL" )
{
uri = "MySQL:" + database + ",host=" + host
+ ",port=" + port + ",user=" + user
+ ",password=" + password + "";
}
else if ( connectionType == "Oracle Spatial" )
{
uri = "OCI:" + user + "/" + password
+ "@" + host + "/" + database;
}
else if ( connectionType == "ODBC" )
{
if ( !user.isEmpty() )
{
if ( password.isEmpty() )
{
uri = "ODBC:" + user + "@" + database;
}
else
{
uri = "ODBC:" + user + "/" + password + "@" + database;
}

}
else
{
uri = "ODBC:" + database;
}
}
else if ( connectionType == "OGDI Vectors" )
{
}
else if ( connectionType == "PostgreSQL" )
{
uri = "PG:dbname='" + database + "' host='" + host
+ "' port='" + port + "' user='" + user
+ "' password='" + password + "'";

}
QgsDebugMsg( "Connection type is=" + connectionType + " and uri=" + uri );
return uri;
}


QString createProtocolURI( QString type, QString url )
{
QString uri = "";
if ( type == "GeoJSON" )
{
uri = url;
}
QgsDebugMsg( "Connection type is=" + type + " and uri=" + uri );
return uri;
}
/***************************************************************************
qgsogrhelperfunctions.cpp
helper functions to create ogr uris for database and protocol drivers
-------------------
begin : Mon Jan 2 2009
copyright : (C) 2009 by Godofredo Contreras Nava
email : frdcn at hotmail.com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id:$ */

#include "qgsogrhelperfunctions.h"
#include "qgslogger.h"
#include <QRegExp>

QString createDatabaseURI( QString connectionType, QString host, QString database, QString port, QString user, QString password )
{
QString uri = "";
//todo:add default ports for all kind of databases
if (connectionType=="ESRI Personal GeoDatabase")
{
uri="PGeo:"+database;
}
else if (connectionType=="ESRI ArcSDE")
{
if (port.isNull()||port.isEmpty())
port="5151";
uri="SDE:"+host+",PORT:"+port+","+database+","+user+","+password;
}
else if (connectionType=="Informix DataBlade")
{
//not tested
uri="IDB:dbname="+database+" server="+host
+" user="+user
+" pass="+password+" ";

}
else if (connectionType=="INGRES")
{
//not tested
uri="@driver=ingres,dbname="+database+",userid="+user+", password="+password+" ";
}
else if (connectionType=="MySQL")
{
uri="MySQL:"+database+",host="+host
+",port="+port+",user="+user
+", password="+password+" ";
}
else if (connectionType=="Oracle Spatial")
{
uri="OCI:"+user+"/"+password
+"@"+host+"/"+database;
}
else if (connectionType=="ODBC")
{
if(!user.isEmpty())
{
if(password.isEmpty())
{
uri="ODBC:"+user+"@"+database;
}
else
{
uri="ODBC:"+user+"/"+password+"@"+database;
}

}
else
{
uri="ODBC:"+database;
}
}
else if (connectionType=="OGDI Vectors")
{
}
else if (connectionType=="PostgreSQL")
{
uri="PG:dbname='"+database+"' host='"+host
+"' port='"+port+"' user='"+user
+"' password='"+password+"' ";

}
QgsDebugMsg("Connection type is="+connectionType+" and uri="+uri);
return uri;
}


QString createProtocolURI( QString type, QString url )
{
QString uri = "";
if ( type == "GeoJSON" )
{
uri = url;
}
QgsDebugMsg( "Connection type is=" + type + " and uri=" + uri );
return uri;
}
49 changes: 26 additions & 23 deletions src/app/ogr/qgsogrhelperfunctions.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
/***************************************************************************
qgsogrhelperfunctions.h
helper functions to create ogr uris for database and protocol drivers
-------------------
begin : Mon Jan 2 2009
copyright : (C) 2009 by Godofredo Contreras Nava
email : frdcn at hotmail.com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id:$ */

#include <QString>

QString createDatabaseURI( QString connectionType, QString host, QString database, QString port, QString user, QString password );
QString createProtocolURI( QString type, QString url );
/***************************************************************************
qgsogrhelperfunctions.h
helper functions to create ogr uris for database and protocol drivers
-------------------
begin : Mon Jan 2 2009
copyright : (C) 2009 by Godofredo Contreras Nava
email : frdcn at hotmail.com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/* $Id:$ */

#include <QString>

/* Create database uri from connection parameters */
QString createDatabaseURI(QString connectionType, QString host, QString database, QString port, QString user, QString password);

/* Create protocol uri from connection parameters */
QString createProtocolURI(QString type, QString url);

0 comments on commit 10e4a7f

Please sign in to comment.