On 8/2/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> How do I update a PickleCol to the database?
>
> Class Thingy(SQLObject):
> dicty = PickleCol()
> testy = StringCol()
>
> thingy = Thingy(dicty={'foo': 'bar'} testy='foo') # it shows up in
> mysql
>
> thingy.testy = 'Hello, world!' # updated in mysql
> thingy.dicty['foo'] # returns what you'd expect
> thingy.dicty['foo'] = 'baz' *not* updated in mysql
> thing.dicty['foo'] # returns 'baz', as expected!
>
> thing.dicty = {'foo': 'mumble', 1: 2} # updated in mysql
>
My normal usage of pickle col is to put whatever data structure is
stored in there into it's own variable, do all the work and then save
it back if need be. Using your example:
thingy.testy = 'Hello, world!'
dicty = thingy.dicty
dicty['foo']
dicty['foo'] = 'baz'
thingy.dicty = dicty
This will ensure that your data doesn't get corrupted by not updating
the database when you think it will. It's also more efficient if you
think about it. Imagine a really large set of computations that you
may have to do using your dictionary, changing values in it
constantly. Now imagine that every time you changed a value in your
dict it ran a query on your SQL server! That would slow things down
considerably.
Hope this helps,
Lee
--
Lee McFadden
blog: http://www.splee.co.uk
work: http://fireflisystems.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---