greenew / pypyodbc

Automatically exported from code.google.com/p/pypyodbc
0 stars 0 forks source link

Cannot use NamedTupleRow #27

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
Create cursor with conn.cursor(pypyodbc.NamedTupleRow)

What is the expected output? What do you see instead?

Traceback (most recent call last):
  File "statsco.py", line 21, in <module>
    row = c.fetchone()
  File "/usr/local/lib/python2.7/dist-packages/pypyodbc.py", line 1839, in fetchone
    return self._row_type(value_list)
  File "/usr/local/lib/python2.7/dist-packages/pypyodbc.py", line 1073, in __init__
    super(Row, self).__init__(*iterable)
TypeError: __init__() takes exactly 1 argument (191 given)

What version of the product are you using? On what operating system?

Version 1.2.0 on Ubuntu 12.04.2 64 bit
iSeries 6.1

Please provide any additional information below.

Same exception with MutableNamedTupleRow

Original issue reported on code.google.com by cara...@gmail.com on 27 Oct 2013 at 9:57

GoogleCodeExporter commented 8 years ago
I have been stepping through the source code trying to fix this issue myself, 
and so far I have worked out the following:

1. The Row object is dynamically created with the list of fields (using the 
recordtype module)
2. This field list is empty, it gets populated from the _Col
3. When I run a query using MutableNamedTupleRow, Cursor._ColBufferList does 
not get correctly populated. This means that the Row object does not get 
created properly.

Is this likely to be fixed any time soon? I don't really know enough about the 
low-level portions of the pypyodbc code to fix the _ColBufferList.

It might be possible to use the Cursor.description list to create the Row 
object instead; I'm not sure.

Original comment by zep...@gmail.com on 21 May 2014 at 7:52

GoogleCodeExporter commented 8 years ago
I believe that what I said in my previous comment is correct; 
Cursor._ColBufferList is not getting populated properly when a query is 
executed.

I fixed this by modifying the _UpdateDesc function a bit, although I still need 
to run tests to make sure that it doesn't break anything else. Basically, I 
just moved the following line to the *end* of the function, instead of it being 
inside the if statement:

self._row_type = self.row_type_callable(self)

This forces the Row object to be created *after* the _ColBufferList is 
populated, which fixes the TypeError exception with NamedTupleRow and 
MutableNamedTupleRow.

I'll try to submit some kind of patch, but this really is just a one line 
change.

Original comment by zep...@gmail.com on 24 Sep 2014 at 7:08