Problem with .NET connector 5.0
Posted by:
Alex
Date: August 29, 2006 07:16AM
Hi,
I don'really know what's going on here. Maybe someone cane help me out?
I get System.ArgumentOutOfRangeException when trying to run this code. After the code I will go more in to details what I've found out so far.
///C#
MySqlParameter[] parameters = {
new MySqlParameter("aImageName", MySqlDbType.VarChar),
new MySqlParameter("aHeading", MySqlDbType.VarChar)
};
parameters[0].Value = imgName;
parameters[1].Value = heading;
MySqlCommand command = new MySqlCommand("sp_CreateContent", Connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.AddRange(parameters);
command.CommandType = CommandType.StoredProcedure;
returnReader = command.ExecuteReader();
//
The StoredProcedure looks like this:
DELIMITER $$
DROP PROCEDURE IF EXISTS `database`.`sp_CreateContent` $$
CREATE PROCEDURE `sp_CreateContent`(
aImageName varchar(255), aHeading varchar(255))
BEGIN
INSERT INTO content (ImageName, Heading)
VALUES (aImageName, aHeading);
END $$
DELIMITER ;
/////
This is what happens inside MySql.Data.dll.
MySqlDataReader ExecuteReader(CommandBehavior behavior) calls statement.Execute(Parameters);
in Execute it calls BindParameters();
There it calls DataSet ds = connection.ProcedureCache.GetProcedure(connection, spName), everything seems okey so far. the connection object is there and so the correct spName.
Now we are going in in some code i don't follow quit well.
public DataSet GetProcedure(MySqlConnection conn, string spName)
{
int hash = spName.GetHashCode();
DataSet ds = (DataSet)procHash[hash];
if (ds == null)
{
ds = AddNew(conn, spName);
hash gets a value of -244690031
procHash has it'max size set to 25
ds== null
so AddNew is called with the MySqlConnection object and the correct spName.
private DataSet AddNew(MySqlConnection connection, string spName)
{
DataSet procData = GetProcData(connection, spName);
No strange things here right..
In GetProcData some properties will be set:
string[] restrictions = new string[4];
restrictions[1] = schema;
restrictions[2] = name;
so 0 and 3 will be null.
Then:
ISSchemaProvider isp = new ISSchemaProvider(connection);
DataTable parametersTable = isp.GetProcedureParameters(
restrictions, procTable);
GetProcedureParameters calls GetParametersFromShowCreate(dt, restrictions, routines);
the showCreateSql prop is set to "SHOW CREATE PROCEDURE database.sp_CreateContent"
ParseProcedureBody(parametersTable, reader.GetString(2), routine, nameToRestrict); is called, first we go in to reader.GetString(2).
There we call IMySqlValue val = GetFieldValue(index);
In GetFieldValue(index) we return values[index].
values has 3 MySqlString items.
values[0] contains the name of the storedProcedure
values[1] contains an empty string "".
values[2] contains a string "\0\0\0\0\0..." of length 255.
values[2] is returned to GetString and is also return to ParseProcedureBody(parametersTable, reader.GetString(2), routine, nameToRestrict); as a string.
So now we go into ParseProcedureBody function in ISSchemaProvider.
There we create a ConextString with first parameter quotePattern = "``" and !noBackslash (true)
then we do: int leftParen = cs.IndexOf(body, '('); where cs is ConextString and body is the same as values[2] (\0\0\0\0...) so leftParen will be set to -1.
then we do: body = body.Substring(leftParen + 1);
so body will be unchanged.
then: int rightParen = FindRightParen(body, quotePattern);
then: string parms = body.Substring(0, rightParen).Trim();
still no change to the string.
then:
quotePattern += "()";
cs.ContextMarkers = quotePattern;
string[] paramDefs = cs.Split(parms, ",");
now we have a string array with one item, {"\0\0\0\0\..."}
then:
ArrayList parmArray = new ArrayList(paramDefs);
body = body.Substring(rightParen + 1).Trim().ToLower(CultureInfo.InvariantCulture);
and BAM!
now... we try to substring a 255 lenth string with rightParen set to 255+1... and what happens...
An exception of type 'System.ArgumentOutOfRangeException' occurred
Additional information: startIndex cannot be larger than length of string.
--------
Can anyone please see what I'm doing wrong here?
Why is value[2] set to "\0\0\0\0\0" ?
Edited 1 time(s). Last edit at 08/29/2006 11:03AM by Alex .