By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,550 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,550 IT Pros & Developers. It's quick & easy.

Class update detection

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Jul 18 '05 #2

P: n/a
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
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.