How do I use SQLite to read data from the Firefox cookies file? - sqlite

In my Firefox profile directory there is a cookies.sqlite file which holds the data for Firefox's cookies. I grabbed the Firefox SQLite Manager extension and loaded this file, which works, but how can I use plain query commands to read the cookies out of that file?
This is what I've tried so far:
$ sqlite3 cookies.sqlite
sqlite> SELECT * FROM dbname.sqlite_master WHERE type='table';
SQL error: file is encrypted or is not a database
I can't even list the tables, so I'm not able to start trying to list the cookies yet. If I can connect I'd like to be able to read and write data there, but I'm new to SQLite.

I had the same problem trying to read the cookies.sqlite file on Mac OS 10.6.8 (Snow Leopard). I downloaded SQLite 3.7.10 from http://www.sqlite.org/download.html and then I could open the file.
Here's a walkthrough of what I did...
Download SQLite 3, go to your downloads folder and unzip the file so that you now have a new SQLite 3 sitting in your downloads folder.
Open up a new finder window, press CMD + Shift + G, in the 'go to' dialog that pops up enter ~/Library/Application Support/Firefox/Profiles and then press return.
Presuming you only have one Firefox profile, you should see a folder here called XXXXXXXX.default (where the XXX string will be some random characters). Open this folder, or if you have more than one profile, open the folder of the profile you are looking for.
Inside you will find the cookies.sqlite database file, you can use this here directly, but you might want to make a copy somewhere else to use without risk of messing up the one that Firefox uses. If you want to use the Firefox one directly then I think you have to quit Firefox first, otherwise it has a lock on the file.
Open a new terminal window, and drag the sqlite3 binary from the downloads folder to the terminal window, this should enter the path to sqlite3 onto the command line.
Now, drag the cookies.sqlite3 database (the original or your copy) to the terminal, press return in the terminal.
If all goes well you should get the sqlite> command prompt. If you enter .tables you should see the table moz_cookies, which you can then query and investigate further.
The following commands might help:
.mode column
.headers on
select * from moz_cookies where domain = '.stackoverflow.com';
You should see all the values stored in your cookie for this site.
If you want to update the existing sqlite3 on your Mac, I did sudo mv /usr/bin/sqlite3 /usr/bin/sqlite3.old (just in case of any future problems, I can move it back again) and then sudo mv ~/downloads/sqlite3 /usr/bin/sqlite3.

I was able to open it with DBeaver, an open source universal database manager.

Use sqlite3
sqlite3 file.sqlite
Then use the below command to view the tables
.tables

Related

How do I run SQL commands through Notepad++?

I am trying to start out using Notepad++ to run SQLite commands. I have tried following two brief YouTube tutorials to get me going. I can run the initial .bat file, but still cannot run the .sql file.
I have a Windows system environment Path variable set to the folder containing sqlite3.exe
"C:\Users\Adam\sqlite\"
I have saved the following file RunSQLite.bat in the folder containing sqlite3.exe
sqlite3.exe testDB.db
I have created a second file queries.sql
SELECT 34;
When I try to run queries.sql from Notepad++, using the RUN command:
C:\Users\Adam\sqlite\RunSQLite.bat "$(FULL_CURRENT_PATH)"
the only file that appears to run is RunSQLite.bat, giving the output:
SQLite version 3.36.0 2021-06-18 18:36:39
Enter ".help" for usage hints.
sqlite>
Can anyone tell where I have gone wrong?
Thanks in advance.
aphopk
This C:\Users\Adam\sqlite\RunSQLite.bat "$(FULL_CURRENT_PATH)" will do exactly the same thing if run at the shell. RunSQLite.bat does not take any arguments so the Run command in npp is working as expected.
sqlite3 takes input from an external file with the .read command.
Path issues notwithstanding a bat file something like this should accomplish the task:
sqlite3.exe testDB.db ".read %1"
Notepad++ is a text editor, so you can now use it to edit your SQL file. After selecting the Language > SQL, Notepad++ will highlight SQL syntax as you type. Try typing some SQL, like
SELECT "Hi";
SELECT * FROM mydatabase WHERE id LIKE 'ID%';
You will see color, bold, and other possible formatting applied to the text you type. If you save the file as something.sql, and then load something.sql in your SQL client, the client will run the SQL commands from that file. If you have an existing somethingElse.sql file, you can open it in Notepad++, which will auto-recognize that it’s SQL and apply the syntax highlighting, allowing you to edit it and save it.
By using the Run > Run dialog, you can run an arbitrary command. For example, if your SQL client has a command-line mode accessed thru sqlclient.exe, you could type
c:\path\to\sqlclient.exe $(FILE_NAME)
If you just run it, that probably won’t show you any results… but if you ran
cmd /k c:\path\to\sqlclient.exe $(FILE_NAME)
It will open a new cmd.exe Windows command prompt, and show the output from that file.
If instead of running, you hit “SAVE”, you can give it a name (which will end up later in the Run menu), and/or a keyboard shortcut, so that you can easily re-use that many times.
If you want to do something more fancy, use the NppExec plugin, which includes a better batch/scripting language. Once again, you can save the NppExec script, and make it show up in the Macro menu.
If Python is a programming language you know or could learn (or if, like me, you know enough other programming languages that you can fake the Python), then the Python Script plugin will allow you to do even fancier stuff. (Python is a complete programming language, and has many libraries written, which could act as an interface between your SQL source file and your database engine; PythonScript has access to a full python2.7 interpreter. For example, you could write a script in Python which executes the commands from your SQL, grabs the results from your database engine, and displays them in Notepad++, either inline with your original SQL code, or in a new text document. You are really limited only by your imagination and knowledge of Python.)

