Bug #29930 Incorrect docs of MYSQL_FIELD
Submitted: 20 Jul 2007 12:13 Modified: 23 Jan 2008 18:45
Reporter: Andrey Hristov Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: C API (client library) Severity:S3 (Non-critical)
Version:5.0 bk, 5.1 bk OS:Any
Assigned to: CPU Architecture:Any

[20 Jul 2007 12:13] Andrey Hristov
Description:
http://dev.mysql.com/doc/refman/5.0/en/c-api-datatypes.html :
# unsigned long length

The width of the field. This corresponds to the display length, in bytes.

However, this is not true for BIT. For BIT the length on disk in bytes is sent.

[14:58:08] andrey@lmy004:~/dev/php6> mysql --column-type-info -h 127.0.0.1 test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.1.21-beta-debug-log Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> select * from bittable;
Field   1:  `a`
Catalog:    `def`
Database:   `test`
Table:      `bittable`
Org_table:  `bittable`
Type:       BIT
Collation:  binary (63)
Length:     12
Max_length: 0
Decimals:   0
Flags:      UNSIGNED

0 rows in set (0.00 sec)

mysql> prepare xyz from "select * from bittable";
Query OK, 0 rows affected (0.00 sec)
Statement prepared

mysql> execute xyz;
Field   1:  `a`
Catalog:    `def`
Database:   `test`
Table:      `bittable`
Org_table:  `bittable`
Type:       BIT
Collation:  binary (63)
Length:     12
Max_length: 0
Decimals:   0
Flags:      UNSIGNED

0 rows in set (0.00 sec)

How to repeat:
See statements above.
[20 Jul 2007 12:45] Sveta Smirnova
Thank you for the report.

Verified as described.
[20 Jul 2007 22:17] Jim Winstead
This bug report is either wrong, or it is a server bug. MYSQL_FIELD::length should *always* be the display length of the field, regardless of type. Anything else will break things like Connector/ODBC.

Fixing this for MYSQL_FIELD::length was Bug #13601.

Here's what I get with 5.1.20:

mysql> create table t1 (a bit(3));
Query OK, 0 rows affected (0.02 sec)

mysql> insert into t1 values (b'001'), (b'100');
Query OK, 2 rows affected (0.03 sec)
Records: 2  Duplicates: 0  Warnings: 0

mysql> select * from t1
    -> ;
Field   1:  `a`
Catalog:    `def`
Database:   `test`
Table:      `t1`
Org_table:  `t1`
Type:       BIT
Collation:  binary (63)
Length:     3
Max_length: 1
Decimals:   0
Flags:      UNSIGNED 

+------+
| a    |
+------+
|     | 
|     | 
+------+
2 rows in set (0.00 sec)

mysql> prepare xyz from "select * from t1";
Query OK, 0 rows affected (0.00 sec)
Statement prepared

mysql> execute xyz;
Field   1:  `a`
Catalog:    `def`
Database:   `test`
Table:      `t1`
Org_table:  `t1`
Type:       BIT
Collation:  binary (63)
Length:     3
Max_length: 1
Decimals:   0
Flags:      UNSIGNED 

+------+
| a    |
+------+
|     | 
|     | 
+------+
2 rows in set (0.00 sec)
[23 Jan 2008 18:45] Jim Winstead
As agreed by Andrey, this is not a bug. The documentation is correct, and the output of the server agrees with this.