From: Simon W. <cs...@ba...> - 2003-10-05 09:30:52
|
Ian Bicking wrote: > Also, someone mentioned PyGreSQL support at some point, but I lost the > details. I tried adding it, but it acted weird, and I didn't try very > hard. Can anyone test what's in CVS and see what needs to be done? > Does anyone care about PoPy? That was me. Here's the code I added to DBConnection.py try: from pyPgSQL import PgSQL except ImportError: PgSQL = None __all__ = ['MySQLConnection', 'PostgresConnection', 'SQLiteConnection', 'DBMConnection', 'PyPgSQLConnection'] class PyPgSQLConnection(PostgresConnection): def __init__(self, dsn=None, host=None, db=None, user=None, passwd=None, autoCommit=1, **kw): assert PgSQL, 'PgSQL module cannot be found' if not autoCommit and not kw.has_key('pool'): # Pooling doesn't work with transactions... kw['pool'] = 0 self.db = db DBAPI.__init__(self, **kw) def makeConnection(self): return PgSQL.connect(database=self.db) def _queryInsertID(self, conn, table, idName, names, values): c = conn.cursor() q = self._insertSQL(table, names, values) if self.debug: print 'QueryIns: %s' % q c.execute(q) c.execute('SELECT %s FROM %s WHERE oid = %s' % (idName, table, c.oidValue)) return c.fetchone()[0] My PyPgSQLConnection class simply extends the existing PostgresConnection class and redefines the methods that differ for PyPgSQL. I haven't tested it formally (it was something of a 15 minutes hack) but I've been using it for a few weeks without running in to any problems. Cheers, Simon Willison http://simon.incutio.com/ |