[Zope] help with zodb

Garrett G. Hodgson garry@sage.att.com
Thu, 02 Mar 2000 15:39:18 -0500


thank you for your help.  forgive my being obtuse,
but i'm still not getting it.

Jeff K. Hoffman jeff.hoffman@goingv.com wrote:

> Only one process can access a ZODB at a time. You have two. The first is
> Zope, and the second is the external method.

ok.  by "a ZODB" do you mean that the call in my external method
is trying to reopen the ZODB zope is using?  i'd assumed i was 
crating another one, with a separate FileStorage.

> You don't need to re-open the ZODB inside your external method. By the
> time you've gotten there, Zope already has it open.

ok, then how does code in my external method get at that?
that is, how do i create an object and stuff it in the DB?
all the code examples i've seen follow the pattern in GetPeople().

> AFAIK, you simply need to create an instance of your object and set it as
> an attribute of another persistent object. The persistence should happen
> automatically.

how do i do this?

i get the feeling i'm just missing something, perhaps thinking like
a python programmer rather than a zope guru.  i feel like there's 
some big obvious point that has escaped me, and i'm waiting for the
big "AHA!".

so, one more try.  given the following external method:

import ZODB, ZODB.FileStorage


def GetPeople( self ):
	"Return list of people in DB"

	db = ZODB.DB( ZODB.FileStorage.FileStorage( 'TestDB.fs' ) )
	connection = db.open()
	root = connection.root()
	people = []
	for key in root.keys():
		people.append( root[ key ] )
	return people

if __name__ == '__main__':
	for person in GetPeople( None ):
		print person.name, 'is', person.age, 'years old'


referenced from a DTML Method:

<dtml-in "GetPeople()">
	<dtml-var name> is <dtml-var age> years old.<br>
</dtml-in>

when i restart zope and view the method, it works once, but shows
no persons.  the second time, it fails with the traceback.

what do i change to make it work?

thank you for your patience.

-- 
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