Where is the SQLite database stored i.e. directory path on windows 7 when created ?
A SQLite database is a regular file. It is created in your script current directory.
.databases
If you run this command inside SQLite
.databases
it lists the path of all currently connected databases. Sample output:
seq name file
--- --------------- ----------------------------------------------------------
0 main /home/me/a.db
There is no "standard place" for a sqlite database. The file's location is specified to the library, and may be in your home directory, in the invoking program's folder, or any other place.
If it helps, sqlite databases are, by convention, named with a .db file extension.
If you are running Rails (its the default db in Rails) check the {RAILS_ROOT}/config/database.yml file and you will see something like:
database: db/development.sqlite3
This means that it will be in the {RAILS_ROOT}/db directory.
When you call sqlite3_open() you specify the filepath the database is opened from/saved to, if it is not an absolute path it is specified relative to your current working directory.
It depends on how you initialized the database. If you used the command line shell for SQLite (e.g. sqlite3 ex1) to create the database, it'll be a path from the root of your local machine. If you used a Python script to create the database, it'll be a path from your project.
To check the former, run the command line shell:
sqlite3
sqlite> .databases
To check the path in your project, you can print the path in the connection. For example:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DATABASE = 'db'
def get_db_connection():
print(os.path.join(BASE_DIR, DATABASE, "database.db"))
conn = sqlite3.connect(os.path.join(BASE_DIR, DATABASE, "database.db"))
conn.row_factory = sqlite3.Row
return conn
In my case I think it was an access issue. I saved the SQLite files to "C:/Program Files (x86)/sqlite". I CD'd there, ran sqlite3, and created a database called test.db:
As you can see, I ran .database, which told me the .db file was created in the same directory, so I went to confirm in File Explorer, and it wasn't there:
Curiously the database was working correctly in spite of this.
It was only through trial-and-error that I discovered that I could save in some locations, but not others. It appears to me that SQLite can't save to locations that require elevation. In my case, moving from Program Files to My Documents made the issue go away.
I find it quite irritating that SQLite doesn't just tell me "access denied" instead of trying to be clever and saving to some location that I can't even find.
In Windows machines (Windows 2010), by default, the new SQLite database files will be stored in the same folder where Sqlite3.EXE application is stored in your machine. However , we can create a new folder in Windows and within sqlite> prompt, you may use the .cd to change to the new working directory.
It is a good idea to give a .db file extension to the new database files that you create (even though it is not mandatory to have any file extension)
The SQLite command, .databases will show the default database "main" or currently created or currently opened database or all "attached" database files with file path. The .attach is useful to attach more than one database file to the current connection when we want to work with tables belonging to different databases.
Regards,
Biju Joseph N.,
Houston TX, USA (January 12, 2023)
the database path will be displayed, when using .databases
SQLite is created in your python directory where you installed the python.
SQLit Database is simply a file where your local data is stored on your local machine
In Windows 10 if in the prompt command the path where you start sqlite is
C:\users\USER_NAME
You can find it in the user home folder.
The .db file is stored where you start the sqlite command.
I hope this solve the issue
Related
I'm building a small app with a local in memory database using Delphi 10.3 with FireDAC set to SQLite.
What is de default path to the database file that SQLite uses? (i.e. Database parameter is left blank)
I want to transfer the database file to another PC. I suppose it has the .db file extension, but I'm unable to locate the file.
from http://docwiki.embarcadero.com/RADStudio/Sydney/en/Using_SQLite_with_FireDAC:
"To create and open an SQLite in-memory database use the following
parameters:
DriverID=SQLite Database=:memory: Or just leave the Database parameter
empty:"
This made me think that there should be a file that eventually stores the data, but it turns out there is none. All data is lost after the database is free'd.
By definition "in memory" means no file. If you need a file for your data then add a filename (complete with path) to the Database value in TFDConnection's Params.
You can do it in the object inspector at design time or by code at run time it looks like:
FDConnection1.Params.Values['Database'] := 'C:\ProgramData\YourCompany\YourApp\YourFile.sqlite3';
Of course it is better to set the path by querying Windows for the location of "Program Data".
I'm finding that new sqlite3 database files are locked before any use that I am aware of.
sqlite3 new.sqlite
sqlite> SELECT * FROM SQLITE_MASTER;
Error: database is locked
lsof on the new file is empty. Copying the database file to a new location doesn't help. Permissions on the file are OK.
How else can I determine why a new sqlite3 file might be locked?
Looking at the docs, my best guess is that this is occuring because the database file is on an NFS mount for Vagrant. According to the docs:
One should note that POSIX advisory locking is known to be buggy or
even unimplemented on many NFS implementations ... Your best defense
is to not use SQLite for files on a network filesystem.
https://www.sqlite.org/lockingv3.html
I was able to resolve the issue by setting file permissions on the mounted folder on the host machine.
I have created an Oracle Directory on my local computer (c:\temp),
and as an example I also put several files inside that directory:
word.docx
excel.xls
pic.jpeg
pdf.pdf
My question is how I can get all the filenames inside that directory from PL/SQL?
Thank you
You can't. PL/SQL doesn't provide a function to list the contents of a directory.
Assuming that the Oracle database is installed on your local server (the database generally cannot access files stored on the client file system) you can, however, create a Java stored procedure that lists the contents of an operating system directory and call that from PL/SQL. The thread I links to provides one implementation of this sort of procedure. There are other implementations floating around on the internet as well.
I've just started to work with Node-webkit, and think it's great.
I've setup a db using the "Web SQL Database" option, mentioned here, and it seems to work well. Much like Sqlite, which I'm a bit familiar with.
From the docs, this is implemented using sqlite, so I'd like to be able to find the actual db file this create on disk and look at it with a Sqlite editor, like sqliteman.
Where is the db file saved to?
I couldn't find it in the docs, or by googling it ;-)
Since node-webkit version 0.6.1, you may retrieve the dataPath from the App object. The WebSQL files will be stored within the databases folder.
Wiki: https://github.com/rogerwang/node-webkit/wiki/App
Get the application's data path in user's directory.
Windows: %LOCALAPPDATA%/;
Linux: ~/.config/;
OSX: ~/Library/Application Support/ where is the field in the manifest.
Example:
require('nw.gui').App.dataPath;
I'm on a mac, and I used the tool Sloth to see the files that are opened by an application... Basically it's a GUI version of the command line lsof (list open files)
It pointed me to the following path:
~/Library/Application Support/YOUR_APP_NAME/databases/file__0/
and the sqlite db file was in there!
I have downloaded the "Precompiled Binaries for windows" for the "SQLite" from here. I opened the command-line-shell and followed this, creating one table named "tbl1".
now I am looking at my desk trying to find the database file which contains tbl1, but I can't find it anywhere.
my question is: after creating a database in the SQLite, where the database file is stored ? i.e.: what is the path of my created-database ?
I am using windows7 and have basic knowledge about SQL and database
By default (if no additional path is specified), the database is created in the current working directory.
That is, sqlite.exe ex1 creates the "ex1" database in the current directory. (Use cd from the same command shell to see what what the current working directory is.)
On the other hand, sqlite.exe C:\databases\ex1 would create the "ex1" database in the "C:\databases" directory.
To create the database on the desktop for the current user, something sqlite.exe "%USERPROFILE%\Desktop\ex1" should work. (This uses an environment variable called USERPROFILE which is expanded and used as part of the path.)
The same principle holds for any SQLite connection - the path to the database file is first resolved; either relative (as in the first case) or absolute (as in the second and third).
It creates the DB file in the given file path else by default it will create the file in your current working directory. If you can't find it then just search for the .db file inside your current project directory.