const char *sqlite3_db_name(sqlite3 *db, int N);
The sqlite3_db_name(D,N) interface returns a pointer to the schema name for the N-th database on database connection D, or a NULL pointer of N is out of range. An N value of 0 means the main database file. An N of 1 is the "temp" schema. Larger values of N correspond to various ATTACH-ed databases.
Space to hold the string that is returned by sqlite3_db_name() is managed by SQLite itself. The string might be deallocated by any operation that changes the schema, including ATTACH or DETACH or calls to sqlite3_serialize() or sqlite3_deserialize(), even operations that occur on a different thread. Applications that need to remember the string long-term should make their own copy. Applications that are accessing the same database connection simultaneously on multiple threads should mutex-protect calls to this API and should make their own private copy of the result prior to releasing the mutex.