[Mono-bugs] [Bug 62935][Cri] New - System.Data.Odbc.OdbcParameter:setBuffer () causes System.Text.ASCIIEncoding:GetBytes (string, int, int, byte[], int) to throw Arg_InsufficientSpace

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 12 Aug 2004 11:42:33 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by paulsdsrubbish@hotmail.com.

http://bugzilla.ximian.com/show_bug.cgi?id=62935

--- shadow/62935	2004-08-12 11:42:32.000000000 -0400
+++ shadow/62935.tmp.12392	2004-08-12 11:42:33.000000000 -0400
@@ -0,0 +1,170 @@
+Bug#: 62935
+Product: Mono: Class Libraries
+Version: unspecified
+OS: All
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Critical
+Component: CORLIB
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: paulsdsrubbish@hotmail.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: System.Data.Odbc.OdbcParameter:setBuffer () causes System.Text.ASCIIEncoding:GetBytes (string, int, int, byte[], int) to throw Arg_InsufficientSpace
+
+Description of Problem:
+
+System.Data.Odbc.OdbcParameter:setBuffer () causes
+System.Text.ASCIIEncoding:GetBytes (string, int, int, byte[], int) to throw
+Arg_InsufficientSpace
+
+
+
+Steps to reproduce the problem:
+1. Run an ODBC stored procedure.  My case that's postgres
+2. Actual code:
+
+public int CreateDocumentCollection(System.Data.IDbConnection dbCon, string
+docCollectionExternalId, object docCollectionParentId, string
+docCollectionComment)
+		{
+			int retValue = 0;
+
+			try
+			{
+				//Create command from connection
+				IDbCommand cmd = dbCon.CreateCommand();
+
+				//Command text - will actually be DB 
+				cmd.CommandType = CommandType.StoredProcedure;
+				cmd.CommandText = "select public.create_documentcollection(?, ?, ?);";
+
+				//Create parameters
+				OdbcParameter param = new OdbcParameter("", OdbcType.VarChar, 255);
+				param.Value = DbUtilities.PrepareString(docCollectionExternalId);
+				cmd.Parameters.Add(param);
+
+				param = new OdbcParameter("", OdbcType.Int);
+				param.Value = DbUtilities.PrepareInt(docCollectionParentId);
+				cmd.Parameters.Add(param);
+
+				param = new OdbcParameter("", OdbcType.NText);
+				param.Value = DbUtilities.PrepareString(docCollectionComment);
+				cmd.Parameters.Add(param);
+
+
+				// Execute command
+				retValue = (int)cmd.ExecuteScalar();
+			}
+			catch (SystemException ex)
+			{
+				throw new XmlDbException("CreateDocumentCollection failed while
+attempting to execute command on database." + ex.Message, ex);
+			}
+
+			return retValue;
+		}
+
+[Postgresql procedure]
+CREATE OR REPLACE FUNCTION public.create_documentcollection( 
+documentcollection.doccollectionexternalid%TYPE , 
+documentcollection.doccollectionparentid%TYPE , 
+documentcollection.doccollectioncomment%TYPE)
+RETURNS int4 AS
+'DECLARE
+	arg_doccollectionexternalid ALIAS FOR $1;
+	arg_doccollectionparentid ALIAS FOR $2;
+	arg_doccollectioncomment ALIAS FOR $3;
+
+	uniqueId	documentcollection.doccollectionid%TYPE;
+BEGIN
+	-- First select the id to see if the value already exists.  
+	-- If it does then just return that id, otherwise add it.
+
+	SELECT INTO uniqueId doccollectionid from documentcollection WHERE
+doccollectionexternalid = arg_doccollectionexternalid ;
+
+	IF NOT FOUND THEN
+	BEGIN
+		uniqueId := get_next_documentcollectionid();
+		INSERT INTO documentcollection
+		(
+			doccollectionid , doccollectionexternalid , doccollectionparentid ,
+doccollectioncomment
+		)
+		VALUES
+		(
+			uniqueId , 
+			arg_doccollectionexternalid ,
+			arg_doccollectionparentid ,
+			arg_doccollectioncomment
+		);
+	END;
+	ELSE
+		RETURN uniqueId;
+	END IF;
+
+	RETURN uniqueId;	
+END;
+'LANGUAGE 'plpgsql' VOLATILE;
+
+3. 
+
+Actual Results:
+Inner exception:
+Arg_InsufficientSpace
+in <0x0017b> System.Text.ASCIIEncoding:GetBytes (string,int,int,byte[],int)
+in <0x0016e> System.Data.Odbc.OdbcParameter:setBuffer ()
+in <0x0004c> (wrapper remoting-invoke-with-check)
+System.Data.Odbc.OdbcParameter:setBuffer ()
+in <0x0002b> System.Data.Odbc.OdbcParameter:Bind (intptr,int)
+in <0x00062> (wrapper remoting-invoke-with-check)
+System.Data.Odbc.OdbcParameter:Bind (intptr,int)
+in <0x00281> System.Data.Odbc.OdbcCommand:Prepare ()
+in <0x0004c> (wrapper remoting-invoke-with-check)
+System.Data.Odbc.OdbcCommand:Prepare ()
+in <0x00037> System.Data.Odbc.OdbcCommand:ExecSQL (string)
+in <0x00053> (wrapper remoting-invoke-with-check)
+System.Data.Odbc.OdbcCommand:ExecSQL (string)
+in <0x0009f> System.Data.Odbc.OdbcCommand:ExecuteNonQuery (bool)
+in <0x00057> (wrapper remoting-invoke-with-check)
+System.Data.Odbc.OdbcCommand:ExecuteNonQuery (bool)
+in <0x00015> System.Data.Odbc.OdbcCommand:ExecuteReader
+(System.Data.CommandBehavior)
+in <0x00051> (wrapper remoting-invoke-with-check)
+System.Data.Odbc.OdbcCommand:ExecuteReader (System.Data.CommandBehavior)
+in <0x00016> System.Data.Odbc.OdbcCommand:ExecuteReader ()
+in <0x0004d> (wrapper remoting-invoke-with-check)
+System.Data.Odbc.OdbcCommand:ExecuteReader ()
+in <0x0002d> System.Data.Odbc.OdbcCommand:ExecuteScalar ()
+in <0x001db>
+uk.co.ds.xmldb.odbc.OdbcPgsqlXmlDbIndexerCreation:CreateDocumentCollection
+(System.Data.IDbConnection,string,object,string)
+
+
+Expected Results:
+Same code works flawlessly under the Microsoft .Net Runtime.
+
+
+How often does this happen? 
+Everytime
+
+
+Additional Information:
+
+I believe it has something to do with OdbcParameter.cs, specifically the
+setBuffer() function.  It uses a magic number (20) as part of it's buffer
+array creation stategy, and a class member "size".  It does not seem to use
+the actual created string (paramValueString) in actually creating the
+byte[] buffer size.
+
+Also it assumes that one character==one byte by passing across
+paramValueString.Length to System.Text.Encoding.ASCII.GetBytes - although
+as it is ascii perhaps that's a valid assumption?
+
+I'm an experienced programmer but new to the mono and linux platforms and
+their tools - otherwise I would probably be able to help more!