[Tutor] python-mysql

Bernard Lebel python at bernardlebel.com
Fri Aug 13 11:05:44 CEST 2004


Does anyone have any experience with mysql-python 1.0.0 win32?
I installed it, it seems to work, I can connect to the sql database.
However, few things seem not to work. Here is the connection code:

import _mysql
sql = _mysql

# host (server)
sHost = 'xxx.xxx.x.x'

# uid (user)
sUser = 'xsi_client'

# pwd (password)
sPwd = 'XSIBatchServe'

# database
sDB = 'XSI_R'

# Connect to database by creating a database obect
oCon = sql.connection( sHost, sUser, sPwd , sDB )

I know I am connected because if I run
print oCon
I get this message:
<_mysql.connection open to 'xxx.xxx.x.x' at a96db8>
I also have access to all the module functions on the oCon object.

However the problem is that I can't go further. I'm trying to build a query:

oQuery = oCon.query
oQueryResult = oQuery( ' SELECT from_rule, where_rule, order_rule ' + ' FROM
clients LEFT JOIN rules ON rules.id=clients.rule_id' + ' WHERE
clients.c_id=' + str(31) )

Now if I run
print str( oQueryResult )
I get

If I run "oCon.query.__doc__", I am told to use cursor() to create a cursor,
then use cursor.execute() to execute a query. Ok, fine, but it seems I can't
create cursor!!
I tried "oCursor = oCon.cursor()" and "oCursor = oCon.query.cursor()", but
no luck.

Soooo I'm stuck!
Anyone has any advice? I posted this on the python-mysql SourceForce forum
page, but got no reply.

Thanks in advance

More information about the Tutor mailing list