[Qgis-developer] addFeatures without knowing new feature's id, bug?

Giuseppe Sucameli brush.tyler at gmail.com
Tue Jan 17 14:47:04 EST 2012


Hi Denis,

On Tue, Jan 17, 2012 at 7:20 AM, Denis Rouzaud <denis.rouzaud at gmail.com> wrote:
> If you have any clue, it's great! I'm a little bit lost.

few minutes ago Jef fixed it in changeset 70288272f752...

Now calling the addFeature method w/o set the value for
the pk field in the attributeMap, the postgres provider uses
the pk's default value.

Please, try again and report here.

Regards.

> On 01/16/2012 04:54 PM, Jürgen E. Fischer wrote:
>
> Hi Denis,
>
> On Mon, 16. Jan 2012 at 13:04:01 +0100, Denis Rouzaud wrote:
>
> I am trying to add a feature to a PostGIS table, in which there is a
> serial primary key 'id'.
>
> Without defining id, here is what I get when I try addFeatures:
> ERROR: null value in column "id" violates not-null constraint
>
> You could setup a DEFAULT value for the id column in PostgreSQL (like SERIAL
> does it).
>
> and I tried
> iid  = self.layer.dataProvider().fieldNameIndex('id')
> if iid != -1:
> f.addAttribute(iid,'nextval(distribution.dimension_id_seq::regclass)')
> which leaded to
> ERROR: invalid input syntax for integer:
> "nextval(distribution.dimension_id_seq::regclass)"
>
> QGIS interprets that as string and tries to stuff it into the integer column
> which obviously fails.
>
> Is there a bug in the provider, or should I get first the new id (if
> yes, how do I do this) ?
>
> You could use QgsDataProvider::maximumValue() to fetch it and increment it
> yourself.  But that might still produce concurrency problems, if multiple
> people
> work in parallel.  I'd stick with a DEFAULT in PostgreSQL.
>
>
> Jürgen
>
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>



-- 
Giuseppe Sucameli


More information about the Qgis-developer mailing list