24 #include <QStringList> 29 : mSSLmode( SSLprefer )
31 , mUseEstimatedMetadata( false )
32 , mSelectAtIdDisabled( false )
41 , mUseEstimatedMetadata( false )
42 , mSelectAtIdDisabled( false )
59 while ( i < uri.
length() && uri[i] !=
'=' && !uri[i].isSpace() )
66 if ( i == uri.
length() || uri[i] !=
'=' )
68 QgsDebugMsg(
QString(
"= expected after parameter name, skipping text '%1'" ).arg( pname ) );
83 QString pval = getValue( uri, i );
85 if ( pname ==
"table" )
92 mTable = getValue( uri, i );
105 while ( i < uri.
length() && uri[i] !=
')' )
107 if ( uri[i] ==
'\\' )
117 mGeometryColumn = uri.
mid( start, i - start );
118 mGeometryColumn.
replace(
"\\)",
")" );
119 mGeometryColumn.
replace(
"\\\\",
"\\" );
125 mGeometryColumn = QString::null;
128 else if ( pname ==
"key" )
132 else if ( pname ==
"estimatedmetadata" )
134 mUseEstimatedMetadata = pval ==
"true";
136 else if ( pname ==
"srid" )
140 else if ( pname ==
"type" )
144 else if ( pname ==
"selectatid" )
146 mSelectAtIdDisabled = pval ==
"false";
148 else if ( pname ==
"service" )
152 else if ( pname ==
"authcfg" )
154 mAuthConfigId = pval;
156 else if ( pname ==
"user" )
160 else if ( pname ==
"password" )
164 else if ( pname ==
"connect_timeout" )
168 else if ( pname ==
"dbname" )
172 else if ( pname ==
"host" )
176 else if ( pname ==
"hostaddr" )
180 else if ( pname ==
"port" )
184 else if ( pname ==
"tty" )
188 else if ( pname ==
"options" )
192 else if ( pname ==
"sslmode" )
194 if ( pval ==
"disable" )
196 else if ( pval ==
"allow" )
198 else if ( pval ==
"prefer" )
200 else if ( pval ==
"require" )
203 else if ( pname ==
"requiressl" )
210 else if ( pname ==
"krbsrvname" )
214 else if ( pname ==
"gsslib" )
220 QgsDebugMsg(
"parameter \"" + pname +
"\":\"" + pval +
"\" added" );
232 if ( aUri.
contains(
" password=" ) )
235 safeName.
replace( regexp,
" " );
237 else if ( aUri.
contains(
",password=" ) )
240 safeName.
replace( regexp,
"," );
245 safeName.
replace( regexp,
" " );
247 else if (( aUri.
contains(
"OCI:" ) )
251 safeName.
replace( regexp,
"/@" );
256 safeName = strlist[0] +
',' + strlist[1] +
',' + strlist[2] +
',' + strlist[3];
263 return mAuthConfigId;
328 return mGeometryColumn;
344 mUseEstimatedMetadata = theFlag;
349 return mUseEstimatedMetadata;
354 mSelectAtIdDisabled = theFlag;
359 return mSelectAtIdDisabled;
387 void QgsDataSourceURI::skipBlanks(
const QString &
uri,
int &i )
390 while ( i < uri.
length() && uri[i].isSpace() )
396 skipBlanks( uri, i );
400 if ( i < uri.
length() && ( uri[i] ==
'\'' || uri[i] ==
'"' ) )
402 QChar delim = uri[i];
411 QgsDebugMsg(
"unterminated quoted string in connection info string" );
415 if ( uri[i] ==
'\\' )
420 if ( uri[i] != delim && uri[i] !=
'\\' )
423 else if ( uri[i] == delim )
435 while ( i < uri.
length() )
437 if ( uri[i].isSpace() )
443 if ( uri[i] ==
'\\' )
448 if ( uri[i] !=
'\\' && uri[i] !=
'\'' )
456 skipBlanks( uri, i );
465 if ( mDatabase !=
"" )
467 connectionItems <<
"dbname='" + escape( mDatabase ) +
'\'';
470 if ( mService !=
"" )
472 connectionItems <<
"service='" + escape( mService ) +
'\'';
474 else if ( mHost !=
"" )
476 connectionItems <<
"host=" + mHost;
482 connectionItems <<
"port=" + mPort;
485 if ( mUsername !=
"" )
487 connectionItems <<
"user='" + escape( mUsername ) +
'\'';
489 if ( mPassword !=
"" )
491 connectionItems <<
"password='" + escape( mPassword ) +
'\'';
496 connectionItems <<
"sslmode=disable";
498 connectionItems <<
"sslmode=allow";
500 connectionItems <<
"sslmode=require";
503 connectionItems <<
"sslmode=prefer";
506 if ( !mAuthConfigId.
isEmpty() )
508 if ( expandAuthConfig )
512 QgsDebugMsg(
QString(
"Data source URI FAILED to update via loading configuration ID '%1'" ).arg( mAuthConfigId ) );
517 connectionItems <<
"authcfg=" + mAuthConfigId;
521 return connectionItems.
join(
" " );
530 theUri +=
QString(
" key='%1'" ).
arg( escape( mKeyColumn ) );
533 if ( mUseEstimatedMetadata )
535 theUri +=
QString(
" estimatedmetadata=true" );
549 if ( mSelectAtIdDisabled )
551 theUri +=
QString(
" selectatid=false" );
556 if ( it.key().contains(
'=' ) || it.key().contains(
' ' ) )
562 theUri +=
' ' + it.key() +
"='" + escape( it.value() ) +
'\'';
565 QString columnName( mGeometryColumn );
566 columnName.replace(
'\\',
"\\\\" );
567 columnName.replace(
')',
"\\)" );
569 theUri +=
QString(
" table=%1%2 sql=%3" )
610 return QString(
"\"%1\".\"%2\"" )
611 .
arg( escape( mSchema,
'"' ),
612 escape( mTable,
'"' ) );
615 .
arg( escape( mTable,
'"' ) );
665 mAuthConfigId = authcfg;
711 Q_FOREACH (
const QString& val, value )
719 return mParams.
remove( key );
724 return mParams.
value( key );
729 return mParams.
values( key );
QString srid() const
Returns the srid.
QString database() const
Returns the database.
QgsDataSourceURI()
default constructor
bool contains(const Key &key) const
int removeParam(const QString &key)
Remove generic param (generic mode)
static QgsAuthManager * instance()
Enforce singleton pattern.
QList< T > values() const
QString quotedTablename() const
quoted table name
QString geometryColumn() const
Return the name of the geometry column.
void setMinimal(bool minimal)
void setEncodedUri(const QByteArray &uri)
set complete encoded uri (generic mode)
static QString removePassword(const QString &aUri)
Removes password element from uris.
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
QString password() const
Returns the password.
QList< QPair< QString, QString > > queryItems() const
void setDatabase(const QString &database)
Set database.
static QGis::WkbType fromNewWkbType(QgsWKBTypes::Type type)
Converts from new (post 2.10) WKB type (OGC) to old WKB type.
void setSrid(const QString &srid)
Sets the srid.
WkbType
Used for symbology operations.
QString join(const QString &separator) const
void setSql(const QString &sql)
Sets the SQL query.
bool useEstimatedMetadata() const
Returns true if estimated metadata are used.
QStringList params(const QString &key) const
Get multiple generic param (generic mode)
void setKeyColumn(const QString &column)
Sets the name of the (primary) key column.
QString keyColumn() const
Returns the name of the (primary) key column.
void setPattern(const QString &pattern)
static QgsWKBTypes::Type fromOldWkbType(QGis::WkbType type)
Converts from old (pre 2.10) WKB type (OGR) to new WKB type.
iterator insertMulti(const Key &key, const T &value)
void disableSelectAtId(bool theFlag)
Set to true to disable selection by id.
QString authConfigId() const
Any associated authentication configuration ID.
Q_DECL_DEPRECATED QGis::WkbType wkbType() const
The (old) wkb type.
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
Returns the SSL mode.
void setSchema(const QString &schema)
set the table schema
bool hasParam(const QString &key) const
Test if param exists (generic mode)
QString connectionInfo(bool expandAuthConfig=true) const
return connection part of URI
bool updateDataSourceUriItems(QStringList &connectionItems, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QgsDataSourceURI with an authentication config.
void setConnection(const QString &aHost, const QString &aPort, const QString &aDatabase, const QString &aUsername, const QString &aPassword, SSLmode sslmode=SSLprefer, const QString &authConfigId=QString())
Set all connection related members at once.
void setAuthConfigId(const QString &authcfg)
Set authentication configuration ID.
QString host() const
Returns the host.
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QString schema() const
Returns the schema.
void clearSchema()
Clears the schema.
QString param(const QString &key) const
Get generic param (generic mode)
void setUsername(const QString &username)
set username
QString service() const
Returns the service name.
QString & replace(int position, int n, QChar after)
void setEncodedQuery(const QByteArray &query)
QString mid(int position, int n) const
Handles storage of information regarding WKB types and their properties.
Q_DECL_DEPRECATED void setWkbType(QGis::WkbType type)
QString table() const
Returns the table.
QByteArray encodedQuery() const
bool selectAtIdDisabled() const
Returns whether the selection by id is disabled.
void addQueryItem(const QString &key, const QString &value)
QString sql() const
Returns the SQL query.
QByteArray encodedUri() const
return complete encoded uri (generic mode)
static Type parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT string.
void setPassword(const QString &password)
set password
static QString displayString(Type type)
Returns a display string type for a WKB type, eg the geometry name used in WKT geometry representatio...
QString uri(bool expandAuthConfig=true) const
return complete uri
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QgsWKBTypes::Type newWkbType() const
The wkb type.
QString username() const
Returns the username.
QString port() const
Returns the port.
QByteArray toAscii() 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.
const T value(const Key &key) const
int remove(const Key &key)
QList< Key > uniqueKeys() const