[Zope] ZODB question, again

Garry Hodgson garry@sage.att.com
Mon, 20 Mar 2000 10:03:37 -0500


Michel Pelletier wrote:
> 
> Garry Hodgson wrote:
> >
> > ok, persistent fool that i am, i'm still trying to figure out
> > how to use ZODB in an External Method to do some simple (ha!)
> > database stuff.
> You cannot open the object database twice.

that makes sense.

> In this case, Zope opens it
> first, and then you open it second

ok, this i don't get.  i'd have thought that since i opened
what i thought was my own instance of a Zope DB, using my own
FileStorage pointing to a file in /tmp:

	db = ZODB.DB( ZODB.FileStorage.FileStorage( '/tmp/foo.fs' ) )
	connection = db.open()
	root = connection.root()

that this would have nothing to do with the DB that Zope
was using for its internals.  all of the code examples i've
seen for ZODB are from python programs, and all include code like this.
if this *is* using Zope's internal DB instance, then that would imply 
that you can't use ZODB outside of Zope when Zope is running.
what am i missing?

> (why you are getting the
> AttributeError I don't know, a traceback there would help).

it appears that was unrelated.  i actually got my example to
work since posting.  the "unable to access" thing only happens
when i get an exception due to bugs in my code.

> Basically what you are doing is sort-of a no-no unless you know what you
> are doing.  First, a database cannot be opened twice, even from the same
> process.  Second, you do not need to open the database again, because it
> is already open and accessible to you from your external method:
> 
> def anExtMeth(self):
>   connection = self._p_jar

cool.  that's good to know.

> Also, you need to be very careful with what you are doing.  You are
> inserting objects right into the root level of the object database, this
> is not really a good idea.

indeed.  that's part of why i wanted to use a completely separate
database.  the other part is so i can use the same routines outside
of Zope, perhaps at the same time.

> Pick your own name (like GarryHodgsonApplication) and assign your
> counter objects as sub-attributes of that.

i'll try that.  thanks for your help.


-- 
Garry Hodgson                   Every night 
garry@sage.att.com                a child is born
Software Innovation Services        is a Holy Night.
AT&T Labs                         - Sophia Lyon Fahs