From 7ea3db7989e31480d4149b1fd2ad3875b60f3dbf Mon Sep 17 00:00:00 2001 From: g_j_m Date: Tue, 1 Mar 2005 17:47:55 +0000 Subject: [PATCH] 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 --- providers/postgres/qgspostgresprovider.cpp | 66 ++++++++++++---------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/providers/postgres/qgspostgresprovider.cpp b/providers/postgres/qgspostgresprovider.cpp index e8cfd1a877b..e62b9f1360a 100644 --- a/providers/postgres/qgspostgresprovider.cpp +++ b/providers/postgres/qgspostgresprovider.cpp @@ -683,6 +683,7 @@ void QgsPostgresProvider::reset() #endif // set up the cursor PQexec(connection,"end work"); + PQexec(connection,"begin work"); PQexec(connection, (const char *)declare); //--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" "This is most likely because it is a view.\n" "For Qgis to work correctly the view must have a" - " column called oid. This column should have an integer" - " type and be unique for each row in the view." + " column called oid.\nThis column should have an integer" + " type and be unique for each row in the view.\n" " 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.")); QApplication::setOverrideCursor(Qt::waitCursor); } @@ -1229,40 +1230,44 @@ void QgsPostgresProvider::calculateExtents() #endif PGresult *result = PQexec(connection, (const char *) sql); std::string box3d = PQgetvalue(result, 0, 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); + if (box3d != "") + { + std::string s; - 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 minx = 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 miny = 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); + 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); - layerExtent.setXmax(maxx); - layerExtent.setXmin(minx); - layerExtent.setYmax(maxy); - layerExtent.setYmin(miny); + 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); #ifdef QGISDEBUG - QString xMsg; - QTextOStream(&xMsg).precision(18); - QTextOStream(&xMsg).width(18); - QTextOStream(&xMsg) << "Set extents to: " << layerExtent. - xMin() << ", " << layerExtent.yMin() << " " << layerExtent.xMax() << ", " << layerExtent.yMax(); - std::cerr << xMsg << std::endl; + QString xMsg; + QTextOStream(&xMsg).precision(18); + QTextOStream(&xMsg).width(18); + QTextOStream(&xMsg) << "Set extents to: " << layerExtent. + xMin() << ", " << layerExtent.yMin() << " " << layerExtent.xMax() << ", " << layerExtent.yMax(); + std::cerr << xMsg << std::endl; #endif - // clear query result - PQclear(result); + // clear query result + PQclear(result); + } } bool QgsPostgresProvider::deduceEndian() @@ -1282,6 +1287,7 @@ bool QgsPostgresProvider::deduceEndian() #endif // get the same value using a binary cursor + PQexec(connection,"begin work"); QString oidDeclare = QString("declare oidcursor binary cursor for select oid from %1 where oid = %2").arg(tableName).arg(oidValue); // set up the cursor