@@ -41,6 +41,10 @@ email : sherman at mrcc.com
41
41
#include < pg_config.h>
42
42
#endif
43
43
44
+ // Note: Because the the geometry type select SQL is also in the qgspostgresprovider
45
+ // code this parameter is duplicated there.
46
+ static const int sGeomTypeSelectLimit = 100 ;
47
+
44
48
QgsPgSourceSelect::QgsPgSourceSelect ( QWidget *parent, Qt::WFlags fl )
45
49
: QDialog( parent, fl ), mColumnTypeThread( NULL ), pd( 0 )
46
50
{
@@ -142,6 +146,7 @@ void QgsPgSourceSelect::on_btnDelete_clicked()
142
146
settings.remove ( key + " /sslmode" );
143
147
settings.remove ( key + " /publicOnly" );
144
148
settings.remove ( key + " /geometryColumnsOnly" );
149
+ settings.remove ( key + " /estimatedMetadata" );
145
150
settings.remove ( key + " /saveUsername" );
146
151
settings.remove ( key + " /savePassword" );
147
152
settings.remove ( key + " /save" );
@@ -352,6 +357,11 @@ QString QgsPgSourceSelect::layerURI( const QModelIndex &index )
352
357
uri += QString ( " key=\" %1\" " ).arg ( pkColumnName );
353
358
}
354
359
360
+ if ( mUseEstimatedMetadata )
361
+ {
362
+ uri += QString ( " estimatedmetadata=true" );
363
+ }
364
+
355
365
uri += QString ( " table=\" %1\" .\" %2\" (%3) sql=%4" )
356
366
.arg ( schemaName ).arg ( tableName )
357
367
.arg ( geomColumnName )
@@ -419,7 +429,7 @@ void QgsPgSourceSelect::on_btnConnect_clicked()
419
429
420
430
bool searchPublicOnly = settings.value ( key + " /publicOnly" ).toBool ();
421
431
bool searchGeometryColumnsOnly = settings.value ( key + " /geometryColumnsOnly" ).toBool ();
422
-
432
+ mUseEstimatedMetadata = settings. value ( key + " /estimatedMetadata " ). toBool ();
423
433
// Need to escape the password to allow for single quotes and backslashes
424
434
425
435
QgsDebugMsg ( " Connection info: " + uri.connectionInfo () );
@@ -562,7 +572,7 @@ void QgsPgSourceSelect::addSearchGeometryColumn( const QString &schema, const QS
562
572
if ( mColumnTypeThread == NULL )
563
573
{
564
574
mColumnTypeThread = new QgsGeomColumnTypeThread ();
565
- mColumnTypeThread ->setConnInfo ( m_privConnInfo );
575
+ mColumnTypeThread ->setConnInfo ( m_privConnInfo, mUseEstimatedMetadata );
566
576
}
567
577
mColumnTypeThread ->addGeometryColumn ( schema, table, column );
568
578
}
@@ -794,9 +804,10 @@ void QgsPgSourceSelect::setSearchExpression( const QString& regexp )
794
804
{
795
805
}
796
806
797
- void QgsGeomColumnTypeThread::setConnInfo ( QString s )
807
+ void QgsGeomColumnTypeThread::setConnInfo ( QString conninfo, bool useEstimatedMetadata )
798
808
{
799
- mConnInfo = s;
809
+ mConnInfo = conninfo;
810
+ mUseEstimatedMetadata = useEstimatedMetadata;
800
811
}
801
812
802
813
void QgsGeomColumnTypeThread::addGeometryColumn ( QString schema, QString table, QString column )
@@ -828,8 +839,19 @@ void QgsGeomColumnTypeThread::getLayerTypes()
828
839
" when geometrytype(%1) IN ('LINESTRING','MULTILINESTRING') THEN 'LINESTRING'"
829
840
" when geometrytype(%1) IN ('POLYGON','MULTIPOLYGON') THEN 'POLYGON'"
830
841
" end "
831
- " from "
832
- " \" %2\" .\" %3\" " ).arg ( " \" " + columns[i] + " \" " ).arg ( schemas[i] ).arg ( tables[i] );
842
+ " from " ).arg ( " \" " + columns[i] + " \" " );
843
+ if ( mUseEstimatedMetadata )
844
+ {
845
+ query += QString ( " (select %1 from %2 where %1 is not null limit %3) as t" )
846
+ .arg ( " \" " + columns[i] + " \" " )
847
+ .arg ( " \" " + schemas[i] + " \" .\" " + tables[i] + " \" " )
848
+ .arg ( sGeomTypeSelectLimit );
849
+ }
850
+ else
851
+ {
852
+ query += " \" " + schemas[i] + " \" .\" " + tables[i] + " \" " ;
853
+ }
854
+
833
855
PGresult* gresult = PQexec ( pd, query.toUtf8 () );
834
856
QString type;
835
857
if ( PQresultStatus ( gresult ) == PGRES_TUPLES_OK )
0 commit comments