How to browse sqlite data in xamarin?

I have a list view in my app, some data is saving to the database before populating list view.
My problem is that can't see the data, and how to verify the data is stored in the database.
I am giving the solution for Visual Studio 2015 (worked for Xamarin).
Locate the database file mentioned in above image, and click on Pull button as it shown in image 2.
Save the file in your desired location.
You can open that file using SQLite Studio or DB Browser for SQLite to verify your data is saved.
You can use use a SQLite browser, such as the open-source multi-platform DB Browser for SQLite, or another tool of your choice.
Getting access to the sqlite file is the next thing:
iOS Simulator:
/Users/administrator/Library/Application Support/iPhone Simulator
You can browse simulator files from that directory in Mac OS X.
Android Emulator:
You can use the command line via adb shell command for browsing file system:
ls - list current directory
cd - change current directory
Once you find the Sqlite file for your app, you can use the pull cmd for copying the file from device (or emulator image):
adb pull /sdcard/file.txt file.txt
I solved this problem in a few steps:
On Windows:
Download a SQLite viewer, for example SQLiteStudio.
Find where the .db or .db3 file is stored, i did it this way:
var databasePath = Path.Combine(FileSystem.AppDataDirectory, "localDB.db3");
Console.WriteLine(databasePath);
For me the path was: /data/user/0/com.companyname.[name]/files/localDB.db3
Find where the Android Debug Bridge (adb) .exe is stored. For me it was stored at: C:\Users[user]\AppData\Local\Android\Sdk\platform-tools. (AppData is a hidden folder, so make sure that hidden folders are visible.
Open a command prompt at this folder.
Try to copy the database file to a local folder on your machine by entering the following line into the command prompt:
adb pull [path to database] [path to local folder]
results in:
adb pull /data/user/0/com.companyname.[name]/files/localDB.db3 C:\Users\[user]\Desktop
If you get an error "Failed to stat remote object ... Permission denied", you have to make sure you have root permission. To do this, enter the following line in the command prompt:
adb root
Try to copy the file again.
If the file is succesfully copied, open it with SQLiteStudio.
et voila
Here is how you can access the sqlite database file in xamarin forms using Rider IDE:
Set your db path
private string GetDatabasePath()
{
return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "db.db");
}
Logging Environment.GetFolderPath(Environment.SpecialFolder.Personal) prints this path on my device
/data/user/0/com.companyname.landpriceexplorer/files
Click the Device File Explorer tab on the right side.
Search for the database file in the device file explorer.
Double click the file to add to the data source.
Open the Database tab and browse your data there.

Getting started with SQLite on windows, why isn't it outputting anything?

I've just started using SQLite, following the tutorials here and I'm using this on windows. I've got sqlite3.exe extracted to a folder on my desktop, and am running the following line in a command prompt to test it:
sqlite3 test.db
which the official documentation claims should create a file called test.db to work with. However, it doesn't appear to be doing anything, no files are created and it gives no errors or success messages, just another sqlite> prompt. Am I missing something to get this working on windows 7? Thanks.
If the database file does not exist, SQLite starts with an empty database.
The file itself will not be created until you actually write to the database.
Try creating something:
CREATE TABLE Test(some stuff);

Accessing SQLite database in android emulator

i am working on an android app which stores data in sqlite db i want to be able to access the data that is currently stored in the emulator. How do i go about connecting to it and perform sql operations.
Open a terminal window
Get a list of AVD devices by entering: adb devices
If your terminal can't find the adb command then have a look at this post for OSX or Windows.
Start a shell connection to your AVD by entering: adb -s emulator-xxxx shell
Browse to the databases location: cd data/data/your.package.name/databases
Type sqlite3 xxxxx.db
For SQLite shell instructions see Command Line Shell For SQLite
There is an example on that link about "sqlite command in adb"
In the eclipse, go in to FileExplorer, here you will find three root folders: here go in to
1.data
2.go in to data folder again
3. here you will find all the package names of the applications.
4. once you find your projects particular package, click on it.
5.you will see a folder called 'databases'
6.in that folder you will get the sqlite db file.
7.in order to pull it out of the emulator, just click on it and on the
top right corner you will find 3 icons: one to delete, one to pull a file from device and the other to push file in the device.
8. after selecting the db file, click on the icon that says 'pull a file from the device'.
Thats it mate ...cheers.

Where is SQLite database stored on disk?

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

Resources