@@ -2116,6 +2116,19 @@ bool QgsPostgresProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
2116
2116
// Start the PostGIS transaction
2117
2117
PQexecNR (connection,QString (" BEGIN" ).toUtf8 ());
2118
2118
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
+
2119
2132
for (QgsGeometryMap::iterator iter = geometry_map.begin ();
2120
2133
iter != geometry_map.end ();
2121
2134
++iter)
@@ -2127,29 +2140,32 @@ bool QgsPostgresProvider::changeGeometryValues(QgsGeometryMap & geometry_map)
2127
2140
{
2128
2141
QgsDebugMsg (" iterating over feature id " + QString::number (iter.key ()));
2129
2142
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);
2139
2145
2140
- QgsDebugMsg (" Updating with: " + sql);
2146
+ QList<QByteArray> qparam;
2147
+ qparam.append ( geomParam.toUtf8 () );
2148
+ qparam.append ( QString (" %1" ).arg ( iter.key () ).toUtf8 () );
2141
2149
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 );
2143
2155
if ( result==0 || PQresultStatus (result)==PGRES_FATAL_ERROR )
2144
2156
throw PGException (result);
2157
+
2145
2158
PQclear (result);
2146
2159
} // if (*iter)
2160
+
2147
2161
} // for each feature
2148
2162
2149
2163
PQexecNR (connection,QString (" COMMIT" ).toUtf8 ());
2164
+ PQexecNR (connection,QString (" DEALLOCATE updatefeatures" ).toUtf8 ());
2150
2165
} catch (PGException &e) {
2151
- e.showErrorMessage ( tr (" Error while changing attributes " ) );
2166
+ e.showErrorMessage ( tr (" Error while changing geometry values " ) );
2152
2167
PQexecNR (connection,QString (" ROLLBACK" ).toUtf8 ());
2168
+ PQexecNR (connection,QString (" DEALLOCATE updatefeatures" ).toUtf8 ());
2153
2169
returnvalue = false ;
2154
2170
}
2155
2171
0 commit comments