Skip to main content
Solved

Geopackage writer and triggers issue

  • January 24, 2022
  • 7 replies
  • 67 views

jorge_rosales
Contributor
Forum|alt.badge.img+8

If a execute this workspace:

 

imageUsing an existing (and empty) database with this trigger on parcel table:

 

imageI get this error:

 

image 

There seems to be a conflict between the "prepared statement" used by FME and the trigger. Are they incompatible?

 

Note: This project is a simplified version of another in which the database schema and the logic implemented by the trigger are considerably more complex.

 

 

 

 

Best answer by markatsafe

@Jorge Rosales​  After a little digging and research, we don't think it's an FME issue. Modifying the trigger SQL slightly makes the trigger behave.  In SQLite, when inserting or updating data with a trigger, it seems you have to specify whether you are referencing the original record (OLD) or the update record(NEW). Adding this reference to the trigger SQL let's it run:

DROP TRIGGER "main"."parcel_insert";
CREATE TRIGGER parcel_insert
  AFTER INSERT ON parcel
WHEN (NEW.code IS NULL) 
BEGIN
  SELECT RAISE(ABORT, 'Invalid parcel code');
END

Note the addition of NEW to line 4:

                        WHEN (NEW.code IS NULL) 

You should now only get an error if the replacement value for code (NEW.code) = <null>

 

I've attached a revised version of the workspace (FME 2021.2). 

 

More details on SQLite triggers and the OLD | NEW references here

 

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

7 replies

Forum|alt.badge.img+2
  • 1891 replies
  • January 24, 2022

@Jorge Rosales​ Thanks for including the nice example workspace and test Geopackage. I was able to reproduce the ERROR. I'm not sure what is causing conflict between the table insert and the trigger. I've asked our development team to look at the issue and I'll report back.


jorge_rosales
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • 44 replies
  • January 24, 2022

Thank you very much @Mark Stoakes​, I'm waiting for news.

 


Forum|alt.badge.img+2
  • 1891 replies
  • January 26, 2022

@Jorge Rosales​ It looks like this issue arises in the underlying GDAL Geopackage driver FME uses for the the Geopackage format. We're trying to trace down source issue


caracadrian
Contributor
Forum|alt.badge.img+23
  • Contributor
  • 571 replies
  • January 27, 2022

From what I can tell FME doesn't like the "parcel_insert" trigger.

I you delete it (via DB Browser for SQLite) and validate "code" attribute via a transformer, FME is able to write in the table.


jorge_rosales
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • 44 replies
  • January 27, 2022

@Jorge Rosales​ It looks like this issue arises in the underlying GDAL Geopackage driver FME uses for the the Geopackage format. We're trying to trace down source issue

Thanks for the update @Mark Stoakes​. If it is confirmed, I hope that the GDAL team fixs the error.


Forum|alt.badge.img+2
  • 1891 replies
  • Best Answer
  • February 7, 2022

@Jorge Rosales​  After a little digging and research, we don't think it's an FME issue. Modifying the trigger SQL slightly makes the trigger behave.  In SQLite, when inserting or updating data with a trigger, it seems you have to specify whether you are referencing the original record (OLD) or the update record(NEW). Adding this reference to the trigger SQL let's it run:

DROP TRIGGER "main"."parcel_insert";
CREATE TRIGGER parcel_insert
  AFTER INSERT ON parcel
WHEN (NEW.code IS NULL) 
BEGIN
  SELECT RAISE(ABORT, 'Invalid parcel code');
END

Note the addition of NEW to line 4:

                        WHEN (NEW.code IS NULL) 

You should now only get an error if the replacement value for code (NEW.code) = <null>

 

I've attached a revised version of the workspace (FME 2021.2). 

 

More details on SQLite triggers and the OLD | NEW references here

 

 


jorge_rosales
Contributor
Forum|alt.badge.img+8
  • Author
  • Contributor
  • 44 replies
  • February 8, 2022

You are right. Thank you very much for the support @Mark Stoakes​