Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Opening a SQLite database in readonly mode

7 views
Skip to first unread message

Paul Moore

unread,
Jul 6, 2009, 8:05:02 AM7/6/09
to Python List
The SQLite documentation mentions a flag, SQLITE_OPEN_READONLY, to
open a database read only. I can't find any equivalent documented in
the Python standard library documentation for the sqlite3 module (or,
for that matter, on the pysqlite library's website).

Is it possible to open a sqlite database in readonly mode, in Python?

Thanks,
Paul.

Joshua Kugler

unread,
Jul 6, 2009, 4:45:45 PM7/6/09
to pytho...@python.org

Yes, but most likely not with pysqlite. The python sqlite3 module in the
standard library, and the pysqlite module are both DB-API compliant, which
means they probably do not have a method to open the DB read only (as that
is usually enforced at the user permission level).

If you want to use that flag, take a look at APSW. It is a very thin layer
on top of the SQLite C API, and thus supports everything that the C API
supports. It is not, however, DB API compliant, but is very close so not
hard to pick up.

BTW, APSW is written by the same author as pysqlite.

j


Paul Moore

unread,
Jul 6, 2009, 6:50:08 PM7/6/09
to Joshua Kugler, pytho...@python.org
2009/7/6 Joshua Kugler <jos...@joshuakugler.com>:

Excellent, thanks. I'll have to think whether I want the extra
dependency but at least I know it's possible now.

Thanks for the pointer.
Paul.

Roger Binns

unread,
Jul 7, 2009, 2:16:10 AM7/7/09
to pytho...@python.org
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Joshua Kugler wrote:
> BTW, APSW is written by the same author as pysqlite.

Not even remotely true :-) pysqlite was written by various people, with
the maintainer of the last several years being Gerhard H�ring. I am the
(sole) author of APSW and have not contributed any code to pysqlite
although ideas have flowed freely between the projects and we share a
mailing list.

I started APSW in late 2004 because I wanted to use SQLite from Python
rather than using a layer that pretended SQLite was like other
databases. There were various quirks of pysqlite I also didn't like
(many since corrected) and so scratched my itch.

If you are just doing simple queries then there isn't much apparent
difference. If you want to be a "power user" of SQLite then APSW is for
you. SQLite has many cool features such as virtual tables (you provide
the underlying data for the SQL queries to work on) and VFS (you provide
the file access). See this link for more details:

http://apsw.googlecode.com/svn/publish/pysqlite.html

Roger
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkpS6CUACgkQmOOfHg372QS0/gCgiHD9ukUlQYJGCIMWb9hNMLCM
Y/cAnid4dAeFHIdLBmKzGsXrvANkvhR5
=U0wg
-----END PGP SIGNATURE-----

Joshua Kugler

unread,
Jul 7, 2009, 5:07:55 PM7/7/09
to pytho...@python.org
Roger Binns wrote:
> Joshua Kugler wrote:
>> BTW, APSW is written by the same author as pysqlite.
> Not even remotely true :-)

Sorry about that...since pysqlite and APSW are both discusses on the
pysqlite list, I had made an incorrect assumption. Oops.

j

Joshua Kugler

unread,
Jul 9, 2009, 1:17:25 PM7/9/09
to pytho...@python.org
Joshua Kugler wrote:
> Sorry about that...since pysqlite and APSW are both discusses on the
> pysqlite list, I had made an incorrect assumption. Oops.

"are both discusses?" Yeef, I must have been out of it. Discussed, thank
you. :)

j

Aahz

unread,
Jul 9, 2009, 10:00:21 PM7/9/09
to
In article <mailman.2905.1247159...@python.org>,

Who's Yeef? ;-)
--
Aahz (aa...@pythoncraft.com) <*> http://www.pythoncraft.com/

"as long as we like the same operating system, things are cool." --piranha

0 new messages