Revision 10 as of 2008-02-01 18:41:34

Clear message

SQLite

URL

http://sqlite.org/

licence
Sources are uncopyrighted. Use for any purpose.
platforms
Built and tested under Linux and Win2K.

Pros

I think SQLite may be a good replacement for gadfly, because:

Cons


DB API 2.0 Drivers

pysqlite

URL

http://pysqlite.org/

SourceForge

http://sourceforge.net/projects/pysqlite

licence
zlib/libpng License
platforms
Windows 95/98/2000/XP, POSIX, MacOS X
Python versions
2.1 or later (1.x branch)/2.3 or later (2.0 branch). Included in Python 2.5.

Extensions to DB API

Other Drivers

APSW

URL

http://www.rogerbinns.com/apsw.html

licence
zlib/libpng license
platforms
Windows, POSIX
Python versions
?

Programming Model

APSW is a SQLite 3 wrapper that provides a thin layer over SQLite 3. Although APSW looks vaguely similar to the DBAPI, it is not compliant with that API and instead mirrors the way SQLite 3 works.


Supported Python Applications

Usage Notes

The following solution was difficult to discover with the available documentation (http://pysqlite.org/ was unavailable). If this page can be found by others searching for answers, it may save many hours of frustration.

Id of Most Recent Row

After creating a new row in a table that uses AUTOINCREMENT to create the PRIMARY KEY, one may wish to determine the value of the new row-id, for example if the value is need for a new row in a related table that will be inserted next. The answer is to use the lastrowid property of the cursor class as in newId=c.lastrowid  shown below in a demo context. Tested in Python2.5.1 with the sqlite3 module:

           import sqlite3
           con = sqlite3.connect('demo.db')
           con.execute("""CREATE TABLE tbl (
               id INTEGER PRIMARY KEY AUTOINCREMENT,
               grp INTEGER)""")
           c = con.cursor()
           c.execute("""INSERT INTO tbl (grp) VALUES (0);""")

           newId = c.lastrowid

           print "New rowid =", newId
           c.close()
           con.close()

The result is printed: New rowid = 1

Unable to edit the page? See the FrontPage for instructions.