@@ -115,12 +115,26 @@ QgsPostgresProvider::QgsPostgresProvider( QString const & uri )
115
115
return ;
116
116
}
117
117
118
- sql = QString ( " SELECT "
119
- " has_table_privilege(%1,'DELETE'),"
120
- " has_table_privilege(%1,'UPDATE'),"
121
- " has_table_privilege(%1,'INSERT'),"
122
- " current_schema()" )
123
- .arg ( quotedValue ( mSchemaTableName ) );
118
+ if ( connectionRO->pgVersion () >= 80400 )
119
+ {
120
+ sql = QString ( " SELECT "
121
+ " has_table_privilege(%1,'DELETE'),"
122
+ " has_any_column_privilege(%1,'UPDATE'),"
123
+ " has_column_privilege(%1,%2,'UPDATE'),"
124
+ " has_table_privilege(%1,'INSERT'),"
125
+ " current_schema()" )
126
+ .arg ( quotedValue ( mSchemaTableName ) ).arg ( quotedValue ( geometryColumn ) );
127
+ }
128
+ else
129
+ {
130
+ sql = QString ( " SELECT "
131
+ " has_table_privilege(%1,'DELETE'),"
132
+ " has_table_privilege(%1,'UPDATE'),"
133
+ " has_table_privilege(%1,'UPDATE'),"
134
+ " has_table_privilege(%1,'INSERT'),"
135
+ " current_schema()" )
136
+ .arg ( quotedValue ( mSchemaTableName ) );
137
+ }
124
138
125
139
testAccess = connectionRO->PQexec ( sql );
126
140
if ( PQresultStatus ( testAccess ) != PGRES_TUPLES_OK )
@@ -148,16 +162,22 @@ QgsPostgresProvider::QgsPostgresProvider( QString const & uri )
148
162
if ( QString::fromUtf8 ( PQgetvalue ( testAccess, 0 , 1 ) ) == " t" )
149
163
{
150
164
// UPDATE
151
- enabledCapabilities |= QgsVectorDataProvider::ChangeGeometries | QgsVectorDataProvider:: ChangeAttributeValues;
165
+ enabledCapabilities |= QgsVectorDataProvider::ChangeAttributeValues;
152
166
}
153
167
154
168
if ( QString::fromUtf8 ( PQgetvalue ( testAccess, 0 , 2 ) ) == " t" )
169
+ {
170
+ // UPDATE
171
+ enabledCapabilities |= QgsVectorDataProvider::ChangeGeometries;
172
+ }
173
+
174
+ if ( QString::fromUtf8 ( PQgetvalue ( testAccess, 0 , 3 ) ) == " t" )
155
175
{
156
176
// INSERT
157
177
enabledCapabilities |= QgsVectorDataProvider::AddFeatures;
158
178
}
159
179
160
- mCurrentSchema = QString::fromUtf8 ( PQgetvalue ( testAccess, 0 , 3 ) );
180
+ mCurrentSchema = QString::fromUtf8 ( PQgetvalue ( testAccess, 0 , 4 ) );
161
181
if ( mCurrentSchema == mSchemaName )
162
182
{
163
183
mUri .clearSchema ();
@@ -2055,6 +2075,8 @@ bool QgsPostgresProvider::Conn::hasGEOS()
2055
2075
/* Functions for determining available features in postGIS */
2056
2076
QString QgsPostgresProvider::Conn::postgisVersion ()
2057
2077
{
2078
+ postgresqlVersion = PQserverVersion ( conn );
2079
+
2058
2080
Result result = PQexec ( " select postgis_version()" );
2059
2081
if ( PQntuples ( result ) != 1 )
2060
2082
{
@@ -2694,15 +2716,6 @@ void QgsPostgresProvider::calculateExtents()
2694
2716
2695
2717
sql += QString ( " not IsEmpty(%1) limit 5" ).arg ( quotedIdentifier ( geometryColumn ) );
2696
2718
2697
- #if WASTE_TIME
2698
- sql = QString ( " select "
2699
- " xmax(extent(%1)) as xmax,"
2700
- " xmin(extent(%1)) as xmin,"
2701
- " ymax(extent(%1)) as ymax,"
2702
- " ymin(extent(%1)) as ymin"
2703
- " from %2" ).arg ( quotedIdentifier ( geometryColumn ) ).arg ( mSchemaTableName );
2704
- #endif
2705
-
2706
2719
QgsDebugMsg ( " Getting approximate extent using: '" + sql + " '" );
2707
2720
2708
2721
Result result = connectionRO->PQexec ( sql );
@@ -2733,13 +2746,18 @@ void QgsPostgresProvider::calculateExtents()
2733
2746
QString ext;
2734
2747
2735
2748
// get the extents
2736
- if ( sqlWhereClause.isEmpty () )
2749
+ if ( sqlWhereClause.isEmpty () && !connectionRO-> hasNoExtentEstimate () )
2737
2750
{
2738
2751
result = connectionRO->PQexec ( QString ( " select estimated_extent(%1,%2,%3)" )
2739
2752
.arg ( quotedValue ( mSchemaName ) )
2740
2753
.arg ( quotedValue ( mTableName ) )
2741
2754
.arg ( quotedValue ( geometryColumn ) ) );
2742
- if ( PQntuples ( result ) == 1 )
2755
+ if ( PQresultStatus ( result ) != PGRES_TUPLES_OK )
2756
+ {
2757
+ connectionRO->PQexecNR ( " ROLLBACK" );
2758
+ connectionRO->setNoExtentEstimate ();
2759
+ }
2760
+ else if ( PQntuples ( result ) == 1 )
2743
2761
ext = PQgetvalue ( result, 0 , 0 );
2744
2762
}
2745
2763
@@ -2753,19 +2771,12 @@ void QgsPostgresProvider::calculateExtents()
2753
2771
sql += QString ( " where %1" ).arg ( sqlWhereClause );
2754
2772
2755
2773
result = connectionRO->PQexec ( sql );
2756
- if ( PQntuples ( result ) == 1 )
2774
+ if ( PQresultStatus ( result ) != PGRES_TUPLES_OK )
2775
+ connectionRO->PQexecNR ( " ROLLBACK" );
2776
+ else if ( PQntuples ( result ) == 1 )
2757
2777
ext = PQgetvalue ( result, 0 , 0 );
2758
2778
}
2759
2779
2760
- #if WASTE_TIME
2761
- sql = QString ( " select "
2762
- " xmax(extent(%1)) as xmax,"
2763
- " xmin(extent(%1)) as xmin,"
2764
- " ymax(extent(%1)) as ymax,"
2765
- " ymin(extent(%1)) as ymin"
2766
- " from %2" ).arg ( quotedIdentifier ( geometryColumn ) ).arg ( mSchemaTableName );
2767
- #endif
2768
-
2769
2780
QgsDebugMsg ( " Getting extents using schema.table: " + sql );
2770
2781
2771
2782
QRegExp rx ( " \\ ((.+) (.+),(.+) (.+)\\ )" );
@@ -2784,19 +2795,6 @@ void QgsPostgresProvider::calculateExtents()
2784
2795
}
2785
2796
#endif
2786
2797
2787
- #if 0
2788
- #ifdef QGISDEBUG
2789
- QString xMsg;
2790
- QTextOStream( &xMsg ).precision( 18 );
2791
- QTextOStream( &xMsg ).width( 18 );
2792
- QTextOStream( &xMsg ) << "QgsPostgresProvider: Set extents to: "
2793
- << layerExtent.xMinimum() << ", "
2794
- << layerExtent.yMinimum() << " "
2795
- << layerExtent.xMaximum() << ", "
2796
- << layerExtent.yMaximum();
2797
- QgsDebugMsg( xMsg );
2798
- #endif
2799
- #endif
2800
2798
QgsDebugMsg ( " Set extents to: " + layerExtent.toString () );
2801
2799
}
2802
2800
0 commit comments