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