Bug #11311 mysql_fetch_fields does not return the right data_length value of a column
Submitted: 14 Jun 2005 11:41 Modified: 25 Jul 2005 19:45
Reporter: Josep Maria Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.12 OS:Microsoft Windows (Windows XP SP2)
Assigned to: Jim Winstead CPU Architecture:Any

[14 Jun 2005 11:41] Josep Maria
Description:
Hello, the next query does not return the right value

SELECT LPAD(LINIA,7," ") as CAMPO FROM table

LINIA is a INTEGER field

Calling the mysql_fetch_fields() of libmysql.dll ( We have the last version) (after calling mysql_store_result()) return the length of the field CAMPO as 11, it should be 7 

We use InnoDb Engine.

Sorry by my english.

How to repeat:
SELECT LPAD(LINIA,7," ") as CAMPO FROM table

and call the function mysql_fetch_fields and look the data length value of  the MYSQL_FIELD structure
[14 Jun 2005 12:41] Hartmut Holzgraefe
Verified, uploading test program to the files section.
The table i used for testing is:

create table test.f(i int);
insert into test.f(i) values(1000000000);

the reported CREATE field length for the result field is 11, not the expected 7

looks as if LPAD does not modify the arg length information in its LPAD_init handler?
[14 Jun 2005 12:41] Hartmut Holzgraefe
forgot to mention: its not related to integer input at all, the same happens with char columns as input
[14 Jun 2005 12:43] Hartmut Holzgraefe
mysql_fetch_fields example program

Attachment: mysql_fetch_fields.c (text/plain), 2.70 KiB.

[24 Jun 2005 2:35] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/26391
[24 Jun 2005 16:18] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/26412
[22 Jul 2005 18:46] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/internals/27494
[22 Jul 2005 21:45] Jim Winstead
Fixed in 4.1.14 and 5.0.11.
[25 Jul 2005 19:45] Mike Hillyer
Documented in 4.1.14 and 5.0.11 changelogs:

<listitem><para>The <literal>LPAD()</literal> and <literal>RPAD()</literal> functions returned the wrong length to <literal>mysql_fetch_fields()</literal>. (Bug #11311)</para></listitem>