[Twisted-Python] assignKeyAttr in row object

Dear all, What is the assignKeyAttr method used for in a row object? Is it similar to a primary key that can be used to identity the instance? Liming

Is there any other documentation on using Twisted other than that on the Twisted site? Chuck Wegrzyn

Dave Peticolas wrote:
On Tue, 2004-10-05 at 05:15, Tsai Li Ming wrote:
Dear all,
What is the assignKeyAttr method used for in a row object? Is it similar to a primary key that can be used to identity the instance?
Yes, assignKeyAttr is used to change the primary key of a row object.
dave
Hi Dave, Is it necessary to use assignKeyAttr? From the source code, it doesn't seem to do anything special, except to change the primary key(s)? def assignKeyAttr(self, attrName, value): """Assign to a key attribute. This cannot be done through normal means to protect changing keys of db objects. """ found = 0 for keyColumn, type in self.rowKeyColumns: if keyColumn == attrName: found = 1 if not found: raise DBError("%s is not a key columns." % attrName) self.__dict__[attrName] = value Alternatively, I could set the primary key manually. newRoom = RoomRow() newRoom.roomID = get_unique _id() #newRoom.assignKeyAttr("roomID", get_unique _id()) reflector.insertRow(newRoom).addCallback(onInsert) Liming

Tsai Li Ming wrote:
Dave Peticolas wrote:
On Tue, 2004-10-05 at 05:15, Tsai Li Ming wrote:
Dear all,
What is the assignKeyAttr method used for in a row object? Is it similar to a primary key that can be used to identity the instance?
Yes, assignKeyAttr is used to change the primary key of a row object.
dave
Hi Dave,
Is it necessary to use assignKeyAttr? From the source code, it doesn't seem to do anything special, except to change the primary key(s)?
def assignKeyAttr(self, attrName, value): """Assign to a key attribute.
This cannot be done through normal means to protect changing keys of db objects. """ found = 0 for keyColumn, type in self.rowKeyColumns: if keyColumn == attrName: found = 1 if not found: raise DBError("%s is not a key columns." % attrName) self.__dict__[attrName] = value
Alternatively, I could set the primary key manually. newRoom = RoomRow() newRoom.roomID = get_unique _id() #newRoom.assignKeyAttr("roomID", get_unique _id()) reflector.insertRow(newRoom).addCallback(onInsert)
Liming
My mistake. Twisted has the __setattr__ defined so that key values must be changed via assignKeyAttr. Liming
participants (3)
-
C Wegrzyn
-
Dave Peticolas
-
Tsai Li Ming