Class update detection

  • Thread starter Axium Computer Services
  • Start date
A

Axium Computer Services

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
 
L

Lars Heuer

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
 
M

Miki Tebeka

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
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,234
Latest member
SkyeWeems

Latest Threads

Top