eskoviak / pypyodbc

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

Cannot access row object by column name, attribute error gets thrown #6

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Accessing Row object by attribute fails. This works in pyodbc.

What steps will reproduce the problem?
1. Run a select query
2. Try accessing row object by column name
3. AttributeError will be thrown

E.g.

for row in cursor.fetchall():
    id = row.id # <<<< fails

What is the expected output? What do you see instead?
I expect the value of the column to be return, instead I get an attributeerror

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

Please provide any additional information below.

Original issue reported on code.google.com by johnjian...@gmail.com on 13 Feb 2013 at 4:54

GoogleCodeExporter commented 8 years ago

Original comment by jiangwen...@gmail.com on 15 Feb 2013 at 2:45

GoogleCodeExporter commented 8 years ago

Original comment by jiangwen...@gmail.com on 25 Feb 2013 at 2:30

GoogleCodeExporter commented 8 years ago
You can change one line to enable it:
In the method Cursor.__init__() from:

        self.row_type_callable = row_type_callable or TupleRow
To:
        self.row_type_callable = row_type_callable or NamedTupleRow

After some consideration and testing, I tend to not enable that feature by 
default, which is not in DBI 2.0 standard, and also only ascii attribute will 
success:

for row in cursor.fetchall():
    id = row.号码 # <<<< fails, field name must be ascii attributes

Original comment by jiangwen...@gmail.com on 24 Mar 2013 at 11:42