Reputation: 4168
I am using C# with .NET 4.5. I am making a scraper which collects specific data. Each time a value is scraped, I need to make sure it hasn't already been added to the SQLite db.
To do this, I am making a call each time a value is scraped to query against the db to check if it contains the value, and if not, I make another call to insert the value into the db.
Since I am scraping multiple values per second, this gets to be very IO-intensive, with constant calls to the db.
My question is, is there any better way to do this? Perhaps I could queue the values scraped and then run a batch query at once? Is that possible?
Upvotes: 1
Views: 3937
Reputation: 16687
I see three approaches:
INSERT OR IGNORE
, which will reject an entry if it is already present (based on primary key and unique fields). Or plainly INSERT
(or its equivalent (INSERT or ABORT
) which will return SQLITE_CONSTRAINT
, a value you will have to catch and manage if you want to count failed insertions.BEGIN;
), do your insertions (you can use INSERT OR IGNORE
here as well), commit the transaction (COMMIT;
)Upvotes: 1