diff --git a/src/app/qgsmaptoolcapture.cpp b/src/app/qgsmaptoolcapture.cpp index 7c7c1fb9b32..d63f36a3574 100644 --- a/src/app/qgsmaptoolcapture.cpp +++ b/src/app/qgsmaptoolcapture.cpp @@ -148,8 +148,8 @@ void QgsMapToolCapture::canvasReleaseEvent(QMouseEvent * e) f->setGeometryAndOwnership(&wkb[0],size); // add the fields to the QgsFeature - const QgsFieldMap& fields=provider->fields(); - for(QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it) + const QgsFieldMap fields=provider->fields(); + for(QgsFieldMap::const_iterator it = fields.constBegin(); it != fields.constEnd(); ++it) { f->addAttribute(it.key(), provider->getDefaultValue(it.key()) ); } @@ -371,7 +371,7 @@ void QgsMapToolCapture::canvasReleaseEvent(QMouseEvent * e) f->setGeometryAndOwnership(&wkb[0],size); // add the fields to the QgsFeature - const QgsFieldMap& fields = provider->fields(); + const QgsFieldMap fields = provider->fields(); for(QgsFieldMap::const_iterator it = fields.begin(); it != fields.end(); ++it) { f->addAttribute(it.key(), provider->getDefaultValue(it.key())); diff --git a/src/providers/postgres/qgspostgresprovider.cpp b/src/providers/postgres/qgspostgresprovider.cpp index 5fa3ed7cf12..6d163a1104c 100644 --- a/src/providers/postgres/qgspostgresprovider.cpp +++ b/src/providers/postgres/qgspostgresprovider.cpp @@ -1549,7 +1549,6 @@ bool QgsPostgresProvider::addFeature(QgsFeature& f, int primaryKeyHighWater) ) { charactertype=true; - break; // no need to continue with this loop } } @@ -1557,16 +1556,26 @@ bool QgsPostgresProvider::addFeature(QgsFeature& f, int primaryKeyHighWater) // important: escape quotes in field value fieldvalue.replace("'", "''"); - // XXX isn't it better to always escape field value? - if(charactertype) - { - insert+="'"; - } - insert+=fieldvalue; - if(charactertype) - { - insert+="'"; - } + //request default value explicitly if fieldvalue is an empty string + if(fieldvalue.isEmpty()) + { + insert += "DEFAULT"; + } + else + { + // XXX isn't it better to always escape field value? + if(charactertype) + { + insert+="'"; + } + + insert+=fieldvalue; + + if(charactertype) + { + insert+="'"; + } + } } }