Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Class update detection

Reply
Thread Tools

Class update detection

 
 
Axium Computer Services
Guest
Posts: n/a
 
      05-10-2004
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
 
Reply With Quote
 
 
 
 
Lars Heuer
Guest
Posts: n/a
 
      05-10-2004
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


 
Reply With Quote
 
 
 
 
Miki Tebeka
Guest
Posts: n/a
 
      05-11-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Update On The Windows Phone 7 Update Update Lawrence D'Oliveiro NZ Computing 2 02-25-2011 08:03 AM
compile time detection of multiple template class usage alexandru.nicau@gmail.com C++ 0 06-27-2007 05:02 PM
UPDATE: Analog Joystick Detection Mystery Brad Computer Information 0 02-17-2006 12:28 PM
Nested Class, Member Class, Inner Class, Local Class, Anonymous Class E11 Java 1 10-12-2005 03:34 PM
Spybot S&D update 655KB detection rules joevan Computer Support 4 07-10-2005 12:20 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57