[ANN] pysqlite 2.0.alpha3

Gerhard Haering gh at ghaering.de
Fri Apr 22 01:34:32 CEST 2005

pysqlite 2.0.alpha3

I'm glad to announce pysqlite 2.0.alpha3, which will be the last alpha
release.  Documentation and more testing will be what I'm concentrating
on in the beta test phase, so here's the explanation of the new features
within the change log.

Download it from Sourceforge:

Changes since 2.0.alpha2

- Fixed various memory leaks and refcount problems.

- Connection, Cursor and row factories.

    o Connection factory: Subclass pysqlite2.dbapi2.Connection and
    provide the parameter to pysqlite2.dbapi2.connect to use that class

    o Cursor factory: Subclass pysqlite2.dbapi2.Cursor and provide the
    parameter to the cursor() method of the Connection class so that
    cursors of your class are created.

    o Row factory: set the row_factory attribute in your cursor to a
    callable that accepts a tuple and returns the "real" row object.

    Combine the three for maximimal power and convenience like in the
    following example, where we transparently use the db_row module from
    http://opensource.theopalgroup.com/ to be able to access columns by
    name instead of by index. A fast alternative to PgResultSet in
    pysqlite 1.x.

    from pysqlite2 import dbapi2 as sqlite
    import db_row

    class DbRowConnection(sqlite.Connection):
        def __init__(self, *args, **kwargs):
            sqlite.Connection.__init__(self, *args, **kwargs)

        def cursor(self):
            return DbRowCursor(self)

    class DbRowCursor(sqlite.Cursor):
        def execute(self, *args, **kwargs):
            sqlite.Cursor.execute(self, *args, **kwargs)
            if self.description:
                self.row_factory = db_row.IMetaRow(self.description) 

    con = sqlite.connect(":memory:") #, factory=DbRowConnection)
    cur = con.cursor(factory=DbRowCursor)
    cur.execute("create table test(i integer)")
    cur.execute("select 4+5 as foo")
    for row in cur:
        print ">", row
        print row["foo"]
    print cur.fetchone()["foo"]

- The first parameter to .execute() and .executemany() can now also be a
  Unicode string:

  cur.execute(u"insert into person(name) values ('Häring')")

- The conversion in SQLite types mode for TEXT is now unicode, not UTF-8
  encoded bytestrings.

  i. e. if the column type is TEXT, then you get back unicode objects now.

- Implemented user functions and aggregates.

    Where a number of parameters is expected, -1 means variable number
    of arguments.

    The functions and aggregates must return values of the type NoneType, int,
    float, str, unicode or buffer (BLOB).

    Example code:

    def f(*args):
        return sum(args)

    class Sum:
        def __init__(self):
            self.sum = 0

        def step(self, x):
            self.sum += int(x)

        def finalize(self):
            return self.sum

    con = sqlite.connect(":memory:")

    # Syntax: function name, number of parameters, callable
    con.create_function("myfunc", -1, f)

    # Syntax: aggregate name, number of parameters, aggregate class
    con.create_aggregate("myaggr", 1, Sum)

- Added MANIFEST.in file, so that bdist_rpm and sdist will work.

- Release GIL during SQLite calls.

- After a cursor.executemany, cursor.rowcount now delivers the sum of all
  changes, not only the changes in the last call to the prepared statement.

- Implemented checks that the SQLite objects are used from the same
  thread they were created in. Otherwise raise a ProgrammingError.

  If you're 100% sure that you want to use the same connection object in
  multiple threads, because you use proper locking, you can turn the
  check of by using the parameter ''check_same_thread=0''.

- Allow for parameters to be dictionaries, too. Then, the name-based
  binding in SQLite 3 is used:

    cur.execute("select name from test where name=:name", {"name": "foo"})

- Improved error handling.

- Allow for explicit transaction start:

    >>> con = sqlite.connect(":memory:", no_implicit_begin=True)
    >>> con.begin()
    >>> con.rollback()
    >>> con.commit()

- Implemented cursor.lastrowid

- Avoid code duplication: handle execute() and executemany() internally
  in the same function.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/python-announce-list/attachments/20050422/8325befd/attachment.pgp

More information about the Python-announce-list mailing list