Properly prepare insertIfNotExist queries.

Due to recent oopsies in my SQL, I thought I'd better fix this one too ;)

Tested with MySQL and SQLite - I don't have PostgreSQL on my laptop, so let's see what Jenkins says.

@eMerzh @LukasReschke @Raydiation