QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
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 <QRegularExpression>
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 const QString pname = uri.mid( start, i - start );
56
57 skipBlanks( uri, i );
58
59 if ( i == uri.length() || uri[i] != '=' )
60 {
61 // no "=", so likely not a parameter name
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 const QString pval = getValue( uri, i );
77
78 if ( pname == QLatin1String( "table" ) )
79 {
80 if ( i < uri.length() && 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 ( i < uri.length() && 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 mSelectAtIdDisabledSet = true;
143 mSelectAtIdDisabled = pval == QLatin1String( "false" );
144 }
145 else if ( pname == QLatin1String( "service" ) )
146 {
147 mService = pval;
148 }
149 else if ( pname == QLatin1String( "authcfg" ) )
150 {
151 mAuthConfigId = pval;
152 }
153 else if ( pname == QLatin1String( "user" ) || pname == QLatin1String( "username" ) ) // Also accepts new WFS provider naming
154 {
155 mUsername = pval;
156 }
157 else if ( pname == QLatin1String( "password" ) )
158 {
159 mPassword = pval;
160 }
161 else if ( pname == QLatin1String( "connect_timeout" ) )
162 {
163 QgsDebugMsgLevel( QStringLiteral( "connection timeout ignored" ), 3 );
164 }
165 else if ( pname == QLatin1String( "dbname" ) )
166 {
167 mDatabase = pval;
168 }
169 else if ( pname == QLatin1String( "host" ) )
170 {
171 mHost = pval;
172 }
173 else if ( pname == QLatin1String( "hostaddr" ) )
174 {
175 QgsDebugMsg( QStringLiteral( "database host ip address ignored" ) );
176 }
177 else if ( pname == QLatin1String( "port" ) )
178 {
179 mPort = pval;
180 }
181 else if ( pname == QLatin1String( "driver" ) )
182 {
183 mDriver = pval;
184 }
185 else if ( pname == QLatin1String( "tty" ) )
186 {
187 QgsDebugMsg( QStringLiteral( "backend debug tty ignored" ) );
188 }
189 else if ( pname == QLatin1String( "options" ) )
190 {
191 QgsDebugMsg( QStringLiteral( "backend debug options ignored" ) );
192 }
193 else if ( pname == QLatin1String( "sslmode" ) )
194 {
195 mSSLmode = decodeSslMode( pval );
196 }
197 else if ( pname == QLatin1String( "requiressl" ) )
198 {
199 if ( pval == QLatin1String( "0" ) )
200 mSSLmode = SslDisable;
201 else
202 mSSLmode = SslPrefer;
203 }
204 else if ( pname == QLatin1String( "krbsrvname" ) )
205 {
206 QgsDebugMsg( QStringLiteral( "kerberos server name ignored" ) );
207 }
208 else if ( pname == QLatin1String( "gsslib" ) )
209 {
210 QgsDebugMsg( QStringLiteral( "gsslib ignored" ) );
211 }
212 else
213 {
214 QgsDebugMsgLevel( "parameter \"" + pname + "\":\"" + pval + "\" added", 4 );
215 setParam( pname, pval );
216 }
217 }
218 }
219}
220
221QString QgsDataSourceUri::removePassword( const QString &aUri )
222{
223 QRegularExpression regexp;
224 regexp.setPatternOptions( QRegularExpression::InvertedGreedinessOption );
225 QString safeName( aUri );
226 if ( aUri.contains( QLatin1String( " password=" ) ) )
227 {
228 regexp.setPattern( QStringLiteral( " password=.* " ) );
229 safeName.replace( regexp, QStringLiteral( " " ) );
230 }
231 else if ( aUri.contains( QLatin1String( ",password=" ) ) )
232 {
233 regexp.setPattern( QStringLiteral( ",password=.*," ) );
234 safeName.replace( regexp, QStringLiteral( "," ) );
235 }
236 else if ( aUri.contains( QLatin1String( "IDB:" ) ) )
237 {
238 regexp.setPattern( QStringLiteral( " pass=.* " ) );
239 safeName.replace( regexp, QStringLiteral( " " ) );
240 }
241 else if ( ( aUri.contains( QLatin1String( "OCI:" ) ) )
242 || ( aUri.contains( QLatin1String( "ODBC:" ) ) ) )
243 {
244 regexp.setPattern( QStringLiteral( "/.*@" ) );
245 safeName.replace( regexp, QStringLiteral( "/@" ) );
246 }
247 else if ( aUri.contains( QLatin1String( "SDE:" ) ) )
248 {
249 QStringList strlist = aUri.split( ',' );
250 safeName = strlist[0] + ',' + strlist[1] + ',' + strlist[2] + ',' + strlist[3];
251 }
252 return safeName;
253}
254
256{
257 return mAuthConfigId;
258}
259
261{
262 return mUsername;
263}
264
265void QgsDataSourceUri::setUsername( const QString &username )
266{
267 mUsername = username;
268}
269
271{
272 return mService;
273}
274
276{
277 return mHost;
278}
279
281{
282 return mDatabase;
283}
284
286{
287 return mPassword;
288}
289
290void QgsDataSourceUri::setPassword( const QString &password )
291{
292 mPassword = password;
293}
294
296{
297 return mPort;
298}
299
301{
302 return mDriver;
303}
304
306{
307 return mSSLmode;
308}
309
311{
312 return mSchema;
313}
314
316{
317 return mTable;
318}
319
321{
322 return mSql;
323}
324
326{
327 return mGeometryColumn;
328}
329
331{
332 return mKeyColumn;
333}
334
335
336void QgsDataSourceUri::setDriver( const QString &driver )
337{
338 mDriver = driver;
339}
340
341
342void QgsDataSourceUri::setKeyColumn( const QString &column )
343{
344 mKeyColumn = column;
345}
346
347
349{
350 mUseEstimatedMetadata = flag;
351}
352
354{
355 return mUseEstimatedMetadata;
356}
357
359{
360 mSelectAtIdDisabledSet = true;
361 mSelectAtIdDisabled = flag;
362}
363
365{
366 return mSelectAtIdDisabled;
367}
368
369void QgsDataSourceUri::setSql( const QString &sql )
370{
371 mSql = sql;
372}
373
375{
376 mSchema.clear();
377}
378
379void QgsDataSourceUri::setSchema( const QString &schema )
380{
381 mSchema = schema;
382}
383
384QString QgsDataSourceUri::escape( const QString &val, QChar delim = '\'' ) const
385{
386 QString escaped = val;
387
388 escaped.replace( '\\', QLatin1String( "\\\\" ) );
389 escaped.replace( delim, QStringLiteral( "\\%1" ).arg( delim ) );
390
391 return escaped;
392}
393
394void QgsDataSourceUri::setGeometryColumn( const QString &geometryColumn )
395{
396 mGeometryColumn = geometryColumn;
397}
398
399void QgsDataSourceUri::setTable( const QString &table )
400{
401 mTable = table;
402}
403
404void QgsDataSourceUri::skipBlanks( const QString &uri, int &i )
405{
406 // skip space before value
407 while ( i < uri.length() && uri[i].isSpace() )
408 i++;
409}
410
411QString QgsDataSourceUri::getValue( const QString &uri, int &i )
412{
413 skipBlanks( uri, i );
414
415 // Get the parameter value
416 QString pval;
417 if ( i < uri.length() && ( uri[i] == '\'' || uri[i] == '"' ) )
418 {
419 const QChar delim = uri[i];
420
421 i++;
422
423 // value is quoted
424 for ( ;; )
425 {
426 if ( i == uri.length() )
427 {
428 QgsDebugMsg( QStringLiteral( "unterminated quoted string in connection info string" ) );
429 return pval;
430 }
431
432 if ( uri[i] == '\\' )
433 {
434 i++;
435 if ( i == uri.length() )
436 continue;
437 if ( uri[i] != delim && uri[i] != '\\' )
438 i--;
439 }
440 else if ( uri[i] == delim )
441 {
442 i++;
443 break;
444 }
445
446 pval += uri[i++];
447 }
448 }
449 else
450 {
451 // value is not quoted
452 while ( i < uri.length() )
453 {
454 if ( uri[i].isSpace() )
455 {
456 // end of value
457 break;
458 }
459
460 if ( uri[i] == '\\' )
461 {
462 i++;
463 if ( i == uri.length() )
464 break;
465 if ( uri[i] != '\\' && uri[i] != '\'' )
466 i--;
467 }
468
469 pval += uri[i++];
470 }
471 }
472
473 skipBlanks( uri, i );
474
475 return pval;
476}
477
478QString QgsDataSourceUri::connectionInfo( bool expandAuthConfig ) const
479{
480 QStringList connectionItems;
481
482 if ( !mDatabase.isEmpty() )
483 {
484 connectionItems << "dbname='" + escape( mDatabase ) + '\'';
485 }
486
487 if ( !mService.isEmpty() )
488 {
489 connectionItems << "service='" + escape( mService ) + '\'';
490 }
491 else if ( !mHost.isEmpty() )
492 {
493 connectionItems << "host=" + mHost;
494 }
495
496 if ( mService.isEmpty() )
497 {
498 if ( !mPort.isEmpty() )
499 connectionItems << "port=" + mPort;
500 }
501
502 if ( !mDriver.isEmpty() )
503 {
504 connectionItems << "driver='" + escape( mDriver ) + '\'';
505 }
506
507 if ( !mUsername.isEmpty() )
508 {
509 connectionItems << "user='" + escape( mUsername ) + '\'';
510
511 if ( !mPassword.isEmpty() )
512 {
513 connectionItems << "password='" + escape( mPassword ) + '\'';
514 }
515 }
516
517 if ( mSSLmode != SslPrefer ) // no need to output the default
518 {
519 connectionItems << QStringLiteral( "sslmode=" ) + encodeSslMode( mSSLmode );
520 }
521
522 if ( !mAuthConfigId.isEmpty() )
523 {
524 if ( expandAuthConfig )
525 {
526 if ( !QgsApplication::authManager()->updateDataSourceUriItems( connectionItems, mAuthConfigId ) )
527 {
528 QgsDebugMsg( QStringLiteral( "Data source URI FAILED to update via loading configuration ID '%1'" ).arg( mAuthConfigId ) );
529 }
530 }
531 else
532 {
533 connectionItems << "authcfg=" + mAuthConfigId;
534 }
535 }
536
537 return connectionItems.join( QLatin1Char( ' ' ) );
538}
539
540QString QgsDataSourceUri::uri( bool expandAuthConfig ) const
541{
542 QString uri = connectionInfo( expandAuthConfig );
543
544 if ( !mKeyColumn.isEmpty() )
545 {
546 uri += QStringLiteral( " key='%1'" ).arg( escape( mKeyColumn ) );
547 }
548
549 if ( mUseEstimatedMetadata )
550 {
551 uri += QLatin1String( " estimatedmetadata=true" );
552 }
553
554 if ( !mSrid.isEmpty() )
555 {
556 uri += QStringLiteral( " srid=%1" ).arg( mSrid );
557 }
558
559 if ( mWkbType != QgsWkbTypes::Unknown && mWkbType != QgsWkbTypes::NoGeometry )
560 {
561 uri += QLatin1String( " type=" );
562 uri += QgsWkbTypes::displayString( mWkbType );
563 }
564
565 if ( mSelectAtIdDisabled )
566 {
567 uri += QLatin1String( " selectatid=false" );
568 }
569
570 for ( auto it = mParams.constBegin(); it != mParams.constEnd(); ++it )
571 {
572 if ( it.key().contains( '=' ) || it.key().contains( ' ' ) )
573 {
574 QgsDebugMsg( QStringLiteral( "invalid uri parameter %1 skipped" ).arg( it.key() ) );
575 continue;
576 }
577
578 uri += ' ' + it.key() + "='" + escape( it.value() ) + '\'';
579 }
580
581 uri += mHttpHeaders.toSpacedString();
582
583 QString columnName( mGeometryColumn );
584 columnName.replace( '\\', QLatin1String( "\\\\" ) );
585 columnName.replace( ')', QLatin1String( "\\)" ) );
586
587 if ( !mTable.isEmpty() )
588 {
589 uri += QStringLiteral( " table=%1%2" )
590 .arg( quotedTablename(),
591 mGeometryColumn.isEmpty() ? QString() : QStringLiteral( " (%1)" ).arg( columnName ) );
592 }
593 else if ( !mSchema.isEmpty() )
594 {
595 uri += QStringLiteral( " schema='%1'" ).arg( escape( mSchema ) );
596 }
597
598 if ( !mSql.isEmpty() )
599 {
600 uri += QStringLiteral( " sql=" ) + mSql;
601 }
602
603 return uri;
604}
605
606// from qurl.h
607QByteArray toLatin1_helper( const QString &string )
608{
609 if ( string.isEmpty() )
610 return string.isNull() ? QByteArray() : QByteArray( "" );
611 return string.toLatin1();
612}
613
615{
616 QUrlQuery url;
617 for ( auto it = mParams.constBegin(); it != mParams.constEnd(); ++it )
618 {
619 url.addQueryItem( it.key(), it.value() );
620 }
621
622 if ( !mUsername.isEmpty() )
623 url.addQueryItem( QStringLiteral( "username" ), mUsername );
624
625 if ( !mPassword.isEmpty() )
626 url.addQueryItem( QStringLiteral( "password" ), mPassword );
627
628 if ( !mAuthConfigId.isEmpty() )
629 url.addQueryItem( QStringLiteral( "authcfg" ), mAuthConfigId );
630
631 mHttpHeaders.updateUrlQuery( url );
632
633 return toLatin1_helper( url.toString( QUrl::FullyEncoded ) );
634}
635
636void QgsDataSourceUri::setEncodedUri( const QByteArray &uri )
637{
638 mParams.clear();
639 mUsername.clear();
640 mPassword.clear();
641 mAuthConfigId.clear();
642
643 QUrl url;
644 url.setQuery( QString::fromLatin1( uri ) );
645 const QUrlQuery query( url );
646
647 mHttpHeaders.setFromUrlQuery( query );
648
649 const auto constQueryItems = query.queryItems( QUrl::ComponentFormattingOption::FullyDecoded );
650 for ( const QPair<QString, QString> &item : constQueryItems )
651 {
652 if ( !item.first.startsWith( QgsHttpHeaders::PARAM_PREFIX ) )
653 {
654 if ( item.first == QLatin1String( "username" ) )
655 mUsername = item.second;
656 else if ( item.first == QLatin1String( "password" ) )
657 mPassword = item.second;
658 else if ( item.first == QLatin1String( "authcfg" ) )
659 mAuthConfigId = item.second;
660 else
661 mParams.insert( item.first, item.second );
662 }
663 }
664}
665
666void QgsDataSourceUri::setEncodedUri( const QString &uri )
667{
668 setEncodedUri( uri.toLatin1() );
669}
670
672{
673 if ( !mSchema.isEmpty() )
674 return QStringLiteral( "\"%1\".\"%2\"" )
675 .arg( escape( mSchema, '"' ),
676 escape( mTable, '"' ) );
677 else
678 return QStringLiteral( "\"%1\"" )
679 .arg( escape( mTable, '"' ) );
680}
681
682void QgsDataSourceUri::setConnection( const QString &host,
683 const QString &port,
684 const QString &database,
685 const QString &username,
686 const QString &password,
687 SslMode sslmode,
688 const QString &authConfigId )
689{
690 mHost = host;
691 mDatabase = database;
692 mPort = port;
693 mUsername = username;
694 mPassword = password;
695 mSSLmode = sslmode;
696 mAuthConfigId = authConfigId;
697}
698
699void QgsDataSourceUri::setConnection( const QString &service,
700 const QString &database,
701 const QString &username,
702 const QString &password,
703 SslMode sslmode,
704 const QString &authConfigId )
705{
706 mService = service;
707 mDatabase = database;
708 mUsername = username;
709 mPassword = password;
710 mSSLmode = sslmode;
711 mAuthConfigId = authConfigId;
712}
713
714void QgsDataSourceUri::setDataSource( const QString &schema,
715 const QString &table,
716 const QString &geometryColumn,
717 const QString &sql,
718 const QString &keyColumn )
719{
720 mSchema = schema;
721 mTable = table;
722 mGeometryColumn = geometryColumn;
723 mSql = sql;
724 mKeyColumn = keyColumn;
725}
726
727void QgsDataSourceUri::setAuthConfigId( const QString &authcfg )
728{
729 mAuthConfigId = authcfg;
730}
731
732void QgsDataSourceUri::setDatabase( const QString &database )
733{
734 mDatabase = database;
735}
736
738{
739 return mWkbType;
740}
741
743{
744 mWkbType = wkbType;
745}
746
748{
749 return mSrid;
750}
751
752void QgsDataSourceUri::setSrid( const QString &srid )
753{
754 mSrid = srid;
755}
756
758{
759 if ( sslMode == QLatin1String( "prefer" ) )
760 return SslPrefer;
761 else if ( sslMode == QLatin1String( "disable" ) )
762 return SslDisable;
763 else if ( sslMode == QLatin1String( "allow" ) )
764 return SslAllow;
765 else if ( sslMode == QLatin1String( "require" ) )
766 return SslRequire;
767 else if ( sslMode == QLatin1String( "verify-ca" ) )
768 return SslVerifyCa;
769 else if ( sslMode == QLatin1String( "verify-full" ) )
770 return SslVerifyFull;
771 else
772 return SslPrefer; // default
773}
774
776{
777 switch ( sslMode )
778 {
779 case SslPrefer: return QStringLiteral( "prefer" );
780 case SslDisable: return QStringLiteral( "disable" );
781 case SslAllow: return QStringLiteral( "allow" );
782 case SslRequire: return QStringLiteral( "require" );
783 case SslVerifyCa: return QStringLiteral( "verify-ca" );
784 case SslVerifyFull: return QStringLiteral( "verify-full" );
785 }
786 return QString();
787}
788
789void QgsDataSourceUri::setParam( const QString &key, const QString &value )
790{
791 // maintain old API
792 if ( key == QLatin1String( "username" ) )
793 mUsername = value;
794 else if ( key == QLatin1String( "password" ) )
795 mPassword = value;
796 else if ( key == QLatin1String( "authcfg" ) )
797 mAuthConfigId = value;
798 else
799 {
800 // may be multiple
801 mParams.insert( key, value );
802 }
803}
804
805void QgsDataSourceUri::setParam( const QString &key, const QStringList &value )
806{
807 for ( const QString &val : value )
808 {
809 setParam( key, val );
810 }
811}
812
813int QgsDataSourceUri::removeParam( const QString &key )
814{
815 if ( key == QLatin1String( "username" ) && !mUsername.isEmpty() )
816 {
817 mUsername.clear();
818 return 1;
819 }
820 else if ( key == QLatin1String( "password" ) && !mPassword.isEmpty() )
821 {
822 mPassword.clear();
823 return 1;
824 }
825 else if ( key == QLatin1String( "authcfg" ) && !mAuthConfigId.isEmpty() )
826 {
827 mAuthConfigId.clear();
828 return 1;
829 }
830
831 return mParams.remove( key );
832}
833
834QString QgsDataSourceUri::param( const QString &key ) const
835{
836 // maintain old api
837 if ( key == QLatin1String( "username" ) && !mUsername.isEmpty() )
838 return mUsername;
839 else if ( key == QLatin1String( "password" ) && !mPassword.isEmpty() )
840 return mPassword;
841 else if ( key == QLatin1String( "authcfg" ) && !mAuthConfigId.isEmpty() )
842 return mAuthConfigId;
843
844 return mParams.value( key );
845}
846
847QStringList QgsDataSourceUri::params( const QString &key ) const
848{
849 // maintain old api
850 if ( key == QLatin1String( "username" ) && !mUsername.isEmpty() )
851 return QStringList() << mUsername;
852 else if ( key == QLatin1String( "password" ) && !mPassword.isEmpty() )
853 return QStringList() << mPassword;
854 else if ( key == QLatin1String( "authcfg" ) && !mAuthConfigId.isEmpty() )
855 return QStringList() << mAuthConfigId;
856
857 return mParams.values( key );
858}
859
860bool QgsDataSourceUri::hasParam( const QString &key ) const
861{
862 // maintain old api
863 if ( key == QLatin1String( "username" ) && !mUsername.isEmpty() )
864 return true;
865 else if ( key == QLatin1String( "password" ) && !mPassword.isEmpty() )
866 return true;
867 else if ( key == QLatin1String( "authcfg" ) && !mAuthConfigId.isEmpty() )
868 return true;
869
870 return mParams.contains( key );
871}
872
874{
875 QSet<QString> paramKeys;
876 for ( const QString &key : mParams.keys() )
877 paramKeys.insert( key );
878 if ( !mHost.isEmpty() )
879 paramKeys.insert( QLatin1String( "host" ) );
880 if ( !mPort.isEmpty() )
881 paramKeys.insert( QLatin1String( "port" ) );
882 if ( !mDriver.isEmpty() )
883 paramKeys.insert( QLatin1String( "driver" ) );
884 if ( !mService.isEmpty() )
885 paramKeys.insert( QLatin1String( "service" ) );
886 if ( !mDatabase.isEmpty() )
887 paramKeys.insert( QLatin1String( "dbname" ) );
888 if ( !mSchema.isEmpty() )
889 paramKeys.insert( QLatin1String( "schema" ) );
890 if ( !mTable.isEmpty() )
891 paramKeys.insert( QLatin1String( "table" ) );
892 // Ignore mGeometryColumn: not a key ==> embedded in table value
893 if ( !mSql.isEmpty() )
894 paramKeys.insert( QLatin1String( "sql" ) );
895 if ( !mAuthConfigId.isEmpty() )
896 paramKeys.insert( QLatin1String( "authcfg" ) );
897 if ( !mUsername.isEmpty() )
898 paramKeys.insert( QLatin1String( "username" ) );
899 if ( !mPassword.isEmpty() )
900 paramKeys.insert( QLatin1String( "password" ) );
901 if ( mSSLmode != SslPrefer )
902 paramKeys.insert( QLatin1String( "sslmode" ) );
903 if ( !mKeyColumn.isEmpty() )
904 paramKeys.insert( QLatin1String( "key" ) );
905 if ( mUseEstimatedMetadata )
906 paramKeys.insert( QLatin1String( "estimatedmetadata" ) );
907 if ( mSelectAtIdDisabledSet )
908 paramKeys.insert( QLatin1String( "selectatid" ) );
909 if ( mWkbType != QgsWkbTypes::Unknown )
910 paramKeys.insert( QLatin1String( "type" ) );
911 if ( !mSrid.isEmpty() )
912 paramKeys.insert( QLatin1String( "srid" ) );
913 return paramKeys;
914}
static QgsAuthManager * authManager()
Returns the application's authentication manager instance.
QString srid() const
Returns the spatial reference ID associated with the URI.
SslMode
Available SSL connection modes.
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.
QByteArray encodedUri() const
Returns the complete encoded URI as a byte array.
QStringList params(const QString &key) const
Returns multiple generic parameter values corresponding to the specified key.
void setSchema(const QString &schema)
Sets the scheme for the URI.
bool hasParam(const QString &key) const
Returns true if a parameter with the specified key exists.
int removeParam(const QString &key)
Removes a generic parameter by key.
static SslMode decodeSslMode(const QString &sslMode)
Decodes SSL mode string into enum value.
QgsWkbTypes::Type wkbType() const
Returns the WKB type associated with the URI.
void setSql(const QString &sql)
Sets the sql filter for the URI.
void setEncodedUri(const QByteArray &uri)
Sets the complete encoded uri.
QString table() const
Returns the table name stored in the URI.
void setTable(const QString &table)
Sets table to table.
void setAuthConfigId(const QString &authcfg)
Sets the authentication configuration ID for the URI.
void setWkbType(QgsWkbTypes::Type type)
Sets the WKB type associated with the URI.
QString quotedTablename() const
Returns the URI's table name, escaped and quoted.
void setGeometryColumn(const QString &geometryColumn)
Sets geometry column name to geometryColumn.
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 connectionInfo(bool expandAuthConfig=true) const
Returns the connection part of the URI.
QString uri(bool expandAuthConfig=true) const
Returns the complete URI as a string.
void setUsername(const QString &username)
Sets the username for the URI.
QString param(const QString &key) const
Returns a generic parameter value corresponding to the specified key.
void disableSelectAtId(bool flag)
Set to true to disable selection by feature ID.
bool selectAtIdDisabled() const
Returns whether the selection by feature ID is disabled.
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.
QString username() const
Returns the username stored in the URI.
static QString encodeSslMode(SslMode sslMode)
Encodes SSL mode enum value into a string.
QString driver() const
Returns the driver name stored in the URI.
QString host() const
Returns the host name stored in the URI.
void setParam(const QString &key, const QString &value)
Sets a generic parameter value on the URI.
QString service() const
Returns the service name associated with the URI.
void setKeyColumn(const QString &column)
Sets the name of the (primary) key column.
bool useEstimatedMetadata() const
Returns true if estimated metadata should be used for the connection.
SslMode sslMode() const
Returns the SSL mode associated with the URI.
QString password() const
Returns the password stored in the URI.
QString keyColumn() const
Returns the name of the (primary) key column for the referenced table.
QString authConfigId() const
Returns any associated authentication configuration ID stored in the URI.
QString port() const
Returns the port stored in the URI.
QSet< QString > parameterKeys() const
Returns parameter keys used in the uri: specialized ones ("table", "schema", etc.) or generic paramet...
QString database() const
Returns the database name stored in the URI.
void clearSchema()
Clears the schema stored in the URI.
void setDriver(const QString &driver)
Sets the driver name stored in the URI.
void setDatabase(const QString &database)
Sets the URI database name.
QString geometryColumn() const
Returns the name of the geometry column stored in the URI, if set.
void setSrid(const QString &srid)
Sets the spatial reference ID associated with the URI.
static QString removePassword(const QString &aUri)
Removes the password element from a URI.
QString sql() const
Returns the SQL filter stored in the URI, if set.
void setPassword(const QString &password)
Sets the password for the URI.
QString toSpacedString() const
Returns key/value pairs as strings separated by space.
static const QString PARAM_PREFIX
Used in uri to pass headers as params.
bool updateUrlQuery(QUrlQuery &uri) const
Updates an uri by adding all the HTTP headers.
void setFromUrlQuery(const QUrlQuery &uri)
Loads headers from the uri.
static Type parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT string.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
static QString displayString(Type type) SIP_HOLDGIL
Returns a non-translated display string type for a WKB type, e.g., the geometry name used in WKT geom...
QByteArray toLatin1_helper(const QString &string)
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
#define QgsDebugMsg(str)
Definition: qgslogger.h:38