質問

どうすれば使用できますか CursorUseResultMixInmysqldb. 。明白なことは、次のとおりです。

con=MySQLdb.connect(host='localhost', user='test', passwd='xx', db='yy')
curs = con.cursor(MySQLdb.cursors.CursorUseResultMixIn)

しかし、これは私にこのエラーを与えてくれます:

  File "C:\Python26\lib\site-packages\MySQLdb\connections.py", line 226, in cursor
    return (cursorclass or self.cursorclass)(self)
TypeError: object.__new__() takes no parameters

私は何が間違っているのですか?

ここで関連情報ここ

役に立ちましたか?

解決

MySQLdb.cursors モジュールは使用します CursorUseResultMixIn このような:

class SSCursor(CursorUseResultMixIn, CursorTupleRowsMixIn,
               BaseCursor):

    """This is a Cursor class that returns rows as tuples and stores
    the result set in the server."""

それは文字通りの定義全体です SSCursor.

basecursorを異なる方法でサブクラス化する必要性がある場合を除き、使用することができます SSCursor このような:

import MySQLdb.cursors as cursors
con = MySQLdb.connect(host = 'localhost', user = 'test', passwd = 'xx', 
                           db = 'yy', cursorclass = cursors.SSCursor)

詩aもあります cursors.SSDictCursor 結果をサーバーに保存しながら、辞書として行を返します。

PPS。 Ubuntu 11.10で、 MySQLdb.cursors 通常、モジュールはにあります /usr/lib/pymodules/python2.7/MySQLdb/cursors.py.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top