[ZODB-Dev] Problems when reading from ZODB

Dieter Maurer dieter at handshake.de
Mon May 19 00:18:06 EDT 2003


Luis Machado wrote at 2003-5-17 13:37 -0500:
 > I'm just starting to play with ZODB and I can not find what I'm doing
 > wrong in the following programs.
 > ...
 > c = Customer()
 > 
 > for i in range (1,100):
 >  ...
 >  customerDB.insert(c.company,c)
 >  customerDB._p_changed = 1  
 >  get_transaction().commit()
 > ...
 > So far, this works fine, but when I tried to read the customers from the
 > ZODB database, no matter what is the key, for name, address1, city, etc,
 > I always get the last value stored in the database.

The reasons:

  You only insert one single object (you make 100 inserts but
  always of the same object). As a consequence,
  all key,value pairs in the ZODB have the same object as value
  and therefore the same attributes.

  Move the "c=Customer()" into the loop.
  Then you should get the expected result.


Dieter



More information about the ZODB-Dev mailing list