A MysqlPacket that represents a specific column's metadata in the result. Parsing is automatically done and the results are exported via public attributes on the class such as: db, table_name, name, length, type_code.
| 223 | |
| 224 | |
| 225 | class FieldDescriptorPacket(MysqlPacket): |
| 226 | """A MysqlPacket that represents a specific column's metadata in the result. |
| 227 | |
| 228 | Parsing is automatically done and the results are exported via public |
| 229 | attributes on the class such as: db, table_name, name, length, type_code. |
| 230 | """ |
| 231 | |
| 232 | def __init__(self, data, encoding): |
| 233 | MysqlPacket.__init__(self, data, encoding) |
| 234 | self._parse_field_descriptor(encoding) |
| 235 | |
| 236 | def _parse_field_descriptor(self, encoding): |
| 237 | """Parse the 'Field Descriptor' (Metadata) packet. |
| 238 | |
| 239 | This is compatible with MySQL 4.1+ (not compatible with MySQL 4.0). |
| 240 | """ |
| 241 | self.catalog = self.read_length_coded_string() |
| 242 | self.db = self.read_length_coded_string() |
| 243 | self.table_name = self.read_length_coded_string().decode(encoding) |
| 244 | self.org_table = self.read_length_coded_string().decode(encoding) |
| 245 | self.name = self.read_length_coded_string().decode(encoding) |
| 246 | self.org_name = self.read_length_coded_string().decode(encoding) |
| 247 | ( |
| 248 | self.charsetnr, |
| 249 | self.length, |
| 250 | self.type_code, |
| 251 | self.flags, |
| 252 | self.scale, |
| 253 | ) = self.read_struct("<xHIBHBxx") |
| 254 | # 'default' is a length coded binary and is still in the buffer? |
| 255 | # not used for normal result sets... |
| 256 | |
| 257 | def description(self): |
| 258 | """Provides a 7-item tuple compatible with the Python PEP249 DB Spec.""" |
| 259 | return ( |
| 260 | self.name, |
| 261 | self.type_code, |
| 262 | None, # TODO: display_length; should this be self.length? |
| 263 | self.get_column_length(), # 'internal_size' |
| 264 | self.get_column_length(), # 'precision' # TODO: why!?!? |
| 265 | self.scale, |
| 266 | self.flags % 2 == 0, |
| 267 | ) |
| 268 | |
| 269 | def get_column_length(self): |
| 270 | if self.type_code == FIELD_TYPE.VAR_STRING: |
| 271 | mblen = MBLENGTH.get(self.charsetnr, 1) |
| 272 | return self.length // mblen |
| 273 | return self.length |
| 274 | |
| 275 | def __str__(self): |
| 276 | return f"{self.__class__} {self.db!r}.{self.table_name!r}.{self.name!r}, type={self.type_code}, flags={self.flags:x}" |
| 277 | |
| 278 | |
| 279 | class OKPacketWrapper: |
nothing calls this directly
no outgoing calls
no test coverage detected