Class update detection

Discussion in 'Python' started by Axium Computer Services, May 10, 2004.

  1. I have a relational database that has several tables each more or less
    translating to a python class and the fields of each table translating
    into attributes of the python class. I have no problem creating an
    instance of the class, running a query and filling the attributes. Then
    this information will be accessible from a UI. The problem I am running
    into is when the user is done working in the UI I need to determine if
    any of the class attributes have been changed to I can issue an update
    query to the database with the changes. Is there a generally accepted
    method to do this? Is there some way to create a checksum of the class
    attributes?

    Any help would be much appreciated.

    Thanks

    Steven Potter
     
    Axium Computer Services, May 10, 2004
    #1
    1. Advertising

  2. Axium Computer Services

    Lars Heuer Guest

    Hi Axium,

    [...]
    > this information will be accessible from a UI. The problem I am running
    > into is when the user is done working in the UI I need to determine if
    > any of the class attributes have been changed to I can issue an update
    > query to the database with the changes. Is there a generally accepted

    [...]

    I.e. SQLObject (and other ORMs, too) does this job. If you update a
    class attribute, it automatically updates the underlying DB tables.
    http://sqlobject.org/


    Best regards,
    Lars
     
    Lars Heuer, May 10, 2004
    #2
    1. Advertising

  3. Axium Computer Services

    Miki Tebeka Guest

    Hello Steven,

    > I need to determine if
    > any of the class attributes have been changed to I can issue an update
    > query to the database with the changes. Is there a generally accepted
    > method to do this? Is there some way to create a checksum of the class
    > attributes?

    Do you mean something in the lines of:
    class C:
    def __init__(self, a, b):
    self.a, self.b = a, b
    self.dirty = 0
    def __setattr__(self, k, v):
    if k in ("a", "b"):
    self.dirty = 1
    self.__dict__[k] = v
    >> c = C(1,2)
    >>> c.dirty

    0
    >>> c.a = 10
    >>> c.a

    10
    >>> c.dirty

    1
    >>>


    Another option is to generate a checksum (using md5 and str) on all the
    attributes you're interested in at the end of __init__ and a function
    `dirty' will compute this checksum and return 1 if it was changed.
    Note that if you have nested objects this might be a problem.

    HTH.
    Miki
     
    Miki Tebeka, May 11, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shailender Bathula
    Replies:
    1
    Views:
    773
    Sanjay
    Feb 17, 2005
  2. E11
    Replies:
    1
    Views:
    4,941
    Thomas Weidenfeller
    Oct 12, 2005
  3. christopher diggins
    Replies:
    16
    Views:
    784
    Pete Becker
    May 4, 2005
  4. Joseph Turian
    Replies:
    5
    Views:
    627
  5. Replies:
    0
    Views:
    315
Loading...

Share This Page