22 #include <QStringList>
27 : mSSLmode( SSLprefer )
29 , mUseEstimatedMetadata( false )
30 , mSelectAtIdDisabled( false )
31 , mWkbType(
QGis::WKBUnknown )
37 : mSSLmode( SSLprefer )
39 , mUseEstimatedMetadata( false )
40 , mSelectAtIdDisabled( false )
41 , mWkbType(
QGis::WKBUnknown )
44 while ( i < uri.length() )
57 while ( i < uri.length() && uri[i] !=
'=' && !uri[i].isSpace() )
60 QString pname = uri.mid( start, i - start );
83 if ( pname ==
"table" )
104 while ( i < uri.length() && uri[i] !=
')' )
106 if ( uri[i] ==
'\\' )
111 if ( i == uri.length() )
127 else if ( pname ==
"key" )
131 else if ( pname ==
"estimatedmetadata" )
135 else if ( pname ==
"srid" )
139 else if ( pname ==
"type" )
141 QString geomTypeUpper = pval.toUpper();
142 if ( geomTypeUpper ==
"POINT" )
146 else if ( geomTypeUpper ==
"LINESTRING" || geomTypeUpper ==
"LINE" )
150 else if ( geomTypeUpper ==
"POLYGON" )
154 else if ( geomTypeUpper ==
"MULTIPOINT" )
158 else if ( geomTypeUpper ==
"MULTILINESTRING" )
162 else if ( geomTypeUpper ==
"MULTIPOLYGON" )
171 else if ( pname ==
"selectatid" )
175 else if ( pname ==
"service" )
179 else if ( pname ==
"user" )
183 else if ( pname ==
"password" )
187 else if ( pname ==
"connect_timeout" )
191 else if ( pname ==
"dbname" )
195 else if ( pname ==
"host" )
199 else if ( pname ==
"hostaddr" )
203 else if ( pname ==
"port" )
207 else if ( pname ==
"tty" )
211 else if ( pname ==
"options" )
215 else if ( pname ==
"sslmode" )
217 if ( pval ==
"disable" )
219 else if ( pval ==
"allow" )
221 else if ( pval ==
"prefer" )
223 else if ( pval ==
"require" )
226 else if ( pname ==
"requiressl" )
233 else if ( pname ==
"krbsrvname" )
237 else if ( pname ==
"gsslib" )
243 QgsDebugMsg(
"invalid connection option \"" + pname +
"\" ignored" );
252 regexp.setMinimal(
true );
253 QString safeName( aUri );
254 if ( aUri.contains(
" password=" ) )
256 regexp.setPattern(
" password=.* " );
257 safeName.replace( regexp,
" " );
259 else if ( aUri.contains(
",password=" ) )
261 regexp.setPattern(
",password=.*," );
262 safeName.replace( regexp,
"," );
264 else if ( aUri.contains(
"IDB:" ) )
266 regexp.setPattern(
" pass=.* " );
267 safeName.replace( regexp,
" " );
269 else if (( aUri.contains(
"OCI:" ) )
270 || ( aUri.contains(
"ODBC:" ) ) )
272 regexp.setPattern(
"/.*@" );
273 safeName.replace( regexp,
"/@" );
275 else if ( aUri.contains(
"SDE:" ) )
277 QStringList strlist = aUri.split(
"," );
278 safeName = strlist[0] +
"," + strlist[1] +
"," + strlist[2] +
"," + strlist[3];
391 QString val = theVal;
393 val.replace(
"\\",
"\\\\" );
394 val.replace( delim, QString(
"\\%1" ).arg( delim ) );
402 while ( i < uri.length() && uri[i].isSpace() )
412 if ( uri[i] ==
'\'' || uri[i] ==
'"' )
414 QChar delim = uri[i];
421 if ( i == uri.length() )
423 QgsDebugMsg(
"unterminated quoted string in connection info string" );
427 if ( uri[i] ==
'\\' )
430 if ( i == uri.length() )
432 if ( uri[i] != delim && uri[i] !=
'\\' )
435 else if ( uri[i] == delim )
447 while ( i < uri.length() )
449 if ( uri[i].isSpace() )
455 if ( uri[i] ==
'\\' )
458 if ( i == uri.length() )
460 if ( uri[i] !=
'\\' && uri[i] !=
'\'' )
475 QStringList connectionItems;
486 else if (
mHost !=
"" )
488 connectionItems <<
"host=" +
mHost;
494 connectionItems <<
"port=" +
mPort;
508 connectionItems <<
"sslmode=disable";
510 connectionItems <<
"sslmode=allow";
512 connectionItems <<
"sslmode=require";
515 connectionItems <<
"sslmode=prefer";
518 return connectionItems.join(
" " );
532 theUri += QString(
" estimatedmetadata=true" );
535 if ( !
mSrid.isEmpty() )
537 theUri += QString(
" srid=%1" ).arg(
mSrid );
550 theUri +=
"LINESTRING";
556 theUri +=
"MULTIPOINT";
559 theUri +=
"MULTILINESTRING";
562 theUri +=
"MULTIPOLYGON";
568 theUri +=
"LINESTRINGM";
571 theUri +=
"POLYGONM";
574 theUri +=
"MULTIPOINTM";
577 theUri +=
"MULTILINESTRINGM";
580 theUri +=
"MULTIPOLYGONM";
590 theUri += QString(
" selectatid=false" );
594 columnName.replace(
"\\",
"\\\\" );
595 columnName.replace(
")",
"\\)" );
597 theUri += QString(
" table=%1%2 sql=%3" )
599 .arg(
mGeometryColumn.isNull() ? QString() : QString(
" (%1)" ).arg( columnName ) )
608 foreach ( QString key,
mParams.uniqueKeys() )
610 foreach ( QString value,
mParams.values( key ) )
612 url.addQueryItem( key, value );
615 return url.encodedQuery();
622 url.setEncodedQuery( uri );
623 QPair<QString, QString> item;
624 foreach ( item, url.queryItems() )
626 mParams.insertMulti( item.first, item.second );
638 return QString(
"\"%1\".\"%2\"" )
642 return QString(
"\"%1\"" )
648 const QString &database,
649 const QString &username,
650 const QString &password,
662 const QString &database,
663 const QString &username,
664 const QString &password,
675 const QString &table,
676 const QString &geometryColumn,
678 const QString &keyColumn )
715 mParams.insertMulti( key, value );
720 foreach ( QString val, value )
722 mParams.insertMulti( key, val );
743 return mParams.contains( key );