Bug #58373 ReadInteger problem
Submitted: 22 Nov 2010 9:22 Modified: 2 Dec 2010 14:11
Reporter: Barbara Post Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.3.5 OS:Windows (MySql 5.1.22-community)
Assigned to: CPU Architecture:Any

[22 Nov 2010 9:22] Barbara Post
Description:
Hello,

I have an insert request which fails. It's just an insert of an int value into an int primary key column.

Before setting up a test case, here is the code where I see a problem. Code is different from what it looked like in 6.2.2 version of connector I previously used without problems. Thank you in advance for feedback about what is wrong. Maybe there is a problem in my DB schema if the code looks correct.

MySqlPacket, around line 151 : my debug cursor goes into case "254".

 public int ReadFieldLength()
        {
            byte c = ReadByte();

            switch (c)
            {
                case 251: return -1;
                case 252: return ReadInteger(2);
                case 253: return ReadInteger(3);
                case 254: return ReadInteger(8);
                default: return c;
            }
        }

Then around line 230 : numbytes is equal to 8 then the debug.Assert fails and breaks my unit test (NUnit 2.5.8).

 public int ReadInteger(int numbytes)
        {
            if (numbytes == 3)
                return Read3ByteInt();
            Debug.Assert(numbytes <= 4);
            return (int)ReadLong(numbytes);
        }

Either :
- the Debug.Assert is wrong ?
- or ReadLong(8) should be called instead of ReadInteger(8) in ReadFieldLength() ?
- or I have something incoherent between my column definition and data ?

I personally think that the Debug.Assert is wrng. But what about case when param numbyte equals 2 ?

Thanks,

Barbara

How to repeat:
Not filled in yet, will be filled if feedback asked (have to trim down my code, this takes some time).
[22 Nov 2010 9:26] Barbara Post
A precision : my column in DB is of exact type "unsigned int, not null, auto inc".
[22 Nov 2010 9:42] Barbara Post
Another precision : tThe error happens when the inserted ID is read after insert, and the value to insert was generated by Guid.NewGuid().ToString().
[22 Nov 2010 9:51] Tonci Grgin
Hi Barbara.

It would be nice to have a small but complete test case (along with DDL/DML needed) attached and MySQL server version noted.
[22 Nov 2010 13:32] Barbara Post
OK, when I have time, soon...
[22 Nov 2010 16:01] Tonci Grgin
Barbara, don't get me wrong. I get tens of reports daily and if I'm to check them I really need something to work on. Worst thing would be that, guided by wrong assumptions, I test the report "my way" and declare it !Bg...
[24 Nov 2010 12:07] Barbara Post
Test case : console app to run + script to create testdb DB

Attachment: BugReport58373.zip (application/zip, text), 183.19 KiB.

[24 Nov 2010 12:09] Barbara Post
Well, I was finally able to pinpoint the bug and uploaded a test case.

The primary key of the table I insert into is named "ID", and the auto incremented value it has before I insert is quite big.

There is a problem when retrieving the last inserted id, because of the "ID" name. I wonder about wether this is a known bug...
[30 Nov 2010 9:22] Bogdan Degtyariov
Setting the status to verified.
Got the following stack trace:

    at MySqlPacket.ReadInteger(Int32 numbytes)  
    at MySqlPacket.ReadFieldLength()  
    at NativeDriver.GetResult(Int32& affectedRow, Int32& insertedId)  
    at Driver.GetResult(Int32 statementId, Int32& affectedRows, Int32& insertedId)  
    at Driver.NextResult(Int32 statementId)  
    at MySqlDataReader.NextResult()  
    at MySqlCommand.ExecuteReader(CommandBehavior behavior)  
    at MySqlCommand.ExecuteReader()  
    at MySqlCommand.ExecuteScalar()  
    at TestBug.Main(String[] args)  C:\Projects\bugs\58373\BugReport58373\BugReport58373\Program.cs(34)
    at AppDomain._nExecuteAssembly(Assembly assembly, String[] args)  
    at AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)  
    at HostProc.RunUsersAssembly()  
    at ThreadHelper.ThreadStart_Context(Object state)  
    at ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)  
    at ThreadHelper.ThreadStart()  

The program '[9204] BugReport58316.vshost.exe: Managed (v2.0.50727)' has exited with code 1 (0x1).
[30 Nov 2010 18:29] 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/125548

849 Reggie Burnett	2010-11-30
      - fixed ReadFieldLength to return a long so bigint autoincrement columns can work (bug #58373)
[30 Nov 2010 18:32] Reggie Burnett
fixed in 6.0.8, 6.1.6, 6.2.5, 6.3.6+
[2 Dec 2010 14:11] Tony Bedford
An entry has been added to the 6.0.8, 6.1.6, 6.2.5, and 6.3.6 changelogs:

ReadFieldLength() returned incorrect value for BIGINT autoincrement columns.