I would like to pull a dataset as a dictionary, however when I use the as_dict argument in pymssql I get a duplicate set of data, one with the column names and the other with the column numbers
For example if the fields are firstname and lastname a one row query would look like {'0':'Smith','1':'John','firstname':'John','lastname':'Smith'}
How do I eliminate the column number set? (or choose which kind of dictionary I'd like to have?
Please advise,
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi, I'm a new pymssql user and I just downloaded and installed it today (version 1.0.2) and i have the same problem. To solve it I have added some code to these functions in pymssql.py: fetchmany(), fetchone() and fetchmany().
between lines 242 and 243 of fetchone() of original file, I added these 3 line:
for i in row.keys():
if type(i) == int:
del row _
to delete the elements with interger key.
Between lines 279 and 280 of fetchmany() of original file, I added these 3 line:
for i in t.keys():
if type(i) == int:
del t
and also between lines 305-306 I added these:
for r in list:
for i in r.keys():
if type(i) == int:
del r
It work for me.. I hope I was hopefull..
Bye_
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sorry about that … I don't know how to make the indenting come out correctly. All of the lines in that last post should have been formatted correctly and
I'm sorry, not hopefull, but helfull :)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello:
I would like to pull a dataset as a dictionary, however when I use the as_dict argument in pymssql I get a duplicate set of data, one with the column names and the other with the column numbers
For example if the fields are firstname and lastname a one row query would look like {'0':'Smith','1':'John','firstname':'John','lastname':'Smith'}
How do I eliminate the column number set? (or choose which kind of dictionary I'd like to have?
Please advise,
Thanks!
This way you can obtain only numeric indexes
[tuple([row[r] for r in sorted(row.keys()) if type(r) == int]) for row in conn]
this way the rest
[tuple([row[r] for r in sorted(row.keys()) if type(r) != int]) for row in conn]
adapt to your needs.
Hi, I'm a new pymssql user and I just downloaded and installed it today (version 1.0.2) and i have the same problem. To solve it I have added some code to these functions in pymssql.py: fetchmany(), fetchone() and fetchmany().
between lines 242 and 243 of fetchone() of original file, I added these 3 line:
for i in row.keys():
if type(i) == int:
del row _
to delete the elements with interger key.
Between lines 279 and 280 of fetchmany() of original file, I added these 3 line:
for i in t.keys():
if type(i) == int:
del t
and also between lines 305-306 I added these:
for r in list:
for i in r.keys():
if type(i) == int:
del r
It work for me.. I hope I was hopefull..
Bye_
Sorry about that … I don't know how to make the indenting come out correctly. All of the lines in that last post should have been formatted correctly and
I'm sorry, not hopefull, but helfull :)
Sorry about that, I make an other mistake in all code I written before.
About fecthone():
for i in row.keys():
if type(i) == int:
del row_
About fetchmany():
for i in t.keys():
if type(i) == int:
del t
About fetchall():
for r in list:
for i in r.keys():
if type(i) == int:
del r
bye.._
Sorry about that, I make an other mistake in all code I written before.
About fecthone():
for x in row.keys():
if type(x) == int:
del row
About fetchmany():
for x in t.keys():
if type(x) == int:
del t
About fetchall():
for r in list:
for x in r.keys():
if type(x) == int:
del r
bye..