couple more questions about sqlite

John Machin sjmachin at lexicon.net
Fri Aug 18 19:23:54 EDT 2006


John Salerno wrote:
> andychambers2002 at yahoo.co.uk wrote:
> >> 2. What's the difference between sqlite and pysqlite? Do you need both,
> >> just one, or is one an older version of the same thing?
> >
> > To access your database from python you need both (or some alternative
> > to pysqlite)
>
> I can understand this in terms of MySQL being one thing, and mysqldb
> being the necessary module for Python to use MySQL. But in 2.5, for
> example, which comes with sqlite3, is this all you need, or do you still
> need pysqlite? Or are these two different things that can access the
> sqlite system? (I guess I kind of thought there would be just one
> standard module used for each type of database, such as mysqldb being
> the one used for MySQL.)

Your confusion is quite understandable. I started looking at sqlite
when the announcement that it would be included in Python 2.5 came out.
Puzzlement reigned. I ended up with the following up the front of my
experimental module:

import sys
PY_VERSION = sys.version_info[:2]
if PY_VERSION >= (2, 5):
    import sqlite3
else:
    from pysqlite2 import dbapi2 as sqlite3
print "Python  :", sys.version
print "pysqlite:", sqlite3.version
print "sqlite  :", sqlite3.sqlite_version

Interestingly, at the time pysqlite2 was providing a version of the
underlying C library that was 2.4-compatible but *later* than the
version that came with 2.5a2 [I haven't checked since].

So, if you want to try out sqlite now, download pysqlite2 and use it
with Python 2.4. If you have the 2.5 release candidate, you can try
your code with it as well, using version-detecting code along the above
lines.

I would strongly recommend for a learner of SQL and the Python DBAPI:
(1) start with sqlite; it's great, and there's minimal admin involved
(2) download the command-line utility from the sqlite website -- you'll
need it for the minimal admin, plus it's handy for quick one-line SQL
statements, peeking at the schema, etc.

HTH,
John




More information about the Python-list mailing list