Question

In my database I have three tables (A,B,C) in which table A has foreign keys into both B and C. When I delete from either B or C, I want to also delete the row in A if BOTH foreign keys are null, and I have a constraint placed on the foreign keys that sets them to null if the B or C table deletes that key. I have two triggers on tables B and C to delete a row from A when appropriate and this seems to be working okay.

The trouble I'm having is there is a file name stored in table A that I want to delete but I can't if I set up triggers to handle my situation. So is there any way to know when a trigger is fired? Do I have to manually execute the logic for my trigger so I can delete the file too?

tl;dr: How can I execute some java code when a trigger is fired in my applications sqlite database?

Was it helpful?

Solution

SQLite itself has user-defined functions, but the Android database API does not allow you to access them.

You have to do the checks in your code whenever you have issued such a DELETE statement.

OTHER TIPS

Best way to do this I found is to return the rowID.

long newRowId;
newRowId = db.insert(tableName,primaryKey,values); (insert or delete or whatever)

If that trigger fires you will get a row id of -1. Then just show your message or run your query where you delete something else when you get a row id of -1

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top