Skip to content
Permalink
Browse files

Cope with postgres schema and table names that contain . characters.

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@6152 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
g_j_m
g_j_m committed Nov 30, 2006
1 parent 3791685 commit 78fc31af653c71d9ff7c661537381abe511fc2e4
Showing with 22 additions and 13 deletions.
  1. +6 −4 src/gui/qgsdbsourceselect.cpp
  2. +6 −3 src/gui/qgsvectorlayer.cpp
  3. +10 −6 src/providers/postgres/qgspostgresprovider.cpp
@@ -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 += ")";

@@ -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()
@@ -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());
}
@@ -27,6 +27,7 @@
#include <QEvent>
#include <QCustomEvent>
#include <QTextOStream>
#include <QRegExp>

// for ntohl
#ifdef WIN32
@@ -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)

0 comments on commit 78fc31a

Please sign in to comment.
You can’t perform that action at this time.