@@ -52,6 +52,15 @@ def setUpClass(cls):
52
52
sql += "VALUES (1, 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
53
53
cur .execute (sql )
54
54
55
+ # table with multiple column primary key
56
+ sql = "CREATE TABLE test_pg_mk (id INTEGER NOT NULL, name TEXT NOT NULL, PRIMARY KEY(id,name))"
57
+ cur .execute (sql )
58
+ sql = "SELECT AddGeometryColumn('test_pg_mk', 'geometry', 4326, 'POLYGON', 'XY')"
59
+ cur .execute (sql )
60
+ sql = "INSERT INTO test_pg_mk (id, name, geometry) "
61
+ sql += "VALUES (1, 'toto', GeomFromText('POLYGON((0 0,1 0,1 1,0 1,0 0))', 4326))"
62
+ cur .execute (sql )
63
+
55
64
con .commit ()
56
65
con .close ()
57
66
@@ -79,6 +88,17 @@ def test_SplitFeature(self):
79
88
layer .startEditing ()
80
89
layer .splitFeatures ([QgsPoint (0.5 , - 0.5 ), QgsPoint (0.5 , 1.5 )], 0 )== 0 or die ("error in split" )
81
90
layer .splitFeatures ([QgsPoint (- 0.5 , 0.5 ), QgsPoint (1.5 , 0.5 )], 0 )== 0 or die ("error in split" )
91
+ layer .commitChanges () or die ("this commit should work" )
92
+ layer .featureCount () == 4 or die ("we should have 4 features after 2 split" )
93
+
94
+ def test_SplitFeatureWithFailedCommit (self ):
95
+ """Create spatialite database"""
96
+ layer = QgsVectorLayer ("dbname=test.sqlite table=test_pg_mk (geometry)" , "test_pg_mk" , "spatialite" )
97
+ assert (layer .isValid ())
98
+ assert (layer .hasGeometryType ())
99
+ layer .startEditing ()
100
+ layer .splitFeatures ([QgsPoint (0.5 , - 0.5 ), QgsPoint (0.5 , 1.5 )], 0 )== 0 or die ("error in split" )
101
+ layer .splitFeatures ([QgsPoint (- 0.5 , 0.5 ), QgsPoint (1.5 , 0.5 )], 0 )== 0 or die ("error in split" )
82
102
if layer .commitChanges ():
83
103
die ("this commit should fail" )
84
104
layer .rollBack ()
0 commit comments