Skip to content
Permalink
Browse files
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@8390 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Apr 30, 2008
1 parent 518a97b commit 38fc0b9e77b1006a4f4885b1311b73d18a774cb4
Showing with 30 additions and 20 deletions.
  1. +20 −15 src/app/qgsattributedialog.cpp
  2. +10 −5 src/providers/postgres/qgspostgresprovider.cpp
@@ -96,25 +96,30 @@ bool QgsAttributeDialog::queryAttributes(const QgsFieldMap& fields, QgsFeature&
QgsAttributeDialog attdialog(fields, featureAttributes);

if (attdialog.exec() == QDialog::Accepted)
{
{
int i=0;
for (QgsAttributeMap::const_iterator it = featureAttributes.begin(); it != featureAttributes.end(); ++it)
for (QgsAttributeMap::const_iterator it = featureAttributes.begin(); it != featureAttributes.end(); ++it, i++)
{
QString value = attdialog.value(i++);
QString value = attdialog.value(i);

switch( fields[it.key()].type() )
if( attdialog.isDirty(i) )
{
case QVariant::Int:
f.changeAttribute(it.key(), value=="" ? QVariant( QString::null ) : QVariant( value.toInt() ) );
break;

case QVariant::Double:
f.changeAttribute(it.key(), value=="" ? QVariant( QString::null ) : QVariant( value.toDouble() ) );
break;

default:
f.changeAttribute(it.key(), value=="NULL" ? QVariant(QString::null) : QVariant(value) );
break;
switch( fields[it.key()].type() )
{
case QVariant::Int:
f.changeAttribute(it.key(), value=="" ? QVariant( QString::null ) : QVariant( value.toInt() ) );
break;

case QVariant::Double:
f.changeAttribute(it.key(), value=="" ? QVariant( QString::null ) : QVariant( value.toDouble() ) );
break;

default:
f.changeAttribute(it.key(), value=="NULL" ? QVariant(QString::null) : QVariant(value) );
break;
}
} else {
f.changeAttribute(it.key(), QVariant(value) );
}
}
return true;
@@ -1794,17 +1794,21 @@ bool QgsPostgresProvider::addFeatures(QgsFeatureList & flist)
}

insert += "," + quotedIdentifier(fieldname);

QString defVal = getDefaultValue( it.key() ).toString();

if( i==flist.size() )
{
if( !defVal.isNull() && *it==defVal)
if( *it==defVal )
{
values += "," + defVal;
if( defVal.isNull() ) {
values += ",NULL";
} else {
values += "," + defVal;
}
}
else
{
else
{
values += "," + quotedValue( it->toString() );
}
}
@@ -1819,6 +1823,7 @@ bool QgsPostgresProvider::addFeatures(QgsFeatureList & flist)

insert += values + ")";

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

0 comments on commit 38fc0b9

Please sign in to comment.