MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / BaseCursor

Class BaseCursor

asyncpg/cursor.py:83–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81
82
83class BaseCursor(connresource.ConnectionResource):
84
85 __slots__ = (
86 '_state',
87 '_args',
88 '_portal_name',
89 '_exhausted',
90 '_query',
91 '_record_class',
92 )
93
94 def __init__(self, connection, query, state, args, record_class):
95 super().__init__(connection)
96 self._args = args
97 self._state = state
98 if state is not None:
99 state.attach()
100 self._portal_name = None
101 self._exhausted = False
102 self._query = query
103 self._record_class = record_class
104
105 def _check_ready(self):
106 if self._state is None:
107 raise exceptions.InterfaceError(
108 'cursor: no associated prepared statement')
109
110 if self._state.closed:
111 raise exceptions.InterfaceError(
112 'cursor: the prepared statement is closed')
113
114 if not self._connection._top_xact:
115 raise exceptions.NoActiveSQLTransactionError(
116 'cursor cannot be created outside of a transaction')
117
118 async def _bind_exec(self, n, timeout):
119 self._check_ready()
120
121 if self._portal_name:
122 raise exceptions.InterfaceError(
123 'cursor already has an open portal')
124
125 con = self._connection
126 protocol = con._protocol
127
128 self._portal_name = con._get_unique_id('portal')
129 buffer, _, self._exhausted = await protocol.bind_execute(
130 self._state, self._args, self._portal_name, n, True, timeout)
131 return buffer
132
133 async def _bind(self, timeout):
134 self._check_ready()
135
136 if self._portal_name:
137 raise exceptions.InterfaceError(
138 'cursor already has an open portal')
139
140 con = self._connection

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…