[Mono-list] DataBinding

Igor Nosyryev nosyryev@attbi.com
Fri, 2 May 2003 09:14:01 -0400


This is a multi-part message in MIME format.

------=_NextPart_000_0048_01C3108B.2BC05770
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi, Larry,

Go to the namespace Mono.Data.Tds.Protocol. Make changes to 2 classes:

1. Class TdsComm. Method GetString adds extra byte to a string at end. =
It suppose to be '\0', but '\0' is valid value in .NET string, so this =
byte must not be used.=20

Code before:

  public string GetString (int len, bool wide)
  {
   if (wide) {
    char[] chars =3D new char[len];
    for (int i =3D 0; i < len; ++i) {
     int lo =3D ((byte) GetByte ()) & 0xFF;
     int hi =3D ((byte) GetByte ()) & 0xFF;
     chars[i] =3D (char) (lo | ( hi << 8));
    }
    return new String (chars);
   }
   else {
    byte[] result =3D new byte[len + 1];
    Array.Copy (GetBytes (len, false), result, len);
    return (encoder.GetString (result));
   }
  }
=20
Fix:

  public string GetString (int len, bool wide)
  {
   if (wide) {
    char[] chars =3D new char[len];
    for (int i =3D 0; i < len; ++i) {
     int lo =3D ((byte) GetByte ()) & 0xFF;
     int hi =3D ((byte) GetByte ()) & 0xFF;
     chars[i] =3D (char) (lo | ( hi << 8));
    }
    return new String (chars);
   }
   else {
    byte[] result =3D new byte[len];
    Array.Copy (GetBytes (len, false), result, len);
    return (encoder.GetString (result));
   }
  }
=20
2. Class Tds. Method GetDecimalValue. Method reads extra byte if a =
DECIMAL field contains NULL. As a result server's response is parsed =
incorrectly and this method fires an exception.

Code before:

  private object GetDecimalValue (byte precision, byte scale)
  {
   int[] bits =3D new int[4] {0,0,0,0};

   int len =3D (comm.GetByte() & 0xff) - 1;
   bool positive =3D (comm.GetByte () =3D=3D 1);

   if (len < 0)
    return null;
   if (len > 16)
    throw new OverflowException ();

   for (int i =3D 0, index =3D 0; i < len && i < 16; i +=3D 4, index =
+=3D 1)=20
    bits[index] =3D comm.GetTdsInt ();

   if (bits [3] !=3D 0)=20
    return new TdsBigDecimal (precision, scale, !positive, bits);
   else
    return new Decimal (bits[0], bits[1], bits[2], !positive, scale);
  }
=20
Fix:

  private object GetDecimalValue (byte precision, byte scale)
  {
   int[] bits =3D new int[4] {0,0,0,0};

   int len =3D (comm.GetByte() & 0xff) - 1;
   if (len < 0) return null;

   bool positive =3D (comm.GetByte () =3D=3D 1);

   if (len > 16)
    throw new OverflowException ();

   for (int i =3D 0, index =3D 0; i < len && i < 16; i +=3D 4, index =
+=3D 1)=20
    bits[index] =3D comm.GetTdsInt ();

   if (bits [3] !=3D 0)=20
    return new TdsBigDecimal (precision, scale, !positive, bits);
   else
    return new Decimal (bits[0], bits[1], bits[2], !positive, scale);
  }
=20
----------------------------------------
Igor Nosyryev
E-mail: nosyryev@attbi.com

  ----- Original Message -----=20
  From: Jones, Larry=20
  To: 'mono-list@lists.ximian.com'=20
  Sent: Friday, May 02, 2003 4:14 AM
  Subject: RE: [Mono-list] DataBinding


  Thanks Igor.  But how can I get the fixes?

  Larry Jones=20
  Hydrel/Lithonia Lighting=20

    -----Original Message-----
    From: Igor Nosyryev [mailto:nosyryev@attbi.com]
    Sent: Thursday, May 01, 2003 10:49 AM
    To: Jones, Larry
    Cc: mono-list
    Subject: Re: [Mono-list] DataBinding


    Mono's System.Data.SqlClient is based on the implementation of TDS =
protocol (namespace Mono.Data.Tds.Protocol). This implementation has =
serious bugs which could make effects like you described.=20
    On 4/21/2003 I posted fixes to 2 bugs (String and Decimal values) =
