Skip to content

Commit

Permalink
fix for #835
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@7661 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 26, 2007
1 parent be9f8be commit bd35aec
Showing 1 changed file with 52 additions and 41 deletions.
93 changes: 52 additions & 41 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -902,18 +902,23 @@ QString QgsPostgresProvider::getPrimaryKey()
"from pg_namespace where nspname = '" + mSchemaName + "'))";
PGresult* types = executeDbCommand(connection, sql);

assert(PQntuples(types) > 0); // should never happen

QString columnName = PQgetvalue(types, 0, 0);
QString columnType = PQgetvalue(types, 0, 1);

if (columnType != "int4")
log.append(tr("The unique index on column") +
" '" + columnName + "' " +
tr("is unsuitable because Qgis does not currently support"
" non-int4 type columns as a key into the table.\n"));
if( PQntuples(types) > 0 )
{
QString columnName = PQgetvalue(types, 0, 0);
QString columnType = PQgetvalue(types, 0, 1);

if (columnType != "int4")
log.append(tr("The unique index on column") +
" '" + columnName + "' " +
tr("is unsuitable because Qgis does not currently support"
" non-int4 type columns as a key into the table.\n"));
else
suitableKeyColumns.push_back(std::make_pair(columnName, columnType));
}
else
suitableKeyColumns.push_back(std::make_pair(columnName, columnType));
{
QgsDebugMsg( QString("name and type of %3. column of %1.%2 not found").arg(mSchemaName).arg(mTables).arg(col) );
}

PQclear(types);
}
Expand Down Expand Up @@ -2333,40 +2338,46 @@ void QgsPostgresProvider::calculateExtents()
QgsDebugMsg("Getting extents using schema.table: " + sql);

PGresult *result = PQexec(connection, (const char *) (sql.utf8()));
Q_ASSERT(PQntuples(result) == 1);
std::string box3d = PQgetvalue(result, 0, 0);

if (box3d != "")
if(PQntuples(result)>0)
{
std::string s;

box3d = box3d.substr(box3d.find_first_of("(")+1);
box3d = box3d.substr(box3d.find_first_not_of(" "));
s = box3d.substr(0, box3d.find_first_of(" "));
double minx = strtod(s.c_str(), NULL);

box3d = box3d.substr(box3d.find_first_of(" ")+1);
s = box3d.substr(0, box3d.find_first_of(" "));
double miny = strtod(s.c_str(), NULL);

box3d = box3d.substr(box3d.find_first_of(",")+1);
box3d = box3d.substr(box3d.find_first_not_of(" "));
s = box3d.substr(0, box3d.find_first_of(" "));
double maxx = strtod(s.c_str(), NULL);

box3d = box3d.substr(box3d.find_first_of(" ")+1);
s = box3d.substr(0, box3d.find_first_of(" "));
double maxy = strtod(s.c_str(), NULL);
std::string box3d = PQgetvalue(result, 0, 0);

layerExtent.setXmax(maxx);
layerExtent.setXmin(minx);
layerExtent.setYmax(maxy);
layerExtent.setYmin(miny);

// clear query result
PQclear(result);
if (box3d != "")
{
std::string s;

box3d = box3d.substr(box3d.find_first_of("(")+1);
box3d = box3d.substr(box3d.find_first_not_of(" "));
s = box3d.substr(0, box3d.find_first_of(" "));
double minx = strtod(s.c_str(), NULL);

box3d = box3d.substr(box3d.find_first_of(" ")+1);
s = box3d.substr(0, box3d.find_first_of(" "));
double miny = strtod(s.c_str(), NULL);

box3d = box3d.substr(box3d.find_first_of(",")+1);
box3d = box3d.substr(box3d.find_first_not_of(" "));
s = box3d.substr(0, box3d.find_first_of(" "));
double maxx = strtod(s.c_str(), NULL);

box3d = box3d.substr(box3d.find_first_of(" ")+1);
s = box3d.substr(0, box3d.find_first_of(" "));
double maxy = strtod(s.c_str(), NULL);

layerExtent.setXmax(maxx);
layerExtent.setXmin(minx);
layerExtent.setYmax(maxy);
layerExtent.setYmin(miny);
}
}
else
{
QgsDebugMsg("extents query failed");
}

// clear query result
PQclear(result);

#endif

// #ifdef QGISDEBUG
Expand Down

0 comments on commit bd35aec

Please sign in to comment.