Read a column descriptor packet for each column in the result.
(self)
| 1402 | return tuple(row) |
| 1403 | |
| 1404 | def _get_descriptions(self): |
| 1405 | """Read a column descriptor packet for each column in the result.""" |
| 1406 | self.fields = [] |
| 1407 | self.converters = [] |
| 1408 | use_unicode = self.connection.use_unicode |
| 1409 | conn_encoding = self.connection.encoding |
| 1410 | description = [] |
| 1411 | |
| 1412 | for i in range(self.field_count): |
| 1413 | field = self.connection._read_packet(FieldDescriptorPacket) |
| 1414 | self.fields.append(field) |
| 1415 | description.append(field.description()) |
| 1416 | field_type = field.type_code |
| 1417 | if use_unicode: |
| 1418 | if field_type == FIELD_TYPE.JSON: |
| 1419 | # When SELECT from JSON column: charset = binary |
| 1420 | # When SELECT CAST(... AS JSON): charset = connection encoding |
| 1421 | # This behavior is different from TEXT / BLOB. |
| 1422 | # We should decode result by connection encoding regardless charsetnr. |
| 1423 | # See https://github.com/PyMySQL/PyMySQL/issues/488 |
| 1424 | encoding = conn_encoding # SELECT CAST(... AS JSON) |
| 1425 | elif field_type in TEXT_TYPES: |
| 1426 | if field.charsetnr == 63: # binary |
| 1427 | # TEXTs with charset=binary means BINARY types. |
| 1428 | encoding = None |
| 1429 | else: |
| 1430 | encoding = conn_encoding |
| 1431 | else: |
| 1432 | # Integers, Dates and Times, and other basic data is encoded in ascii |
| 1433 | encoding = "ascii" |
| 1434 | else: |
| 1435 | encoding = None |
| 1436 | converter = self.connection.decoders.get(field_type) |
| 1437 | if converter is converters.through: |
| 1438 | converter = None |
| 1439 | if DEBUG: |
| 1440 | print(f"DEBUG: field={field}, converter={converter}") |
| 1441 | self.converters.append((encoding, converter)) |
| 1442 | |
| 1443 | eof_packet = self.connection._read_packet() |
| 1444 | assert eof_packet.is_eof_packet(), "Protocol error, expecting EOF" |
| 1445 | self.description = tuple(description) |
| 1446 | |
| 1447 | |
| 1448 | class LoadLocalFile: |
no test coverage detected