Bug #16485 Internals documentation is wrong about FIELD wire protocol for 4.0
Submitted: 13 Jan 2006 15:51 Modified: 23 Jun 2006 12:30
Reporter: Mark Matthews Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:4.0 OS:
Assigned to: MC Brown CPU Architecture:Any

[13 Jan 2006 15:51] Mark Matthews
Description:
The internals manual describes the elements of the FIELD structure as represented on the "wire" for MySQL-4.0 and older like so:

VERSION 4.0
Bytes                      Name
-----                      ----
n (Length Coded String)    table
n (Length Coded String)    name
4 (Length Coded Binary)    length
2 (Length Coded Binary)    type
2 (Length Coded Binary)    flags
1                          decimals
n (Length Coded Binary)    default

However, it's easy to see this isn't the case from libmysql.c -> unpack_fields(), at least for the column type and length:

field->length= (uint) uint3korr(row->data[2]);
field->type=   (enum enum_field_types) (uchar) row->data[3][0];

(unit3korr is a macro from my_global.h):

/*
   ATTENTION !

    Please, note, uint3korr reads 4 bytes (not 3) !
    It means, that you have to provide enough allocated space !
*/
#define uint3korr(A)    (long) (*((unsigned int *) (A)) & 0xFFFFFF)

I didn't yet check the rest of the elements, but we should double check that at least things match up with how they actually are.

How to repeat:
Via inspection.