@@ -77,36 +77,60 @@ QgsPostgresProvider::QgsPostgresProvider(QString const & uri)
77
77
// string:
78
78
// host=192.168.1.5 dbname=test port=5342 user=gsherman password=xxx table=tablename
79
79
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
+
80
103
// 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=" );
83
106
#ifdef QGISDEBUG
84
107
qDebug ( " ****************************************" );
85
108
qDebug ( " **** Postgresql Layer Creation *****" );
86
109
qDebug ( " ****************************************" );
87
- qDebug ( (const char *)(QString (" URI: " ) + uri ).toLocal8Bit ().data () );
110
+ qDebug ( (const char *)(QString (" URI: " ) + uriModified ).toLocal8Bit ().data () );
88
111
QString msg;
89
112
90
113
qDebug ( " tableStart: " + msg.setNum (tableStart) );
91
114
qDebug ( " sqlStart: " + msg.setNum (sqlStart));
92
115
#endif
93
- mTableName = uri.mid (tableStart + 6 , sqlStart - tableStart -6 );
116
+ mTableName = uriModified.mid (tableStart + 6 , sqlStart - tableStart -6 );
117
+
94
118
if (sqlStart > -1 )
95
119
{
96
- sqlWhereClause = uri .mid (sqlStart + 5 );
120
+ sqlWhereClause = uriModified .mid (sqlStart + 5 );
97
121
}
98
122
else
99
123
{
100
124
sqlWhereClause = QString::null;
101
125
}
102
- QString connInfo = uri .left (uri .find (" table=" ));
126
+ QString connInfo = uriModified .left (uriModified .find (" table=" ));
103
127
#ifdef QGISDEBUG
104
128
qDebug ( (const char *)(QString (" Table name is " ) + mTableName ).toLocal8Bit ().data ());
105
129
qDebug ( (const char *)(QString (" SQL is " ) + sqlWhereClause).toLocal8Bit ().data () );
106
130
qDebug ( " Connection info is " + connInfo);
107
131
#endif
108
132
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
110
134
// inside double quote marks, separated by a .
111
135
QRegExp reg (" \" (.+)\"\\ .\" (.+)\" .+\\ ((.+)\\ )" );
112
136
reg.indexIn (mTableName );
0 commit comments