Skip to content
Permalink
Browse files

- set primary key value to NULL in split when there is no default value.

- modified the test accordingly
  • Loading branch information
vmora committed Jul 11, 2013
1 parent 827ed31 commit 45ab8ccc8582036dff93fba014a29f95d306ac0f
Showing with 24 additions and 0 deletions.
  1. +4 −0 src/core/qgsvectorlayereditutils.cpp
  2. +20 −0 tests/src/python/test_qgsspatialiteprovider.py
@@ -254,6 +254,10 @@ int QgsVectorLayerEditUtils::splitFeatures( const QList<QgsPoint>& splitLine, bo
{
newAttributes[ pkIdx ] = defaultValue;
}
else //try with NULL
{
newAttributes[ pkIdx ] = QVariant();
}
}

newFeature.setAttributes( newAttributes );
@@ -52,6 +52,15 @@ def setUpClass(cls):
sql += "VALUES (1, 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
cur.execute(sql)

# table with multiple column primary key
sql = "CREATE TABLE test_pg_mk (id INTEGER NOT NULL, name TEXT NOT NULL, PRIMARY KEY(id,name))"
cur.execute(sql)
sql = "SELECT AddGeometryColumn('test_pg_mk', 'geometry', 4326, 'POLYGON', 'XY')"
cur.execute(sql)
sql = "INSERT INTO test_pg_mk (id, name, geometry) "
sql += "VALUES (1, 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
cur.execute(sql)

con.commit()
con.close()

@@ -79,6 +88,17 @@ def test_SplitFeature(self):
layer.startEditing()
layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0)==0 or die("error in split")
layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0)==0 or die("error in split")
layer.commitChanges() or die("this commit should work")
layer.featureCount() == 4 or die("we should have 4 features after 2 split")

def test_SplitFeatureWithFailedCommit(self):
"""Create spatialite database"""
layer = QgsVectorLayer("dbname=test.sqlite table=test_pg_mk (geometry)", "test_pg_mk", "spatialite")
assert(layer.isValid())
assert(layer.hasGeometryType())
layer.startEditing()
layer.splitFeatures([QgsPoint(0.5, -0.5), QgsPoint(0.5, 1.5)], 0)==0 or die("error in split")
layer.splitFeatures([QgsPoint(-0.5, 0.5), QgsPoint(1.5, 0.5)], 0)==0 or die("error in split")
if layer.commitChanges():
die("this commit should fail")
layer.rollBack()

0 comments on commit 45ab8cc

Please sign in to comment.
You can’t perform that action at this time.