Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix adding features on geometryless tables
git-svn-id: http://svn.osgeo.org/qgis/trunk@14834 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
brushtyler committed Dec 3, 2010
1 parent 1d3b4f8 commit 3e0bd61
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/providers/postgres/qgspostgresprovider.cpp
Expand Up @@ -2265,33 +2265,32 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist )
connectionRW->PQexecNR( "BEGIN" );

// Prepare the INSERT statement
QString insert = QString( "INSERT INTO %1(" ).arg( mQuery );
QString values;
QString insert = QString( "INSERT INTO %1 (" ).arg( mQuery );
QString values = ") VALUES (";
QString delim = ",";
int offset = 1;

if ( !geometryColumn.isNull() )
{
insert += quotedIdentifier( geometryColumn );
values = QString( ") VALUES (GeomFromWKB($1%1,%2)" )
.arg( connectionRW->useWkbHex() ? "" : "::bytea" )
.arg( srid );
values += QString( "GeomFromWKB($%1%2,%3)" )
.arg( offset )
.arg( connectionRW->useWkbHex() ? "" : "::bytea" )
.arg( srid );
offset += 1;
delim = ",";
}
else
{
delim = "";
}

int offset;
if ( primaryKeyType != "tid" && primaryKeyType != "oid" )
{
insert += delim + quotedIdentifier( primaryKey );
values += delim + "$2";
offset = 3;
}
else
{
offset = 2;
values += delim + QString( "$%1" ).arg( offset );
offset += 1;
delim = ",";
}

const QgsAttributeMap &attributevec = flist[0].attributeMap();
Expand Down Expand Up @@ -2393,11 +2392,14 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist )
{
const QgsAttributeMap &attributevec = features->attributeMap();

QString geomParam;
appendGeomString( features->geometry(), geomParam );

QStringList params;
params << geomParam;
if ( !geometryColumn.isNull() )
{
QString geomParam;
appendGeomString( features->geometry(), geomParam );

params << geomParam;
}

if ( primaryKeyType != "tid" && primaryKeyType != "oid" )
{
Expand Down

0 comments on commit 3e0bd61

Please sign in to comment.