Reputation: 11
Is there a way I can get a SQLite database name in Python.
I am using the following code to get the database name:
con=sqlite3.connect(":memory:")
cursor = con.cursor()
cursor.execute("PRAGMA database_list;")
curr_table = cursor.fetchall()
But the output I get is:
[(0, u'main', u'')]
When I should be getting something like
[(0,u'main',u'/Users/testdb.db'),
(2,u'test',u'/Users/testdb.db')]
Upvotes: 0
Views: 5112
Reputation: 7441
You should be connecting to the actual file - otherwise you cannot view the databases within it.
So, you just need to change your code to this:
con=sqlite3.connect('/Users/testdb.db')
cursor = con.cursor()
cursor.execute("PRAGMA database_list;")
curr_table = cursor.fetchall()
Upvotes: 3