but they are not in CVS yet. You could try apply fixes and try again.

    Good luck!

    ----------------------------------------
    Igor Nosyryev
    E-mail: nosyryev@attbi.com

    ----- Original Message -----=20
    From: "Jones, Larry" <LJones@Lithonia.com>
    To: <mono-list@ximian.com>
    Sent: Wednesday, April 30, 2003 8:51 PM
    Subject: [Mono-list] DataBinding


    > I got a test MS Sql access going in an ASP.NET (.aspx) page by =
doing
    > response.writes.  But when I tried to DataBind it to a DataList or =
Datagrid,
    > it would fail or hang.  I could run the exact same program on a =
IIS 5.0
    > Server with the same Sql Data base accessed and it runs fine.  So =
something
    > is wrong with the .aspx DataBinding.
    >=20
    > Larry Jones
    > Hydrel/Lithonia Lighting
    > _______________________________________________
    > Mono-list maillist  -  Mono-list@lists.ximian.com
    > http://lists.ximian.com/mailman/listinfo/mono-list 
------=_NextPart_000_0048_01C3108B.2BC05770
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1170" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>
<DIV><FONT face=3DVerdana size=3D2>Hi, Larry,</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Go to the namespace =
Mono.Data.Tds.Protocol. Make=20
changes to 2 classes:</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>1. Class TdsComm. Method GetString =
adds extra=20
byte to a string at end. It suppose to be '\0', but '\0' is valid value =
in .NET=20
string, so this byte must not be used. </FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Code before:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><FONT face=3D"Courier New">&nbsp;&nbsp;public string =
GetString=20
(int len, bool wide)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if (wide)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;char[] chars =3D new=20
char[len];<BR>&nbsp;&nbsp;&nbsp;&nbsp;for (int i =3D 0; i &lt; len; ++i) =

