Example #1
0
    def select_for_update(self, dbclass, key):
        """
        This method works like L{select_by_primary_key} above, except that it
        doesn't select anything but returns a dummy object (an empty dbobj)
        that will allow setting attributes, yielding proper UPDATE statements.
        Note that supplying a primary key that does not exist will go
        unnoticed: The UPDATE statements won't create an error, they just
        won't affect any rows.

        This method is primarily ment for transaction based (i.e. www)
        applications.
        """
        if type(key) != TupleType: key = ( key, )
        primary_key = keys.primary_key(dbclass)

        if len(key) != len(primary_key.key_attributes):
            msg = "The primary key for %s must have %i elements." % \
                     ( repr(dbclass), len(primary_key.key_attributes), )
            raise IllegalPrimaryKey(msg)

        info = stupid_dict()
        for property, value in zip(primary_key.attributes(), key):        
            info[property.column] = value

        return dbclass.__from_result__(self, info)
Example #2
0
 def rollback(self):
     """
     Undo the changes you made to the database since the last commit()
     """
     self._updates = stupid_dict()
     db = getattr(self._conn, "db", None)
     if db is not None:
         db.rollback()