

It is possible to write just for host_key, in but I think that the single comma could be simply overlooked. You need to ensure that Chrome is closed so that you can modify the database without possible conflicts.Changes to the SQLite database must be committed using the commit() method before close() or the end of the with block.You cannot execute a new query this way when you intend to continue processing the previous query’s results. This replaces the original cursor’s content. You process the cursor results in a for loop but inside the loop you execute another query using the (same!) cursor.Notice that we create a tuple for the parameters: (your_host_key,) This SQL query alone will do the work, there is no need to run it repeatedly in a loop ( for) or conditionally using if:Ĭursor.execute("DELETE FROM cookies WHERE host_key=?", (your_host_key,)).I think you want to filter (and delete) by host_key. You try to filter by a column id but it looks like there is no such a column. cursor.execute("DELETE FROM cookies WHERE id=?", row).Do not add new SQL queries inside the for loop - see below.Ĭurrently I see these problems in your program: When the block ends the database connection is automatically closed. You can extend my example by adding commands inside the with block. In the example it is a single value assigned to the single variable host_key. Python’s way to assign the values to individual variables is unpacking. Every row is a tuple consisting of the values in individual columns. When you iterate the cursor you are getting the individual rows. The tricky part for you could be the unpacking in the for loop: for (host_key,) in … With contextlib.closing(nnect(database_file)) as connection:įor (host_key,) in cursor.execute('SELECT DISTINCT host_key FROM cookies'):
#Sqlite manager chrome code#
Here is an example code listing distinct host_keys in Python: import sqlite3ĭatabase_file = '/mnt/c/Users/vaclav.brozik/AppData/Local/Google/Chrome/User Data/Default/Network/Cookies' They may be easier to use but can be a little overwhelming at the beginning. There are also GUI tools to play with SQL databases and queries. Notice that in the sqlite3 CLI you need to terminate the queries using semicolon (not needed in the Python’s execute() method). īefore the experiments terminate your Chrome (to have the database consistent) and copy the database to a new file to play with so you do not wreck you Chrome data. Sqlite> SELECT DISTINCT host_key FROM cookies LIMIT 5 Example of listing the database schema and first five host_keys: $ sqlite3 '/mnt/c/Users/vaclav.brozik/AppData/Local/Google/Chrome/User Data/Default/Network/Cookies'ĬREATE TABLE meta(key LONGVARCHAR NOT NULL UNIQUE PRIMARY KEY, value LONGVARCHAR) ĬREATE TABLE cookies(creation_utc INTEGER NOT NULL,host_key TEXT NOT NULL,top_frame_site_key TEXT NOT NULL,name TEXT NOT NULL,value TEXT NOT NULL,encrypted_value BLOB NOT NULL,path TEXT NOT NULL,expires_utc INTEGER NOT NULL,is_secure INTEGER NOT NULL,is_httponly INTEGER NOT NULL,last_access_utc INTEGER NOT NULL,has_expires INTEGER NOT NULL,is_persistent INTEGER NOT NULL,priority INTEGER NOT NULL,samesite INTEGER NOT NULL,source_scheme INTEGER NOT NULL,source_port INTEGER NOT NULL,is_same_party INTEGER NOT NULL,last_update_utc INTEGER NOT NULL) ĬREATE UNIQUE INDEX cookies_unique_index ON cookies(host_key, top_frame_site_key, name, path) You are going to use two languages (SQL and Python) so you need to have some knowledge of both of them. I would recommend you installing the sqlite3 command line interface and playing with SQL commands interactively there first.
