Skip to content
Permalink
Browse files

Also retrieve generated values for pktInt

  • Loading branch information
m-kuhn committed Apr 7, 2016
1 parent eecd77a commit 5cd2319c3f33824a865be8220d12ee02501d7f84
@@ -1918,7 +1918,7 @@ bool QgsPostgresProvider::addFeatures( QgsFeatureList &flist )

insert += values + ')';

if ( mPrimaryKeyType == pktFidMap )
if ( mPrimaryKeyType == pktFidMap || mPrimaryKeyType == pktInt )
{
insert += " RETURNING ";

@@ -165,15 +165,26 @@ def test_query_attribute(dbconn, query, att, val, fidval):
test_query_attribute(self.dbconn, '(SELECT -1::int8 i, NULL::geometry(Point) g)', 'i', -1, 1)
test_query_attribute(self.dbconn, '(SELECT -65535::int8 i, NULL::geometry(Point) g)', 'i', -65535, 1)

def testPktMapInsert(self):
def testPktIntInsert(self):
vl = QgsVectorLayer('{} table="qgis_test"."{}" key="pk" sql='.format(self.dbconn, 'bikes_view'), "bikes_view", "postgres")
self.assertTrue(vl.isValid())
f = QgsFeature(vl.fields())
f['pk'] = NULL
f['name'] = 'Cilo'
r, f = vl.dataProvider().addFeatures([f])
self.assertTrue(r)
self.assertNotEqual(f[0]['pk'], NULL)
self.assertNotEqual(f[0]['pk'], NULL, f[0].attributes())
vl.deleteFeatures([f[0].id()])

def testPktMapInsert(self):
vl = QgsVectorLayer('{} table="qgis_test"."{}" key="obj_id" sql='.format(self.dbconn, 'oid_serial_table'), "oid_serial", "postgres")
self.assertTrue(vl.isValid())
f = QgsFeature(vl.fields())
f['obj_id'] = vl.dataProvider().defaultValue(0)
f['name'] = 'Test'
r, f = vl.dataProvider().addFeatures([f])
self.assertTrue(r)
self.assertNotEqual(f[0]['obj_id'], NULL, f[0].attributes())
vl.deleteFeatures([f[0].id()])

if __name__ == '__main__':
@@ -310,7 +310,7 @@ INSERT INTO qgis_test.child_table2_good (geom, code2) VALUES ('srid=4326;Point(-
INSERT INTO qgis_test.child_table2_good (geom, code2) VALUES ('srid=4326;Point(-1 1)'::geometry, 'child2 2');

--------------------------------------
-- A writable view
-- A writable view with an int pk
--

CREATE TABLE qgis_test.bikes
@@ -342,3 +342,18 @@ END; $BODY$

CREATE TRIGGER bikes_view_ON_INSERT INSTEAD OF INSERT ON qgis_test.bikes_view
FOR EACH ROW EXECUTE PROCEDURE qgis_test.bikes_view_insert();

--------------------------------------
-- A string primary key to force usage of pktMap
--

CREATE SEQUENCE qgis_test.oid_serial;

CREATE TABLE qgis_test.oid_serial_table
(
obj_id varchar(16) NOT NULL,
name character varying(255),
CONSTRAINT pkey_oid_serial PRIMARY KEY (obj_id)
);

ALTER TABLE qgis_test.oid_serial_table ALTER COLUMN obj_id SET DEFAULT 'prf_' || nextval('qgis_test.oid_serial');

0 comments on commit 5cd2319

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