Programmatically accessing Z SQL Methods
I've got a pretty solid understanding of how to get around Zope from the Product API point of view, and there is good documentation on using Z SQL Methods from the DTML point of view. I'm finding myself in the grey overlapping area, and there isn't a lot of documentation yet. I'm finding myself having trouble getting started. Here's a deal: If I get a boost up the learning curve with a few answers, I'll put it in a How-To once I understand it all. I would like the user to select the Database Connection when my Product is being added. When the Product installs itself, I want it to check the database it's been passed for the existance of a particular table. If it does not exist, I want to create said table and do some initial populating. So far my scheme for doing this involves adding a Z SQL Method to the current folder, putting some SQL in it, running it, putting some SQL in it, running it, etc, etc, and then removing it when I'm done. This seems like a stupid way to go about things. I'd much rather just be able to take my connection and submit some SQL programmatically. So, I guess question is simply, "How do I submit an SQL query, starting from a connection_id?" Thanks, Mike. -- --- | Mike Pelletier Work: 519-746-1607 /opeware! | Software Developer Home: 519-725-7710 --- | mike@zopeware.com Fax: 519-746-7566 http://www.zopeware.com | Zopeware is not endorsed by Digital Creations
Mike Pelletier wrote:
I would like the user to select the Database Connection when my Product is being added.
Take a look at the function SQLConnectionIDs(self) in lib/python//Products/ZSQLMethods/SQL.py It selects all avaiable Database conections ids.
When the Product installs itself, I want it to check the database it's been passed for the existance of a particular table. If it does not exist, I want to create said table and do some initial populating.
Some databases connectors have a standard api for querying tables and columns. The tab browse calls it. The problem is that not all DB connectors completely implements the api. The MySQL one, for example, doesn't implements it. With it you have to directly query the DB. If you have the connection id, you get the connection with: connection = getattr(self, self.connection_id) self is your product. Connection is an object that implements a __call__ method. You should make your query: dummy, result = self.connection().query(command) Oops! The query method returns a tuple, I don't remember what is the first returned value. I didn't used it. See the source.
So far my scheme for doing this involves adding a Z SQL Method to the current folder, putting some SQL in it, running it, putting some SQL in it, running it, etc, etc, and then removing it when I'm done. This seems like a stupid way to go about things. I'd much rather just be able to take my connection and submit some SQL programmatically. So, I guess question is simply, "How do I submit an SQL query, starting from a connection_id?"
I've did somenthing like it in the PMySQLInput wizard, see it in the contrib area. hope this helps, -- Paulo Eduardo Neves PUC-Rio de Janeiro Pager: Central: 292-4499 cod. 213 99 64 ou use a URL: http://www.learn.fplf.org.br/neves/mensagempager.html
participants (2)
-
Mike Pelletier -
Paulo Eduardo Neves