user1761538
user1761538

Reputation: 1

Where is the location of my sqlite database file?

I have created a database in C by using sqlite. Here is code:

int x = sqlite3_open(argv[1], &db);

argv[1] is a argument which contains the name of database. I think that the database should be stored in a file which ends with .db, but I am unable to find that file.

Where can I find the mentioned file (file with structure of database etc ...)?

Upvotes: 0

Views: 6248

Answers (4)

CL.
CL.

Reputation: 180020

sqlite3_open is documented as creating the database, but SQLite will not actually create the file until you do any changes to the database.

Create a table to ensure that the file will be created.

Upvotes: 0

fvu
fvu

Reputation: 32953

sqlite3_open is defined as

int sqlite3_open(
   const char *filename,   /* Database filename (UTF-8) */
   sqlite3 **ppDb          /* OUT: SQLite db handle */
);

so the database is called whatever you put in the first argument was. the .db suffix will not be added automagically.

As for the directory the file was stored in, if you specified an absolute path in argv1 that's where the file will be stored, if not it should be in the current working directory.

If you really need that file back and it's not where you expect it to be, nor does it have a .db extension (because you forgot to specify it) and you can't remember the name you gave there's one last possibility: see the sqlite file format specification, a sqlite file always starts with "SQLite format 3\000" (a null terminated string).

find / -exec grep -l "SQLite format 3" {} \;

This will print name & path of all files containing that string, but that command will take some time...

Upvotes: 1

LSerni
LSerni

Reputation: 57388

The file will be created wherever your path specified, or wherever the program was running from (e.g. your C:\Users\User Name directory).

It has not necessarily a .db extension, that is: you can create a file named however you want. If you need to find it, maybe you can try looking for files created in a given time interval.

Your best option is to always specify a full path, and create files with the .sqlite or .db extension.

Upvotes: 1

Omkant
Omkant

Reputation: 9204

I you are using Linux you can use the "locate "command on the terminal like this

locate *.db

in the / directory . You will get the location

Upvotes: -1

Related Questions