Skip to content

Commit 53ad04e

Browse files
author
jef
committed
fix #1007
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8267 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 513a0ea commit 53ad04e

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2116,6 +2116,19 @@ bool QgsPostgresProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
21162116
// Start the PostGIS transaction
21172117
PQexecNR(connection,QString("BEGIN").toUtf8());
21182118

2119+
QString update = QString("UPDATE %1 SET %2=GeomFromWKB($1%3,%4) WHERE %5=$2")
2120+
.arg( mSchemaTableName )
2121+
.arg( quotedIdentifier(geometryColumn) )
2122+
.arg( useWkbHex ? "" : "::bytea" )
2123+
.arg( srid )
2124+
.arg( quotedIdentifier(primaryKey) );
2125+
2126+
PGresult *stmt = PQprepare(connection, "updatefeatures", update.toUtf8(), 2, NULL);
2127+
if(stmt==0 || PQresultStatus(stmt)==PGRES_FATAL_ERROR)
2128+
throw PGException(stmt);
2129+
2130+
PQclear(stmt);
2131+
21192132
for(QgsGeometryMap::iterator iter = geometry_map.begin();
21202133
iter != geometry_map.end();
21212134
++iter)
@@ -2127,29 +2140,32 @@ bool QgsPostgresProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
21272140
{
21282141
QgsDebugMsg("iterating over feature id " + QString::number(iter.key()));
21292142

2130-
QString sql = QString("UPDATE %1 SET %2=GeomFromWKB('")
2131-
.arg( mSchemaTableName )
2132-
.arg( quotedIdentifier(geometryColumn) );
2133-
appendGeomString(&*iter, sql);
2134-
sql += QString("'%1,%2) WHERE %3=%4")
2135-
.arg( useWkbHex ? "::bytea" : "" )
2136-
.arg( srid )
2137-
.arg( quotedIdentifier(primaryKey) )
2138-
.arg( iter.key() );
2143+
QString geomParam;
2144+
appendGeomString(&*iter, geomParam);
21392145

2140-
QgsDebugMsg("Updating with: " + sql);
2146+
QList<QByteArray> qparam;
2147+
qparam.append( geomParam.toUtf8() );
2148+
qparam.append( QString("%1").arg( iter.key() ).toUtf8() );
21412149

2142-
PGresult* result=PQexec(connection, sql.toUtf8());
2150+
const char *param[2];
2151+
param[0] = qparam[0];
2152+
param[1] = qparam[1];
2153+
2154+
PGresult *result = PQexecPrepared(connection, "updatefeatures", 2, param, NULL, NULL, 0);
21432155
if( result==0 || PQresultStatus(result)==PGRES_FATAL_ERROR )
21442156
throw PGException(result);
2157+
21452158
PQclear(result);
21462159
} // if (*iter)
2160+
21472161
} // for each feature
21482162

21492163
PQexecNR(connection,QString("COMMIT").toUtf8());
2164+
PQexecNR(connection,QString("DEALLOCATE updatefeatures").toUtf8());
21502165
} catch(PGException &e) {
2151-
e.showErrorMessage( tr("Error while changing attributes") );
2166+
e.showErrorMessage( tr("Error while changing geometry values") );
21522167
PQexecNR(connection,QString("ROLLBACK").toUtf8());
2168+
PQexecNR(connection,QString("DEALLOCATE updatefeatures").toUtf8());
21532169
returnvalue = false;
21542170
}
21552171

0 commit comments

Comments
 (0)