QGIS API Documentation  3.12.1-BucureČ™ti (121cc00ff0)
qgsdatasourceuri.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdatasourceuri.h - Structure to contain the component parts
3  of a data source URI
4  -------------------
5  begin : Dec 5, 2004
6  copyright : (C) 2004 by Gary E.Sherman
7  email : sherman at mrcc.com
8  ***************************************************************************/
9 
10 /***************************************************************************
11  * *
12  * This program is free software; you can redistribute it and/or modify *
13  * it under the terms of the GNU General Public License as published by *
14  * the Free Software Foundation; either version 2 of the License, or *
15  * (at your option) any later version. *
16  * *
17  ***************************************************************************/
18 
19 #include "qgsdatasourceuri.h"
20 #include "qgsauthmanager.h"
21 #include "qgslogger.h"
22 #include "qgswkbtypes.h"
23 #include "qgsapplication.h"
24 
25 #include <QStringList>
26 #include <QRegExp>
27 #include <QUrl>
28 #include <QUrlQuery>
29 
31 {
32  // do nothing
33 }
34 
36 {
37  QString uri = u;
38  int i = 0;
39  while ( i < uri.length() )
40  {
41  skipBlanks( uri, i );
42 
43  if ( uri[i] == '=' )
44  {
45  QgsDebugMsg( QStringLiteral( "parameter name expected before =" ) );
46  i++;
47  continue;
48  }
49 
50  int start = i;
51 
52  while ( i < uri.length() && uri[i] != '=' && !uri[i].isSpace() )
53  i++;
54 
55  QString pname = uri.mid( start, i - start );
56 
57  skipBlanks( uri, i );
58 
59  if ( i == uri.length() || uri[i] != '=' )
60  {
61  QgsDebugMsg( QStringLiteral( "= expected after parameter name, skipping text '%1'" ).arg( pname ) );
62  continue;
63  }
64 
65  i++;
66 
67  if ( pname == QLatin1String( "sql" ) )
68  {
69  // rest of line is a sql where clause
70  skipBlanks( uri, i );
71  mSql = uri.mid( i );
72  break;
73  }
74  else
75  {
76  QString pval = getValue( uri, i );
77 
78  if ( pname == QLatin1String( "table" ) )
79  {
80  if ( uri[i] == '.' )
81  {
82  i++;
83 
84  mSchema = pval;
85  mTable = getValue( uri, i );
86  }
87  else
88  {
89  mTable = pval;
90  }
91 
92  if ( uri[i] == '(' )
93  {
94  i++;
95 
96  start = i;
97  while ( i < uri.length() && uri[i] != ')' )
98  {
99  if ( uri[i] == '\\' )
100  i++;
101  i++;
102  }
103 
104  if ( i == uri.length() )
105  {
106  QgsDebugMsg( QStringLiteral( "closing parenthesis missing" ) );
107  }
108 
109  mGeometryColumn = uri.mid( start, i - start );
110  mGeometryColumn.replace( QLatin1String( "\\)" ), QLatin1String( ")" ) );
111  mGeometryColumn.replace( QLatin1String( "\\\\" ), QLatin1String( "\\" ) );
112 
113  i++;
114  }
115  else
116  {
117  mGeometryColumn = QString();
118  }
119  }
120  else if ( pname == QLatin1String( "schema" ) )
121  {
122  mSchema = pval;
123  }
124  else if ( pname == QLatin1String( "key" ) )
125  {
126  mKeyColumn = pval;
127  }
128  else if ( pname == QLatin1String( "estimatedmetadata" ) )
129  {
130  mUseEstimatedMetadata = pval == QLatin1String( "true" );
131  }
132  else if ( pname == QLatin1String( "srid" ) )
133  {
134  mSrid = pval;
135  }
136  else if ( pname == QLatin1String( "type" ) )
137  {
138  mWkbType = QgsWkbTypes::parseType( pval );
139  }
140  else if ( pname == QLatin1String( "selectatid" ) )
141  {
142  mSelectAtIdDisabled = pval == QLatin1String( "false" );
143  }
144  else if ( pname == QLatin1String( "service" ) )
145  {
146  mService = pval;
147  }
148  else if ( pname == QLatin1String( "authcfg" ) )
149  {
150  mAuthConfigId = pval;
151  }
152  else if ( pname == QLatin1String( "user" ) || pname == QLatin1String( "username" ) ) // Also accepts new WFS provider naming
153  {
154  mUsername = pval;
155  }
156  else if ( pname == QLatin1String( "password" ) )
157  {
158  mPassword = pval;
159  }
160  else if ( pname == QLatin1String( "connect_timeout" ) )
161  {
162  QgsDebugMsg( QStringLiteral( "connection timeout ignored" ) );
163  }
164  else if ( pname == QLatin1String( "dbname" ) )
165  {
166  mDatabase = pval;
167  }
168  else if ( pname == QLatin1String( "host" ) )
169  {
170  mHost = pval;
171  }
172  else if ( pname == QLatin1String( "hostaddr" ) )
173  {
174  QgsDebugMsg( QStringLiteral( "database host ip address ignored" ) );
175  }
176  else if ( pname == QLatin1String( "port" ) )
177  {
178  mPort = pval;
179  }
180  else if ( pname == QLatin1String( "driver" ) )
181  {
182  mDriver = pval;
183  }
184  else if ( pname == QLatin1String( "tty" ) )
185  {
186  QgsDebugMsg( QStringLiteral( "backend debug tty ignored" ) );
187  }
188  else if ( pname == QLatin1String( "options" ) )
189  {
190  QgsDebugMsg( QStringLiteral( "backend debug options ignored" ) );
191  }
192  else if ( pname == QLatin1String( "sslmode" ) )
193  {
194  mSSLmode = decodeSslMode( pval );
195  }
196  else if ( pname == QLatin1String( "requiressl" ) )
197  {
198  if ( pval == QLatin1String( "0" ) )
199  mSSLmode = SslDisable;
200  else
201  mSSLmode = SslPrefer;
202  }
203  else if ( pname == QLatin1String( "krbsrvname" ) )
204  {
205  QgsDebugMsg( QStringLiteral( "kerberos server name ignored" ) );
206  }
207  else if ( pname == QLatin1String( "gsslib" ) )
208  {
209  QgsDebugMsg( QStringLiteral( "gsslib ignored" ) );
210  }
211  else
212  {
213  QgsDebugMsgLevel( "parameter \"" + pname + "\":\"" + pval + "\" added", 4 );
214  setParam( pname, pval );
215  }
216  }
217  }
218 }
219 
220 QString QgsDataSourceUri::removePassword( const QString &aUri )
221 {
222  QRegExp regexp;
223  regexp.setMinimal( true );
224  QString safeName( aUri );
225  if ( aUri.contains( QLatin1String( " password=" ) ) )
226  {
227  regexp.setPattern( QStringLiteral( " password=.* " ) );
228  safeName.replace( regexp, QStringLiteral( " " ) );
229  }
230  else if ( aUri.contains( QLatin1String( ",password=" ) ) )
231  {
232  regexp.setPattern( QStringLiteral( ",password=.*," ) );
233  safeName.replace( regexp, QStringLiteral( "," ) );
234  }
235  else if ( aUri.contains( QLatin1String( "IDB:" ) ) )
236  {
237  regexp.setPattern( QStringLiteral( " pass=.* " ) );
238  safeName.replace( regexp, QStringLiteral( " " ) );
239  }
240  else if ( ( aUri.contains( QLatin1String( "OCI:" ) ) )
241  || ( aUri.contains( QLatin1String( "ODBC:" ) ) ) )
242  {
243  regexp.setPattern( QStringLiteral( "/.*@" ) );
244  safeName.replace( regexp, QStringLiteral( "/@" ) );
245  }
246  else if ( aUri.contains( QLatin1String( "SDE:" ) ) )
247  {
248  QStringList strlist = aUri.split( ',' );
249  safeName = strlist[0] + ',' + strlist[1] + ',' + strlist[2] + ',' + strlist[3];
250  }
251  return safeName;
252 }
253 
255 {
256  return mAuthConfigId;
257 }
258 
260 {
261  return mUsername;
262 }
263 
265 {
266  mUsername = username;
267 }
268 
270 {
271  return mService;
272 }
273 
274 QString QgsDataSourceUri::host() const
275 {
276  return mHost;
277 }
278 
280 {
281  return mDatabase;
282 }
283 
285 {
286  return mPassword;
287 }
288 
290 {
291  mPassword = password;
292 }
293 
294 QString QgsDataSourceUri::port() const
295 {
296  return mPort;
297 }
298 
300 {
301  return mDriver;
302 }
303 
305 {
306  return mSSLmode;
307 }
308 
310 {
311  return mSchema;
312 }
313 
314 QString QgsDataSourceUri::table() const
315 {
316  return mTable;
317 }
318 
319 QString QgsDataSourceUri::sql() const
320 {
321  return mSql;
322 }
323 
325 {
326  return mGeometryColumn;
327 }
328 
330 {
331  return mKeyColumn;
332 }
333 
334 
335 void QgsDataSourceUri::setDriver( const QString &driver )
336 {
337  mDriver = driver;
338 }
339 
340 
341 void QgsDataSourceUri::setKeyColumn( const QString &column )
342 {
343  mKeyColumn = column;
344 }
345 
346 
348 {
349  mUseEstimatedMetadata = flag;
350 }
351 
353 {
354  return mUseEstimatedMetadata;
355 }
356 
358 {
359  mSelectAtIdDisabled = flag;
360 }
361 
363 {
364  return mSelectAtIdDisabled;
365 }
366 
367 void QgsDataSourceUri::setSql( const QString &sql )
368 {
369  mSql = sql;
370 }
371 
373 {
374  mSchema.clear();
375 }
376 
377 void QgsDataSourceUri::setSchema( const QString &schema )
378 {
379  mSchema = schema;
380 }
381 
382 QString QgsDataSourceUri::escape( const QString &val, QChar delim = '\'' ) const
383 {
384  QString escaped = val;
385 
386  escaped.replace( '\\', QLatin1String( "\\\\" ) );
387  escaped.replace( delim, QStringLiteral( "\\%1" ).arg( delim ) );
388 
389  return escaped;
390 }
391 
393 {
394  mGeometryColumn = geometryColumn;
395 }
396 
397 void QgsDataSourceUri::setTable( const QString &table )
398 {
399  mTable = table;
400 }
401 
402 void QgsDataSourceUri::skipBlanks( const QString &uri, int &i )
403 {
404  // skip space before value
405  while ( i < uri.length() && uri[i].isSpace() )
406  i++;
407 }
408 
409 QString QgsDataSourceUri::getValue( const QString &uri, int &i )
410 {
411  skipBlanks( uri, i );
412 
413  // Get the parameter value
414  QString pval;
415  if ( i < uri.length() && ( uri[i] == '\'' || uri[i] == '"' ) )
416  {
417  QChar delim = uri[i];
418 
419  i++;
420 
421  // value is quoted
422  for ( ;; )
423  {
424  if ( i == uri.length() )
425  {
426  QgsDebugMsg( QStringLiteral( "unterminated quoted string in connection info string" ) );
427  return pval;
428  }
429 
430  if ( uri[i] == '\\' )
431  {
432  i++;
433  if ( i == uri.length() )
434  continue;
435  if ( uri[i] != delim && uri[i] != '\\' )
436  i--;
437  }
438  else if ( uri[i] == delim )
439  {
440  i++;
441  break;
442  }
443 
444  pval += uri[i++];
445  }
446  }
447  else
448  {
449  // value is not quoted
450  while ( i < uri.length() )
451  {
452  if ( uri[i].isSpace() )
453  {
454  // end of value
455  break;
456  }
457 
458  if ( uri[i] == '\\' )
459  {
460  i++;
461  if ( i == uri.length() )
462  break;
463  if ( uri[i] != '\\' && uri[i] != '\'' )
464  i--;
465  }
466 
467  pval += uri[i++];
468  }
469  }
470 
471  skipBlanks( uri, i );
472 
473  return pval;
474 }
475 
476 QString QgsDataSourceUri::connectionInfo( bool expandAuthConfig ) const
477 {
478  QStringList connectionItems;
479 
480  if ( !mDatabase.isEmpty() )
481  {
482  connectionItems << "dbname='" + escape( mDatabase ) + '\'';
483  }
484 
485  if ( !mService.isEmpty() )
486  {
487  connectionItems << "service='" + escape( mService ) + '\'';
488  }
489  else if ( !mHost.isEmpty() )
490  {
491  connectionItems << "host=" + mHost;
492  }
493 
494  if ( mService.isEmpty() )
495  {
496  if ( !mPort.isEmpty() )
497  connectionItems << "port=" + mPort;
498  }
499 
500  if ( !mDriver.isEmpty() )
501  {
502  connectionItems << "driver='" + escape( mDriver ) + '\'';
503  }
504 
505  if ( !mUsername.isEmpty() )
506  {
507  connectionItems << "user='" + escape( mUsername ) + '\'';
508 
509  if ( !mPassword.isEmpty() )
510  {
511  connectionItems << "password='" + escape( mPassword ) + '\'';
512  }
513  }
514 
515  if ( mSSLmode != SslPrefer ) // no need to output the default
516  {
517  connectionItems << QStringLiteral( "sslmode=" ) + encodeSslMode( mSSLmode );
518  }
519 
520  if ( !mAuthConfigId.isEmpty() )
521  {
522  if ( expandAuthConfig )
523  {
524  if ( !QgsApplication::authManager()->updateDataSourceUriItems( connectionItems, mAuthConfigId ) )
525  {
526  QgsDebugMsg( QStringLiteral( "Data source URI FAILED to update via loading configuration ID '%1'" ).arg( mAuthConfigId ) );
527  }
528  }
529  else
530  {
531  connectionItems << "authcfg=" + mAuthConfigId;
532  }
533  }
534 
535  return connectionItems.join( QStringLiteral( " " ) );
536 }
537 
538 QString QgsDataSourceUri::uri( bool expandAuthConfig ) const
539 {
540  QString uri = connectionInfo( expandAuthConfig );
541 
542  if ( !mKeyColumn.isEmpty() )
543  {
544  uri += QStringLiteral( " key='%1'" ).arg( escape( mKeyColumn ) );
545  }
546 
547  if ( mUseEstimatedMetadata )
548  {
549  uri += QStringLiteral( " estimatedmetadata=true" );
550  }
551 
552  if ( !mSrid.isEmpty() )
553  {
554  uri += QStringLiteral( " srid=%1" ).arg( mSrid );
555  }
556 
557  if ( mWkbType != QgsWkbTypes::Unknown && mWkbType != QgsWkbTypes::NoGeometry )
558  {
559  uri += QLatin1String( " type=" );
560  uri += QgsWkbTypes::displayString( mWkbType );
561  }
562 
563  if ( mSelectAtIdDisabled )
564  {
565  uri += QStringLiteral( " selectatid=false" );
566  }
567 
568  for ( QMap<QString, QString>::const_iterator it = mParams.begin(); it != mParams.end(); ++it )
569  {
570  if ( it.key().contains( '=' ) || it.key().contains( ' ' ) )
571  {
572  QgsDebugMsg( QStringLiteral( "invalid uri parameter %1 skipped" ).arg( it.key() ) );
573  continue;
574  }
575 
576  uri += ' ' + it.key() + "='" + escape( it.value() ) + '\'';
577  }
578 
579  QString columnName( mGeometryColumn );
580  columnName.replace( '\\', QLatin1String( "\\\\" ) );
581  columnName.replace( ')', QLatin1String( "\\)" ) );
582 
583  if ( !mTable.isEmpty() )
584  {
585  uri += QStringLiteral( " table=%1%2" )
586  .arg( quotedTablename(),
587  mGeometryColumn.isNull() ? QString() : QStringLiteral( " (%1)" ).arg( columnName ) );
588  }
589 
590  if ( !mSql.isEmpty() )
591  {
592  uri += QStringLiteral( " sql=" ) + mSql;
593  }
594 
595  return uri;
596 }
597 
598 // from qurl.h
599 QByteArray toLatin1_helper( const QString &string )
600 {
601  if ( string.isEmpty() )
602  return string.isNull() ? QByteArray() : QByteArray( "" );
603  return string.toLatin1();
604 }
605 
607 {
608  QUrlQuery url;
609  for ( auto it = mParams.constBegin(); it != mParams.constEnd(); ++it )
610  {
611  url.addQueryItem( it.key(), it.value() );
612  }
613 
614  if ( !mUsername.isEmpty() )
615  url.addQueryItem( QStringLiteral( "username" ), mUsername );
616 
617  if ( !mPassword.isEmpty() )
618  url.addQueryItem( QStringLiteral( "password" ), mPassword );
619 
620  if ( !mAuthConfigId.isEmpty() )
621  url.addQueryItem( QStringLiteral( "authcfg" ), mAuthConfigId );
622 
623  return toLatin1_helper( url.toString( QUrl::FullyEncoded ) );
624 }
625 
626 void QgsDataSourceUri::setEncodedUri( const QByteArray &uri )
627 {
628  mParams.clear();
629  mUsername.clear();
630  mPassword.clear();
631  mAuthConfigId.clear();
632 
633  QUrl url;
634  url.setQuery( QString::fromLatin1( uri ) );
635  const QUrlQuery query( url );
636 
637  const auto constQueryItems = query.queryItems();
638  for ( const QPair<QString, QString> &item : constQueryItems )
639  {
640  if ( item.first == QLatin1String( "username" ) )
641  mUsername = item.second;
642  else if ( item.first == QLatin1String( "password" ) )
643  mPassword = item.second;
644  else if ( item.first == QLatin1String( "authcfg" ) )
645  mAuthConfigId = item.second;
646  else
647  mParams.insertMulti( item.first, item.second );
648  }
649 }
650 
651 void QgsDataSourceUri::setEncodedUri( const QString &uri )
652 {
653  setEncodedUri( uri.toLatin1() );
654 }
655 
657 {
658  if ( !mSchema.isEmpty() )
659  return QStringLiteral( "\"%1\".\"%2\"" )
660  .arg( escape( mSchema, '"' ),
661  escape( mTable, '"' ) );
662  else
663  return QStringLiteral( "\"%1\"" )
664  .arg( escape( mTable, '"' ) );
665 }
666 
668  const QString &port,
669  const QString &database,
670  const QString &username,
671  const QString &password,
672  SslMode sslmode,
673  const QString &authConfigId )
674 {
675  mHost = host;
676  mDatabase = database;
677  mPort = port;
678  mUsername = username;
679  mPassword = password;
680  mSSLmode = sslmode;
681  mAuthConfigId = authConfigId;
682 }
683 
685  const QString &database,
686  const QString &username,
687  const QString &password,
688  SslMode sslmode,
689  const QString &authConfigId )
690 {
691  mService = service;
692  mDatabase = database;
693  mUsername = username;
694  mPassword = password;
695  mSSLmode = sslmode;
696  mAuthConfigId = authConfigId;
697 }
698 
700  const QString &table,
701  const QString &geometryColumn,
702  const QString &sql,
703  const QString &keyColumn )
704 {
705  mSchema = schema;
706  mTable = table;
707  mGeometryColumn = geometryColumn;
708  mSql = sql;
709  mKeyColumn = keyColumn;
710 }
711 
712 void QgsDataSourceUri::setAuthConfigId( const QString &authcfg )
713 {
714  mAuthConfigId = authcfg;
715 }
716 
718 {
719  mDatabase = database;
720 }
721 
723 {
724  return mWkbType;
725 }
726 
728 {
729  mWkbType = wkbType;
730 }
731 
732 QString QgsDataSourceUri::srid() const
733 {
734  return mSrid;
735 }
736 
737 void QgsDataSourceUri::setSrid( const QString &srid )
738 {
739  mSrid = srid;
740 }
741 
743 {
744  if ( sslMode == QLatin1String( "prefer" ) )
745  return SslPrefer;
746  else if ( sslMode == QLatin1String( "disable" ) )
747  return SslDisable;
748  else if ( sslMode == QLatin1String( "allow" ) )
749  return SslAllow;
750  else if ( sslMode == QLatin1String( "require" ) )
751  return SslRequire;
752  else if ( sslMode == QLatin1String( "verify-ca" ) )
753  return SslVerifyCa;
754  else if ( sslMode == QLatin1String( "verify-full" ) )
755  return SslVerifyFull;
756  else
757  return SslPrefer; // default
758 }
759 
761 {
762  switch ( sslMode )
763  {
764  case SslPrefer: return QStringLiteral( "prefer" );
765  case SslDisable: return QStringLiteral( "disable" );
766  case SslAllow: return QStringLiteral( "allow" );
767  case SslRequire: return QStringLiteral( "require" );
768  case SslVerifyCa: return QStringLiteral( "verify-ca" );
769  case SslVerifyFull: return QStringLiteral( "verify-full" );
770  }
771  return QString();
772 }
773 
774 void QgsDataSourceUri::setParam( const QString &key, const QString &value )
775 {
776  // maintain old API
777  if ( key == QLatin1String( "username" ) )
778  mUsername = value;
779  else if ( key == QLatin1String( "password" ) )
780  mPassword = value;
781  else if ( key == QLatin1String( "authcfg" ) )
782  mAuthConfigId = value;
783  else
784  {
785  // may be multiple
786  mParams.insertMulti( key, value );
787  }
788 }
789 
790 void QgsDataSourceUri::setParam( const QString &key, const QStringList &value )
791 {
792  for ( const QString &val : value )
793  {
794  setParam( key, val );
795  }
796 }
797 
798 int QgsDataSourceUri::removeParam( const QString &key )
799 {
800  if ( key == QLatin1String( "username" ) && !mUsername.isEmpty() )
801  {
802  mUsername.clear();
803  return 1;
804  }
805  else if ( key == QLatin1String( "password" ) && !mPassword.isEmpty() )
806  {
807  mPassword.clear();
808  return 1;
809  }
810  else if ( key == QLatin1String( "authcfg" ) && !mAuthConfigId.isEmpty() )
811  {
812  mAuthConfigId.clear();
813  return 1;
814  }
815 
816  return mParams.remove( key );
817 }
818 
819 QString QgsDataSourceUri::param( const QString &key ) const
820 {
821  // maintain old api
822  if ( key == QLatin1String( "username" ) && !mUsername.isEmpty() )
823  return mUsername;
824  else if ( key == QLatin1String( "password" ) && !mPassword.isEmpty() )
825  return mPassword;
826  else if ( key == QLatin1String( "authcfg" ) && !mAuthConfigId.isEmpty() )
827  return mAuthConfigId;
828 
829  return mParams.value( key );
830 }
831 
832 QStringList QgsDataSourceUri::params( const QString &key ) const
833 {
834  // maintain old api
835  if ( key == QLatin1String( "username" ) && !mUsername.isEmpty() )
836  return QStringList() << mUsername;
837  else if ( key == QLatin1String( "password" ) && !mPassword.isEmpty() )
838  return QStringList() << mPassword;
839  else if ( key == QLatin1String( "authcfg" ) && !mAuthConfigId.isEmpty() )
840  return QStringList() << mAuthConfigId;
841 
842  return mParams.values( key );
843 }
844 
845 bool QgsDataSourceUri::hasParam( const QString &key ) const
846 {
847  // maintain old api
848  if ( key == QLatin1String( "username" ) && !mUsername.isEmpty() )
849  return true;
850  else if ( key == QLatin1String( "password" ) && !mPassword.isEmpty() )
851  return true;
852  else if ( key == QLatin1String( "authcfg" ) && !mAuthConfigId.isEmpty() )
853  return true;
854 
855  return mParams.contains( key );
856 }
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
QgsWkbTypes::Type wkbType() const
Returns the WKB type associated with the URI.
QString table() const
Returns the table name stored in the URI.
bool useEstimatedMetadata() const
Returns true if estimated metadata should be used for the connection.
void setUsername(const QString &username)
Sets the username for the URI.
bool hasParam(const QString &key) const
Returns true if a parameter with the specified key exists.
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
void clearSchema()
Clears the schema stored in the URI.
static SslMode decodeSslMode(const QString &sslMode)
Decodes SSL mode string into enum value.
QString authConfigId() const
Returns any associated authentication configuration ID stored in the URI.
static Type parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT string.
SslMode sslMode() const
Returns the SSL mode associated with the URI.
QString keyColumn() const
Returns the name of the (primary) key column for the referenced table.
void setConnection(const QString &aHost, const QString &aPort, const QString &aDatabase, const QString &aUsername, const QString &aPassword, SslMode sslmode=SslPrefer, const QString &authConfigId=QString())
Sets all connection related members at once.
QString connectionInfo(bool expandAuthConfig=true) const
Returns the connection part of the URI.
QString username() const
Returns the username stored in the URI.
SslMode
Available SSQL connection modes.
void setGeometryColumn(const QString &geometryColumn)
Sets geometry column name to geometryColumn.
QString host() const
Returns the host name stored in the URI.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
QStringList params(const QString &key) const
Returns multiple generic parameter values corresponding to the specified key.
void setDriver(const QString &driver)
Sets the driver name stored in the URI.
int removeParam(const QString &key)
Removes a generic parameter by key.
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QString geometryColumn() const
Returns the name of the geometry column stored in the URI, if set.
void setKeyColumn(const QString &column)
Sets the name of the (primary) key column.
bool selectAtIdDisabled() const
Returns whether the selection by feature ID is disabled.
void setTable(const QString &table)
Sets table to table.
bool updateDataSourceUriItems(QStringList &connectionItems, const QString &authcfg, const QString &dataprovider=QString())
Provider call to update a QgsDataSourceUri with an authentication config.
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
QString quotedTablename() const
Returns the URI&#39;s table name, escaped and quoted.
static QString encodeSslMode(SslMode sslMode)
Encodes SSL mode enum value into a string.
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
QString port() const
Returns the port stored in the URI.
void setAuthConfigId(const QString &authcfg)
Sets the authentication configuration ID for the URI.
void setSrid(const QString &srid)
Sets the spatial reference ID associated with the URI.
void setWkbType(QgsWkbTypes::Type type)
Sets the WKB type associated with the URI.
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
static QgsAuthManager * authManager()
Returns the application&#39;s authentication manager instance.
void disableSelectAtId(bool flag)
Set to true to disable selection by feature ID.
QString driver() const
Returns the driver name stored in the URI.
void setDataSource(const QString &aSchema, const QString &aTable, const QString &aGeometryColumn, const QString &aSql=QString(), const QString &aKeyColumn=QString())
Sets all data source related members at once.
QByteArray toLatin1_helper(const QString &string)
void setSql(const QString &sql)
Sets the SQL query for the URI.
void setPassword(const QString &password)
Sets the password for the URI.
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
QString sql() const
Returns the SQL query stored in the URI, if set.
QString service() const
Returns the service name associated with the URI.
static QString displayString(Type type)
Returns a display string type for a WKB type, e.g., the geometry name used in WKT geometry representa...
QString password() const
Returns the password stored in the URI.
void setSchema(const QString &schema)
Sets the scheme for the URI.
QString schema() const
Returns the schema stored in the URI.
void setUseEstimatedMetadata(bool flag)
Sets whether estimated metadata should be used for the connection.
QString database() const
Returns the database name stored in the URI.
void setDatabase(const QString &database)
Sets the URI database name.
QString srid() const
Returns the spatial reference ID associated with the URI.
static QString removePassword(const QString &aUri)
Removes the password element from a URI.