MCPcopy Create free account
hub / github.com/PyMySQL/PyMySQL / SSCursor

Class SSCursor

pymysql/cursors.py:397–515  ·  view source on GitHub ↗

Unbuffered Cursor, mainly useful for queries that return a lot of data, or for connections to remote servers over a slow network. Instead of copying every row of data into a buffer, this will fetch rows as needed. The upside of this is the client uses much less memory, and rows

Source from the content-addressed store, hash-verified

395
396
397class SSCursor(Cursor):
398 """
399 Unbuffered Cursor, mainly useful for queries that return a lot of data,
400 or for connections to remote servers over a slow network.
401
402 Instead of copying every row of data into a buffer, this will fetch
403 rows as needed. The upside of this is the client uses much less memory,
404 and rows are returned much faster when traveling over a slow network
405 or if the result set is very big.
406
407 There are limitations, though. The MySQL protocol doesn't support
408 returning the total number of rows, so the only way to tell how many rows
409 there are is to iterate over every row returned. Also, it currently isn't
410 possible to scroll backwards, as only the current row is held in memory.
411 """
412
413 def _conv_row(self, row):
414 return row
415
416 def close(self):
417 conn = self.connection
418 if conn is None:
419 return
420
421 if self._result is not None and self._result is conn._result:
422 self._result._finish_unbuffered_query()
423
424 try:
425 while self.nextset():
426 pass
427 finally:
428 self.connection = None
429
430 __del__ = close
431
432 def _query(self, q):
433 conn = self._get_db()
434 self._clear_result()
435 conn.query(q, unbuffered=True)
436 self._do_get_result()
437 return self.rowcount
438
439 def nextset(self):
440 return self._nextset(unbuffered=True)
441
442 def read_next(self):
443 """Read next row."""
444 return self._conv_row(self._result._read_rowdata_packet_unbuffered())
445
446 def fetchone(self):
447 """Fetch next row."""
448 self._check_executed()
449 row = self.read_next()
450 if row is None:
451 self.warning_count = self._result.warning_count
452 return None
453 self.rownumber += 1
454 return row

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected