Can my code be made more efficient?

You should be able to use “ON CONFLICT” (similar to MySQL ON DUPLICATE KEY):
https://www.sqlite.org/lang_UPSERT.html

INSERT INTO referrals (idate, count)
VALUES (?, 1)
ON CONFLICT(idate) DO UPDATE SET count = count + 1;

Note. I have not tested the code.

1 Like