Skip to content

Commit

Permalink
fix #2137
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12235 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Nov 23, 2009
1 parent 99705ee commit 6024c32
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/providers/postgres/qgspostgresprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2044,7 +2044,7 @@ QByteArray QgsPostgresProvider::paramValue( QString fieldValue, const QString &d
return fieldValue.toUtf8();
}

bool QgsPostgresProvider::addFeatures( QgsFeatureList & flist )
bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist )
{
if ( flist.size() == 0 )
return true;
Expand Down Expand Up @@ -2082,6 +2082,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList & flist )

QStringList defaultValues;
QList<int> fieldId;
int primaryKeyId = -1;

// look for unique attribute values to place in statement instead of passing as parameter
// e.g. for defaults
Expand All @@ -2095,9 +2096,15 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList & flist )

QgsDebugMsg( "Checking field against: " + fieldname );

if ( fieldname.isEmpty() || fieldname == geometryColumn || fieldname == primaryKey )
if ( fieldname.isEmpty() || fieldname == geometryColumn )
continue;

if ( fieldname == primaryKey )
{
primaryKeyId = it.key();
continue;
}

int i;
for ( i = 1; i < flist.size(); i++ )
{
Expand Down Expand Up @@ -2179,15 +2186,16 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList & flist )

if ( primaryKeyType != "tid" )
{
if ( keyDefault.isNull() )
QByteArray key = paramValue( primaryKeyId >= 0 ? attributevec[ primaryKeyId ].toString() : QString::null, keyDefault );

if ( key.isNull() )
{
++primaryKeyHighWater;
params << QString::number( primaryKeyHighWater );
newIds << primaryKeyHighWater;
}
else
{
QByteArray key = paramValue( keyDefault, keyDefault );
params << key;
newIds << key.toInt();
}
Expand Down

0 comments on commit 6024c32

Please sign in to comment.