From ae2eefc6bf6587a25ca439992d9b54a456ec3451 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Mon, 3 Sep 2012 08:12:40 -0500 Subject: [PATCH] executesql allows fields and/or colnames to be independently specfied, thanks Ahtony and Niphlod --- VERSION | 2 +- gluon/dal.py | 44 +++++++++++++++++++++++++++++--------------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/VERSION b/VERSION index 9a3437b2..47aa9623 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.0.6 (2012-09-03 08:09:45) stable +Version 2.0.6 (2012-09-03 08:12:36) stable diff --git a/gluon/dal.py b/gluon/dal.py index c5330345..172a773c 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -7198,21 +7198,34 @@ def index(): [{field1: value1, field2: value2}, {field1: value1b, field2: value2b}] - Added 2012-08-24 "fields" optional argument. If not None, the - results cursor returned by the DB driver will be converted to a - DAL Rows object using the db._adapter.parse() method. This requires - specifying the "fields" argument as 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). + Added 2012-08-24 "fields" and "colnames" optional arguments. If either + is provided, the results cursor returned by the DB driver will be + converted to a DAL Rows object using the db._adapter.parse() method. + + 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). - The field names will be extracted from the Field objects, or optionally, - a list of field names can be provided (in tablename.fieldname format) - via the "colnames" argument. Note, the fields and colnames must be in - the same order as the fields in the results cursor returned from the DB. + 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. """ adapter = self._adapter if placeholders: @@ -7234,7 +7247,8 @@ def index(): # easier to work with. row['field_name'] rather than row[0] return [dict(zip(fields,row)) for row in data] data = adapter.cursor.fetchall() - if fields: + if fields or colnames: + fields = [] if fields is None else fields if not isinstance(fields, list): fields = [fields] extracted_fields = []