@@ -902,18 +902,23 @@ QString QgsPostgresProvider::getPrimaryKey()
902
902
" from pg_namespace where nspname = '" + mSchemaName + " '))" ;
903
903
PGresult* types = executeDbCommand (connection, sql);
904
904
905
- assert (PQntuples (types) > 0 ); // should never happen
906
-
907
- QString columnName = PQgetvalue (types, 0 , 0 );
908
- QString columnType = PQgetvalue (types, 0 , 1 );
909
-
910
- if (columnType != " int4" )
911
- log.append (tr (" The unique index on column" ) +
912
- " '" + columnName + " ' " +
913
- tr (" is unsuitable because Qgis does not currently support"
914
- " non-int4 type columns as a key into the table.\n " ));
905
+ if ( PQntuples (types) > 0 )
906
+ {
907
+ QString columnName = PQgetvalue (types, 0 , 0 );
908
+ QString columnType = PQgetvalue (types, 0 , 1 );
909
+
910
+ if (columnType != " int4" )
911
+ log.append (tr (" The unique index on column" ) +
912
+ " '" + columnName + " ' " +
913
+ tr (" is unsuitable because Qgis does not currently support"
914
+ " non-int4 type columns as a key into the table.\n " ));
915
+ else
916
+ suitableKeyColumns.push_back (std::make_pair (columnName, columnType));
917
+ }
915
918
else
916
- suitableKeyColumns.push_back (std::make_pair (columnName, columnType));
919
+ {
920
+ QgsDebugMsg ( QString (" name and type of %3. column of %1.%2 not found" ).arg (mSchemaName ).arg (mTables ).arg (col) );
921
+ }
917
922
918
923
PQclear (types);
919
924
}
@@ -2333,40 +2338,46 @@ void QgsPostgresProvider::calculateExtents()
2333
2338
QgsDebugMsg (" Getting extents using schema.table: " + sql);
2334
2339
2335
2340
PGresult *result = PQexec (connection, (const char *) (sql.utf8 ()));
2336
- Q_ASSERT (PQntuples (result) == 1 );
2337
- std::string box3d = PQgetvalue (result, 0 , 0 );
2338
-
2339
- if (box3d != " " )
2341
+ if (PQntuples (result)>0 )
2340
2342
{
2341
- std::string s;
2342
-
2343
- box3d = box3d.substr (box3d.find_first_of (" (" )+1 );
2344
- box3d = box3d.substr (box3d.find_first_not_of (" " ));
2345
- s = box3d.substr (0 , box3d.find_first_of (" " ));
2346
- double minx = strtod (s.c_str (), NULL );
2347
-
2348
- box3d = box3d.substr (box3d.find_first_of (" " )+1 );
2349
- s = box3d.substr (0 , box3d.find_first_of (" " ));
2350
- double miny = strtod (s.c_str (), NULL );
2351
-
2352
- box3d = box3d.substr (box3d.find_first_of (" ," )+1 );
2353
- box3d = box3d.substr (box3d.find_first_not_of (" " ));
2354
- s = box3d.substr (0 , box3d.find_first_of (" " ));
2355
- double maxx = strtod (s.c_str (), NULL );
2356
-
2357
- box3d = box3d.substr (box3d.find_first_of (" " )+1 );
2358
- s = box3d.substr (0 , box3d.find_first_of (" " ));
2359
- double maxy = strtod (s.c_str (), NULL );
2343
+ std::string box3d = PQgetvalue (result, 0 , 0 );
2360
2344
2361
- layerExtent.setXmax (maxx);
2362
- layerExtent.setXmin (minx);
2363
- layerExtent.setYmax (maxy);
2364
- layerExtent.setYmin (miny);
2365
-
2366
- // clear query result
2367
- PQclear (result);
2345
+ if (box3d != " " )
2346
+ {
2347
+ std::string s;
2348
+
2349
+ box3d = box3d.substr (box3d.find_first_of (" (" )+1 );
2350
+ box3d = box3d.substr (box3d.find_first_not_of (" " ));
2351
+ s = box3d.substr (0 , box3d.find_first_of (" " ));
2352
+ double minx = strtod (s.c_str (), NULL );
2353
+
2354
+ box3d = box3d.substr (box3d.find_first_of (" " )+1 );
2355
+ s = box3d.substr (0 , box3d.find_first_of (" " ));
2356
+ double miny = strtod (s.c_str (), NULL );
2357
+
2358
+ box3d = box3d.substr (box3d.find_first_of (" ," )+1 );
2359
+ box3d = box3d.substr (box3d.find_first_not_of (" " ));
2360
+ s = box3d.substr (0 , box3d.find_first_of (" " ));
2361
+ double maxx = strtod (s.c_str (), NULL );
2362
+
2363
+ box3d = box3d.substr (box3d.find_first_of (" " )+1 );
2364
+ s = box3d.substr (0 , box3d.find_first_of (" " ));
2365
+ double maxy = strtod (s.c_str (), NULL );
2366
+
2367
+ layerExtent.setXmax (maxx);
2368
+ layerExtent.setXmin (minx);
2369
+ layerExtent.setYmax (maxy);
2370
+ layerExtent.setYmin (miny);
2371
+ }
2372
+ }
2373
+ else
2374
+ {
2375
+ QgsDebugMsg (" extents query failed" );
2368
2376
}
2369
2377
2378
+ // clear query result
2379
+ PQclear (result);
2380
+
2370
2381
#endif
2371
2382
2372
2383
// #ifdef QGISDEBUG
0 commit comments