Manoharan Durga wrote:
> I have a SQlite database called salarydata; it has a table called
> stafflist. I want to generate a report to print the departmentwise
> totals of salaries and advances. The department detail for each staff is
> given in a field called ledger.
>
> I modified the Sample Report generated by AppWizard and tried making a
> simple report. The code is given below.
>
> # -*- coding: utf-8 -*-
>
> import datetime
> import decimal
> import dabo
>
> def getLedgerDataSet():
>
> import sqlite3
> conn=sqlite3.connect('/home/manoharan/apps/Salary/db/salarydata')
> crs = conn.cursor()
> crs.execute("select ledger, sum(salary), sum(advance) from
> stafflist GROUP BY ledger")
> #ds = crs.fetchall()
> ds = []
> for staff in crs.fetchall():
> dsentry = "{'ledger': '" + staff[0] + "', "
> dsentry = dsentry + "salarytotal: " + str(staff[1]) + ", "
> dsentry = dsentry + "advancetotal: " + str(staff[2]) + "}, "
> ds.append(dsentry)
> return ds
>
> The dataset is actually generating the correct number of records; that
> is, one record for each of the department that are in the table. But, in
> the report generated, instead of the values, all the fields display a
> message "string indices must be integers".
>
> The expressions used in the report are self.Record['ledger'] and
> self.Record['salarytotal'] and self.Record['advancetotal']
>
> When I changed the str(staff[1]) to just staff[1], I get this error message:
> TypeError: coercing to Unicode: need string or buffer, int found
>
> Can you please let me know what needs to be changed?
The python expression:
dsentry = dsentry + "salarytotal: " + str(staff[1])
is valid, because you are concantating a string and a string.
The python expression:
dsentry = dsentry + "salarytotal: " + staff[1]
is invalid, because apparently staff[1] is an int.
What you want (I think) is a dataset with record names of 'ledger',
'salarytotal' and
'advancetotal', but you haven't boned up on basic Python yet so you don't know
how to
do it.
Try this:
def getLedgerDataSet():
import sqlite3
conn = sqlite3.connect('/home/manoharan/apps/Salary/db/salarydata')
crs = conn.cursor()
crs.execute("""
select ledger,
sum(salary),
sum(advance)
from stafflist
GROUP BY ledger""")
ds = []
for staff in crs.fetchall():
dsentry = {'ledger': staff[0],
'salarytotal': staff[1],
'advancetotal': staff[2],}
ds.append(dsentry)
return ds
Paul
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: http://leafe.com/archives/byMID/[email protected]