Re: SQL queries and their results
- From: Murray Cumming <murrayc murrayc com>
- To: "D. Scott Nettleton" <dsnettleton gmail com>
- Cc: glom-devel-list <glom-devel-list gnome org>
- Subject: Re: SQL queries and their results
- Date: Sat, 01 May 2010 23:53:33 +0200
On Tue, 2010-04-27 at 12:15 -0400, D. Scott Nettleton wrote:
Sure thing.
It's still incomplete, naturally, so look for tblAccounts.fldBalance
for the field I'm working on right now. I'm using Glom v1.13.2, in
case it makes a difference.
That's an old unstable version that you really shouldn't be depending
on. What distro are you using? I expect us to have packages from Glom
1.14 for Ubuntu Lucid a few days from now.
Anyway, sorry, but I now see that the code mentioned here
http://library.gnome.org/users/glom/unstable/sec-calculated-fields.html.en#using-the-full-pygda-api
is for pgyda 3, not the current pygda 4. I'll update that help text
soon.
So here is what works now for me:
# Return Starting Balance plus all transactions
sum = record["fldStartingBalance"]
query = 'SELECT * FROM "tblTransactions" WHERE "fldAccount" = \'%s\''
% record["fldId"]
# This API is not pretty, but it does at least exist:
data_model = gda.gda_execute_select_command(record.connection, query);
fldAmount_column_id=4
rows = data_model.get_n_rows()
for row_index in range(rows):
sum += data_model.get_value_at(fldAmount_column_id, row_index)
return sum
And here is what should work too when I've fixed a problem in pygda:
# Return Starting Balance plus all transactions
sum = record["fldStartingBalance"]
query = 'SELECT * FROM "tblTransactions" WHERE "fldAccount" = \'%s\''
% record["fldId"]
connection = record.connection
parser = connection.create_parser()
statement = parser.parse_string(query)
data_model = record.connection.statement_execute_select(statement)
# (I also hope to allow direct passing of the SQL string instead of
that statement object)
fldAmount_column_id=4
rows = data_model.get_n_rows()
for row_index in range(rows):
sum += data_model.get_value_at(fldAmount_column_id,
row_index)
return sum
--
murrayc murrayc com
www.murrayc.com
www.openismus.com
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]