25 QString
createDatabaseURI(
const QString &connectionType,
const QString &host,
const QString &database, QString port,
const QString &configId, QString username, QString password,
bool expandAuthConfig )
31 if ( ! configId.isEmpty() )
40 if ( connectionType == QLatin1String(
"ESRI Personal GeoDatabase" ) )
42 uri =
"PGeo:" + database;
44 else if ( connectionType == QLatin1String(
"ESRI ArcSDE" ) )
47 port = QStringLiteral(
"5151" );
49 uri =
"SDE:" + host +
",PORT:" + port +
',' + database +
',' + username +
',' + password;
51 else if ( connectionType == QLatin1String(
"Informix DataBlade" ) )
54 uri =
"IDB:dbname=" + database;
56 if ( !host.isEmpty() )
57 uri += QStringLiteral(
" server=%1" ).arg( host );
59 if ( !username.isEmpty() )
61 uri += QStringLiteral(
" user=%1" ).arg( username );
63 if ( !password.isEmpty() )
64 uri += QStringLiteral(
" pass=%1" ).arg( password );
67 else if ( connectionType == QLatin1String(
"Ingres" ) )
70 uri =
"@driver=ingres,dbname=" + database;
71 if ( !username.isEmpty() )
73 uri += QStringLiteral(
",userid=%1" ).arg( username );
75 if ( !password.isEmpty() )
76 uri += QStringLiteral(
",password=%1" ).arg( password );
79 else if ( connectionType == QLatin1String(
"MySQL" ) )
81 uri =
"MySQL:" + database;
83 if ( !host.isEmpty() )
85 uri += QStringLiteral(
",host=%1" ).arg( host );
87 if ( !port.isEmpty() )
88 uri += QStringLiteral(
",port=%1" ).arg( port );
91 if ( !username.isEmpty() )
93 uri += QStringLiteral(
",user=%1" ).arg( username );
95 if ( !password.isEmpty() )
96 uri += QStringLiteral(
",password=%1" ).arg( password );
99 else if ( connectionType == QLatin1String(
"MSSQL" ) )
101 uri = QStringLiteral(
"MSSQL:" );
103 if ( !host.isEmpty() )
105 uri += QStringLiteral(
";server=%1" ).arg( host );
107 if ( !port.isEmpty() )
108 uri += QStringLiteral(
",%1" ).arg( port );
111 if ( !username.isEmpty() )
113 uri += QStringLiteral(
";uid=%1" ).arg( username );
115 if ( !password.isEmpty() )
116 uri += QStringLiteral(
";pwd=%1" ).arg( password );
119 uri += QLatin1String(
";trusted_connection=yes" );
121 if ( !database.isEmpty() )
122 uri += QStringLiteral(
";database=%1" ).arg( database );
124 else if ( connectionType == QLatin1String(
"Oracle Spatial" ) )
126 uri =
"OCI:" + username;
128 if ( ( !username.isEmpty() && !password.isEmpty() ) ||
129 ( username.isEmpty() && password.isEmpty() ) )
132 if ( !password.isEmpty() )
136 if ( !host.isEmpty() || !database.isEmpty() )
140 if ( !host.isEmpty() )
143 if ( !port.isEmpty() )
147 if ( !database.isEmpty() )
149 if ( !host.isEmpty() )
155 else if ( connectionType == QLatin1String(
"ODBC" ) )
157 if ( !username.isEmpty() )
159 if ( password.isEmpty() )
161 uri =
"ODBC:" + username +
'@' + database;
165 uri =
"ODBC:" + username +
'/' + password +
'@' + database;
171 uri =
"ODBC:" + database;
174 else if ( connectionType == QLatin1String(
"OGDI Vectors" ) )
177 else if ( connectionType == QLatin1String(
"PostgreSQL" ) )
179 uri =
"PG:dbname='" + database +
'\'';
181 if ( !host.isEmpty() )
183 uri += QStringLiteral(
" host='%1'" ).arg( host );
185 if ( !port.isEmpty() )
186 uri += QStringLiteral(
" port='%1'" ).arg( port );
189 if ( !username.isEmpty() )
191 uri += QStringLiteral(
" user='%1'" ).arg( username );
193 if ( !password.isEmpty() )
194 uri += QStringLiteral(
" password='%1'" ).arg( password );
200 if ( !( configId.isEmpty() ) )
202 if ( ! expandAuthConfig )
204 uri += QStringLiteral(
" authcfg='%1'" ).arg( configId );
208 QStringList connectionItems;
209 connectionItems << uri;
212 uri = connectionItems.join( QString() );
216 QgsDebugMsg(
"Connection type is=" + connectionType +
" and uri=" + uri );
221 QString
createProtocolURI(
const QString &type,
const QString &url,
const QString &configId,
const QString &username,
const QString &password,
bool expandAuthConfig )
224 if ( type == QLatin1String(
"HTTP/HTTPS/FTP" ) )
228 if ( !uri.startsWith(
"http://" ) && !uri.startsWith(
"https://" ) && !uri.startsWith(
"ftp://" ) )
230 uri.prepend( QStringLiteral(
"http://" ) );
232 uri.prepend( QStringLiteral(
"/vsicurl/" ) );
234 else if ( type == QLatin1String(
"AWS S3" ) )
237 uri.prepend( QStringLiteral(
"/vsis3/" ) );
239 else if ( type == QLatin1String(
"Google Cloud Storage" ) )
242 uri.prepend( QStringLiteral(
"/vsigs/" ) );
244 else if ( type == QLatin1String(
"Microsoft Azure Blob" ) )
247 uri.prepend( QStringLiteral(
"/vsiaz/" ) );
249 else if ( type == QLatin1String(
"Alibaba Cloud OSS" ) )
252 uri.prepend( QStringLiteral(
"/vsioss/" ) );
254 else if ( type == QLatin1String(
"OpenStack Swift Object Storage" ) )
257 uri.prepend( QStringLiteral(
"/vsiswift/" ) );
259 else if ( type == QLatin1String(
"GeoJSON" ) )
263 else if ( type == QLatin1String(
"CouchDB" ) )
265 uri = QStringLiteral(
"couchdb:%1" ).arg( url );
267 else if ( type == QLatin1String(
"DODS/OPeNDAP" ) )
269 uri = QStringLiteral(
"DODS:%1" ).arg( url );
271 QgsDebugMsg(
"Connection type is=" + type +
" and uri=" + uri );
273 if ( ! configId.isEmpty() )
275 if ( expandAuthConfig )
277 QStringList connectionItems;
278 connectionItems << uri;
281 uri = connectionItems.join( QString() );
286 uri += QStringLiteral(
" authcfg='%1'" ).arg( configId );
289 else if ( !( username.isEmpty() || password.isEmpty( ) ) )
291 uri.replace( QStringLiteral(
"://" ), QStringLiteral(
"://%1:%2@" ).arg( username, password ) );
QString createProtocolURI(const QString &type, const QString &url, const QString &configId, const QString &username, const QString &password, bool expandAuthConfig)
CreateProtocolURI.
bool updateDataSourceUriItems(QStringList &connectionItems, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QgsDataSourceUri with an authentication config.
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
QString createDatabaseURI(const QString &connectionType, const QString &host, const QString &database, QString port, const QString &configId, QString username, QString password, bool expandAuthConfig)
CreateDatabaseURI.