Is there a api for wrap SQLSET with json?

5 views
Skip to first unread message

limodou

unread,
Mar 11, 2008, 7:40:31 AM3/11/08
to web...@googlegroups.com
I want to do some ajax stuff, and I need to wrap SQLSET to json
format, for example:

rows = db().select(db.address.ALL)

And I want to know if there is a api to wrap rows to json format?

--
I like python!
UliPad <<The Python Editor>>: http://code.google.com/p/ulipad/
meide <<wxPython UI module>>: http://code.google.com/p/meide/
My Blog: http://www.donews.net/limodou

voltron

unread,
Mar 11, 2008, 8:32:26 AM3/11/08
to web2py Web Framework
Web2py uses simpleJSON Limodou, I just took this from the examples
page:

import gluon.contrib.simplejson as sj
return sj.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])

Does that help?

limodou

unread,
Mar 11, 2008, 9:02:29 AM3/11/08
to web...@googlegroups.com
On Tue, Mar 11, 2008 at 8:32 PM, voltron <nhy...@googlemail.com> wrote:
>
> Web2py uses simpleJSON Limodou, I just took this from the examples
> page:
>
> import gluon.contrib.simplejson as sj
> return sj.dumps(['foo', {'bar': ('baz', None, 1.0, 2)}])
>
> Does that help?
>
Thanks, I know that. But what I want is to deal with SQLRows, but not
simple variable. So if you pass a SQLRows to sj.dumps() it'll complain
an exception.

voltron

unread,
Mar 11, 2008, 9:05:53 AM3/11/08
to web2py Web Framework
Âh, now I understand, you get errors because of a type mismatch, maybe
using a list comprehension to extract the rows into a list and then
dump the JSON?

limodou

unread,
Mar 11, 2008, 9:29:33 AM3/11/08
to web...@googlegroups.com
On Tue, Mar 11, 2008 at 9:05 PM, voltron <nhy...@googlemail.com> wrote:
>
> Âh, now I understand, you get errors because of a type mismatch, maybe
> using a list comprehension to extract the rows into a list and then
> dump the JSON?
>
So , I decide to write myself.

Michael Wills

unread,
Mar 11, 2008, 11:11:56 AM3/11/08
to web...@googlegroups.com
Something similar to gluon.sqlhtml.SQLTABLE?

limodou

unread,
Mar 11, 2008, 11:48:50 AM3/11/08
to web...@googlegroups.com
On Tue, Mar 11, 2008 at 11:11 PM, Michael Wills <mcw...@gmail.com> wrote:
> Something similar to gluon.sqlhtml.SQLTABLE?
>
yes, I think so. I've already borrowed some code from it.

Massimo Di Pierro

unread,
Mar 11, 2008, 12:14:03 PM3/11/08
to web...@googlegroups.com
from gluon.contrib.simplejson as sj

return sj.dumps(str(db().select(db.address.ALL)) # serializes the csv or

Massimo Di Pierro

unread,
Mar 11, 2008, 12:16:34 PM3/11/08
to web...@googlegroups.com
js.dumps(db().select(...).response)

db().select(...).response

gives you a list of list

db().select(...).colnames

gives you a list of colnames

limodou

unread,
Mar 11, 2008, 8:34:45 PM3/11/08
to web...@googlegroups.com
On Wed, Mar 12, 2008 at 12:16 AM, Massimo Di Pierro
<mdip...@cs.depaul.edu> wrote:
>
> js.dumps(db().select(...).response)
>
> db().select(...).response
>
> gives you a list of list
>
> db().select(...).colnames
>
> gives you a list of colnames
>
thank you so much, I'll see them.
Reply all
Reply to author
Forward
0 new messages