# HG changeset patch # User James Bergstra # Date 1232332768 18000 # Node ID d2d582bcf7dc23987ac55fda329152c297402378 # Parent 7041749cf804d87cb268a8f3f3685fbcda0f6f03 api0 and sql seem to work with session closing diff -r 7041749cf804 -r d2d582bcf7dc pylearn/dbdict/api0.py --- a/pylearn/dbdict/api0.py Sun Jan 18 21:14:14 2009 -0500 +++ b/pylearn/dbdict/api0.py Sun Jan 18 21:39:28 2009 -0500 @@ -408,7 +408,7 @@ def __iter__(h_self): return h_self.query.__iter__() - def insert_kwargs(h_self, **dct): + def insert_kwargs(h_self, session=None, **dct): """ @rtype: DbHandle with reference to self @return: a DbHandle initialized as a copy of dct @@ -419,10 +419,9 @@ @param dct: dictionary to insert """ - rval = h_self._Dict() - if dct: rval.update(dct) - return rval - def insert(h_self, dct): + return h_self.insert(dct, session=session) + + def insert(h_self, dct, session=None): """ @rtype: DbHandle with reference to self @return: a DbHandle initialized as a copy of dct @@ -433,8 +432,15 @@ @param dct: dictionary to insert """ - rval = h_self._Dict() - if dct: rval.update(dct) + if session is None: + s = h_self.session() + rval = h_self._Dict(s) + if dct: rval.update(dct, session=s) + s.commit() + s.close() + else: + rval = h_self._Dict(session) + if dct: rval.update(dct, session=session) return rval def query(h_self, session): @@ -555,7 +561,7 @@ """ db_str ='postgres://%(user)s:%(password)s@%(host)s/%(database)s' % locals() - engine = create_engine(db_str, pool_size=pool_size, echo=echo, poolclass=poolclass) + engine = create_engine(db_str, echo=echo, poolclass=poolclass) return db_from_engine(engine, **kwargs) diff -r 7041749cf804 -r d2d582bcf7dc pylearn/dbdict/sql.py --- a/pylearn/dbdict/sql.py Sun Jan 18 21:14:14 2009 -0500 +++ b/pylearn/dbdict/sql.py Sun Jan 18 21:39:28 2009 -0500 @@ -44,7 +44,6 @@ c = psycopg2.connect(user=user, password=password, database=database, host=host) c.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_SERIALIZABLE) return c - pool_size = 0 this.engine = create_engine('postgres://' ,creator=connect ,poolclass=poolclass