Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jef committed Apr 30, 2008
1 parent d0c0676 commit 31e1c2e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
35 changes: 20 additions & 15 deletions src/app/qgsattributedialog.cpp
Expand Up @@ -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;
Expand Down
15 changes: 10 additions & 5 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -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() );
}
}
Expand All @@ -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);
Expand Down

0 comments on commit 31e1c2e

Please sign in to comment.