Question: The table:

```
ID    TYPE    USER_ID
======================
1     1       15
2     1       15
.     3       15
.     1       15
.

```

should keep multiple USER\_ID's with TYPE=1 but **`only`** 0 or 1 row where TYPE=3.
In the case that TYPE=3, upon insert I need to either update or create (much like `insert on duplicate key update`) that row.
Is there a good way to accomplish this without first `SELECT`ing, and updating or inserting depending on the SELECT results in the program?
Preferably doing this in a single command, and without triggers?

Answer: 
Nope. For all intents and purposes, the STOP button in Xcode immediately terminates the application. There isn't a way to catch this.
**applicationWillResignActive** and **applicationDidEnterBackground** and their counterparts do get triggered when you press the home button on the device or simulator (or when you come back). I don't think you can catch the ones related to termination.