Skip to content

Commit 3690acc

Browse files
author
jef
committed
strip current schema from selected tables to match postgres provider behaviour
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8586 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 3954774 commit 3690acc

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/app/qgsdbsourceselect.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,14 @@ void QgsDbSourceSelect::addTables()
247247
{
248248
m_selectedTables.clear();
249249

250+
QString currentSchema;
251+
QString sql = "select current_schema()";
252+
PGresult *result = PQexec(pd, sql.toUtf8());
253+
if (result && PQresultStatus(result)==PGRES_TUPLES_OK && PQntuples(result)==1 )
254+
{
255+
currentSchema = QString::fromUtf8(PQgetvalue(result, 0, 0));
256+
}
257+
250258
typedef QMap<int, QVector<QString> > schemaInfo;
251259
QMap<QString, schemaInfo> dbInfo;
252260

@@ -282,7 +290,7 @@ void QgsDbSourceSelect::addTables()
282290
}
283291

284292
//now traverse all the schemas and table infos
285-
QString schemaName, tableName, geomColumnName, sql;
293+
QString schemaName, tableName, geomColumnName;
286294
QString query;
287295

288296
QMap<QString, schemaInfo>::const_iterator schema_it = dbInfo.constBegin();
@@ -324,7 +332,14 @@ void QgsDbSourceSelect::addTables()
324332
continue;
325333
}
326334
}
327-
query = "\"" + schemaName + "\".\"" + tableName + "\" " + "(" + geomColumnName + ") sql=" + sql;
335+
336+
if(schemaName!=currentSchema)
337+
{
338+
query += "\"" + schemaName + "\".";
339+
}
340+
341+
query += "\"" + tableName + "\" " + "(" + geomColumnName + ") sql=" + sql;
342+
328343
m_selectedTables.push_back(query);
329344
}
330345
}

0 commit comments

Comments
 (0)