Bobspadger / pyodbc

Automatically exported from code.google.com/p/pyodbc
MIT No Attribution
0 stars 0 forks source link

problem with select #70

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. create a conection from ubuntu to MS SQL SERVER
2.
3.

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

I see IndentationError: expected an indented block
I would like to see the select result

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

Last pyodbc. Ubuntu 9.04
Please provide any additional information below.

>>> conn =
pyodbc.connect("DRIVER={FreeTDS};SERVER=defekas62;UID=emuser;PWD=temporal;DATABA
SE=em620")
cursor = conn.cursor()
>>> for row in cursor.execute("select USERNAME from JOBACTIONS"):
... print row.USERNAME
  File "<stdin>", line 2
    print row.USERNAME
        ^
IndentationError: expected an indented block

Why this error?
Many thanks and sorry for my english

Original issue reported on code.google.com by davidtuti on 27 Aug 2009 at 8:21

GoogleCodeExporter commented 9 years ago
This is actually a general Python issue, not pyodbc, but I can help.  You must 
indent code that is "in" a for loop.  

First, try saving the code to a file instead of using the interactive batch 
session, 
at least while you get used to it.

Second indent like this:

conn =
pyodbc.connect
("DRIVER=FreeTDS};SERVER=defekas62;UID=emuser;PWD=temporal;DATABASE=em620")
cursor = conn.cursor()

for row in cursor.execute("select USERNAME from JOBACTIONS"):
    print row.USERNAME

Also, if your database is case-sensitive, you can use pyodbc.lowercase to force 
all 
returned column names to lower case.  You would then use row.username instead 
of 
row.USERNAME.

Original comment by mkleehammer on 5 Sep 2009 at 4:50

GoogleCodeExporter commented 9 years ago

Original comment by mkleehammer on 21 Nov 2010 at 4:43