|
1 |
| -# Copyright (c) 2023, 2024, Oracle and/or its affiliates. |
| 1 | +# Copyright (c) 2023, 2025, Oracle and/or its affiliates. |
2 | 2 | #
|
3 | 3 | # This program is free software; you can redistribute it and/or modify
|
4 | 4 | # it under the terms of the GNU General Public License, version 2.0, as
|
|
35 | 35 | import re
|
36 | 36 | import warnings
|
37 | 37 |
|
38 |
| -from collections import namedtuple |
39 | 38 | from decimal import Decimal
|
40 | 39 | from typing import (
|
41 | 40 | Any,
|
|
83 | 82 | StrOrBytes,
|
84 | 83 | WarningType,
|
85 | 84 | )
|
86 |
| -from .abstracts import NAMED_TUPLE_CACHE, MySQLConnectionAbstract, MySQLCursorAbstract |
| 85 | +from .abstracts import MySQLConnectionAbstract, MySQLCursorAbstract |
87 | 86 | from .utils import deprecated
|
88 | 87 |
|
89 | 88 | ERR_NO_RESULT_TO_FETCH = "No result set to fetch from"
|
@@ -576,11 +575,6 @@ async def callproc(
|
576 | 575 | self._connection.can_consume_results = False
|
577 | 576 | if isinstance(self, (MySQLCursorDict, MySQLCursorBufferedDict)):
|
578 | 577 | cursor_class = MySQLCursorBufferedDict
|
579 |
| - elif isinstance( |
580 |
| - self, |
581 |
| - (MySQLCursorNamedTuple, MySQLCursorBufferedNamedTuple), |
582 |
| - ): |
583 |
| - cursor_class = MySQLCursorBufferedNamedTuple |
584 | 578 | elif self._raw:
|
585 | 579 | cursor_class = MySQLCursorBufferedRaw
|
586 | 580 | else:
|
@@ -1005,64 +999,6 @@ async def fetchall(self) -> List[Optional[Dict[str, RowItemType]]]:
|
1005 | 999 | ]
|
1006 | 1000 |
|
1007 | 1001 |
|
1008 |
| -class MySQLCursorNamedTuple(MySQLCursor): |
1009 |
| - """ |
1010 |
| - Cursor fetching rows as named tuple. |
1011 |
| -
|
1012 |
| - The fetch methods of this class will return namedtuples instead of tuples. |
1013 |
| - Each row is returned as a namedtuple and the values can be accessed as: |
1014 |
| - row.col1, row.col2 |
1015 |
| - """ |
1016 |
| - |
1017 |
| - def _row_to_python( |
1018 |
| - self, |
1019 |
| - rowdata: RowType, |
1020 |
| - desc: Optional[List[DescriptionType]] = None, # pylint: disable=unused-argument |
1021 |
| - ) -> Optional[RowType]: |
1022 |
| - """Convert a MySQL text result row to Python types |
1023 |
| -
|
1024 |
| - Returns a named tuple. |
1025 |
| - """ |
1026 |
| - row = rowdata |
1027 |
| - |
1028 |
| - if row: |
1029 |
| - columns = tuple(self.column_names) |
1030 |
| - try: |
1031 |
| - named_tuple = NAMED_TUPLE_CACHE[columns] |
1032 |
| - except KeyError: |
1033 |
| - named_tuple = namedtuple("Row", columns) # type:ignore[no-redef, misc] |
1034 |
| - NAMED_TUPLE_CACHE[columns] = named_tuple |
1035 |
| - return named_tuple(*row) |
1036 |
| - return None |
1037 |
| - |
1038 |
| - async def fetchone(self) -> Optional[RowType]: |
1039 |
| - """Return next row of a query result set. |
1040 |
| -
|
1041 |
| - Returns: |
1042 |
| - tuple or None: A row from query result set. |
1043 |
| - """ |
1044 |
| - row = await super().fetchone() |
1045 |
| - if not row: |
1046 |
| - return None |
1047 |
| - return ( |
1048 |
| - self._row_to_python(row, self.description) |
1049 |
| - if hasattr(self._connection, "converter") |
1050 |
| - else row |
1051 |
| - ) |
1052 |
| - |
1053 |
| - async def fetchall(self) -> List[Optional[RowType]]: |
1054 |
| - """Return all rows of a query result set. |
1055 |
| -
|
1056 |
| - Returns: |
1057 |
| - list: A list of tuples with all rows of a query result set. |
1058 |
| - """ |
1059 |
| - return [ |
1060 |
| - self._row_to_python(row, self.description) |
1061 |
| - for row in await super().fetchall() |
1062 |
| - if row |
1063 |
| - ] |
1064 |
| - |
1065 |
| - |
1066 | 1002 | class MySQLCursorBufferedDict(MySQLCursorDict, MySQLCursorBuffered):
|
1067 | 1003 | """
|
1068 | 1004 | Buffered Cursor fetching rows as dictionaries.
|
@@ -1095,38 +1031,6 @@ async def fetchall(self) -> List[Optional[Dict[str, RowItemType]]]:
|
1095 | 1031 | return res
|
1096 | 1032 |
|
1097 | 1033 |
|
1098 |
| -class MySQLCursorBufferedNamedTuple(MySQLCursorNamedTuple, MySQLCursorBuffered): |
1099 |
| - """ |
1100 |
| - Buffered Cursor fetching rows as named tuple. |
1101 |
| - """ |
1102 |
| - |
1103 |
| - async def fetchone(self) -> Optional[RowType]: |
1104 |
| - """Return next row of a query result set. |
1105 |
| -
|
1106 |
| - Returns: |
1107 |
| - tuple or None: A row from query result set. |
1108 |
| - """ |
1109 |
| - self._check_executed() |
1110 |
| - row = await self._fetch_row() |
1111 |
| - if row: |
1112 |
| - return self._row_to_python(row, self.description) |
1113 |
| - return None |
1114 |
| - |
1115 |
| - async def fetchall(self) -> List[Optional[RowType]]: |
1116 |
| - """Return all rows of a query result set. |
1117 |
| -
|
1118 |
| - Returns: |
1119 |
| - list: A list of tuples with all rows of a query result set. |
1120 |
| - """ |
1121 |
| - if self._executed is None or self._rows is None: |
1122 |
| - raise InterfaceError(ERR_NO_RESULT_TO_FETCH) |
1123 |
| - res = [] |
1124 |
| - for row in self._rows[self._next_row :]: |
1125 |
| - res.append(self._row_to_python(row, self.description)) |
1126 |
| - self._next_row = len(self._rows) |
1127 |
| - return res |
1128 |
| - |
1129 |
| - |
1130 | 1034 | class MySQLCursorPrepared(MySQLCursor):
|
1131 | 1035 | """Cursor using MySQL Prepared Statements"""
|
1132 | 1036 |
|
@@ -1481,105 +1385,3 @@ async def fetchmany(
|
1481 | 1385 | for row in await super().fetchmany(size=size)
|
1482 | 1386 | if row
|
1483 | 1387 | ]
|
1484 |
| - |
1485 |
| - |
1486 |
| -class MySQLCursorPreparedNamedTuple(MySQLCursorNamedTuple, MySQLCursorPrepared): |
1487 |
| - """ |
1488 |
| - This class is a blend of features from MySQLCursorNamedTuple and MySQLCursorPrepared |
1489 |
| - """ |
1490 |
| - |
1491 |
| - async def fetchmany(self, size: Optional[int] = None) -> List[RowType]: |
1492 |
| - """Return the next set of rows of a query result set. |
1493 |
| -
|
1494 |
| - When no more rows are available, it returns an empty list. |
1495 |
| - The number of rows returned can be specified using the size argument, |
1496 |
| - which defaults to one. |
1497 |
| -
|
1498 |
| - Returns: |
1499 |
| - list: The next set of rows of a query result set represented |
1500 |
| - as a list of named tuples where column names are used as names. |
1501 |
| - """ |
1502 |
| - return [ |
1503 |
| - self._row_to_python(row, self.description) |
1504 |
| - for row in await super().fetchmany(size=size) |
1505 |
| - if row |
1506 |
| - ] |
1507 |
| - |
1508 |
| - |
1509 |
| -class MySQLCursorPreparedRaw(MySQLCursorPrepared): |
1510 |
| - """ |
1511 |
| - This class is a blend of features from MySQLCursorRaw and MySQLCursorPrepared |
1512 |
| - """ |
1513 |
| - |
1514 |
| - def __init__( |
1515 |
| - self, |
1516 |
| - connection: MySQLConnectionAbstract, |
1517 |
| - read_timeout: Optional[int] = None, |
1518 |
| - write_timeout: Optional[int] = None, |
1519 |
| - ): |
1520 |
| - super().__init__(connection, read_timeout, write_timeout) |
1521 |
| - self._raw: bool = True |
1522 |
| - |
1523 |
| - async def fetchone(self) -> Optional[RowType]: |
1524 |
| - """Return next row of a query result set. |
1525 |
| -
|
1526 |
| - Returns: |
1527 |
| - tuple or None: A row from query result set. |
1528 |
| - """ |
1529 |
| - self._check_executed() |
1530 |
| - if self._cursor_exists: |
1531 |
| - await self._connection.cmd_stmt_fetch( |
1532 |
| - self._prepared["statement_id"], |
1533 |
| - read_timeout=self._read_timeout, |
1534 |
| - write_timeout=self._write_timeout, |
1535 |
| - ) |
1536 |
| - return await self._fetch_row(raw=self._raw) or None |
1537 |
| - |
1538 |
| - async def fetchmany(self, size: Optional[int] = None) -> List[RowType]: |
1539 |
| - """Return the next set of rows of a query result set. |
1540 |
| -
|
1541 |
| - When no more rows are available, it returns an empty list. |
1542 |
| - The number of rows returned can be specified using the size argument, |
1543 |
| - which defaults to one. |
1544 |
| -
|
1545 |
| - Returns: |
1546 |
| - list: The next set of rows of a query result set. |
1547 |
| - """ |
1548 |
| - self._check_executed() |
1549 |
| - res = [] |
1550 |
| - cnt = size or self.arraysize |
1551 |
| - while cnt > 0 and self._have_unread_result(): |
1552 |
| - cnt -= 1 |
1553 |
| - row = await self._fetch_row(raw=self._raw) |
1554 |
| - if row: |
1555 |
| - res.append(row) |
1556 |
| - return res |
1557 |
| - |
1558 |
| - async def fetchall(self) -> List[RowType]: |
1559 |
| - """Return all rows of a query result set. |
1560 |
| -
|
1561 |
| - Returns: |
1562 |
| - list: A list of tuples with all rows of a query result set. |
1563 |
| - """ |
1564 |
| - self._check_executed() |
1565 |
| - rows = [] |
1566 |
| - if self._nextrow[0]: |
1567 |
| - rows.append(self._nextrow[0]) |
1568 |
| - while self._have_unread_result(): |
1569 |
| - if self._cursor_exists: |
1570 |
| - await self._connection.cmd_stmt_fetch( |
1571 |
| - self._prepared["statement_id"], |
1572 |
| - MAX_RESULTS, |
1573 |
| - read_timeout=self._read_timeout, |
1574 |
| - write_timeout=self._write_timeout, |
1575 |
| - ) |
1576 |
| - tmp, eof = await self._connection.get_rows( |
1577 |
| - raw=self._raw, |
1578 |
| - binary=self._binary, |
1579 |
| - columns=self.description, |
1580 |
| - read_timeout=self._read_timeout, |
1581 |
| - ) |
1582 |
| - rows.extend(tmp) |
1583 |
| - await self._handle_eof(eof) |
1584 |
| - self._rowcount = len(rows) |
1585 |
| - return rows |
0 commit comments