Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check whether sqlite database is attached or not?

Tags:

c++

sqlite

I am using sqlite to store my data. I have two databases. In my application, each time a new request comes, I am attaching first db to second db. The problem is, if two request come it is showing the db already in use (it is trying to attach twice with same alias name 'db'). I want to know if there is any way to check whether a database is attached or not?

like image 317
Sandy Avatar asked Feb 19 '23 11:02

Sandy


1 Answers

PRAGMA database_list;

outputs a resultset with full list of available databases. The first column is database name, the second is database file (empty if it is not associated with file). The primary database is always named main, temporary db is always temp.

sqlite> attach "foo.db" as foo;
sqlite> pragma database_list;
0|main|
2|foo|/Users/me/tmp/foo.db
like image 145
hamstergene Avatar answered Mar 02 '23 17:03

hamstergene