QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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 if ( pname.startsWith( QgsHttpHeaders::PARAM_PREFIX ) )
213 {
214 mHttpHeaders.insert( pname, pval );
215 }
216 else
217 {
218 QgsDebugMsgLevel( "parameter \"" + pname + "\":\"" + pval + "\" added", 4 );
219 setParam( pname, pval );
220 }
221 }
222 }
223}
224
225QString QgsDataSourceUri::removePassword( const QString &aUri )
226{
227 QRegularExpression regexp;
228 regexp.setPatternOptions( QRegularExpression::InvertedGreedinessOption );
229 QString safeName( aUri );
230 if ( aUri.contains( QLatin1String( " password=" ) ) )
231 {
232 regexp.setPattern( QStringLiteral( " password=.* " ) );
233 safeName.replace( regexp, QStringLiteral( " " ) );
234 }
235 else if ( aUri.contains( QLatin1String( ",password=" ) ) )
236 {
237 regexp.setPattern( QStringLiteral( ",password=.*," ) );
238 safeName.replace( regexp, QStringLiteral( "," ) );
239 }
240 else if ( aUri.contains( QLatin1String( "IDB:" ) ) )
241 {
242 regexp.setPattern( QStringLiteral( " pass=.* " ) );
243 safeName.replace( regexp, QStringLiteral( " " ) );
244 }
245 else if ( ( aUri.contains( QLatin1String( "OCI:" ) ) )
246 || ( aUri.contains( QLatin1String( "ODBC:" ) ) ) )
247 {
248 regexp.setPattern( QStringLiteral( "/.*@" ) );
249 safeName.replace( regexp, QStringLiteral( "/@" ) );
250 }
251 else if ( aUri.contains( QLatin1String( "SDE:" ) ) )
252 {
253 QStringList strlist = aUri.split( ',' );
254 safeName = strlist[0] + ',' + strlist[1] + ',' + strlist[2] + ',' + strlist[3];
255 }
256 return safeName;
257}
258
260{
261 return mAuthConfigId;
262}
263
265{
266 return mUsername;
267}
268
269void QgsDataSourceUri::setUsername( const QString &username )
270{
271 mUsername = username;
272}
273
275{
276 return mService;
277}
278
280{
281 return mHost;
282}
283
285{
286 return mDatabase;
287}
288
290{
291 return mPassword;
292}
293
294void QgsDataSourceUri::setPassword( const QString &password )
295{
296 mPassword = password;
297}
298
300{
301 return mPort;
302}
303
305{
306 return mDriver;
307}
308
310{
311 return mSSLmode;
312}
313
315{
316 return mSchema;
317}
318
320{
321 return mTable;
322}
323
325{
326 return mSql;
327}
328
330{
331 return mGeometryColumn;
332}
333
335{
336 return mKeyColumn;
337}
338
339
340void QgsDataSourceUri::setDriver( const QString &driver )
341{
342 mDriver = driver;
343}
344
345
346void QgsDataSourceUri::setKeyColumn( const QString &column )
347{
348 mKeyColumn = column;
349}
350
351
353{
354 mUseEstimatedMetadata = flag;
355}
356
358{
359 return mUseEstimatedMetadata;
360}
361
363{
364 mSelectAtIdDisabledSet = true;
365 mSelectAtIdDisabled = flag;
366}
367
369{
370 return mSelectAtIdDisabled;
371}
372
373void QgsDataSourceUri::setSql( const QString &sql )
374{
375 mSql = sql;
376}
377
379{
380 mSchema.clear();
381}
382
383void QgsDataSourceUri::setSchema( const QString &schema )
384{
385 mSchema = schema;
386}
387
388QString QgsDataSourceUri::escape( const QString &val, QChar delim = '\'' ) const
389{
390 QString escaped = val;
391
392 escaped.replace( '\\', QLatin1String( "\\\\" ) );
393 escaped.replace( delim, QStringLiteral( "\\%1" ).arg( delim ) );
394
395 return escaped;
396}
397
398void QgsDataSourceUri::setGeometryColumn( const QString &geometryColumn )
399{
400 mGeometryColumn = geometryColumn;
401}
402
403void QgsDataSourceUri::setTable( const QString &table )
404{
405 mTable = table;
406}
407
408void QgsDataSourceUri::skipBlanks( const QString &uri, int &i )
409{
410 // skip space before value
411 while ( i < uri.length() && uri[i].isSpace() )
412 i++;
413}
414
415QString QgsDataSourceUri::getValue( const QString &uri, int &i )
416{
417 skipBlanks( uri, i );
418
419 // Get the parameter value
420 QString pval;
421 if ( i < uri.length() && ( uri[i] == '\'' || uri[i] == '"' ) )
422 {
423 const QChar delim = uri[i];
424
425 i++;
426
427 // value is quoted
428 for ( ;; )
429 {
430 if ( i == uri.length() )
431 {
432 QgsDebugMsg( QStringLiteral( "unterminated quoted string in connection info string" ) );
433 return pval;
434 }
435
436 if ( uri[i] == '\\' )
437 {
438 i++;
439 if ( i == uri.length() )
440 continue;
441 if ( uri[i] != delim && uri[i] != '\\' )
442 i--;
443 }
444 else if ( uri[i] == delim )
445 {
446 i++;
447 break;
448 }
449
450 pval += uri[i++];
451 }
452 }
453 else
454 {
455 // value is not quoted
456 while ( i < uri.length() )
457 {
458 if ( uri[i].isSpace() )
459 {
460 // end of value
461 break;
462 }
463
464 if ( uri[i] == '\\' )
465 {
466 i++;
467 if ( i == uri.length() )
468 break;
469 if ( uri[i] != '\\' && uri[i] != '\'' )
470 i--;
471 }
472
473 pval += uri[i++];
474 }
475 }
476
477 skipBlanks( uri, i );
478
479 return pval;
480}
481
482QString QgsDataSourceUri::connectionInfo( bool expandAuthConfig ) const
483{
484 QStringList connectionItems;
485
486 if ( !mDatabase.isEmpty() )
487 {
488 connectionItems << "dbname='" + escape( mDatabase ) + '\'';
489 }
490
491 if ( !mService.isEmpty() )
492 {
493 connectionItems << "service='" + escape( mService ) + '\'';
494 }
495 else if ( !mHost.isEmpty() )
496 {
497 connectionItems << "host=" + mHost;
498 }
499
500 if ( mService.isEmpty() )
501 {
502 if ( !mPort.isEmpty() )
503 connectionItems << "port=" + mPort;
504 }
505
506 if ( !mDriver.isEmpty() )
507 {
508 connectionItems << "driver='" + escape( mDriver ) + '\'';
509 }
510
511 if ( !mUsername.isEmpty() )
512 {
513 connectionItems << "user='" + escape( mUsername ) + '\'';
514
515 if ( !mPassword.isEmpty() )
516 {
517 connectionItems << "password='" + escape( mPassword ) + '\'';
518 }
519 }
520
521 if ( mSSLmode != SslPrefer ) // no need to output the default
522 {
523 connectionItems << QStringLiteral( "sslmode=" ) + encodeSslMode( mSSLmode );
524 }
525
526 if ( !mAuthConfigId.isEmpty() )
527 {
528 if ( expandAuthConfig )
529 {
530 if ( !QgsApplication::authManager()->updateDataSourceUriItems( connectionItems, mAuthConfigId ) )
531 {
532 QgsDebugMsg( QStringLiteral( "Data source URI FAILED to update via loading configuration ID '%1'" ).arg( mAuthConfigId ) );
533 }
534 }
535 else
536 {
537 connectionItems << "authcfg=" + mAuthConfigId;
538 }
539 }
540
541 return connectionItems.join( QLatin1Char( ' ' ) );
542}
543
544QString QgsDataSourceUri::uri( bool expandAuthConfig ) const
545{
546 QString uri = connectionInfo( expandAuthConfig );
547
548 if ( !mKeyColumn.isEmpty() )
549 {
550 uri += QStringLiteral( " key='%1'" ).arg( escape( mKeyColumn ) );
551 }
552
553 if ( mUseEstimatedMetadata )
554 {
555 uri += QLatin1String( " estimatedmetadata=true" );
556 }
557
558 if ( !mSrid.isEmpty() )
559 {
560 uri += QStringLiteral( " srid=%1" ).arg( mSrid );
561 }
562
563 if ( mWkbType != Qgis::WkbType::Unknown && mWkbType != Qgis::WkbType::NoGeometry )
564 {
565 uri += QLatin1String( " type=" );
566 uri += QgsWkbTypes::displayString( mWkbType );
567 }
568
569 if ( mSelectAtIdDisabled )
570 {
571 uri += QLatin1String( " selectatid=false" );
572 }
573
574 for ( auto it = mParams.constBegin(); it != mParams.constEnd(); ++it )
575 {
576 if ( it.key().contains( '=' ) || it.key().contains( ' ' ) )
577 {
578 QgsDebugMsg( QStringLiteral( "invalid uri parameter %1 skipped" ).arg( it.key() ) );
579 continue;
580 }
581
582 uri += ' ' + it.key() + "='" + escape( it.value() ) + '\'';
583 }
584
585 uri += mHttpHeaders.toSpacedString();
586
587 QString columnName( mGeometryColumn );
588 columnName.replace( '\\', QLatin1String( "\\\\" ) );
589 columnName.replace( ')', QLatin1String( "\\)" ) );
590
591 if ( !mTable.isEmpty() )
592 {
593 uri += QStringLiteral( " table=%1%2" )
594 .arg( quotedTablename(),
595 mGeometryColumn.isEmpty() ? QString() : QStringLiteral( " (%1)" ).arg( columnName ) );
596 }
597 else if ( !mSchema.isEmpty() )
598 {
599 uri += QStringLiteral( " schema='%1'" ).arg( escape( mSchema ) );
600 }
601
602 if ( !mSql.isEmpty() )
603 {
604 uri += QStringLiteral( " sql=" ) + mSql;
605 }
606
607 return uri;
608}
609
610// from qurl.h
611QByteArray toLatin1_helper( const QString &string )
612{
613 if ( string.isEmpty() )
614 return string.isNull() ? QByteArray() : QByteArray( "" );
615 return string.toLatin1();
616}
617
619{
620 QUrlQuery url;
621 for ( auto it = mParams.constBegin(); it != mParams.constEnd(); ++it )
622 {
623 url.addQueryItem( it.key(), it.value() );
624 }
625
626 if ( !mUsername.isEmpty() )
627 url.addQueryItem( QStringLiteral( "username" ), mUsername );
628
629 if ( !mPassword.isEmpty() )
630 url.addQueryItem( QStringLiteral( "password" ), mPassword );
631
632 if ( !mAuthConfigId.isEmpty() )
633 url.addQueryItem( QStringLiteral( "authcfg" ), mAuthConfigId );
634
635 mHttpHeaders.updateUrlQuery( url );
636
637 return toLatin1_helper( url.toString( QUrl::FullyEncoded ) );
638}
639
640void QgsDataSourceUri::setEncodedUri( const QByteArray &uri )
641{
642 mParams.clear();
643 mUsername.clear();
644 mPassword.clear();
645 mAuthConfigId.clear();
646
647 QUrl url;
648 url.setQuery( QString::fromLatin1( uri ) );
649 const QUrlQuery query( url );
650
651 mHttpHeaders.setFromUrlQuery( query );
652
653 const auto constQueryItems = query.queryItems( QUrl::ComponentFormattingOption::FullyDecoded );
654 for ( const QPair<QString, QString> &item : constQueryItems )
655 {
656 if ( !item.first.startsWith( QgsHttpHeaders::PARAM_PREFIX ) )
657 {
658 if ( item.first == QLatin1String( "username" ) )
659 mUsername = item.second;
660 else if ( item.first == QLatin1String( "password" ) )
661 mPassword = item.second;
662 else if ( item.first == QLatin1String( "authcfg" ) )
663 mAuthConfigId = item.second;
664 else
665 mParams.insert( item.first, item.second );
666 }
667 }
668}
669
670void QgsDataSourceUri::setEncodedUri( const QString &uri )
671{
672 setEncodedUri( uri.toLatin1() );
673}
674
676{
677 if ( !mSchema.isEmpty() )
678 return QStringLiteral( "\"%1\".\"%2\"" )
679 .arg( escape( mSchema, '"' ),
680 escape( mTable, '"' ) );
681 else
682 return QStringLiteral( "\"%1\"" )
683 .arg( escape( mTable, '"' ) );
684}
685
686void QgsDataSourceUri::setConnection( const QString &host,
687 const QString &port,
688 const QString &database,
689 const QString &username,
690 const QString &password,
691 SslMode sslmode,
692 const QString &authConfigId )
693{
694 mHost = host;
695 mDatabase = database;
696 mPort = port;
697 mUsername = username;
698 mPassword = password;
699 mSSLmode = sslmode;
700 mAuthConfigId = authConfigId;
701}
702
703void QgsDataSourceUri::setConnection( const QString &service,
704 const QString &database,
705 const QString &username,
706 const QString &password,
707 SslMode sslmode,
708 const QString &authConfigId )
709{
710 mService = service;
711 mDatabase = database;
712 mUsername = username;
713 mPassword = password;
714 mSSLmode = sslmode;
715 mAuthConfigId = authConfigId;
716}
717
718void QgsDataSourceUri::setDataSource( const QString &schema,
719 const QString &table,
720 const QString &geometryColumn,
721 const QString &sql,
722 const QString &keyColumn )
723{
724 mSchema = schema;
725 mTable = table;
726 mGeometryColumn = geometryColumn;
727 mSql = sql;
728 mKeyColumn = keyColumn;
729}
730
731void QgsDataSourceUri::setAuthConfigId( const QString &authcfg )
732{
733 mAuthConfigId = authcfg;
734}
735
736void QgsDataSourceUri::setDatabase( const QString &database )
737{
738 mDatabase = database;
739}
740
742{
743 return mWkbType;
744}
745
747{
748 mWkbType = wkbType;
749}
750
752{
753 return mSrid;
754}
755
756void QgsDataSourceUri::setSrid( const QString &srid )
757{
758 mSrid = srid;
759}
760
762{
763 if ( sslMode == QLatin1String( "prefer" ) )
764 return SslPrefer;
765 else if ( sslMode == QLatin1String( "disable" ) )
766 return SslDisable;
767 else if ( sslMode == QLatin1String( "allow" ) )
768 return SslAllow;
769 else if ( sslMode == QLatin1String( "require" ) )
770 return SslRequire;
771 else if ( sslMode == QLatin1String( "verify-ca" ) )
772 return SslVerifyCa;
773 else if ( sslMode == QLatin1String( "verify-full" ) )
774 return SslVerifyFull;
775 else
776 return SslPrefer; // default
777}
778
780{
781 switch ( sslMode )
782 {
783 case SslPrefer: return QStringLiteral( "prefer" );
784 case SslDisable: return QStringLiteral( "disable" );
785 case SslAllow: return QStringLiteral( "allow" );
786 case SslRequire: return QStringLiteral( "require" );
787 case SslVerifyCa: return QStringLiteral( "verify-ca" );
788 case SslVerifyFull: return QStringLiteral( "verify-full" );
789 }
790 return QString();
791}
792
793void QgsDataSourceUri::setParam( const QString &key, const QString &value )
794{
795 // maintain old API
796 if ( key == QLatin1String( "username" ) )
797 mUsername = value;
798 else if ( key == QLatin1String( "password" ) )
799 mPassword = value;
800 else if ( key == QLatin1String( "authcfg" ) )
801 mAuthConfigId = value;
802 else
803 {
804 // may be multiple
805 mParams.insert( key, value );
806 }
807}
808
809void QgsDataSourceUri::setParam( const QString &key, const QStringList &value )
810{
811 for ( const QString &val : value )
812 {
813 setParam( key, val );
814 }
815}
816
817int QgsDataSourceUri::removeParam( const QString &key )
818{
819 if ( key == QLatin1String( "username" ) && !mUsername.isEmpty() )
820 {
821 mUsername.clear();
822 return 1;
823 }
824 else if ( key == QLatin1String( "password" ) && !mPassword.isEmpty() )
825 {
826 mPassword.clear();
827 return 1;
828 }
829 else if ( key == QLatin1String( "authcfg" ) && !mAuthConfigId.isEmpty() )
830 {
831 mAuthConfigId.clear();
832 return 1;
833 }
834
835 return mParams.remove( key );
836}
837
838QString QgsDataSourceUri::param( const QString &key ) const
839{
840 // maintain old api
841 if ( key == QLatin1String( "username" ) && !mUsername.isEmpty() )
842 return mUsername;
843 else if ( key == QLatin1String( "password" ) && !mPassword.isEmpty() )
844 return mPassword;
845 else if ( key == QLatin1String( "authcfg" ) && !mAuthConfigId.isEmpty() )
846 return mAuthConfigId;
847
848 return mParams.value( key );
849}
850
851QStringList QgsDataSourceUri::params( const QString &key ) const
852{
853 // maintain old api
854 if ( key == QLatin1String( "username" ) && !mUsername.isEmpty() )
855 return QStringList() << mUsername;
856 else if ( key == QLatin1String( "password" ) && !mPassword.isEmpty() )
857 return QStringList() << mPassword;
858 else if ( key == QLatin1String( "authcfg" ) && !mAuthConfigId.isEmpty() )
859 return QStringList() << mAuthConfigId;
860
861 return mParams.values( key );
862}
863
864bool QgsDataSourceUri::hasParam( const QString &key ) const
865{
866 // maintain old api
867 if ( key == QLatin1String( "username" ) && !mUsername.isEmpty() )
868 return true;
869 else if ( key == QLatin1String( "password" ) && !mPassword.isEmpty() )
870 return true;
871 else if ( key == QLatin1String( "authcfg" ) && !mAuthConfigId.isEmpty() )
872 return true;
873
874 return mParams.contains( key );
875}
876
878{
879 QSet<QString> paramKeys;
880 for ( auto it = mParams.constBegin(); it != mParams.constEnd(); it++ )
881 paramKeys.insert( it.key() );
882
883 if ( !mHost.isEmpty() )
884 paramKeys.insert( QLatin1String( "host" ) );
885 if ( !mPort.isEmpty() )
886 paramKeys.insert( QLatin1String( "port" ) );
887 if ( !mDriver.isEmpty() )
888 paramKeys.insert( QLatin1String( "driver" ) );
889 if ( !mService.isEmpty() )
890 paramKeys.insert( QLatin1String( "service" ) );
891 if ( !mDatabase.isEmpty() )
892 paramKeys.insert( QLatin1String( "dbname" ) );
893 if ( !mSchema.isEmpty() )
894 paramKeys.insert( QLatin1String( "schema" ) );
895 if ( !mTable.isEmpty() )
896 paramKeys.insert( QLatin1String( "table" ) );
897 // Ignore mGeometryColumn: not a key ==> embedded in table value
898 if ( !mSql.isEmpty() )
899 paramKeys.insert( QLatin1String( "sql" ) );
900 if ( !mAuthConfigId.isEmpty() )
901 paramKeys.insert( QLatin1String( "authcfg" ) );
902 if ( !mUsername.isEmpty() )
903 paramKeys.insert( QLatin1String( "username" ) );
904 if ( !mPassword.isEmpty() )
905 paramKeys.insert( QLatin1String( "password" ) );
906 if ( mSSLmode != SslPrefer )
907 paramKeys.insert( QLatin1String( "sslmode" ) );
908 if ( !mKeyColumn.isEmpty() )
909 paramKeys.insert( QLatin1String( "key" ) );
910 if ( mUseEstimatedMetadata )
911 paramKeys.insert( QLatin1String( "estimatedmetadata" ) );
912 if ( mSelectAtIdDisabledSet )
913 paramKeys.insert( QLatin1String( "selectatid" ) );
914 if ( mWkbType != Qgis::WkbType::Unknown )
915 paramKeys.insert( QLatin1String( "type" ) );
916 if ( !mSrid.isEmpty() )
917 paramKeys.insert( QLatin1String( "srid" ) );
918 return paramKeys;
919}
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition: qgis.h:155
@ NoGeometry
No geometry.
@ Unknown
Unknown.
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.
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.
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.
Qgis::WkbType wkbType() const
Returns the WKB type associated with the URI.
void setWkbType(Qgis::WkbType type)
Sets the WKB type associated with the URI.
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 Qgis::WkbType parseType(const QString &wktStr)
Attempts to extract the WKB type from a WKT string.
static QString displayString(Qgis::WkbType 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