[Zope] Using a database connection from an external method

Marius Kjeldahl marius@funcom.com
Thu, 23 Mar 2000 12:01:48 +0100


I'm still figuring out how to integrate stuff in and out of Zope, and
thanks to all the people who gave me the friendly advice that I should
stay away from storing blobs in databases (I kind of knew that already,
but guess I was to busy worrying about marshalling things in and out of
Zope).

Anyway, what I am trying to do now is create an external method that
will receive the REQUEST object with some fields AND the uploaded file.
This external method will insert a record into an SQL table and return a
unique ID which I will use for the filename for storing the image in the
local filesystem (I am not worried about LOTS of images in a single
directory - that can be solved by a more intelligent filesystem
[ReiserFS?] or by some clever directory indexing).

Assuming I am able to pull this off, it should be quite easy to pull the
image back in again using the LocalFS product or my own external method.

I guess the external method will be run in the same process and thread
as the Zope process itself, so I would really like to get hold of the
database connection from my database connection instance in Zope. 

From searching the lists, I have learned:

* How to get the ZODB instance using self._p_jar; but this is not what I
need. I need to get the database object for my MySQL database, not ZODB
* How to call ZSQL methods from external methods by simply doing
self.someZSQLmethod

The last method would probably work, but since adding something to my
database table really consists of a database insert, then getting the
unique ID returned and using this for stuffing an image into the local
filesystem, I would prefer to keep this all in the same External method.

So the question then is:

How can I obtain the database connection to the external database (the
"Z MySQL Database Connection" in my case)? And I do not mean the
connection to ZODB.

Thanks,

Marius Kjeldahl