I’m in the process of making a program that allows you to perform searches from the app. The App will then download the search results and store them in the database. I was using the url as the primary key so that I could make sure that I’m not inputting the same data twice (As URLs are sure to be a unique identifier), however this caused a few issues. The database would give an error and crash when trying to save a row with the same URL. I suppose this is good since I can put my insert statement in a try/catch block. I have some questions though:
-
What should I be catching (try catch block) to detect when an error like this occurs where the item it’s trying to insert into the db is already being stored?
-
This is working with a simple “add each search result to the DB 1 at a time” approach. What if I wanted to do a database transaction and add ~25 at a time. How would I figure out which one was erroring, and what would be the best way to do this? Is there a way for it to continue on with adding the rest that didn’t have the issue?
- How would I go about doing this if I didn’t want to use the url as the primary key?
You could try using
INSERT OR REPLACEhttp://www.sqlite.org/lang_insert.html