2 from .exceptions
import _translate_exception
3 from ._parsers
import _bind_parameters, _extract_description, _extract_col_vals
7 """A database cursor."""
18 connection.register_runtime_udfs()
34 Read-only sequence describing columns of the result set.
35 Each column is an instance of `Description` describing
45 We only use name, type_code, and null_ok; The rest are always ``None``
55 """The number of rows to fetch at a time with `fetchmany`. Default 1.
65 """Number of items to fetch with :func:`fetchmany`."""
66 if not isinstance(value, int):
68 "Value must be an integer, got {} instead".format(
type(value))
73 """Close this cursor."""
77 def execute(self, operation, parameters=None):
78 """Execute a SQL statement.
85 Parameters to substitute into ``operation``.
94 >>> c.execute("select symbol, qty from stocks")
96 [('RHAT', 100.0), ('IBM', 1000.0), ('MSFT', 1000.0), ('IBM', 500.0)]
98 Passing in ``parameters``:
100 >>> c.execute("select symbol qty from stocks where qty <= :max_qty",
101 ... parameters={"max_qty": 500})
102 [('RHAT', 100.0), ('IBM', 500.0)]
106 operation = operation.strip()
108 if parameters
is not None:
112 result = self.connection._client.sql_execute(
113 self.connection._session,
120 except T.TDBException
as e:
125 self.rowcount = len(result.row_set.columns[0].nulls)
130 self._result = result
134 """Execute a SQL statement for many sets of parameters.
139 parameters: list of dict
143 results: list of lists
146 list(self.
execute(operation, params))
for params
in parameters
151 """Fetch a single row from the results set"""
154 except StopIteration:
158 """Fetch ``size`` rows from the results set."""
161 results = [self.
fetchone()
for _
in range(size)]
162 return [x
for x
in results
if x
is not None]
181 Build a results set of python objects.
189 results: Iterator[tuple]
192 if data.row_set.columns:
193 nrows = len(data.row_set.columns[0].nulls)
194 ncols = len(data.row_set.row_desc)
197 for desc, col
in zip(data.row_set.row_desc, data.row_set.columns)
199 for i
in range(nrows):
200 yield tuple(columns[j][i]
for j
in range(ncols))