[Tutor] Mysqldb.py:::Cursor has no 'query' attribute?

Danny Yoo dyoo@hkn.eecs.berkeley.edu
Fri, 22 Mar 2002 11:17:33 -0800 (PST)


On Fri, 22 Mar 2002, Israel Evans wrote:

> I've just started working with MySQL, and the Mysqldb module for python and,
> as usual, I've run into some problems...

Do you mean the "Mysqldb" module, or the "MySQLdb" module?  *grin*  I've
used Andy Dustman's MySQLdb module with good success:

    http://sourceforge.net/projects/mysql-python



> after I type the following code in the the Python shell...
>
> >>> import CompatMysqldb
> >>> conn = CompatMysqldb.mysqldb('test@localhost israel
> SuperSecretPassword1')
> >>> cursor = CompatMysqldb.Cursor(conn)
> >>> cursor.execute('select version(), current_date')
>
> ... I get the error:
>
> Traceback (most recent call last):
>   File "<pyshell#4>", line 1, in ?
>     cursor.execute('select version(), current_date')
>   File "C:\proj\Python22\Lib\site-packages\CompatMysqldb.py", line 243, in
> execute
>     self.__conn.query(op)
>   File "C:\proj\Python22\Lib\site-packages\CompatMysqldb.py", line 123, in
> __getattr__
>     return getattr(self.__curs, key)
> AttributeError: Cursor instance has no attribute 'query'
>
> Anybody know why and what I can do about it?


I'm not too familiar with CompatMysqldb.py.  The equivalent code, using
MySQLdb, would look like:

###
import MySQLdb
conn = MySQLdb.connect(db='test@localhost',
                       user='israel',
                       passwd='SuperSecretPassword1')
cursor = conn.cursor()
cursor.execute('select version(), current_date')
###


Hope this helps!