Python encapsulation of pymysql SSCursor class not working as expected

The following works:

class DB(): def __init__(self, host, user, password, db): self.conn = pymysql.connect( host = host, user = user, passwd = password, charset = 'utf8', cursorclass = pymysql.cursors.DictCursor, db = db ) self.cur = self.conn.cursor() def execute(self, sql): self.cur.execute(sql) def fetchone(self): return self.cur.fetchone() cf = DB("localhost", "user", "pass", "db") cf.execute("SELECT Count(*) FROM Table") aryRes = cf.fetchone() 

But when I replace DictCursor with SSCursor, aryRes contains None, and I get:

 warnings.warn("Previous unbuffered result was left incomplete") 

I tried all combinations:

 import pymysql import pymysql.cursors from pymysql import cursors 

I also confirmed that the following returns correctly (not encapsulated):

 con = pymysql.connect( host = "localhost", user = "user", passwd = "pass", charset = 'utf8', cursorclass = pymysql.cursors.SSCursor, db = "db" ) cur = con.cursor() cur.execute("SELECT Count(*) FROM Table") aryRes = cur.fetchone() 

What am I missing, what will the encapsulated SSCursors do? I am new to Python, so feel free to fix anything that seems right to you.

Forgot to mention ... I am using Python 2.7.12

+5
source share
1 answer

I think you have a problem because you get only one result, while there are others. After fetchone try running fetchall to clear the buffer.

+1
source

Source: https://habr.com/ru/post/1261417/


All Articles