Skip to main content
Solved

Geopackage writer and triggers issue


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 NULLBEGIN
  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

 

 

View original
Did this help you find an answer to your question?

7 replies

Forum|alt.badge.img+2
  • 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
  • January 24, 2022

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

 


Forum|alt.badge.img+2
  • 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+22
  • Contributor
  • 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
  • January 27, 2022
markatsafe wrote:

@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
  • 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 NULLBEGIN
  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
  • February 8, 2022

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


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings