[Zope] ZODB question, again

Garry Hodgson garry@sage.att.com
Thu, 16 Mar 2000 14:03:50 -0500


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.

so i built a very simple app, to implement a counter.
each time you invoke the "Count" method, you get a number
back, and it increments.

running the script (see below) by hand, it works fine.
referencing it from Zope, using this dtml fragment:

	<dtml-var "Count( 'chickens' )">

or just pointing my browser at:
http://kestrel.sage.att.com:8080/Garry/ZODB/Count?name=chickens

to reference an External Method called Count, which 
refers to the Count function in this script, i get:

   Error Type: AttributeError
   Error Value: Counter

if i then click the reload button, i get:

   Could not lock the database file. There must be another
   process that has opened the file. 

and i'm locked out until i restart zope.
can someone please help?  this is getting really
discouraging.  a simple explanation of where i'm 
going wrong would be greatly appreciated.  a small
working example of a working app would be terrific.

thanks


--------------------------------------------------------------
script follows:

import ZODB, ZODB.FileStorage
import Persistence

class Counter(Persistence.Persistent):
	"""A Persistent Counter"""
	def __init__( self, name ):
		self.name = name
		self.value = 0

def Count( name ):
	"Get counter value, then increment, creating if necessary"

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

	if not root.has_key( name ):
		counter = Counter( name )
		root[ name ] = counter
	else:	counter = root[ name ]

	counter.value = counter.value + 1
	
	get_transaction().commit()
	connection.close()
	return counter.value

if __name__ == '__main__':
	print Count( 'chickens' )

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