{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int lo =3D ((byte) GetByte ()) &amp;=20
0xFF;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int hi =3D ((byte) GetByte ()) =
&amp;=20
0xFF;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chars[i] =3D (char) (lo | ( hi =
&lt;&lt;=20
8));<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return new =
String=20
(chars);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;else=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;byte[] result =3D new byte[len +=20
1];<BR>&nbsp;&nbsp;&nbsp;&nbsp;Array.Copy (GetBytes (len, false), =
result,=20
len);<BR>&nbsp;&nbsp;&nbsp;&nbsp;return (encoder.GetString=20
(result));<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR></FONT>&nbsp;</FONT=
></DIV>
<DIV><FONT face=3DVerdana size=3D2>Fix:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><FONT face=3D"Courier New">&nbsp;&nbsp;public string =
GetString=20
(int len, bool wide)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;if (wide)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;char[] chars =3D new=20
char[len];<BR>&nbsp;&nbsp;&nbsp;&nbsp;for (int i =3D 0; i &lt; len; ++i) =

{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int lo =3D ((byte) GetByte ()) &amp;=20
0xFF;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int hi =3D ((byte) GetByte ()) =
&amp;=20
0xFF;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;chars[i] =3D (char) (lo | ( hi =
&lt;&lt;=20
8));<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;&nbsp;return new =
String=20
(chars);<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;&nbsp;else=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;byte[] result =3D <FONT color=3D#ff0000>new =

byte[len]</FONT>;<BR>&nbsp;&nbsp;&nbsp;&nbsp;Array.Copy (GetBytes (len, =
false),=20
result, len);<BR>&nbsp;&nbsp;&nbsp;&nbsp;return (encoder.GetString=20
(result));<BR>&nbsp;&nbsp;&nbsp;}<BR>&nbsp;&nbsp;}<BR></FONT>&nbsp;</FONT=
></DIV>
<DIV><FONT face=3DVerdana size=3D2>2. Class Tds. Method GetDecimalValue. =
Method=20
reads extra byte if a DECIMAL field contains NULL. As a result server's =
response=20
is parsed incorrectly and this method fires an exception.</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DVerdana size=3D2>Code before:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;private object =
GetDecimalValue=20
(byte precision, byte scale)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;int[] =
bits =3D=20
new int[4] {0,0,0,0};</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp;int len =3D =
(comm.GetByte()=20
&amp; 0xff) - 1;<BR>&nbsp;&nbsp;&nbsp;bool positive =3D (comm.GetByte () =
=3D=3D=20
1);</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp;if (len &lt;=20
0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;return null;<BR>&nbsp;&nbsp;&nbsp;if (len =
&gt;=20
16)<BR>&nbsp;&nbsp;&nbsp;&nbsp;throw new OverflowException =
();</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp;for (int i =
=3D 0, index =3D=20
0; i &lt; len &amp;&amp; i &lt; 16; i +=3D 4, index +=3D 1)=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;bits[index] =3D comm.GetTdsInt =
();</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><FONT face=3D"Courier New">&nbsp;&nbsp;&nbsp;if =
(bits [3] !=3D 0)=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;return new TdsBigDecimal (precision, scale,=20
!positive, =
bits);<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;return=20
new Decimal (bits[0], bits[1], bits[2], !positive,=20
scale);<BR>&nbsp;&nbsp;}<BR></FONT>&nbsp;</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>Fix:</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;private object =
GetDecimalValue=20
(byte precision, byte scale)<BR>&nbsp;&nbsp;{<BR>&nbsp;&nbsp;&nbsp;int[] =
bits =3D=20
new int[4] {0,0,0,0};</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp;int len =3D =
(comm.GetByte()=20
&amp; 0xff) - 1;<BR><FONT color=3D#ff0000>&nbsp;&nbsp;&nbsp;if (len &lt; =
0) return=20
null;</FONT></FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2><BR>&nbsp;&nbsp;&nbsp;bool =
positive =3D=20
(comm.GetByte () =3D=3D 1);</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp;if (len &gt;=20
16)<BR>&nbsp;&nbsp;&nbsp;&nbsp;throw new OverflowException =
();</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp;for (int i =
=3D 0, index =3D=20
0; i &lt; len &amp;&amp; i &lt; 16; i +=3D 4, index +=3D 1)=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;bits[index] =3D comm.GetTdsInt =
();</FONT></DIV>
<DIV><FONT face=3D"Courier New"></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2><FONT face=3D"Courier New">&nbsp;&nbsp;&nbsp;if =
(bits [3] !=3D 0)=20
<BR>&nbsp;&nbsp;&nbsp;&nbsp;return new TdsBigDecimal (precision, scale,=20
!positive, =
bits);<BR>&nbsp;&nbsp;&nbsp;else<BR>&nbsp;&nbsp;&nbsp;&nbsp;return=20
new Decimal (bits[0], bits[1], bits[2], !positive,=20
scale);<BR>&nbsp;&nbsp;}<BR></FONT>&nbsp;</FONT></DIV>
<DIV><FONT face=3DVerdana=20
size=3D2>----------------------------------------</FONT></DIV>
<DIV><FONT face=3DVerdana size=3D2>Igor Nosyryev</FONT></DIV>
<DIV><FONT size=3D2><FONT face=3DVerdana>E-mail: </FONT><A=20
href=3D"mailto:nosyryev@attbi.com"><FONT=20
face=3DVerdana>nosyryev@attbi.com</FONT></A></FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV></FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV style=3D"FONT: 10pt arial">----- Original Message ----- </DIV>
  <DIV=20
  style=3D"BACKGROUND: #e4e4e4; FONT: 10pt arial; font-color: =
black"><B>From:</B>=20
  <A title=3DLJones@Lithonia.com =
href=3D"mailto:LJones@Lithonia.com">Jones,=20
  Larry</A> </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>To:</B> <A =
title=3Dmono-list@lists.ximian.com=20
  =
href=3D"mailto:'mono-list@lists.ximian.com'">'mono-list@lists.ximian.com'=
</A>=20
  </DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Sent:</B> Friday, May 02, 2003 4:14 =
AM</DIV>
  <DIV style=3D"FONT: 10pt arial"><B>Subject:</B> RE: [Mono-list]=20
DataBinding</DIV>
  <DIV><FONT size=3D2></FONT><FONT size=3D2></FONT><BR></DIV>
  <DIV><SPAN class=3D914284323-01052003><FONT face=3DArial =
color=3D#0000ff=20
  size=3D2>Thanks Igor.&nbsp; But how can I get the =
fixes?</FONT></SPAN></DIV>
  <DIV>&nbsp;</DIV>
  <P><I><FONT face=3DArial size=3D2>Larry Jones</FONT></I> <BR><I><FONT =
