there's a way....

def executesql(self, query, placeholders=None, as_dict=False, fields=None, 
colnames=None)

taken straight from docstring

        *The "fields" argument is a list of DAL Field objects that match the
        fields returned from the DB. The Field objects should be part of 
one or
        more Table objects defined on the DAL object. The "fields" list can
        include one or more DAL Table objects in addition to or instead of
        including Field objects, or it can be just a single table (not in a
        list). In that case, the Field objects will be extracted from the
        table(s).

        Instead of specifying the "fields" argument, the "colnames" argument
        can be specified as a list of field names in tablename.fieldname 
format.
        Again, these should represent tables and fields defined on the DAL
        object.

        It is also possible to specify both "fields" and the associated
        "colnames". In that case, "fields" can also include DAL Expression
        objects in addition to Field objects. For Field objects in "fields",
        the associated "colnames" must still be in tablename.fieldname 
format.
        For Expression objects in "fields", the associated "colnames" can
        be any arbitrary labels.

        Note, the DAL Table objects referred to by "fields" or "colnames" 
can
        be dummy tables and do not have to represent any real tables in the
        database. Also, note that the "fields" and "colnames" must be in the
        same order as the fields in the results cursor returned from the DB.
*

meaning basically that if your select returns 3 columns, id, name and event 
of the table "whatever" you can get the "usual" object back from executesql 
using either

fields = [db.whatever.id, db.whatever.name, db.whatever.event] 

or

colnames = ['whatever.id', 'whatever.name', 'whatever.event']

Not sure if it's enough to trigger the json creation.

On Tuesday, February 19, 2013 10:19:18 PM UTC+1, Richard wrote:
>
> db.executesql return a sql table object with no represent and other web2py 
> fancy stuff (row_delete, id, etc.).
>
> I think you will have to translate the Niphold SQL into "web2py query", 
> like db(...).select(...)
>
> Richard
>
>
> On Tue, Feb 19, 2013 at 2:21 PM, Christian Espinoza 
> <chesp...@gmail.com<javascript:>
> > wrote:
>
>> Hi guys, for this json service I'm using simplejson implicitly because 
>> the result of db.executesql
>> isn't serialized automatically by decorator, is this the normal behavior 
>> for db.executesql or something I'm missed here?
>>  
>> @auth.requires_login()
>> @service.json
>> def test_trackers():
>>     dthandler = lambda obj: obj.strftime('%d-%m-%Y %H:%M:%S') ifisinstance
>> (obj, datetime.datetime) else None
>>     if auth.user_id == 1:
>>         events = db.executesql(GET_EVENT_ALL, as_dict=True)
>>     else:
>>         if session.customer_id:
>>             rows = db.executesql(GET_EVENT_BY_CUS % (session.customer_id
>> ), as_dict=True)
>>             events = simplejson.dumps(rows, default=dthandler)
>>  
>>     return events
>>
>> Error without using simplejson: Error 321 
>> (net::ERR_INVALID_CHUNKED_ENCODING): Unknown Error 
>>
>> Greetings
>> Christian.
>>
>> -- 
>>  
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "web2py-users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to web2py+un...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to