google-code-export / pymssql

Automatically exported from code.google.com/p/pymssql
GNU Lesser General Public License v2.1
0 stars 0 forks source link

Feature Request: Option to return namedtuple (patch included) #38

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Just watch R Hettinger's pycon video where he talks about namedtuple 
(collections.namedtuple)  It would be great if you added this as an option like 
'asdict'. 

Since you can build the dict, you have all the information to create a 
namedtuple.  
http://docs.python.org/library/collections.html#collections.namedtuple

There are a lot of pluses, like better memory usage like a regular tuple, plus 
self documenting.  We would get the best of both worlds of tuples and dicts.

Original issue reported on code.google.com by dunde...@gmail.com on 25 Mar 2011 at 4:47

GoogleCodeExporter commented 9 years ago
This is a good idea, will have to add this when I get the chance.

Original comment by dam...@gmail.com on 27 Mar 2011 at 2:43

GoogleCodeExporter commented 9 years ago
Example using as concept:
curs = conn.cursor(as_tuple=CustomerType)
curs.execute(...)
for customer for curs:
  print customer.name
Or

curs = conn.cursor(as_dict=UserDictType)
curs.execute(...)
for row for curs:
  print row[name]

Original comment by tonal.pr...@gmail.com on 3 Jun 2011 at 9:44

Attachments:

GoogleCodeExporter commented 9 years ago
I change and debug concept.
Example using:

curs = conn.cursor(row_constr=CustomerType)
curs.execute(...)
for customer for curs:
  print customer.name
Or

curs = conn.cursor(as_dict=true)
curs.execute(...)
for row for curs:
  print row[name]
Or

curs = conn.cursor(as_dict=true, row_constr=CustomDictType)
curs.execute(...)
for row for curs:
  print row[name]

Original comment by tonal.pr...@gmail.com on 28 Jun 2011 at 8:44

Attachments:

GoogleCodeExporter commented 9 years ago

Original comment by rsyr...@gmail.com on 8 Mar 2012 at 3:26

GoogleCodeExporter commented 9 years ago

Original comment by msabr...@gmail.com on 7 Aug 2013 at 1:52

GoogleCodeExporter commented 9 years ago

Original comment by msabr...@gmail.com on 7 Aug 2013 at 1:53

GoogleCodeExporter commented 9 years ago

Original comment by msabr...@gmail.com on 23 Sep 2013 at 10:01