face=3DArial=20
  size=3D2>Hydrel/Lithonia Lighting</FONT></I> </P>
  <BLOCKQUOTE>
    <DIV class=3DOutlookMessageHeader dir=3Dltr align=3Dleft><FONT =
face=3DTahoma=20
    size=3D2>-----Original Message-----<BR><B>From:</B> Igor Nosyryev=20
    [mailto:nosyryev@attbi.com]<BR><B>Sent:</B> Thursday, May 01, 2003 =
10:49=20
    AM<BR><B>To:</B> Jones, Larry<BR><B>Cc:</B> =
mono-list<BR><B>Subject:</B> Re:=20
    [Mono-list] DataBinding<BR><BR></FONT></DIV>
    <DIV><FONT face=3DVerdana size=3D2>Mono's System.Data.SqlClient is =
based on the=20
    implementation of TDS protocol (namespace Mono.Data.Tds.Protocol). =
This=20
    implementation has serious bugs which could make effects like you =
described.=20
    </FONT></DIV>
    <DIV><FONT face=3DVerdana size=3D2>On 4/21/2003 I posted fixes to 2 =
bugs (String=20
    and Decimal values) but they are not in CVS yet. You could try apply =
fixes=20
    and try again.</FONT></DIV>
    <DIV><FONT face=3DVerdana size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT face=3DVerdana size=3D2>Good luck!</FONT></DIV>
    <DIV>&nbsp;</DIV>
    <DIV>
    <DIV><FONT face=3DVerdana=20
    size=3D2>----------------------------------------</FONT></DIV>
    <DIV><FONT size=3D2>Igor Nosyryev</FONT></DIV>
    <DIV><FONT size=3D2>E-mail: </FONT><A =
href=3D"mailto:nosyryev@attbi.com"><FONT=20
    size=3D2>nosyryev@attbi.com</FONT></A></DIV></DIV>
    <DIV><FONT size=3D2></FONT>&nbsp;</DIV>
    <DIV><FONT size=3D2>----- Original Message ----- </FONT>
    <DIV><FONT size=3D2>From: "Jones, Larry" &lt;</FONT><A=20
    href=3D"mailto:LJones@Lithonia.com"><FONT=20
    size=3D2>LJones@Lithonia.com</FONT></A><FONT =
size=3D2>&gt;</FONT></DIV>
    <DIV><FONT size=3D2>To: &lt;</FONT><A =
href=3D"mailto:mono-list@ximian.com"><FONT=20
    size=3D2>mono-list@ximian.com</FONT></A><FONT =
size=3D2>&gt;</FONT></DIV>
    <DIV><FONT size=3D2>Sent: Wednesday, April 30, 2003 8:51 =
PM</FONT></DIV>
    <DIV><FONT size=3D2>Subject: [Mono-list] =
DataBinding</FONT></DIV></DIV>
    <DIV><FONT size=3D2><BR></FONT></DIV><FONT size=3D2>&gt; I got a =
test MS Sql=20
    access going in an ASP.NET (.aspx) page by doing<BR>&gt;=20
    response.writes.&nbsp; But when I tried to DataBind it to a DataList =
or=20
    Datagrid,<BR>&gt; it would fail or hang.&nbsp; I could run the exact =
same=20
    program on a IIS 5.0<BR>&gt; Server with the same Sql Data base =
accessed and=20
    it runs fine.&nbsp; So something<BR>&gt; is wrong with the .aspx=20
    DataBinding.<BR>&gt; <BR>&gt; Larry Jones<BR>&gt; Hydrel/Lithonia=20
    Lighting<BR>&gt; =
_______________________________________________<BR>&gt;=20
    Mono-list maillist&nbsp; -&nbsp; </FONT><A=20
    href=3D"mailto:Mono-list@lists.ximian.com"><FONT=20
    size=3D2>Mono-list@lists.ximian.com</FONT></A><BR><FONT =
size=3D2>&gt; </FONT><A=20
    href=3D"http://lists.ximian.com/mailman/listinfo/mono-list"><FONT=20
    =
size=3D2>http://lists.ximian.com/mailman/listinfo/mono-list</FONT></A>=20
  </BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0048_01C3108B.2BC05770--