Skip to content

Commit bd35aec

Browse files
author
jef
committedNov 26, 2007
fix for #835
git-svn-id: http://svn.osgeo.org/qgis/trunk@7661 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent be9f8be commit bd35aec

File tree

1 file changed

+52
-41
lines changed

1 file changed

+52
-41
lines changed
 

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -902,18 +902,23 @@ QString QgsPostgresProvider::getPrimaryKey()
902902
"from pg_namespace where nspname = '" + mSchemaName + "'))";
903903
PGresult* types = executeDbCommand(connection, sql);
904904

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+
}
915918
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+
}
917922

918923
PQclear(types);
919924
}
@@ -2333,40 +2338,46 @@ void QgsPostgresProvider::calculateExtents()
23332338
QgsDebugMsg("Getting extents using schema.table: " + sql);
23342339

23352340
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)
23402342
{
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);
23602344

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");
23682376
}
23692377

2378+
// clear query result
2379+
PQclear(result);
2380+
23702381
#endif
23712382

23722383
// #ifdef QGISDEBUG

0 commit comments

Comments
 (0)
Please sign in to comment.