after 4 years of python hacking, i'm still shocked at how fast it is
to work with it. in a few minutes i had my existing connection going,
with a few lines of code (there is a little hack for resetting the
registry):
from sqlobject.postgres.pgconnection import PostgresConnection
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
# LOCAL DECLARATIONS
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D
# Reset the class registry to allow reloading.
classregistry.MasterRegistry =3D classregistry._MasterRegistry()
classregistry.registry =3D classregistry.MasterRegistry.registry
#--------------------------------------------------------------------------=
-----
#
class ExistingPgConnection(PostgresConnection):
"""
Provide a connection object for SQLObject that reuses the existing
connection.
"""
def __init__(self, connection):
"""
Initialize with an existing, opened connection from psycopg.
"""
PostgresConnection.__init__(self, autoCommit=3DFalse)
self.existing_connection =3D connection
def makeConnection(self):
# Note: support for autocommit member has been removed in psycopg2.
return self.existing_connection
then in my code i do:
from sqlobject import *
__connection__ =3D ExistingPgConnection(database.m_connection)
class Person(SQLObject):
...
voila!
1. now, to be fair, it only "seems" to work, but i would really need
to dig into that class registry issue to find out if the hack is
enough of a reset. i need to reset the registry because my framework
has an auto reload feature which make it really fast to develop and
i'm not giving that up...
2. also, i'm not sure that returning the same single connection from
makeConnection() is kosher with the connection pool code. i'm not
very familiar with sql databases... why do we need connection pools?
any issue that might help make this clean would be appreciated
(anything off thetop of your head)... thanks
cheers,
On Sat, 8 Jan 2005 22:33:42 +0100 (CET), Philippe Normand
<phil@...> wrote:
>=20
> Le 8/1/2005, "Carlos Ribeiro" <carribeiro@...> a =E9crit:
>=20
> >
> >I had the same issue. I don't think that this is a problem with
> >SQLObject itself; it depends a lot on the way you write your code.
> >Loading the same module twice with a simple "import" should not be a
> >problem, but anything that runs the code more than once will make it
> >fail. I believe that this can be triggered in some situations:
> >
> >- by a reload() call, which makes the module code to be re-executed.
> >
> >- by importing the same module from different locations, in such a way
> >that the internal module cache used by Python isn't able to tell that
> >the module was actually imported before. In this case the module code
> >is effectively run twice, which may also trigger the problem.
> >
>=20
> But it's exactly what i am doing. The problem is that the
> classregistry's addClass hook is too restrictive. If the class is
> already in the registry it should not raise an error (in my opinion).
> Instead it should simply exit from the hook.
>=20
> Can other sqlo dev explain why addClass raises a ValueError such a way ?
>=20
> Philippe
>=20
> -------------------------------------------------------
> The SF.Net email is sponsored by: Beat the post-holiday blues
> Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
> It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
> _______________________________________________
> sqlobject-discuss mailing list
> sqlobject-discuss@...
> https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss
>
|