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

Class Cursor

pymysql/cursors.py:24–367  ·  view source on GitHub ↗

This is the object used to interact with the database. Do not create an instance of a Cursor yourself. Call connections.Connection.cursor(). See `Cursor `_ in the specification.

Source from the content-addressed store, hash-verified

22
23
24class Cursor:
25 """
26 This is the object used to interact with the database.
27
28 Do not create an instance of a Cursor yourself. Call
29 connections.Connection.cursor().
30
31 See `Cursor <https://www.python.org/dev/peps/pep-0249/#cursor-objects>`_ in
32 the specification.
33 """
34
35 #: Max statement size which :meth:`executemany` generates.
36 #:
37 #: Max size of allowed statement is max_allowed_packet - packet_header_size.
38 #: Default value of max_allowed_packet is 1048576.
39 max_stmt_length = 1024000
40
41 def __init__(self, connection):
42 self.connection = connection
43 self.warning_count = 0
44 self.description = None
45 self.rownumber = 0
46 self.rowcount = -1
47 self.arraysize = 1
48 self._executed = None
49 self._result = None
50 self._rows = None
51
52 def close(self):
53 """
54 Closing a cursor just exhausts all remaining data.
55 """
56 conn = self.connection
57 if conn is None:
58 return
59 try:
60 while self.nextset():
61 pass
62 finally:
63 self.connection = None
64
65 def __enter__(self):
66 return self
67
68 def __exit__(self, *exc_info):
69 del exc_info
70 self.close()
71
72 def _get_db(self):
73 if not self.connection:
74 raise err.ProgrammingError("Cursor closed")
75 return self.connection
76
77 def _check_executed(self):
78 if not self._executed:
79 raise err.ProgrammingError("execute() first")
80
81 def _conv_row(self, row):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected