Skip to content

Commit 0bccf04

Browse files

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed
 

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,36 +77,60 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
7777
// string:
7878
// host=192.168.1.5 dbname=test port=5342 user=gsherman password=xxx table=tablename
7979

80+
// A little bit of backwards compability. At r6193 the schema/table
81+
// names became fully quoted, but with the problem that earlier
82+
// project files then didn't load. This bit of code puts in the
83+
// quotes that are now required.
84+
QString uriModified = uri;
85+
int start = uriModified.indexOf("table=\"");
86+
if (start == -1)
87+
{
88+
// Need to put in some "'s
89+
start = uriModified.indexOf("table=");
90+
uriModified.insert(start+6, '"');
91+
int start_dot = uriModified.indexOf('.', start+7);
92+
if (start_dot != -1)
93+
{
94+
uriModified.insert(start_dot, '"');
95+
uriModified.insert(start_dot+2, '"');
96+
}
97+
// and one at the end
98+
int end = uriModified.indexOf(' ',start);
99+
if (end != -1)
100+
uriModified.insert(end, '"');
101+
}
102+
80103
// Strip the table and sql statement name off and store them
81-
int sqlStart = uri.find(" sql");
82-
int tableStart = uri.find("table=");
104+
int sqlStart = uriModified.find(" sql");
105+
int tableStart = uriModified.find("table=");
83106
#ifdef QGISDEBUG
84107
qDebug( "****************************************");
85108
qDebug( "**** Postgresql Layer Creation *****" );
86109
qDebug( "****************************************");
87-
qDebug( (const char*)(QString("URI: ") + uri).toLocal8Bit().data() );
110+
qDebug( (const char*)(QString("URI: ") + uriModified).toLocal8Bit().data() );
88111
QString msg;
89112

90113
qDebug( "tableStart: " + msg.setNum(tableStart) );
91114
qDebug( "sqlStart: " + msg.setNum(sqlStart));
92115
#endif
93-
mTableName = uri.mid(tableStart + 6, sqlStart - tableStart -6);
116+
mTableName = uriModified.mid(tableStart + 6, sqlStart - tableStart -6);
117+
94118
if(sqlStart > -1)
95119
{
96-
sqlWhereClause = uri.mid(sqlStart + 5);
120+
sqlWhereClause = uriModified.mid(sqlStart + 5);
97121
}
98122
else
99123
{
100124
sqlWhereClause = QString::null;
101125
}
102-
QString connInfo = uri.left(uri.find("table="));
126+
QString connInfo = uriModified.left(uriModified.find("table="));
103127
#ifdef QGISDEBUG
104128
qDebug( (const char*)(QString("Table name is ") + mTableName).toLocal8Bit().data());
105129
qDebug( (const char*)(QString("SQL is ") + sqlWhereClause).toLocal8Bit().data() );
106130
qDebug( "Connection info is " + connInfo);
107131
#endif
108132

109-
// Pick up some stuff from the uri: basically two bits of text
133+
// Pick up some stuff from the uriModified: basically two bits of text
110134
// inside double quote marks, separated by a .
111135
QRegExp reg("\"(.+)\"\\.\"(.+)\".+\\((.+)\\)");
112136
reg.indexIn(mTableName);

0 commit comments

Comments
 (0)
Please sign in to comment.