[Zope-dev] SQL-Methods Through-the-FileSystem

Johan Carlsson johanc@torped.se
Sun, 26 Nov 2000 23:22:59 +0100


> Johan Carlsson wrote:
> > 
> > > Seb:
> > > > Does anybody have a good suggestion how to
> > > > develope SQL Method ftfs (through the filesystem)
> > > > rather than ttw.
> > > >
> > > > Perferably in someway similare to the HTMLFile way
> > >
> > > try something like this:
> > >
> > >   from Products.ZSQLMethods.SQL import SQL
> > >   import PoPy
> > >
> > >   def manage_add_user(self,email,password):
> > >
> > >     conn = 'PoPy_database_connection'
> > >     self.sql_add_user=SQL('sql_add_user', '', conn, 'email password', _sql_add_user)
> > >
> > >     _sql_add_user = """
> > >     insert into tbl_users(email,password)
> > >     values (
> > >       <dtml-sqlvar email type=string>,
> > >       <dtml-sqlvar password type=string>
> > >     )
> > >     """
> > 
> > Hi Seb,
> > 
> > I guess I could skip putting it in a method and create the SQL instance
> > as a attribute of the class (that I currently would be working on)?
> 
> yes
> 
> > Why do I need to import the database module?
> 
> sql methods are bound to database connections, you could instantiate one
> without, but than you wouldn't be able to use it. 

What I mean is that if I acquired the DA connection, the import would be unnecessary?
 
> > Couldn't I just try to locate/create a DA when my class is instantiated?
> 
> you could, the search routine in /lib/python/Products/ZSQLMethods/SQL.py
> is a good starting point

Yes, I know, for ones I turned to zope-dev before diving into the source ;-)
 
> > Would it be poor design to create a DA connection as an attribute of the class?
> > Or would it be perferd to create it in the __init__ as a instance attribute?
> 
> do you really want to create a new db connection for every instance of
> your class?

I might, if each instance should connect to  its own database.
For instance I could have different databases (with different user identities)
for different customers sharing the same host machine.

Thanks Seb and Ender, I really got a head start.
Johan