Hi !
(re-posting this, since my earlier post was unsuccessful).
Database back-end is MySQL
=========
Controller:--
=========
def do_something():
  result = db.executesql('select acnm,acgrp,accd from ac',
as_dict=True)
  return dict(result=result)

=====
View:--
=====
do_something.html

{{extend 'layout.html'}}
<table id="custlist"></table>
<script>
jQuery("#custlist").jqGrid({
    datatype: "local",
    height: 250,
    colNames:['Name','Group', 'Code'],
    colModel:[{name:'acnm',index:'acnm', width:150, sortable:true},
                   {name:'acgrp',index:'acnm', width:150,
sortable:true},
                   {name:'accd',index:'acnm', width:150,
sortable:true}
    ],
    multiselect: true,
    caption: "Customer Data"
});
var mydata = {{=XML(result)}};
for(var i=0;i<=mydata.length;i++)
    jQuery("#custlist").jqGrid('addRowData',i+1,mydata[i]);
</script>

============================

But the result is a blank page.

I checked the source of browser page to find that result contained an
array like this:--
[{'acnm': u'Vineet', 'accd': u'200124', 'acgrp': u'home'},......]

Pl. note the u character (for unicode?) before each value in the
dictionary.

Then I tried to do like following:--
1) In controller, parse the dictionary values
2) check if it is string
3) If string, then .encode('utf-8') the values.
4) return the modified dict

But still no success in rendering the view.

Then I tested the jqGrid code by giving a hardcoded "result" array
directly into <script> tag.
It works.....
I tested with returning result=db().select(db.acid>0)
It works.....

So, my question is : How to get rid of the u character while returning
result from executesql('select....)?
I need this executesql for giving very complex queries.

Can anybody pl. help?

Thanks,

Vineet

Reply via email to