Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: DBI DBD::SQLite unable to open Firefox cookies.sqlite database

by Corion (Patriarch)
on Nov 29, 2022 at 12:31 UTC ( [id://11148438]=note: print w/replies, xml ) Need Help??


in reply to DBI DBD::SQLite unable to open Firefox cookies.sqlite database

The open manpage of SQLite also shows the ?immutable parameter when using the uri= form of connecting to a DB. With that, I am able to read the Firefox cookies from a live SQLite database while Firefox is running.

use strict; use warnings; use Data::Dumper; use DBI; use DBD::SQLite; my $mozilla_path = "$ENV{AppData}\\Mozilla\\Firefox\\Profiles"; opendir my $dh, $mozilla_path or die "Couldn't read Mozilla profiles directory $mozilla_path: $! +"; my ($profile) = grep { /\.default/ } readdir $dh; my $file = "$mozilla_path/$profile/cookies.sqlite"; $file =~ s!\\!/!g; die "DB file '$file' not found!" unless -e $file; print "sqlite DBD version: $DBD::SQLite::sqlite_version\n"; my $dsn = "dbi:SQLite:uri=file:///$file?immutable=1"; my $user; my $password; my %dbi_options = ( RaiseError => 1, PrintError => 1, sqlite_open_flags => 'SQLITE_OPEN_READONLY', ); my $dbh = DBI->connect($dsn, $user, $password, \%dbi_options); my $sth = $dbh->prepare(q(SELECT * FROM moz_cookies )); $sth->execute; print Dumper $sth->fetchall_arrayref({});

The URI needs to be different between Windows and Unixish path specifications, but the SQLite documentation has examples for all of them.

Replies are listed 'Best First'.
Re^2: DBI DBD::SQLite unable to open Firefox cookies.sqlite database
by Discipulus (Canon) on Nov 29, 2022 at 12:38 UTC
    Hello Corion,

    just to mention all combinations, I can read the live cookies.sqlite DB even commenting out the sqlite_open_flags => 'SQLITE_OPEN_READONLY'

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11148438]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 15:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found