0

The end goal is to modify Firefox cookies.sqlite db before starting Firefox.

At present, I want to display what tables are in the db. I copied the cookies.sqlite db to my desktop. I'm working with the db on my desktop.

This is my first time using sqlite. I copied some code, but I'm not able to read what tables are in the db. List of tables, db schema, dump etc using the Python sqlite3 API

Here is what I get in the terminal. I see the listing of the tables.

me $ ls cookies.sqlite 
cookies.sqlite
me $ sqlite3 cookies.sqlite
SQLite version 3.8.10.2 2015-05-20 18:17:19
Enter ".help" for usage hints.
sqlite> .tables
moz_cookies
sqlite> .exit
me $ # I run my python script
me $ ./sqlTutorial.bash 
SQLite version: 3.8.10.2
table records...
[]
more table records...
me $ cat dump.sql
BEGIN TRANSACTION;
COMMIT;
me $ 

python code. All I want to do is display the tables in the cookie.sqlite db.

#! /bin/python 

import sqlite3 as lite
import sys

con = lite.connect('cookie.sqlite')

with con:

    cur = con.cursor()    
    cur.execute('SELECT SQLITE_VERSION()')

    data = cur.fetchone()

    print ("SQLite version: %s" % data)

print ("table records...")

cursor = con.cursor()
cursor.execute("SELECT name FROM sqlite_master WHERE type='table';")
print(cursor.fetchall())

print ("more table records...")

with open('dump.sql', 'w') as f:
    for line in con.iterdump():
        f.write('%s\n' % line)
2
  • Ok. Found the error. Wrong db name :-o( should have been cookies.sqlite Commented Jun 15, 2015 at 1:50
  • Why didn't I get an error? I though python would error out on. con = lite.connect('cookie.sqlite') Commented Jun 15, 2015 at 1:53

1 Answer 1

2

As you noticed, the database name is cookies.sqlite not cookie.sqlite.

Why didn't I get an error? I though python would error out on. con = lite.connect('cookie.sqlite')

Connecting to a sqlite database either opens an existing database file, or creates a new one if the database didn't exist.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.