Bug #14592 Wrong column length returned for VARCHAR UTF8 columns
Submitted: 2 Nov 2005 21:59 Modified: 16 Oct 2006 18:58
Reporter: Jorge Bastos Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:1.0.6, 1.07, 5.0.0.0 OS:Windows (Win, WinXP Pro SP2)
Assigned to: Reggie Burnett CPU Architecture:Any

[2 Nov 2005 21:59] Jorge Bastos
Description:
Hi,

I'm trying to get the table shema with the datareader getshematable function, but the value that the columnSize returns does not have nothing to do with the value of the column that the table has.
The strang is for example, a column that has a varchar(30), the column size show's me 90.
Columns that are INT values, the column size is returned ok, but columns that are of varchar type is returned as trippled.
I never needed to get the size from varchar columns so the bug may exist for a long time, sinse i only getted the size from int columns.

The driver is 1.0.6 version and the MySQL Server is 5.0.15, also tryed with a 4.1.15.

Can i get some feedback when this is viewed or fixed?

Thanks,

Jorge Bastos

How to repeat:
Below there's the code that i'm using:

        Dim dt As New DataTable
        Dim MyCon as New MySqlConnection("con string here")
        MyCon.Open()
        str="select * from table_name where codigo='' "
        dim MyCmd as New MySqlCommand(str, MyCon)
        Dim myrd As MySqlDataReader
        myrd = MyCmd.ExecuteReader
        dt = myrd.GetSchemaTable
        MyCon.Close()
        MyCmd.Dispose()
        
' filling a datagrid

       datagrid1.datasource = dt
[6 Nov 2005 10:47] Vasily Kishkin
Could you please advise me where I can check column size in System.Data.DataTable object ?
[6 Nov 2005 10:53] Jorge Bastos
With the folowing code that i've pasted:
Dim dt As New DataTable
        Dim MyCon as New MySqlConnection("con string here")
        MyCon.Open()
        str="select * from table_name where codigo='' "
        dim MyCmd as New MySqlCommand(str, MyCon)
        Dim myrd As MySqlDataReader
        myrd = MyCmd.ExecuteReader
        dt = myrd.GetSchemaTable
        MyCon.Close()
        MyCmd.Dispose()

Then, or you fill a datagrid and in the 3rd column there's the value, or you can even try with:

for i as int32=0 to dt.rows.count -1
     msgbox "column name: " & dt.rows(i).item(0) & char(13) & "column size: " & dt.rows(i).item(2)
next

if you need anything else just call.

Jorge
[6 Nov 2005 10:56] Jorge Bastos
Or more direct to the question you've made me, the column size is in the 3rd possition
dt.rows(i)item(2) 
sinse array start in zero ( 0 )
[8 Nov 2005 11:27] Vasily Kishkin
Thanks for advise. But I have the follow result of test case:

column name: id column size: 11
column name: ch column size: 30

where description of table is:

CREATE TABLE `test` (
  `id` int(11) default NULL,
  `ch` varchar(30) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

I attached my test case. Could you please build and run ?
[8 Nov 2005 11:28] Vasily Kishkin
Test case

Attachment: 14592.zip (application/force-download, text), 5.24 KiB.

[8 Nov 2005 14:27] Jorge Bastos
Hi there,
I've runned the attach you sent, it's really working, but what i founded was, that on my still don't work, so, the only diference between my tables and the one you've sent if the charset.
The one you sent was with a "latin1" charset, i've changed to utf8 and the collation to utf8_general_ci, that is the one that i use in all my database's and tables.after change the table to this parameters the value still returned ok sinse the varchar column still with latin1_swedish_ci, but when i change the column collation to utf8_general_ci it comes with the value trippled again. so i think this may be the problem, don't really know the conection between the collation and this but.... hope this can help you fix it if this is a bug, as i think it may be.
So, when you'll have more news you'll say?

Jorge
[15 Nov 2005 19:28] Vasily Kishkin
I was able to reproduce the bug with utf8. 
My results are:

column name: id column size: 11
column name: ch column size: 90

and table definition is:

CREATE TABLE `test` (
  `id` int(11) default NULL,
  `ch` varchar(30) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
[15 Nov 2005 19:55] Jorge Bastos
Cool, that means that'll be fixes in the upcoming 1.0.7 version?

Jorge Bastos
[25 Sep 2006 8:54] Tonci Grgin
Changing synopsis from "Getting Table shema with DataReader" to "Wrong column length returned for VARCHAR UTF8 columns"
[25 Sep 2006 10:48] Jorge Bastos
No problem.
Is this beeing included for the next 1.0.8 version?

Jorge
[26 Sep 2006 16:14] 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/commits/12552
[26 Sep 2006 16:16] 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/commits/12553
[26 Sep 2006 16:16] Reggie Burnett
Fixed in 1.0.8 and 5.0.1
[26 Sep 2006 16:18] Jorge Bastos
Fantastic.
Thanks, Any prevision for 1.0.8 ?

Jorge
[16 Oct 2006 18:58] MC Brown
A note has been added to the 5.0.1 and 1.0.8 changelogs.
[16 Feb 2010 10:58] Tonci Grgin
Bug#51206.