Skip to content

Commit

Permalink
Cope with postgres schema and table names that contain . characters.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@6152 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m committed Nov 30, 2006
1 parent f3861ad commit b2a13cf
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
10 changes: 6 additions & 4 deletions src/gui/qgsdbsourceselect.cpp
Expand Up @@ -561,12 +561,14 @@ bool QgsDbSourceSelect::getGeometryColumnInfo(PGconn *pg,

if (schemaName.length() > 0)
{
v += '"';
v += schemaName;
v += ".";
v += "\".";
}

v += '"';
v += tableName;
v += " (";
v += "\" (";
v += PQgetvalue(result, idx, PQfnumber(result, "f_geometry_column"));
v += ")";

Expand Down Expand Up @@ -665,8 +667,8 @@ QString QgsDbSourceSelect::fullDescription(QString schema, QString table,
{
QString full_desc = "";
if (schema.length() > 0)
full_desc = schema + ".";
full_desc += table + " (" + column + ")";
full_desc = '"' + schema + "\".\"";
full_desc += table + "\" (" + column + ")";
return full_desc;
}
void QgsDbSourceSelect::dbChanged()
Expand Down
9 changes: 6 additions & 3 deletions src/gui/qgsvectorlayer.cpp
Expand Up @@ -2267,9 +2267,12 @@ bool QgsVectorLayer::setDataProvider( QString const & provider )
{
QgsDebugMsg("Beautifying layer name " + name());
// adjust the display name for postgres layers
QString lName(name());
lName = lName.mid(lName.find(".") + 1);
lName = lName.left(lName.find("(") - 1); // Take one away, to avoid a trailing space
QRegExp reg("\".+\"\.\"(.+)\"");
reg.indexIn(name());
QStringList stuff = reg.capturedTexts();
QString lName = stuff[1];
if (lName.length() == 0) // fallback
lName = name();
setLayerName(lName);
QgsDebugMsg("Beautifying layer name " + name());
}
Expand Down
16 changes: 10 additions & 6 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -27,6 +27,7 @@
#include <QEvent>
#include <QCustomEvent>
#include <QTextOStream>
#include <QRegExp>

// for ntohl
#ifdef WIN32
Expand Down Expand Up @@ -104,14 +105,17 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
qDebug( (const char*)(QString("SQL is ") + sqlWhereClause).toLocal8Bit().data() );
qDebug( "Connection info is " + connInfo);
#endif
// calculate the schema if specified
mSchemaName = "";
if (mTableName.find(".") > -1) {
mSchemaName = mTableName.left(mTableName.find("."));
}

// Pick up some stuff from the uri: basically two bits of text
// inside double quote marks, separated by a .
QRegExp reg("\"(.+)\"\.\"(.+)\"");
reg.indexIn(mTableName);
QStringList stuff = reg.capturedTexts();

mSchemaName = stuff[1];
mTableName = stuff[2];
geometryColumn = mTableName.mid(mTableName.find(" (") + 2);
geometryColumn.truncate(geometryColumn.length() - 1);
mTableName = mTableName.mid(mTableName.find(".") + 1, mTableName.find(" (") - (mTableName.find(".") + 1));

// Keep a schema qualified table name for convenience later on.
if (mSchemaName.length() > 0)
Expand Down

0 comments on commit b2a13cf

Please sign in to comment.