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