Skip to content

Commit 31e1c2e

Browse files
author
jef
committedApr 30, 2008
fix for #130:
- skip type check for unchanged defaults in QgsAttributDialog - don't replace NULL default value with empty string git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8390 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed
 

‎src/app/qgsattributedialog.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,30 @@ bool QgsAttributeDialog::queryAttributes(const QgsFieldMap& fields, QgsFeature&
9696
QgsAttributeDialog attdialog(fields, featureAttributes);
9797

9898
if (attdialog.exec() == QDialog::Accepted)
99-
{
99+
{
100100
int i=0;
101-
for (QgsAttributeMap::const_iterator it = featureAttributes.begin(); it != featureAttributes.end(); ++it)
101+
for (QgsAttributeMap::const_iterator it = featureAttributes.begin(); it != featureAttributes.end(); ++it, i++)
102102
{
103-
QString value = attdialog.value(i++);
103+
QString value = attdialog.value(i);
104104

105-
switch( fields[it.key()].type() )
105+
if( attdialog.isDirty(i) )
106106
{
107-
case QVariant::Int:
108-
f.changeAttribute(it.key(), value=="" ? QVariant( QString::null ) : QVariant( value.toInt() ) );
109-
break;
110-
111-
case QVariant::Double:
112-
f.changeAttribute(it.key(), value=="" ? QVariant( QString::null ) : QVariant( value.toDouble() ) );
113-
break;
114-
115-
default:
116-
f.changeAttribute(it.key(), value=="NULL" ? QVariant(QString::null) : QVariant(value) );
117-
break;
107+
switch( fields[it.key()].type() )
108+
{
109+
case QVariant::Int:
110+
f.changeAttribute(it.key(), value=="" ? QVariant( QString::null ) : QVariant( value.toInt() ) );
111+
break;
112+
113+
case QVariant::Double:
114+
f.changeAttribute(it.key(), value=="" ? QVariant( QString::null ) : QVariant( value.toDouble() ) );
115+
break;
116+
117+
default:
118+
f.changeAttribute(it.key(), value=="NULL" ? QVariant(QString::null) : QVariant(value) );
119+
break;
120+
}
121+
} else {
122+
f.changeAttribute(it.key(), QVariant(value) );
118123
}
119124
}
120125
return true;

‎src/providers/postgres/qgspostgresprovider.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,17 +1794,21 @@ bool QgsPostgresProvider::addFeatures(QgsFeatureList & flist)
17941794
}
17951795

17961796
insert += "," + quotedIdentifier(fieldname);
1797-
1797+
17981798
QString defVal = getDefaultValue( it.key() ).toString();
17991799

18001800
if( i==flist.size() )
18011801
{
1802-
if( !defVal.isNull() && *it==defVal)
1802+
if( *it==defVal )
18031803
{
1804-
values += "," + defVal;
1804+
if( defVal.isNull() ) {
1805+
values += ",NULL";
1806+
} else {
1807+
values += "," + defVal;
1808+
}
18051809
}
1806-
else
1807-
{
1810+
else
1811+
{
18081812
values += "," + quotedValue( it->toString() );
18091813
}
18101814
}
@@ -1819,6 +1823,7 @@ bool QgsPostgresProvider::addFeatures(QgsFeatureList & flist)
18191823

18201824
insert += values + ")";
18211825

1826+
QgsDebugMsg( QString("prepare addfeatures: %1").arg(insert) );
18221827
PGresult *stmt = PQprepare(connection, "addfeatures", insert.toUtf8(), fieldId.size()+2, NULL);
18231828
if(stmt==0 || PQresultStatus(stmt)==PGRES_FATAL_ERROR)
18241829
throw PGException(stmt);

0 commit comments

Comments
 (0)
Please sign in to comment.