22 #include <QStringList>
27 : mSSLmode( SSLprefer )
29 , mUseEstimatedMetadata( false )
30 , mSelectAtIdDisabled( false )
31 , mWkbType(
QGis::WKBUnknown )
37 : mSSLmode( SSLprefer )
39 , mUseEstimatedMetadata( false )
40 , mSelectAtIdDisabled( false )
41 , mWkbType(
QGis::WKBUnknown )
44 while ( i < uri.length() )
57 while ( i < uri.length() && uri[i] !=
'=' && !uri[i].isSpace() )
60 QString pname = uri.mid( start, i - start );
83 if ( pname ==
"table" )
104 while ( i < uri.length() && uri[i] !=
')' )
106 if ( uri[i] ==
'\\' )
111 if ( i == uri.length() )
127 else if ( pname ==
"key" )
131 else if ( pname ==
"estimatedmetadata" )
135 else if ( pname ==
"srid" )
139 else if ( pname ==
"type" )
141 QString geomTypeUpper = pval.toUpper();
142 if ( geomTypeUpper ==
"POINT" )
146 else if ( geomTypeUpper ==
"LINESTRING" || geomTypeUpper ==
"LINE" )
150 else if ( geomTypeUpper ==
"POLYGON" )
154 else if ( geomTypeUpper ==
"MULTIPOINT" )
158 else if ( geomTypeUpper ==
"MULTILINESTRING" )
162 else if ( geomTypeUpper ==
"MULTIPOLYGON" )
171 else if ( pname ==
"selectatid" )
175 else if ( pname ==
"service" )
179 else if ( pname ==
"user" )
183 else if ( pname ==
"password" )
187 else if ( pname ==
"connect_timeout" )
191 else if ( pname ==
"dbname" )
195 else if ( pname ==
"host" )
199 else if ( pname ==
"hostaddr" )
203 else if ( pname ==
"port" )
207 else if ( pname ==
"tty" )
211 else if ( pname ==
"options" )
215 else if ( pname ==
"sslmode" )
217 if ( pval ==
"disable" )
219 else if ( pval ==
"allow" )
221 else if ( pval ==
"prefer" )
223 else if ( pval ==
"require" )
226 else if ( pname ==
"requiressl" )
233 else if ( pname ==
"krbsrvname" )
237 else if ( pname ==
"gsslib" )
243 QgsDebugMsg(
"invalid connection option \"" + pname +
"\" ignored" );
252 regexp.setMinimal(
true );
253 QString safeName( aUri );
254 if ( aUri.contains(
" password=" ) )
256 regexp.setPattern(
" password=.* " );
257 safeName.replace( regexp,
" " );
259 else if ( aUri.contains(
",password=" ) )
261 regexp.setPattern(
",password=.*," );
262 safeName.replace( regexp,
"," );
264 else if ( aUri.contains(
"IDB:" ) )
266 regexp.setPattern(
" pass=.* " );
267 safeName.replace( regexp,
" " );
269 else if (( aUri.contains(
"OCI:" ) )
270 || ( aUri.contains(
"ODBC:" ) ) )
272 regexp.setPattern(
"/.*@" );
273 safeName.replace( regexp,
"/@" );
275 else if ( aUri.contains(
"SDE:" ) )
277 QStringList strlist = aUri.split(
"," );
278 safeName = strlist[0] +
"," + strlist[1] +
"," + strlist[2] +
"," + strlist[3];
391 QString val = theVal;
393 val.replace(
"\\",
"\\\\" );
394 val.replace( delim, QString(
"\\%1" ).arg( delim ) );
402 while ( i < uri.length() && uri[i].isSpace() )
412 if ( uri[i] ==
'\'' || uri[i] ==
'"' )
414 QChar delim = uri[i];
421 if ( i == uri.length() )
423 QgsDebugMsg(
"unterminated quoted string in connection info string" );
427 if ( uri[i] ==
'\\' )
430 if ( i == uri.length() )
432 if ( uri[i] != delim && uri[i] !=
'\\' )
435 else if ( uri[i] == delim )
447 while ( i < uri.length() )
449 if ( uri[i].isSpace() )
455 if ( uri[i] ==
'\\' )
458 if ( i == uri.length() )
460 if ( uri[i] !=
'\\' && uri[i] !=
'\'' )
475 QStringList connectionItems;
486 else if (
mHost !=
"" )
488 connectionItems <<
"host=" +
mHost;
494 connectionItems <<
"port=" +
mPort;
508 connectionItems <<
"sslmode=disable";
510 connectionItems <<
"sslmode=allow";
512 connectionItems <<
"sslmode=require";
515 connectionItems <<
"sslmode=prefer";
518 return connectionItems.join(
" " );
532 theUri += QString(
" estimatedmetadata=true" );
535 if ( !
mSrid.isEmpty() )
537 theUri += QString(
" srid=%1" ).arg(
mSrid );
550 theUri +=
"LINESTRING";
556 theUri +=
"MULTIPOINT";
559 theUri +=
"MULTILINESTRING";
562 theUri +=
"MULTIPOLYGON";
568 theUri +=
"LINESTRINGM";
571 theUri +=
"POLYGONM";
574 theUri +=
"MULTIPOINTM";
577 theUri +=
"MULTILINESTRINGM";
580 theUri +=
"MULTIPOLYGONM";
590 theUri += QString(
" selectatid=false" );
594 columnName.replace(
"\\",
"\\\\" );
595 columnName.replace(
")",
"\\)" );
597 theUri += QString(
" table=%1%2 sql=%3" )
599 .arg(
mGeometryColumn.isNull() ? QString() : QString(
" (%1)" ).arg( columnName ) )
608 foreach ( QString key,
mParams.uniqueKeys() )
610 foreach ( QString value,
mParams.values( key ) )
612 url.addQueryItem( key, value );
615 return url.encodedQuery();
622 url.setEncodedQuery( uri );
623 QPair<QString, QString> item;
624 foreach ( item, url.queryItems() )
626 mParams.insertMulti( item.first, item.second );
638 return QString(
"\"%1\".\"%2\"" )
642 return QString(
"\"%1\"" )
648 const QString &database,
649 const QString &username,
650 const QString &password,
662 const QString &database,
663 const QString &username,
664 const QString &password,
675 const QString &table,
676 const QString &geometryColumn,
678 const QString &keyColumn )
715 mParams.insertMulti( key, value );
720 foreach ( QString val, value )
722 mParams.insertMulti( key, val );
743 return mParams.contains( key );
QString mService
service name
QgsDataSourceURI()
default constructor
int removeParam(const QString &key)
Remove generic param (generic mode)
QString quotedTablename() const
quoted table name
QString geometryColumn() const
QString mSql
SQL query or where clause used to limit features returned from the layer.
void setEncodedUri(const QByteArray &uri)
set complete encoded uri (generic mode)
static QString removePassword(const QString &aUri)
Removes password element from uris.
QString mGeometryColumn
geometry column
void setDatabase(const QString &database)
Set database.
QString connectionInfo() const
return connection part of URI
WkbType
Used for symbology operations.
QString mSrid
SRID or a null string if not specified.
The QGis class provides global constants for use throughout the application.
bool mSelectAtIdDisabled
Disable SelectAtId capability (eg. to trigger the attribute table memory model for expensive views) ...
QString mTable
spatial table
bool useEstimatedMetadata() const
QStringList params(const QString &key) const
Get multiple generic param (generic mode)
QString keyColumn() const
QString mPort
port the database server listens on
void setConnection(const QString &aHost, const QString &aPort, const QString &aDatabase, const QString &aUsername, const QString &aPassword, SSLmode sslmode=SSLprefer)
Set all connection related members at once.
QString getValue(const QString &uri, int &i)
void setPassword(QString password)
set password
void disableSelectAtId(bool theFlag)
QGis::WkbType wkbType() const
void skipBlanks(const QString &uri, int &i)
QString uri() const
return complete uri
void setParam(const QString &key, const QString &value)
Set generic param (generic mode)
void setUseEstimatedMetadata(bool theFlag)
set use Estimated Metadata
enum SSLmode sslMode() const
bool hasParam(const QString &key) const
Test if param exists (generic mode)
void setSrid(QString srid)
QString mPassword
password
QString param(const QString &key) const
Get generic param (generic mode)
enum SSLmode mSSLmode
ssl mode
void setKeyColumn(QString column)
void setUsername(QString username)
set username
QMap< QString, QString > mParams
Generic params store.
QString mDatabase
database name
void setWkbType(QGis::WkbType type)
QGis::WkbType mWkbType
geometry type (or QGis::WKBUnknown if not specified)
QString mKeyColumn
key column
bool selectAtIdDisabled() const
QByteArray encodedUri() const
return complete encoded uri (generic mode)
bool mUseEstimatedMetadata
Use estimated metadata flag.
QString mUsername
username
QString escape(const QString &uri, QChar delim) const
void setDataSource(const QString &aSchema, const QString &aTable, const QString &aGeometryColumn, const QString &aSql=QString(), const QString &aKeyColumn=QString())
Set all data source related members at once.