neves at inf
Mar 4, 1999, 2:42 PM
Post #2 of 4
Mike Pelletier wrote:
Re: Programmatically accessing Z SQL Methods
[In reply to]
> 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
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
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