executesql allows fields and/or colnames to be independently specfied, thanks Ahtony and Niphlod
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.0.6 (2012-09-03 08:09:45) stable
|
Version 2.0.6 (2012-09-03 08:12:36) stable
|
||||||
|
|||||||
+29
-15
@@ -7198,21 +7198,34 @@ def index():
|
|||||||
|
|
||||||
[{field1: value1, field2: value2}, {field1: value1b, field2: value2b}]
|
[{field1: value1, field2: value2}, {field1: value1b, field2: value2b}]
|
||||||
|
|
||||||
Added 2012-08-24 "fields" optional argument. If not None, the
|
Added 2012-08-24 "fields" and "colnames" optional arguments. If either
|
||||||
results cursor returned by the DB driver will be converted to a
|
is provided, the results cursor returned by the DB driver will be
|
||||||
DAL Rows object using the db._adapter.parse() method. This requires
|
converted to a DAL Rows object using the db._adapter.parse() method.
|
||||||
specifying the "fields" argument as a list of DAL Field objects
|
|
||||||
that match the fields returned from the DB. The Field objects should
|
The "fields" argument is a list of DAL Field objects that match the
|
||||||
be part of one or more Table objects defined on the DAL object.
|
fields returned from the DB. The Field objects should be part of one or
|
||||||
The "fields" list can include one or more DAL Table objects in addition
|
more Table objects defined on the DAL object. The "fields" list can
|
||||||
to or instead of including Field objects, or it can be just a single
|
include one or more DAL Table objects in addition to or instead of
|
||||||
table (not in a list). In that case, the Field objects will be
|
including Field objects, or it can be just a single table (not in a
|
||||||
extracted from the table(s).
|
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,
|
Instead of specifying the "fields" argument, the "colnames" argument
|
||||||
a list of field names can be provided (in tablename.fieldname format)
|
can be specified as a list of field names in tablename.fieldname format.
|
||||||
via the "colnames" argument. Note, the fields and colnames must be in
|
Again, these should represent tables and fields defined on the DAL
|
||||||
the same order as the fields in the results cursor returned from the DB.
|
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
|
adapter = self._adapter
|
||||||
if placeholders:
|
if placeholders:
|
||||||
@@ -7234,7 +7247,8 @@ def index():
|
|||||||
# easier to work with. row['field_name'] rather than row[0]
|
# easier to work with. row['field_name'] rather than row[0]
|
||||||
return [dict(zip(fields,row)) for row in data]
|
return [dict(zip(fields,row)) for row in data]
|
||||||
data = adapter.cursor.fetchall()
|
data = adapter.cursor.fetchall()
|
||||||
if fields:
|
if fields or colnames:
|
||||||
|
fields = [] if fields is None else fields
|
||||||
if not isinstance(fields, list):
|
if not isinstance(fields, list):
|
||||||
fields = [fields]
|
fields = [fields]
|
||||||
extracted_fields = []
|
extracted_fields = []
|
||||||
|
|||||||
Reference in New Issue
Block a user