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" || pname == 
"username" ) 
   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 == 
"driver" )
   188       else if ( pname == 
"tty" )
   192       else if ( pname == 
"options" )
   196       else if ( pname == 
"sslmode" )
   198         if ( pval == 
"disable" )
   200         else if ( pval == 
"allow" )
   202         else if ( pval == 
"prefer" )
   204         else if ( pval == 
"require" )
   206         else if ( pval == 
"verify-ca" )
   208         else if ( pval == 
"verify-full" )
   211       else if ( pname == 
"requiressl" )
   218       else if ( pname == 
"krbsrvname" )
   222       else if ( pname == 
"gsslib" )
   228         QgsDebugMsg( 
"parameter \"" + pname + 
"\":\"" + pval + 
"\" added" );
   240   if ( aUri.
contains( 
" password=" ) )
   243     safeName.
replace( regexp, 
" " );
   245   else if ( aUri.
contains( 
",password=" ) )
   248     safeName.
replace( regexp, 
"," );
   253     safeName.
replace( regexp, 
" " );
   255   else if (( aUri.
contains( 
"OCI:" ) )
   259     safeName.
replace( regexp, 
"/@" );
   264     safeName = strlist[0] + 
',' + strlist[1] + 
',' + strlist[2] + 
',' + strlist[3];
   271   return mAuthConfigId;
   341   return mGeometryColumn;
   364   mUseEstimatedMetadata = theFlag;
   369   return mUseEstimatedMetadata;
   374   mSelectAtIdDisabled = theFlag;
   379   return mSelectAtIdDisabled;
   407 void QgsDataSourceURI::skipBlanks( 
const QString &
uri, 
int &i )
   410   while ( i < uri.
length() && uri[i].isSpace() )
   416   skipBlanks( uri, i );
   420   if ( i < uri.
length() && ( uri[i] == 
'\'' || uri[i] == 
'"' ) )
   422     QChar delim = uri[i];
   431         QgsDebugMsg( 
"unterminated quoted string in connection info string" );
   435       if ( uri[i] == 
'\\' )
   440         if ( uri[i] != delim && uri[i] != 
'\\' )
   443       else if ( uri[i] == delim )
   455     while ( i < uri.
length() )
   457       if ( uri[i].isSpace() )
   463       if ( uri[i] == 
'\\' )
   468         if ( uri[i] != 
'\\' && uri[i] != 
'\'' )
   476   skipBlanks( uri, i );
   485   if ( mDatabase != 
"" )
   487     connectionItems << 
"dbname='" + escape( mDatabase ) + 
'\'';
   490   if ( mService != 
"" )
   492     connectionItems << 
"service='" + escape( mService ) + 
'\'';
   494   else if ( mHost != 
"" )
   496     connectionItems << 
"host=" + mHost;
   502       connectionItems << 
"port=" + mPort;
   507     connectionItems << 
"driver='" + escape( mDriver ) + 
'\'';
   510   if ( mUsername != 
"" )
   512     connectionItems << 
"user='" + escape( mUsername ) + 
'\'';
   514     if ( mPassword != 
"" )
   516       connectionItems << 
"password='" + escape( mPassword ) + 
'\'';
   521     connectionItems << 
"sslmode=disable";
   523     connectionItems << 
"sslmode=allow";
   525     connectionItems << 
"sslmode=require";
   528     connectionItems << 
"sslmode=prefer";
   531     connectionItems << 
"sslmode=verify-ca";
   533     connectionItems << 
"sslmode=verify-full";
   535   if ( !mAuthConfigId.
isEmpty() )
   537     if ( expandAuthConfig )
   541         QgsDebugMsg( 
QString( 
"Data source URI FAILED to update via loading configuration ID '%1'" ).arg( mAuthConfigId ) );
   546       connectionItems << 
"authcfg=" + mAuthConfigId;
   550   return connectionItems.
join( 
" " );
   559     theUri += 
QString( 
" key='%1'" ).
arg( escape( mKeyColumn ) );
   562   if ( mUseEstimatedMetadata )
   564     theUri += 
QString( 
" estimatedmetadata=true" );
   578   if ( mSelectAtIdDisabled )
   580     theUri += 
QString( 
" selectatid=false" );
   585     if ( it.key().contains( 
'=' ) || it.key().contains( 
' ' ) )
   591     theUri += 
' ' + it.key() + 
"='" + escape( it.value() ) + 
'\'';
   594   QString columnName( mGeometryColumn );
   595   columnName.replace( 
'\\', 
"\\\\" );
   596   columnName.replace( 
')', 
"\\)" );
   598   theUri += 
QString( 
" table=%1%2 sql=%3" )
   639     return QString( 
"\"%1\".\"%2\"" )
   640            .
arg( escape( mSchema, 
'"' ),
   641                  escape( mTable, 
'"' ) );
   644            .
arg( escape( mTable, 
'"' ) );
   694   mAuthConfigId = authcfg;
   740   Q_FOREACH ( 
const QString& val, value )
   748   return mParams.
remove( key );
   753   return mParams.
value( key );
   758   return mParams.
values( key );
 bool selectAtIdDisabled() const
Returns whether the selection by id is disabled. 
 
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
 
void setMinimal(bool minimal)
 
void setEncodedUri(const QByteArray &uri)
set complete encoded uri (generic mode) 
 
QString param(const QString &key) const
Get generic param (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 (OGC) to old WKB type. 
 
void setSrid(const QString &srid)
Sets the srid. 
 
enum SSLmode sslMode() const
Returns the SSL mode. 
 
WkbType
Used for symbology operations. 
 
QString join(const QString &separator) const
 
void setSql(const QString &sql)
Sets the SQL query. 
 
QString keyColumn() const
Returns the name of the (primary) key column. 
 
void setKeyColumn(const QString &column)
Sets the name of the (primary) key column. 
 
QString port() const
Returns the port. 
 
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. 
 
QString password() const
Returns the password. 
 
Q_DECL_DEPRECATED QGis::WkbType wkbType() const
The (old) wkb type. 
 
iterator insertMulti(const Key &key, const T &value)
 
void disableSelectAtId(bool theFlag)
Set to true to disable selection by id. 
 
QString geometryColumn() const
Return the name of the geometry column. 
 
QString schema() const
Returns the schema. 
 
bool hasParam(const QString &key) const
Test if param exists (generic mode) 
 
QString database() const
Returns the database. 
 
void setParam(const QString &key, const QString &value)
Set generic param (generic mode) 
 
void setUseEstimatedMetadata(bool theFlag)
set use Estimated Metadata 
 
QString srid() const
Returns the srid. 
 
void setSchema(const QString &schema)
set the table schema 
 
QString service() const
Returns the service name. 
 
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. 
 
QString uri(bool expandAuthConfig=true) const
return complete uri 
 
QString sql() const
Returns the SQL query. 
 
void setAuthConfigId(const QString &authcfg)
Set authentication configuration ID. 
 
QString quotedTablename() const
quoted table name 
 
bool contains(QChar ch, Qt::CaseSensitivity cs) const
 
void clearSchema()
Clears the schema. 
 
QString username() const
Returns the username. 
 
QByteArray encodedUri() const
return complete encoded uri (generic mode) 
 
void setDriver(const QString &driver)
Sets the driver name. 
 
void setUsername(const QString &username)
set username 
 
QString & replace(int position, int n, QChar after)
 
void setEncodedQuery(const QByteArray &query)
 
QgsWKBTypes::Type newWkbType() const
The wkb type. 
 
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 host() const
Returns the host. 
 
QByteArray encodedQuery() const
 
QString table() const
Returns the table. 
 
QString authConfigId() const
Any associated authentication configuration ID. 
 
void addQueryItem(const QString &key, const QString &value)
 
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 connectionInfo(bool expandAuthConfig=true) const
return connection part of URI 
 
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
 
bool useEstimatedMetadata() const
Returns true if estimated metadata are used. 
 
QStringList params(const QString &key) const
Get multiple generic param (generic mode) 
 
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
 
QString driver() const
Returns the driver.