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