Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a SQLite database is an in-memory database or not

Tags:

sqlite

I have an handler for a connection to an sqlite3 database. I would like to know if the database is an in-memory database or not.

Is there any API to do so?

like image 781
Siscia Avatar asked Sep 06 '25 03:09

Siscia


1 Answers

At the C API layer you can use sqlite3_db_filename to get the filename. If it's NULL or empty you've got a temporary or in-memory database.

The sqlite3_db_filename(D,N) interface returns a pointer to a filename associated with database N of connection D. The main database file has the name "main". If there is no attached database N on the database connection D, or if database N is a temporary or in-memory database, then this function will return either a NULL pointer or an empty string.

Whatever client API library you're using likely acts the same: the filename will be empty.

like image 73
Schwern Avatar answered Sep 08 '25 01:09

Schwern