[Yum-devel] [PATCH] Support newer pysqlite for yum proper

Tim Lauridsen tim at rasmil.dk
Fri Oct 27 13:07:26 UTC 2006

Jeremy Katz wrote:
> And here's the biggest chunk needed for python2.5 and/or the newer
> pysqlite support.
> The big change with the newer version of pysqlite is that it actually
> follows the python DB-API[1].  This means that (by default) rows are
> just returned as tuples.  Luckily, it's easy to make it so that we can
> get back dict-like rows.  So half of the changes here are going from
> something like row.name -> row["name"].
> The other (and more annoying) change is that pysqlite now uses qmark
> instead of pyformat for escaping in queries.  Which means that to
> support both we either have to
>   a) do a conversion on the fly
>   b) maintain two copies of the code
> Since b seems like it would be a maintenance nitemare, I've gone for a.
> First, I converted everything to qmark style (this uses ? instead of %s
> for parameters) and then have imported a chunk of Wichert Akkerman's
> python-dhm so that we can convert on the fly to pyformat style escaping.
> While ugly, it seems to work and I've done some very basic smoke testing
> with both python 2.5 and python 2.4 and things seem to be fine with
> both.  More testing is definitely needed, though.
> Other thoughts or opinions on ways to go about this?  I'm more than open
> to listening because I really don't like this as it stands :-/  
> Jeremy
> [1] http://www.python.org/dev/peps/pep-0249/
I agree with your choice to to conversion on the fly, i dont think it is 
so ugly, the code is as easy to read as it was before.

The only other way is can think of is to make a custom Conection & 
Cursor class there inherit from the original sqlite classes

here is some psudo code to show what i mean.


    import sqlite3 as sqlite
    SQLITE3 = True
except ImportError:
    import sqlite 
    SQLITE3 = False

def connect(db):
    return Connection(db)

class Connection(sqlite.Connection)

    def __init__(self,db):

    def cursor(self):
	return Cursor()

class Cursor(sqlite.Cursor)
    def __init__(self):

    def execute(self,sql):
	if SQLITE3:
	return sqlite.cursor.execute(sql)


import sqlitecust as sqlite


More information about the Yum-devel mailing list