On 26 May 2009, at 1:11am, Dennis Volodomanov wrote: > Basically these are file names being inserted into a table, so, before > each insert we check whether that file exists in the table already or > not (by doing a SELECT on an indexed lowercase full file path). So, it > really matters to me that the first insert completes and data is > available for a select that follows immediately from another thread > (but > same database connection).
Ah ! Okay, if that's what you want, you can take advantage of the variations on the INSERT call. Define the filename column as UNIQUE, or if there's a combination, create a UNIQUE index for the table, then use one of INSERT OR REPLACE INSERT OR FAIL INSERT OR IGNORE depending on which logic best serves what your program does. So if you don't care if the filename is already in the table, you can use INSERT OR IGNORE, so the INSERT will always work but never generate duplicate entries. On the other hand, if you need to trap and handle the case where the filename is already there, use INSERT OR FAIL, and the error you get back will tell you whether the filename was already in the table. See http://www.sqlite.org/lang_conflict.html for a detailed discussion of what happens for the various clauses. Because catching and dealing with the duplication is handled within the library function, using these things appropriately should mean that you don't have to do any fancy worrying about threads, processes or simultaneity at all: if anything funny goes on, only one of the INSERT operations will succeed. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users