Skip to content
Permalink
Browse files

fix for #835

git-svn-id: http://svn.osgeo.org/qgis/trunk@7661 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef
jef committed Nov 26, 2007
1 parent be9f8be commit bd35aecf1e7b5a6ea97d16a2726684a7f2f43e56
Showing with 52 additions and 41 deletions.
  1. +52 −41 src/providers/postgres/qgspostgresprovider.cpp
@@ -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);
}
@@ -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

0 comments on commit bd35aec

Please sign in to comment.
You can’t perform that action at this time.