thanks M; I'll delve deeper On 1 Mar 2010, at 19:07, mdipierro <mdipie...@cs.depaul.edu> wrote:
> This should work. I just tried it again and works for me. Something > else is the problem. Can you show me a piece of code that exhibt the > problem and your complete traceback? > > On Mar 1, 12:59 pm, Mengu <whalb...@gmail.com> wrote: >> massimo, >> >> there is also a problem, i cannot store a datetime object in session, >> it says unmarshallable object. why is that? >> >> On 1 Mart, 19:55, Carl <carl.ro...@gmail.com> wrote: >> >>> Sorry, not quite there. >> >>> I can't see why for myself but when I pass a python list into this >>> SQLCustom definition in db.py data is stored (and pickled) without >>> complaint but when I unpickle the data, the data is returned as a >>> python string (perhaps because the field it of native 'text') >> >>> If I use a field of type 'text' and perform the pickling in my >>> module >>> code then I can put lists in and get lists out. >> >>> Any idea why? it'd be real nice to define the pickling once in db.py >> >>> On Feb 23, 10:30 am, Carl <carl.ro...@gmail.com> wrote: >> >>>> thanks for the turn of speed! >> >>>> I now have this in db.py and it works a treat... >>>> import pickle >>>> from gluon.sql import SQLCustomType >>>> serialize = SQLCustomType(type='text', >>>> native='text', >>>> encoder=(lambda x: '"%s"' % >>>> pickle.dumps(x).replace('""', '""')), >>>> decoder=(lambda x: pickle.loads(x))) >>>> ... >>>> Field('answer', serialize) >> >>>> On Feb 23, 10:22 am, mdipierro <mdipie...@cs.depaul.edu> wrote: >> >>>>> My bad. The encoder should be not >> >>>>> encoder = (lambda x:cPickle.dumps(s) >> >>>>> but >> >>>>> encoder = (lambda x: "'%s'" % cPickle.dumps(s).replace("'", "''")) >> >>>>> This is why the SQLCustomType API needs to be rewritten. >> >>>>> On Feb 23, 4:06 am, Carl <carl.ro...@gmail.com> wrote: >> >>>>>> print _insert() gets this... >> >>>>>> INSERT INTO puzzle(assessment_ref, pia, pio, rung, score, answer, >>>>>> version, cDate, mDate) VALUES ('AP5P', 'Which of these lines is a >>>>>> *comment* in Python code? >> >>>>>> .= # a comment >>>>>> .- // a comment >>>>>> .- * a comment', 'Which of these lines is a *comment* in >>>>>> Python code? >> >>>>>> .- # a comment >>>>>> .- // a comment >>>>>> .- * a comment', 1, 1, (lp0 >>>>>> S'0' >>>>>> p1 >>>>>> a., 1, 1266919327.86, 1266919327.86); >> >>>>>> the S'0' >>>>>> p1 >>>>>> a. >>>>>> is the parameter causing the hiccup. It might be the single- >>>>>> quotes? or >>>>>> the carriage-returns? >> >>>>>> Perhaps I need to escape my parameter in encoder/decoder in >>>>>> db.py? >> >>>>>> On Feb 23, 9:50 am, mdipierro <mdipie...@cs.depaul.edu> wrote: >> >>>>>>> before the >> >>>>>>> ... insert(....) >> >>>>>>> can you >> >>>>>>> print ..._insert(...) >> >>>>>>> this will tell us what is being sent to the db. >> >>>>>>> On Feb 23, 3:29 am, Carl <carl.ro...@gmail.com> wrote: >> >>>>>>>> I decided to go ahead and move my pickling to db.py with the >>>>>>>> following >>>>>>>> additions: >> >>>>>>>> import pickle >>>>>>>> from gluon.sql import SQLCustomType >>>>>>>> serialise = SQLCustomType(type='text', >>>>>>>> native='text', >>>>>>>> encoder=(lambda x: pickle.dumps(x)), >>>>>>>> decoder=(lambda x: pickle.loads(x))) >>>>>>>> ... >>>>>>>> Field ('answer', serialise) >> >>>>>>>> When I try and insert a row I get the following error: >>>>>>>> File "E:\projects\workspace\TestEnvoy\web2py\gluon\sql.py", >>>>>>>> line >>>>>>>> 1850, in insert >>>>>>>> self._db._execute(query) >>>>>>>> File "E:\projects\workspace\TestEnvoy\web2py\gluon\sql.py", >>>>>>>> line >>>>>>>> 890, in <lambda> >>>>>>>> self._execute = lambda *a, **b: self._cursor.execute(*a, >>>>>>>> **b) >>>>>>>> OperationalError: near "S": syntax error >> >>>>>>>> When I had the pickle.dumps/loads calls within a module all >>>>>>>> worked >>>>>>>> fine. >>>>>>>> Where I have gone wrong? >> >>>>>>>> On Feb 18, 4:42 am, mdipierro <mdipie...@cs.depaul.edu> wrote: >> >>>>>>>>> You should do: >> >>>>>>>>> from gluon.sql import SQLCustomType >> >>>>>>>>> pickle = >>>>>>>>> SQLCustomType( >>>>>>>>> type >>>>>>>>> ='text', >>>>>>>>> native >>>>>>>>> ='text', >>>>>>>>> encoder = (lambda x:cPickle.dumps(s)), >>>>>>>>> decoder = (lambda x: cPikcle.loads(s)) >>>>>>>>> ) >> >>>>>>>>> Field('mypickle',pickle) >> >>>>>>>>> **** SQLCustomField may disappear in the new DAL in faviour >>>>>>>>> of a more >>>>>>>>> customizable mechanism **** >> >>>>>>>>> On Feb 17, 9:20 pm, spiffytech <spiffyt...@gmail.com> wrote: >> >>>>>>>>>> That would work, calling MY_PICKLE functions everywhere >>>>>>>>>> seems like as >>>>>>>>>> much work as calling pickle functions. It would be nice if >>>>>>>>>> the >>>>>>>>>> pickling could be done transparently behind the scenes, so my >>>>>>>>>> controller code could be cleaner and less error-prone. >> >>>>>>>>>> -Brian >> >>>>>>>>>> On Feb 17, 2:34 pm, Thadeus Burgess <thade...@thadeusb.com> >>>>>>>>>> wrote: >> >>>>>>>>>>> Could you write a function that handles the inserts/ >>>>>>>>>>> selects instead? >> >>>>>>>>>>> class MY_PICKLE(): >>>>>>>>>>> @classmethod >>>>>>>>>>> def get(keyname): >>>>>>>>>>> pkldump = db(db.pickle_table.keyname == >>>>>>>>>>> keyname).select().first() >>>>>>>>>>> return pickle.loads(pkldump.value) >>>>>>>>>>> @classmethod >>>>>>>>>>> def save(keyname, value): >>>>>>>>>>> pkldump = db(db.pickle_table.keyname == >>>>>>>>>>> keyname).select().first() >>>>>>>>>>> if pkldump: >>>>>>>>>>> pkldump.update_record(value=pickle.dumps(value)) >>>>>>>>>>> else: >>>>>>>>>>> db.picke_table.insert >>>>>>>>>>> (keyname=keyname,value=pickle.dumps(value)) >> >>>>>>>>>>> a_list = MY_PICKLE.get("listkey") >> >>>>>>>>>>> # do some stuff to list >> >>>>>>>>>>> MY_PICKLE.save("listkey", a_list) >> >>>>>>>>>>> -Thadeus >> >>>>>>>>>>> On Wed, Feb 17, 2010 at 1:20 PM, spiffytech >>>>>>>>>>> <spiffyt...@gmail.com> wrote: >>>>>>>>>>>> I'm serializing with Pickle in my app, but it's a hassle >>>>>>>>>>>> to dump/load >>>>>>>>>>>> the data every time I mess with it. Is there a way to >>>>>>>>>>>> make the >>>>>>>>>>>> serializing happen automatically with DB access? >> >>>>>>>>>>>> -Brian >> >>>>>>>>>>>> On Feb 17, 1:46 pm, Carl <carl.ro...@gmail.com> wrote: >>>>>>>>>>>>> thanks Jorge; most helpful in pointing me in the right >>>>>>>>>>>>> direction. >> >>>>>>>>>>>>> The python to pickle is simply; for example: >>>>>>>>>>>>> import pickle >>>>>>>>>>>>> flat_retort = pickle.dumps(retort) >> >>>>>>>>>>>>> and to unpickle; for example: >>>>>>>>>>>>> import pickle >>>>>>>>>>>>> options = pickle.loads(rows[0].retort) >> >>>>>>>>>>>>> On Feb 17, 3:57 pm, JorgeRpo <jorgeh...@gmail.com> wrote: >> >>>>>>>>>>>>>> On Feb 17, 10:47 am, Carl <carl.ro...@gmail.com> wrote: >> >>>>>>>>>>>>>>> I have a Python list that I want to store and retrieve >>>>>>>>>>>>>>> from the data >>>>>>>>>>>>>>> store. >> >>>>>>>>>>>>>>> The individual items of the list are of no use unless >>>>>>>>>>>>>>> used with the >>>>>>>>>>>>>>> items of the complete list and there are no use-cases >>>>>>>>>>>>>>> requiring >>>>>>>>>>>>>>> searching for a specified list item. The number of >>>>>>>>>>>>>>> items in the list >>>>>>>>>>>>>>> is between one and fifteen (any more is beyond end >>>>>>>>>>>>>>> users to manage). >> >>>>>>>>>>>>>>> I'd like to store and retrieve the list in a single >>>>>>>>>>>>>>> field. On >>>>>>>>>>>>>>> retrieval the data would be in a Python list object. >> >>>>>>>>>>>>>>> What's an approach I can use? >> >>>>>>>>>>>>>> serialize >>>>>>>>>>>>>> -- >>>>>>>>>>>>>> sig text >> >>>>>>>>>>>> -- >>>>>>>>>>>> You received this message because you are subscribed to >>>>>>>>>>>> the Google Groups "web2py-users" group. >>>>>>>>>>>> To post to this group, send email to web2py@googlegroups.com >>>>>>>>>>>> . >>>>>>>>>>>> To unsubscribe from this group, send email to >>>>>>>>>>>> web2py+unsubscr...@googlegroups.com >>>>>>>>>>>> . >>>>>>>>>>>> For more options, visit this group athttp:// >>>>>>>>>>>> groups.google.com/group/web2py?hl=en. > > -- > You received this message because you are subscribed to the Google > Groups "web2py-users" group. > To post to this group, send email to web...@googlegroups.com. > To unsubscribe from this group, send email to > web2py+unsubscr...@googlegroups.com > . > For more options, visit this group at > http://groups.google.com/group/web2py?hl=en > . > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to web...@googlegroups.com. To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.