0

OurSQL is the MySQL driver for Python, more here. I fail with the connection, I doubt the problem to be with port or host -- more details here about environment vars, I am working with Ubuntu.

$ cat t.py 
import oursql
conn=oursql.connect(db='test', user='root', passwd='hello')
#, port=3306)
#, host='127.0.0.1')
conn=oursql.connect(db='test')
curs = conn.cursor(oursql.DictCursor)
curs = conn.cursor(try_plain_query=False)
a=curs.execute('SELECT * from test.pic')

print(a)
$ cat test.sql 
select * from test.pic;

$ python t.py |wc
      1       1       5    
$ mysql test < test.sql |wc
      9      78     610

WHY DIFFERENT LENGTHS??

THIS LINE WRONG (above)????
conn=oursql.connect(db='test', user='root', passwd='hello')

1 Answer 1

3

You can't simply print the result of curs.execute(...) in this way. You're supposed to use the fetchone(...) or fetchmany(...) or fetchall(...) methods of the cursor object to retrieve its results.

Also, as the API documentation points out, iterating over the cursor is equivalent to repeatedly calling fetchone(). So, your script could end with something like:

curs.execute('SELECT * from test.pic')

for row in curs:
    print(row)
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, got it working -- nice a=curs.fetchall(); print(a), +1.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.