bug fix: a spatial table with no rows would cause a crash

tidy up: text in the dialog box about views and oid's etc was all on
one line.


git-svn-id: http://svn.osgeo.org/qgis/trunk@2885 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
g_j_m 2005-03-01 17:47:55 +00:00
parent 9f20770581
commit 7ea3db7989

View File

@ -683,6 +683,7 @@ void QgsPostgresProvider::reset()
#endif #endif
// set up the cursor // set up the cursor
PQexec(connection,"end work"); PQexec(connection,"end work");
PQexec(connection,"begin work"); PQexec(connection,"begin work");
PQexec(connection, (const char *)declare); PQexec(connection, (const char *)declare);
//--std::cout << "Error: " << PQerrorMessage(connection) << std::endl; //--std::cout << "Error: " << PQerrorMessage(connection) << std::endl;
@ -761,10 +762,10 @@ QString QgsPostgresProvider::getPrimaryKey(){
QObject::tr("The table or view has no oid column. \n" QObject::tr("The table or view has no oid column. \n"
"This is most likely because it is a view.\n" "This is most likely because it is a view.\n"
"For Qgis to work correctly the view must have a" "For Qgis to work correctly the view must have a"
" column called oid. This column should have an integer" " column called oid.\nThis column should have an integer"
" type and be unique for each row in the view." " type and be unique for each row in the view.\n"
" For better performance, the column should" " For better performance, the column should"
" also be indexed or be derived come from an indexed" " also be indexed or be\n derived from an indexed"
" column.")); " column."));
QApplication::setOverrideCursor(Qt::waitCursor); QApplication::setOverrideCursor(Qt::waitCursor);
} }
@ -1229,40 +1230,44 @@ void QgsPostgresProvider::calculateExtents()
#endif #endif
PGresult *result = PQexec(connection, (const char *) sql); PGresult *result = PQexec(connection, (const char *) sql);
std::string box3d = PQgetvalue(result, 0, 0); std::string box3d = PQgetvalue(result, 0, 0);
std::string s;
box3d = box3d.substr(box3d.find_first_of("(")+1); if (box3d != "")
box3d = box3d.substr(box3d.find_first_not_of(" ")); {
s = box3d.substr(0, box3d.find_first_of(" ")); std::string s;
double minx = strtod(s.c_str(), NULL);
box3d = box3d.substr(box3d.find_first_of(" ")+1); box3d = box3d.substr(box3d.find_first_of("(")+1);
s = box3d.substr(0, box3d.find_first_of(" ")); box3d = box3d.substr(box3d.find_first_not_of(" "));
double miny = strtod(s.c_str(), NULL); s = box3d.substr(0, box3d.find_first_of(" "));
double minx = strtod(s.c_str(), NULL);
box3d = box3d.substr(box3d.find_first_of(",")+1); box3d = box3d.substr(box3d.find_first_of(" ")+1);
box3d = box3d.substr(box3d.find_first_not_of(" ")); s = box3d.substr(0, box3d.find_first_of(" "));
s = box3d.substr(0, box3d.find_first_of(" ")); double miny = strtod(s.c_str(), NULL);
double maxx = strtod(s.c_str(), NULL);
box3d = box3d.substr(box3d.find_first_of(" ")+1); box3d = box3d.substr(box3d.find_first_of(",")+1);
s = box3d.substr(0, box3d.find_first_of(" ")); box3d = box3d.substr(box3d.find_first_not_of(" "));
double maxy = strtod(s.c_str(), NULL); s = box3d.substr(0, box3d.find_first_of(" "));
double maxx = strtod(s.c_str(), NULL);
layerExtent.setXmax(maxx); box3d = box3d.substr(box3d.find_first_of(" ")+1);
layerExtent.setXmin(minx); s = box3d.substr(0, box3d.find_first_of(" "));
layerExtent.setYmax(maxy); double maxy = strtod(s.c_str(), NULL);
layerExtent.setYmin(miny);
layerExtent.setXmax(maxx);
layerExtent.setXmin(minx);
layerExtent.setYmax(maxy);
layerExtent.setYmin(miny);
#ifdef QGISDEBUG #ifdef QGISDEBUG
QString xMsg; QString xMsg;
QTextOStream(&xMsg).precision(18); QTextOStream(&xMsg).precision(18);
QTextOStream(&xMsg).width(18); QTextOStream(&xMsg).width(18);
QTextOStream(&xMsg) << "Set extents to: " << layerExtent. QTextOStream(&xMsg) << "Set extents to: " << layerExtent.
xMin() << ", " << layerExtent.yMin() << " " << layerExtent.xMax() << ", " << layerExtent.yMax(); xMin() << ", " << layerExtent.yMin() << " " << layerExtent.xMax() << ", " << layerExtent.yMax();
std::cerr << xMsg << std::endl; std::cerr << xMsg << std::endl;
#endif #endif
// clear query result // clear query result
PQclear(result); PQclear(result);
}
} }
bool QgsPostgresProvider::deduceEndian() bool QgsPostgresProvider::deduceEndian()
@ -1282,6 +1287,7 @@ bool QgsPostgresProvider::deduceEndian()
#endif #endif
// get the same value using a binary cursor // get the same value using a binary cursor
PQexec(connection,"begin work"); PQexec(connection,"begin work");
QString oidDeclare = QString("declare oidcursor binary cursor for select oid from %1 where oid = %2").arg(tableName).arg(oidValue); QString oidDeclare = QString("declare oidcursor binary cursor for select oid from %1 where oid = %2").arg(tableName).arg(oidValue);
// set up the cursor // set up the cursor