SQLite Forum

Can I get the file name of a temporary on-disk database?
Login
Yes, there are other ways I could generate a name for the temp database file. I was using tmpnam which is not considered safe, so started looking at mkstemp instead. It *does* give me the temp file name I need, however...

No matter how I end up with a temp file name, the issue remains: The creation of that file name, and the creation of the *file* with that name won't be "atomic", meaning that there's a slight chance of the same name being snapped up by some other process in between the time the name is generated and the file is actually created. 

My understanding is that mkstemp provides that kind of atomicity (whereas tmpnam does not), but if I have to close and delete the file before passing the name into sqlite3_open to let it create a temp database with that name, the atomicity of msktemp is not helpful in this case. And nothing else is going to give me that atomicity either.

I assume that letting SQLite create the temp database itself (by passing an empty string to sqlite3_open) is also "atomic" in this sense, but again, that's of no use to me since I need to know what name it used so I can do an ATTACH DATABASE with it.