I use sqlite3_create_function() to attach C++ functions to SQLite
triggers.  For example, I create the SQL function INSERT_HANDLER(),
bound to the C++ function InsertTriggerHandler().  Then I create a
trigger:

  CREATE TRIGGER trig AFTER INSERT ON TableName
  FOR EACH ROW
  WHEN (INSERT_HANDLER(new.A, new.B) NOTNULL)
  BEGIN
      SELECT RAISE(FAIL, 'Error during insert trigger.');
  END

The trouble is, although the trigger persists indefinitely, the
INSERT_HANDLER() function is only defined for as long as the database
connection it was created with exists, and only when the INSERT that
causes the trigger uses the same connection.

Is there any way to create a more broadly available, persistent custom
function, short of building it into sqlite?  Or does anyone have
another suggestion to solve the implicit problem?

Thanks,

- Pam

Reply via email to