Read a column descriptor packet for each column in the result.
(self)
| 1456 | return tuple(row) |
| 1457 | |
| 1458 | def _get_descriptions(self): |
| 1459 | """Read a column descriptor packet for each column in the result.""" |
| 1460 | self.fields = [] |
| 1461 | self.converters = [] |
| 1462 | use_unicode = self.connection.use_unicode |
| 1463 | conn_encoding = self.connection.encoding |
| 1464 | description = [] |
| 1465 | |
| 1466 | for i in range(self.field_count): |
| 1467 | field = self.connection._read_packet(FieldDescriptorPacket) |
| 1468 | self.fields.append(field) |
| 1469 | description.append(field.description()) |
| 1470 | field_type = field.type_code |
| 1471 | if use_unicode: |
| 1472 | if field_type == FIELD_TYPE.JSON: |
| 1473 | # When SELECT from JSON column: charset = binary |
| 1474 | # When SELECT CAST(... AS JSON): charset = connection encoding |
| 1475 | # This behavior is different from TEXT / BLOB. |
| 1476 | # We should decode result by connection encoding regardless charsetnr. |
| 1477 | # See https://github.com/PyMySQL/PyMySQL/issues/488 |
| 1478 | encoding = conn_encoding # SELECT CAST(... AS JSON) |
| 1479 | elif field_type in TEXT_TYPES: |
| 1480 | if field.charsetnr == 63: # binary |
| 1481 | # TEXTs with charset=binary means BINARY types. |
| 1482 | encoding = None |
| 1483 | else: |
| 1484 | encoding = conn_encoding |
| 1485 | else: |
| 1486 | # Integers, Dates and Times, and other basic data is encoded in ascii |
| 1487 | encoding = "ascii" |
| 1488 | else: |
| 1489 | encoding = None |
| 1490 | converter = self.connection.decoders.get(field_type) |
| 1491 | if converter is converters.through: |
| 1492 | converter = None |
| 1493 | if DEBUG: |
| 1494 | print(f"DEBUG: field={field}, converter={converter}") |
| 1495 | self.converters.append((encoding, converter)) |
| 1496 | |
| 1497 | eof_packet = self.connection._read_packet() |
| 1498 | assert eof_packet.is_eof_packet(), "Protocol error, expecting EOF" |
| 1499 | self.description = tuple(description) |
| 1500 | |
| 1501 | |
| 1502 | def _send_local_file(filename: str, conn: Connection): |
no test coverage detected