24 #include <QStringList>
29 : mSSLmode( SSLprefer )
31 , mUseEstimatedMetadata( false )
32 , mSelectAtIdDisabled( false )
33 , mWkbType(
QGis::WKBUnknown )
39 : mSSLmode( SSLprefer )
41 , mUseEstimatedMetadata( false )
42 , mSelectAtIdDisabled( false )
43 , mWkbType(
QGis::WKBUnknown )
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;
701 Q_FOREACH (
const QString& val, value )
709 return mParams.
remove( key );
714 return mParams.
value( key );
719 return mParams.
values( key );
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
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
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 to old WKB type.
void setSrid(const QString &srid)
The QGis class provides global constants for use throughout the application.
QString join(const QString &separator) const
WkbType
Used for symbology operations.
void setSql(const QString &sql)
bool useEstimatedMetadata() const
QStringList params(const QString &key) const
Get multiple generic param (generic mode)
void setKeyColumn(const QString &column)
QString keyColumn() const
void setPattern(const QString &pattern)
static Type flatType(Type type)
iterator insertMulti(const Key &key, const T &value)
void disableSelectAtId(bool theFlag)
QString authConfigId() const
Any associated authentication configuration ID.
QGis::WkbType wkbType() const
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
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.
bool contains(QChar ch, Qt::CaseSensitivity cs) const
QString param(const QString &key) const
Get generic param (generic mode)
void setUsername(const QString &username)
set username
QString & replace(int position, int n, QChar after)
void setEncodedQuery(const QByteArray &query)
QString mid(int position, int n) const
void setWkbType(QGis::WkbType type)
QByteArray encodedQuery() const
bool selectAtIdDisabled() const
void addQueryItem(const QString &key, const QString &value)
QByteArray encodedUri() const
return complete encoded uri (generic mode)
static Type parseType(const QString &wktStr)
void setPassword(const QString &password)
set password
static QString displayString(Type type)
QString uri(bool expandAuthConfig=true) const
return complete uri
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
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