File tree Expand file tree Collapse file tree 5 files changed +26
-15
lines changed Expand file tree Collapse file tree 5 files changed +26
-15
lines changed Original file line number Diff line number Diff line change @@ -156,6 +156,11 @@ void QgsDataSourceURI::setSql(QString sql)
156
156
mSql = sql;
157
157
}
158
158
159
+ void QgsDataSourceURI::clearSchema ()
160
+ {
161
+ mSchema = " " ;
162
+ }
163
+
159
164
void QgsDataSourceURI::skipBlanks (const QString &uri, int &i)
160
165
{
161
166
// skip space before value
@@ -246,11 +251,10 @@ QString QgsDataSourceURI::connInfo() const
246
251
QString QgsDataSourceURI::uri () const
247
252
{
248
253
return connInfo ()
249
- + QString (" table=\" %1\" .\" %2\" (%3) sql=%4" )
250
- .arg (mSchema )
251
- .arg (mTable )
252
- .arg (mGeometryColumn )
253
- .arg (mSql );
254
+ + QString (" table=%1 (%2) sql=%3" )
255
+ .arg ( quotedTablename () )
256
+ .arg ( mGeometryColumn )
257
+ .arg ( mSql );
254
258
}
255
259
256
260
QString QgsDataSourceURI::quotedTablename () const
Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ class CORE_EXPORT QgsDataSourceURI
68
68
QString sql () const ;
69
69
QString geometryColumn () const ;
70
70
71
+ void clearSchema ();
71
72
void setSql (QString sql);
72
73
73
74
private:
Original file line number Diff line number Diff line change @@ -2581,16 +2581,7 @@ void QgsGrassModuleGdalInput::updateQgisLayers()
2581
2581
QgsDataSourceURI dsUri (provider->dataSourceUri ());
2582
2582
uri = " PG:" + dsUri.connInfo ();
2583
2583
2584
- // FIXME:
2585
- // GDAL prepends the schema only to tables that are not in the
2586
- // current schema. The default schema is the user schema, if it
2587
- // exists or public otherwise.
2588
- // So we need to query current_schema() here like GDAL does (see
2589
- // OGRPGTableLayer::ReadTableDefinition). But do we want a static
2590
- // PostgreSQL depencency here?
2591
- // This workaround makes public tables inaccessible, if a
2592
- // user schema exists.
2593
- if ( dsUri.schema ()!=" public" && dsUri.schema ()!=dsUri.username () ) {
2584
+ if ( dsUri.schema ()!=" " ) {
2594
2585
ogrLayer = dsUri.schema () + " ." ;
2595
2586
}
2596
2587
Original file line number Diff line number Diff line change @@ -126,6 +126,17 @@ const QString POSTGRES_DESCRIPTION = "PostgreSQL/PostGIS data provider";
126
126
}
127
127
PQclear (testAccess);
128
128
129
+ PGresult *schema = PQexec (connection, " SELECT current_schema()" );
130
+ if (PQresultStatus (schema) == PGRES_TUPLES_OK)
131
+ {
132
+ mCurrentSchema = PQgetvalue (schema, 0 , 0 );
133
+ if (mCurrentSchema ==mSchemaName ) {
134
+ mUri .clearSchema ();
135
+ setDataSourceUri ( mUri .uri () );
136
+ }
137
+ }
138
+ PQclear (schema);
139
+
129
140
if (!getGeometryDetails ()) // gets srid and geometry type
130
141
{
131
142
// the table is not a geometry table
Original file line number Diff line number Diff line change @@ -369,6 +369,10 @@ class QgsPostgresProvider:public QgsVectorDataProvider
369
369
* Name of the schema
370
370
*/
371
371
QString mSchemaName ;
372
+ /* *
373
+ * Name of the current schema
374
+ */
375
+ QString mCurrentSchema ;
372
376
/* *
373
377
* SQL statement used to limit the features retreived
374
378
*/
You can’t perform that action at this time.
0 commit comments