[SQLObject] SQLObject ported to pyPgSQL
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Simon W. <cs...@ba...> - 2003-09-01 07:42:33
|
Hi all, I've just discovered SQLObject and I absolutely love it. We use the pyPgSQL module from http://pypgsql.sourceforge.net/ rather than psycopg so I've ported SQLObject to it. Here's the code I added to DBConnect.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 if dsn is None: dsn = [] if db: dsn.append('dbname=%s' % db) if user: dsn.append('user=%s' % user) if passwd: dsn.append('password=%s' % passwd) if host: # @@: right format? dsn.append('host=%s' % host) dsn = ' '.join(dsn) self.dsn = dsn DBAPI.__init__(self, **kw) def makeConnection(self): return PgSQL.connect(self.dsn) 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] So far this seems to work fine but I haven't tested it exhaustively as I'm still learning my away around SQLObject itself. Thanks, Simon Willison http://simon.incutio.com/ |