Bug #7641 Database query fails on Mono with exception in PreparedStatement:Execute
Submitted: 3 Jan 2005 17:19 Modified: 11 Nov 2005 7:51
Reporter: Matthew Pearson Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:1.0.3 OS:Windows (Windows/Mono)
Assigned to: CPU Architecture:Any

[3 Jan 2005 17:19] Matthew Pearson
Description:
I've been using NHibernate with both Mono 1.1.3 and .NET 1.1. this issue only occurs when I use Mono. Executing an NHibernate query results in an exception in MySql.Data.MySqlClient.PreparedStatement:Execute (see dump below):

2005-01-03 17:08:09,715 [3456    ] INFO  NHibernate.Loader.Loader       - select project0_.ID as ID, project0_.Name as Name from Project project0_ where ( ID = 1  )
2005-01-03 17:08:09,715 [3456    ] INFO  NHibernate.Impl.BatcherImpl    - Preparing select project0_.ID as ID, project0_.Name as Name from Project project0_ where ( ID = 1  )
2005-01-03 17:08:09,825 [3456    ] ERROR NHibernate.ADOException        - Could not execute query
Exception: System.ArgumentException
Message: index
Parameter name: index is greater than array.Length
in <0x000f4> System.Collections.BitArray:CopyTo (System.Array,int)
in <0x001a8> MySql.Data.MySqlClient.PreparedStatement:Execute (MySql.Data.MySqlClient.MySqlParameterCollection)
in <0x000ff> MySql.Data.MySqlClient.MySqlCommand:GetNextResultSet (MySql.Data.MySqlClient.MySqlDataReader)
in <0x00055> (wrapper remoting-invoke-with-check) MySql.Data.MySqlClient.MySqlCommand:GetNextResultSet (MySql.Data.MySqlClient.MySqlDataReader)
in <0x00079> MySql.Data.MySqlClient.MySqlDataReader:NextResult ()
in <0x00059> (wrapper remoting-invoke-with-check) MySql.Data.MySqlClient.MySqlDataReader:NextResult ()
in <0x000a5> MySql.Data.MySqlClient.MySqlCommand:ExecuteReader (System.Data.CommandBehavior)
in <0x0000d> MySql.Data.MySqlClient.MySqlCommand:ExecuteReader ()
in <0x0000b> MySql.Data.MySqlClient.MySqlCommand:System.Data.IDbCommand.ExecuteReader ()
in <0x00070> NHibernate.Impl.BatcherImpl:ExecuteReader (System.Data.IDbCommand)
in <0x00076> NHibernate.Loader.Loader:GetResultSet (System.Data.IDbCommand,NHibernate.Engine.RowSelection,NHibernate.Engine.ISessionImplementor)

How to repeat:
I'm not familiar enough with ADO.net to build a test case; I presume run an ADO query on Mono with the connector.

Suggested fix:
I am not familiar with the internals connector or ADO.net but it seems that the offending line of code is the last one of this block:

//TODO: support long data here
// create our null bitmap
BitArray nullMap = new BitArray( parameters.Count ); //metaData.Length );
for (int x=0; x < parameters.Count; x++)
{
	if (parameters[x].Value == DBNull.Value)
	nullMap[x] = true;
}
byte[] nullMapBytes = new byte[ (parameters.Count + 7)/8 ];
nullMap.CopyTo( nullMapBytes, 0 );

as a quick hack I included changed the call to CopyTo to:

if (nullMapBytes.Length > 0 && nullMap.Length > 0)
	nullMap.CopyTo( nullMapBytes, 0 );

this seemed to stop the error from occuring and the application behaves identically to when it runs on .NET 1.1 from then on.
[11 Oct 2005 7:51] Vasily Kishkin
Could you please provide full text of test case ? Thanks
[12 Nov 2005 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".