@@ -1151,44 +1151,44 @@ void QgsPostgresProvider::findColumns(tableCols& cols)
1151
1151
// This sql is derived from the one that defines the view
1152
1152
// 'information_schema.view_column_usage' in PostgreSQL, with a few
1153
1153
// mods to suit our purposes.
1154
- QString sql = " "
1155
- " SELECT DISTINCT "
1156
- " nv.nspname AS view_schema, "
1157
- " v.relname AS view_name, "
1158
- " a.attname AS view_column_name, "
1159
- " nt.nspname AS table_schema, "
1160
- " t.relname AS table_name, "
1161
- " a.attname AS column_name, "
1162
- " t.relkind as table_type, "
1163
- " typ.typname as column_type "
1164
- " FROM "
1165
- " pg_namespace nv, "
1166
- " pg_class v, "
1167
- " pg_depend dv,"
1168
- " pg_depend dt, "
1169
- " pg_class t, "
1170
- " pg_namespace nt, "
1171
- " pg_attribute a,"
1172
- " pg_user u, "
1173
- " pg_type typ "
1174
- " WHERE "
1175
- " nv.oid = v.relnamespace AND "
1176
- " v.relkind = 'v'::\" char\" AND "
1177
- " v.oid = dv.refobjid AND "
1178
- " dv.refclassid = 'pg_class'::regclass::oid AND "
1179
- " dv.classid = 'pg_rewrite'::regclass::oid AND "
1180
- " dv.deptype = 'i'::\" char\" AND "
1181
- " dv.objid = dt.objid AND "
1182
- " dv.refobjid <> dt.refobjid AND "
1183
- " dt.classid = 'pg_rewrite'::regclass::oid AND "
1184
- " dt.refclassid = 'pg_class'::regclass::oid AND "
1185
- " dt.refobjid = t.oid AND "
1186
- " t.relnamespace = nt.oid AND "
1187
- " (t.relkind = 'r'::\" char\" OR t.relkind = 'v'::\" char\" ) AND "
1188
- " t.oid = a.attrelid AND "
1189
- " dt.refobjsubid = a.attnum AND "
1190
- " nv.nspname NOT IN ('pg_catalog', 'information_schema' ) AND "
1191
- " a.atttypid = typ.oid" ;
1154
+ QString sql = " "
1155
+ " SELECT DISTINCT "
1156
+ " nv.nspname AS view_schema, "
1157
+ " v.relname AS view_name, "
1158
+ " a.attname AS view_column_name, "
1159
+ " nt.nspname AS table_schema, "
1160
+ " t.relname AS table_name, "
1161
+ " a.attname AS column_name, "
1162
+ " t.relkind as table_type, "
1163
+ " typ.typname as column_type "
1164
+ " FROM "
1165
+ " pg_namespace nv, "
1166
+ " pg_class v, "
1167
+ " pg_depend dv,"
1168
+ " pg_depend dt, "
1169
+ " pg_class t, "
1170
+ " pg_namespace nt, "
1171
+ " pg_attribute a,"
1172
+ " pg_user u, "
1173
+ " pg_type typ "
1174
+ " WHERE "
1175
+ " nv.oid = v.relnamespace AND "
1176
+ " v.relkind = 'v'::\" char\" AND "
1177
+ " v.oid = dv.refobjid AND "
1178
+ " dv.refclassid = 'pg_class'::regclass::oid AND "
1179
+ " dv.classid = 'pg_rewrite'::regclass::oid AND "
1180
+ " dv.deptype = 'i'::\" char\" AND "
1181
+ " dv.objid = dt.objid AND "
1182
+ " dv.refobjid <> dt.refobjid AND "
1183
+ " dt.classid = 'pg_rewrite'::regclass::oid AND "
1184
+ " dt.refclassid = 'pg_class'::regclass::oid AND "
1185
+ " dt.refobjid = t.oid AND "
1186
+ " t.relnamespace = nt.oid AND "
1187
+ " (t.relkind = 'r'::\" char\" OR t.relkind = 'v'::\" char\" ) AND "
1188
+ " t.oid = a.attrelid AND "
1189
+ " dt.refobjsubid = a.attnum AND "
1190
+ " nv.nspname NOT IN ('pg_catalog', 'information_schema' ) AND "
1191
+ " a.atttypid = typ.oid" ;
1192
1192
1193
1193
// A structure to store the results of the above sql.
1194
1194
typedef std::map<QString, TT> columnRelationsType;
@@ -1201,6 +1201,7 @@ void QgsPostgresProvider::findColumns(tableCols& cols)
1201
1201
1202
1202
PGresult* result = PQexec (connection, (const char *)(sql.utf8 ()));
1203
1203
// Store the results of the query for convenient access
1204
+
1204
1205
for (int i = 0 ; i < PQntuples (result); ++i)
1205
1206
{
1206
1207
TT temp;
@@ -1220,45 +1221,45 @@ void QgsPostgresProvider::findColumns(tableCols& cols)
1220
1221
// adjust the view column name if necessary.
1221
1222
1222
1223
1223
- QString viewQuery = " SELECT definition FROM pg_views "
1224
- " WHERE schemaname = '" + temp.view_schema + " ' AND "
1225
- " viewname = '" + temp.view_name + " '" ;
1226
-
1227
- // Maintain a cache of the above SQL.
1228
- QString viewDef;
1229
- if (!viewDefs.contains (viewQuery))
1230
- {
1231
- PGresult* r = PQexec (connection, (const char *)(viewQuery.utf8 ()));
1232
- if (PQntuples (r) > 0 )
1233
- viewDef = PQgetvalue (r, 0 , 0 );
1234
- else
1235
- QgsDebugMsg (" Failed to get view definition for " + temp.view_schema + " ." + temp.view_name );
1236
- viewDefs[viewQuery] = viewDef;
1237
- }
1238
-
1239
- viewDef = viewDefs.value (viewQuery);
1240
-
1241
- // Now pick the view definiton apart, looking for
1242
- // temp.column_name to the left of an 'AS'.
1243
-
1244
- // This regular expression needs more testing. Since the view
1245
- // definition comes from postgresql and has been 'standardised', we
1246
- // don't need to deal with everything that the user could put in a view
1247
- // definition. Does the regexp have to deal with the schema??
1248
- if (!viewDef.isEmpty ())
1249
- {
1250
- QRegExp s (" .* \" ?" + QRegExp::escape (temp.table_name ) +
1251
- " \" ?\\ .\" ?" + QRegExp::escape (temp.column_name ) +
1252
- " \" ? AS \" ?(\\ w+)\" ?,* .*" );
1253
-
1254
- QgsDebugMsg (viewQuery + " \n " + viewDef + " \n " + s.pattern ());
1255
-
1256
- if (s.indexIn (viewDef) != -1 )
1257
- {
1258
- temp.view_column_name = s.cap (1 );
1259
- // std::cerr<<__FILE__<<__LINE__<<' '<<temp.view_column_name.toLocal8Bit().data()<<'\n';
1260
- }
1261
- }
1224
+ QString viewQuery = " SELECT definition FROM pg_views "
1225
+ " WHERE schemaname = '" + temp.view_schema + " ' AND "
1226
+ " viewname = '" + temp.view_name + " '" ;
1227
+
1228
+ // Maintain a cache of the above SQL.
1229
+ QString viewDef;
1230
+ if (!viewDefs.contains (viewQuery))
1231
+ {
1232
+ PGresult* r = PQexec (connection, (const char *)(viewQuery.utf8 ()));
1233
+ if (PQntuples (r) > 0 )
1234
+ viewDef = PQgetvalue (r, 0 , 0 );
1235
+ else
1236
+ QgsDebugMsg (" Failed to get view definition for " + temp.view_schema + " ." + temp.view_name );
1237
+ viewDefs[viewQuery] = viewDef;
1238
+ }
1239
+
1240
+ viewDef = viewDefs.value (viewQuery);
1241
+
1242
+ // Now pick the view definiton apart, looking for
1243
+ // temp.column_name to the left of an 'AS'.
1244
+
1245
+ // This regular expression needs more testing. Since the view
1246
+ // definition comes from postgresql and has been 'standardised', we
1247
+ // don't need to deal with everything that the user could put in a view
1248
+ // definition. Does the regexp have to deal with the schema??
1249
+ if (!viewDef.isEmpty ())
1250
+ {
1251
+ QRegExp s (" .* \" ?" + QRegExp::escape (temp.table_name ) +
1252
+ " \" ?\\ .\" ?" + QRegExp::escape (temp.column_name ) +
1253
+ " \" ? AS \" ?(\\ w+)\" ?,* .*" );
1254
+
1255
+ QgsDebugMsg (viewQuery + " \n " + viewDef + " \n " + s.pattern ());
1256
+
1257
+ if (s.indexIn (viewDef) != -1 )
1258
+ {
1259
+ temp.view_column_name = s.cap (1 );
1260
+ // std::cerr<<__FILE__<<__LINE__<<' '<<temp.view_column_name.toLocal8Bit().data()<<'\n';
1261
+ }
1262
+ }
1262
1263
1263
1264
QgsDebugMsg (temp.view_schema + " ."
1264
1265
+ temp.view_name + " ."
0 commit comments